void Commander::computeActionsBase() { checkBuildplan(); //Dont call too often int cFrame = Broodwar->getFrameCount(); if (cFrame - lastCallFrame < 10) { return; } lastCallFrame = cFrame; //Check if we shall launch an attack if (currentState == DEFEND) { if (shallEngage()) { forceAttack(); } } //Check if we shall go back to defend if (currentState == ATTACK) { bool activeFound = false; for (int i = 0; i < (int)squads.size(); i++) { if (squads.at(i)->isRequired() && squads.at(i)->isActive()) { activeFound = true; } } //No active required squads found. //Go back to defend. if (!activeFound) { currentState = DEFEND; TilePosition defSpot = findChokePoint(); for (int i = 0; i < (int)squads.size(); i++) { squads.at(i)->setGoal(defSpot); } } } if (currentState == DEFEND) { //Check if we need to attack/kite enemy workers in the base checkWorkersAttack(AgentManager::getInstance()->getClosestBase(Broodwar->self()->getStartLocation())); TilePosition defSpot = findChokePoint(); for (int i = 0; i < (int)squads.size(); i++) { if (!squads.at(i)->hasGoal()) { if (defSpot.x() != -1) { squads.at(i)->defend(defSpot); } } } } if (currentState == ATTACK) { for (int i = 0; i < (int)squads.size(); i++) { if (squads.at(i)->isOffensive()) { if (!squads.at(i)->hasGoal()) { TilePosition closeEnemy = getClosestEnemyBuilding(TilePosition(squads.at(i)->getCenter())); if (closeEnemy.x() >= 0) { squads.at(i)->attack(closeEnemy); } } } else { TilePosition defSpot = findChokePoint(); if (defSpot.x() != -1) { squads.at(i)->defend(defSpot); } } } } //Check if there are obstacles we can remove. Needed for some //strange maps. if (Broodwar->getFrameCount() % 150 == 0) { checkRemovableObstacles(); } //Compute Squad actions. int st = (int)GetTickCount(); int et = 0; int elapsed = 0; for(int i = 0; i < (int)squads.size(); i++) { et = (int)GetTickCount(); elapsed = et - st; if (elapsed >= 30) { return; } squads.at(i)->computeActions(); } //Check if any own buildings is under attack, if so try to assist them vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents(); for (int i = 0; i < (int)agents.size(); i++) { BaseAgent* agent = agents.at(i); if (!agent->getUnit()->isLoaded()) { if (agent->isAlive() && agent->isBuilding() && agent->isUnderAttack()) { assistBuilding(agent); } if (agent->isAlive() && agent->isWorker() && agent->isUnderAttack()) { assistWorker(agent); } } } //Attack if we have filled all supply spots if (currentState == DEFEND) { int supplyUsed = Broodwar->self()->supplyUsed() / 2; if (supplyUsed >= 198) { forceAttack(); } } //Terran only: Check for repairs and finish unfinished buildings if (Constructor::isTerran()) { //Check if there are unfinished buildings we need //to complete. checkUnfinishedBuildings(); } //Check for units not belonging to a squad checkNoSquadUnits(); }
void Commander::computeActionsBase() { checkBuildplan(); //Dont call too often int cFrame = Broodwar->getFrameCount(); if (cFrame - lastCallFrame < 5) { return; } lastCallFrame = cFrame; //See if we need to assist a base or worker that is under attack if (assistBuilding()) return; if (assistWorker()) return; //Check if we shall launch an attack if (currentState == DEFEND) { if (shallEngage()) { forceAttack(); } } //Check if we shall go back to defend if (currentState == ATTACK) { bool activeFound = false; for (Squad* s : squads) { if (s->isRequired() && s->isActive()) { activeFound = true; } } //No active required squads found. //Go back to defend. if (!activeFound) { currentState = DEFEND; TilePosition defSpot = findChokePoint(); for (Squad* s : squads) { s->setGoal(defSpot); } } } if (currentState == DEFEND) { //Check if we need to attack/kite enemy workers in the base checkWorkersAttack(AgentManager::getInstance()->getClosestBase(Broodwar->self()->getStartLocation())); TilePosition defSpot = findChokePoint(); for (Squad* s : squads) { if (!s->hasGoal()) { if (defSpot.x != -1) { s->defend(defSpot); } } } } if (currentState == ATTACK) { for (Squad* s : squads) { if (s->isOffensive()) { if (!s->hasGoal() && s->isActive()) { TilePosition toAttack = findAttackPosition(); if (toAttack.x >= 0) { s->attack(toAttack); } } } else { TilePosition defSpot = findChokePoint(); if (defSpot.x != -1) { s->defend(defSpot); } } } } //Compute Squad actions. for(auto &sq : squads) { sq->computeActions(); } //Attack if we have filled all supply spots if (currentState == DEFEND) { int supplyUsed = Broodwar->self()->supplyUsed() / 2; if (supplyUsed >= 198) { forceAttack(); } } //Check if there are obstacles we can remove. Needed for some maps. checkRemovableObstacles(); //Terran only: Check for repairs and finish unfinished buildings if (Constructor::isTerran()) { //Check if there are unfinished buildings we need //to complete. checkDamagedBuildings(); } //Check for units not belonging to a squad checkNoSquadUnits(); }