void WorkerData::drawDepotDebugInfo() { for (BWAPI::UnitInterface* depot : depots) { int x = depot->getPosition().x - 64; int y = depot->getPosition().y - 32; if (Config::Debug::DrawWorkerInfo) BWAPI::Broodwar->drawBoxMap(x-2, y-1, x+75, y+14, BWAPI::Colors::Black, true); if (Config::Debug::DrawWorkerInfo) BWAPI::Broodwar->drawTextMap(x, y, "\x04 Workers: %d", getNumAssignedWorkers(depot)); std::vector<BWAPI::UnitInterface*> minerals = getMineralPatchesNearDepot(depot); for (size_t m(0); m<minerals.size(); ++m) { BWAPI::UnitInterface* mineral = minerals[m]; int x = mineral->getPosition().x; int y = mineral->getPosition().y; if (workersOnMineralPatch.find(mineral) != workersOnMineralPatch.end()) { //if (Config::Debug::DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawBoxMap(x-2, y-1, x+75, y+14, BWAPI::Colors::Black, true); //if (Config::Debug::DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawTextMap(x, y, "\x04 Workers: %d", workersOnMineralPatch[mineral]); } } } }
// selects which units will be scouting // currently only selects the worker scout after first pylon built // this does NOT take that worker away from worker manager, but it still works // TODO: take this worker away from worker manager in a clever way void GameCommander::setScoutUnits() { // if we have just built our first suply provider, set the worker to a scout if (numWorkerScouts == 0) { // get the first supply provider we come across in our units, this should be the first one we make BWAPI::UnitInterface* supplyProvider = getFirstSupplyProvider(); // if it exists if (supplyProvider) { // grab the closest worker to the supply provider to send to scout BWAPI::UnitInterface* workerScout = getClosestWorkerToTarget(supplyProvider->getPosition()); // if we find a worker (which we should) add it to the scout vector if (workerScout) { numWorkerScouts++; scoutUnits.insert(workerScout); assignedUnits.insert(workerScout); WorkerManager::Instance().setScoutWorker(workerScout); } } } }
void WorkerManager::drawResourceDebugInfo() { if (!Config::Debug::DrawResourceInfo) { return; } for (BWAPI::UnitInterface* worker : workerData.getWorkers()) { UAB_ASSERT(worker != NULL, "Worker was null"); char job = workerData.getJobCode(worker); BWAPI::Position pos = worker->getTargetPosition(); BWAPI::Broodwar->drawTextMap(worker->getPosition().x, worker->getPosition().y - 5, "\x07%c", job); BWAPI::Broodwar->drawLineMap(worker->getPosition().x, worker->getPosition().y, pos.x, pos.y, BWAPI::Colors::Cyan); BWAPI::UnitInterface* depot = workerData.getWorkerDepot(worker); if (depot) { BWAPI::Broodwar->drawLineMap(worker->getPosition().x, worker->getPosition().y, depot->getPosition().x, depot->getPosition().y, BWAPI::Colors::Orange); } } }
void GameCommander::setScoutUnits() { // if we haven't set our first worker scout, try and do it if (!workerScoutSet) { BWAPI::UnitInterface* supplyProvider = getFirstSupplyProvider(); // if it exists if (supplyProvider) { // grab the closest worker to the supply provider to send to scout BWAPI::UnitInterface* workerScout = getClosestWorkerToTarget(supplyProvider->getPosition()); // if we find a worker (which we should) add it to the scout vector if (workerScout) { workerScoutSet = true; scoutUnits.insert(workerScout); assignedUnits.insert(workerScout); WorkerManager::Instance().setScoutWorker(workerScout); } } } else { // we have previously set a worker scout, so go through our units to find him and if he exists put him in the scout squad BWAPI::UnitInterface * workerScout = WorkerManager::Instance().getWorkerScout(); if (workerScout) { scoutUnits.insert(workerScout); } } }
// calculates whether or not to regroup bool Squad::needsToRegroup() { if (!Config::Micro::UseSparcraftSimulation) { return false; } // if we are not attacking, never regroup if (units.empty() || (order.type != SquadOrder::Attack)) { regroupStatus = std::string("\x04 No combat units available"); return false; } BWAPI::UnitInterface* unitClosest = unitClosestToEnemy(); if (!unitClosest) { regroupStatus = std::string("\x04 No closest unit"); return false; } SparCraft::ScoreType score = 0; //do the SparCraft Simulation! CombatSimulation sim; sim.setCombatUnits(unitClosest->getPosition(), Config::Micro::CombatRegroupRadius + InformationManager::Instance().lastFrameRegroup * 300); score = sim.simulateCombat(); // if we are DT rushing and we haven't lost a DT yet, no retreat! if (Config::Strategy::StrategyName == "Protoss_DTRush" && (BWAPI::Broodwar->self()->deadUnitCount(BWAPI::UnitTypes::Protoss_Dark_Templar) == 0)) { regroupStatus = std::string("\x04 DARK TEMPLAR HOOOOO!"); return false; } bool retreat = score < 0; int switchTime = 100; bool waiting = false; // we should not attack unless 5 seconds have passed since a retreat if (retreat != lastRetreatSwitchVal) { if (!retreat && (BWAPI::Broodwar->getFrameCount() - lastRetreatSwitch < switchTime)) { waiting = true; retreat = lastRetreatSwitchVal; } else { waiting = false; lastRetreatSwitch = BWAPI::Broodwar->getFrameCount(); lastRetreatSwitchVal = retreat; } } if (retreat) { regroupStatus = std::string("\x04 Retreat - simulation predicts defeat"); } else { regroupStatus = std::string("\x04 Attack - simulation predicts success"); } return retreat; }