bool Constructor::executeOrder(UnitType type) { //Max 5 concurrent buildings allowed at the same time if ((int)buildQueue.size() >= 5) { return false; } //Check if we meet requirements for the building map<UnitType,int> reqs = type.requiredUnits(); for(map<UnitType,int>::iterator j=reqs.begin(); j!=reqs.end(); j++) { if (!AgentManager::getInstance()->hasBuilding((*j).first)) { return false; } } if (type.isResourceDepot()) { TilePosition pos = BuildingPlacer::getInstance()->findExpansionSite(); if (pos.x == -1) { //No expansion site found. if ((int)buildPlan.size() > 0) buildPlan.erase(buildPlan.begin()); return true; } } if (type.isRefinery()) { TilePosition rSpot = BuildingPlacer::getInstance()->searchRefinerySpot(); if (rSpot.x < 0) { //No buildspot found if ((int)buildPlan.size() > 0) buildPlan.erase(buildPlan.begin()); return true; } } if (isZerg()) { pair<UnitType, int> builder = type.whatBuilds(); if (builder.first.getID() != UnitTypes::Zerg_Drone.getID()) { //Needs to be morphed if (executeMorph(builder.first, type)) { return true; } else { return false; } } } //Check if we have resources if (!ResourceManager::getInstance()->hasResources(type)) { return false; } bool found = false; Agentset agents = AgentManager::getInstance()->getAgents(); for (auto &a : agents) { if (a->isFreeWorker()) { if (a->canBuild(type)) { found = true; if (a->assignToBuild(type)) { lock(0, a->getUnitID()); return true; } else { //Unable to find a buildspot. Dont bother checking for all //other workers handleNoBuildspotFound(type); return false; } } } } return false; }
bool BuildPlanner::executeOrder(UnitType type) { //Max 3 concurrent buildings allowed at the same time if ((int)buildQueue.size() >= 3) { return false; } ////Hold if we are to build a new base //if ((int)buildQueue.size() > 0) //{ // if (buildQueue.at(0).toBuild.isResourceDepot()) // { // return false; // } // vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents(); // for (int i = 0; i < (int)agents.size(); i++) // { // if (agents.at(i)->getUnitType().isResourceDepot() && agents.at(i)->getUnit()->isBeingConstructed()) // { // return false; // TODO: Check if necessary // } // } //} if (type.isResourceDepot()) { TilePosition pos = CoverMap::getInstance()->findExpansionSite(); if (pos.x() == -1) { Broodwar->printf("Removing expand as no expansion site could be found"); //No expansion site found. if ((int)buildOrder.size() > 0) buildOrder.erase(buildOrder.begin()); return true; } } if (type.isRefinery()) { TilePosition rSpot = CoverMap::getInstance()->searchRefinerySpot(); if (rSpot.x() < 0) { //No buildspot found if ((int)buildOrder.size() > 0) buildOrder.erase(buildOrder.begin()); return true; } } if (isZerg()) { pair<UnitType, int> builder = type.whatBuilds(); if (builder.first.getID() != UnitTypes::Zerg_Drone) { //Needs to be morphed return executeMorph(builder.first, type); } } //Check if we have resources if (!ResourceManager::getInstance()->hasResources(type)) { return false; } // TODO: Check if we can improve finding the best worker vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents(); for (int i = 0; i < (int)agents.size(); i++) { BaseAgent* agent = agents.at(i); if (agent != NULL && agent->isAlive()) { if (agent->canBuild(type)) { if (agent->assignToBuild(type)) { lock(0, agent->getUnitID()); return true; } else { //Unable to find a buildspot. Dont bother checking for all //other workers handleNoBuildspotFound(type); Broodwar->printf("No build spot found for %s", type.getName().c_str()); return false; } } } } return false; }