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()); } }