void Constructor::handleNoBuildspotFound(UnitType toBuild) { bool removeOrder = false; if (toBuild.getID() == UnitTypes::Protoss_Photon_Cannon) removeOrder = true; if (toBuild.getID() == UnitTypes::Terran_Missile_Turret) removeOrder = true; if (toBuild.isAddon()) removeOrder = true; if (toBuild.getID() == UnitTypes::Zerg_Spore_Colony) removeOrder = true; if (toBuild.getID() == UnitTypes::Zerg_Sunken_Colony) removeOrder = true; if (toBuild.isResourceDepot()) removeOrder = true; if (toBuild.isRefinery()) removeOrder = true; if (removeOrder) { remove(toBuild); } if (!removeOrder) { if (isProtoss() && !supplyBeingBuilt()) { //Insert a pylon to increase PSI coverage if (!nextIsOfType(UnitTypes::Protoss_Pylon)) { buildPlan.insert(buildPlan.begin(), UnitTypes::Protoss_Pylon); } } } }
void Constructor::computeActions() { //Check if we need more supply buildings if (isTerran() || isProtoss()) { if (shallBuildSupply()) { buildPlan.insert(buildPlan.begin(), Broodwar->self()->getRace().getSupplyProvider()); } } //Check if we need to expand if (!hasResourcesLeft()) { expand(Broodwar->self()->getRace().getCenter()); } if (buildPlan.size() == 0 && buildQueue.size() == 0) { //Nothing to do return; } //Dont call too often int cFrame = Broodwar->getFrameCount(); if (cFrame - lastCallFrame < 10) { return; } lastCallFrame = cFrame; if (AgentManager::getInstance()->getNoWorkers() == 0) { //No workers so cant do anything return; } //Check if we have possible "locked" items in the buildqueue for (int i = 0; i < (int)buildQueue.size(); i++) { int elapsed = cFrame - buildQueue.at(i).assignedFrame; if (elapsed >= 2000) { //Reset the build request WorkerAgent* worker = (WorkerAgent*)AgentManager::getInstance()->getAgent(buildQueue.at(i).assignedWorkerId); if (worker != NULL) { worker->reset(); } buildPlan.insert(buildPlan.begin(), buildQueue.at(i).toBuild); ResourceManager::getInstance()->unlockResources(buildQueue.at(i).toBuild); buildQueue.erase(buildQueue.begin() + i); return; } } //Check if we can build next building in the buildplan if ((int)buildPlan.size() > 0) { executeOrder(buildPlan.at(0)); } }
void BuildPlanner::computeActions() { //Dont call too often int cFrame = Broodwar->getFrameCount(); if (cFrame - lastCallFrame < 40) { return; } lastCallFrame = cFrame; if (AgentManager::getInstance()->getNoWorkers() == 0) { //No workers so cant do anything return; } //Check if we have possible "locked" items in the buildqueue for (int i = 0; i < (int)buildQueue.size(); i++) { int elapsed = cFrame - buildQueue.at(i).assignedFrame; if (elapsed >= 2000) { Broodwar->printf("Failed to build %s in time, resetting order", buildQueue.at(i).toBuild.getName().c_str()); //Reset the build request WorkerAgent* worker = (WorkerAgent*)AgentManager::getInstance()->getAgent(buildQueue.at(i).assignedWorkerId); if (worker != NULL) { worker->reset(); } addBuildingFirst(buildQueue.at(i).toBuild); ResourceManager::getInstance()->unlockResources(buildQueue.at(i).toBuild); buildQueue.erase(buildQueue.begin() + i); return; } } //Check if we need more supply buildings if (isTerran() || isProtoss()) { if (shallBuildSupply()) { addBuildingFirst(Broodwar->self()->getRace().getSupplyProvider()); } } //Check if we can build next building in the buildorder if ((int)buildOrder.size() > 0) { BuildPlan plan = buildOrder.at(0); if (plan.frameDelay <= Broodwar->getFrameCount()) { executeOrder(plan.type); } } if (!hasResourcesLeft() || ResourceManager::getInstance()->hasResources(2000, 0, false)) { expand(Broodwar->self()->getRace().getCenter()); } }
bool BuildPlanner::shallBuildSupply() { UnitType supply = Broodwar->self()->getRace().getSupplyProvider(); //1. If command center is next in queue, dont build pylon /*if (buildOrder.size() > 0) { if (buildOrder.at(0).isResourceDepot()) { return false; } }*/ //2. Check if any building is unpowered (Protoss only) if (isProtoss()) { if (buildOrder.size() > 0) { if (buildOrder.at(0).type.getID() != UnitTypes::Protoss_Pylon.getID()) { vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents(); for (int i = 0; i < (int)agents.size(); i++) { BaseAgent* agent = agents.at(i); if (agent->isAlive()) { Unit* cUnit = agent->getUnit(); if (cUnit->isUnpowered()) { return true; } } } } } } //3. Check if we need supplies int supplyTotal = Broodwar->self()->supplyTotal() / 2; int supplyUsed = Broodwar->self()->supplyUsed() / 2; if (supplyTotal - supplyUsed > 8) { return false; } if (supplyTotal >= 200) { //Reached max supply return false; } //4. Check if there is a supply already in the list if (nextIsOfType(supply)) { return false; } //5. Check if we are already building a supply if (supplyBeingBuilt()) { return false; } //Broodwar->printf("Supplies: %d/%d. Adding supply to buildorder", supplyUsed, supplyTotal); return true; }