// UnitType constructor ActionTypeData::ActionTypeData(BWAPI::UnitType t, const ActionID id) : type (UnitType) , unit (t) , raceID (GetRaceID(t.getRace())) , actionID (id) , mineralPriceVal (t.mineralPrice() * Constants::RESOURCE_SCALE) , gasPriceVal (t.gasPrice() * Constants::RESOURCE_SCALE) , supplyRequiredVal (t.supplyRequired()) , supplyProvidedVal (t.supplyProvided()) , buildTimeVal (t.buildTime()) , numberProduced (1) , name (t.getName()) , metaName (t.getName()) , building (t.isBuilding()) , worker (t.isWorker()) , refinery (t.isRefinery()) , resourceDepot (t.isResourceDepot()) , supplyProvider (t.supplyProvided() > 0 && !t.isResourceDepot()) , canProduceBool (t.isBuilding() && t.canProduce()) , canAttackBool (t.canAttack()) , whatBuildsUnitType (t.whatBuilds().first) , addon (t.isAddon()) , morphed (false) , reqAddon (false) , reqAddonID (0) { if (t == BWAPI::UnitTypes::Zerg_Zergling || t == BWAPI::UnitTypes::Zerg_Scourge) { numberProduced = 2; } if (t == BWAPI::UnitTypes::Zerg_Lair || t == BWAPI::UnitTypes::Zerg_Hive || t == BWAPI::UnitTypes::Zerg_Greater_Spire || t == BWAPI::UnitTypes::Zerg_Lurker || t == BWAPI::UnitTypes::Zerg_Guardian || t == BWAPI::UnitTypes::Zerg_Sunken_Colony || t == BWAPI::UnitTypes::Zerg_Spore_Colony) { morphed = true; } setShortName(); }
bool BuildingPlacer::tileOverlapsBaseLocation(BWAPI::TilePosition tile, BWAPI::UnitType type) const { // if it's a resource depot we don't care if it overlaps if (type.isResourceDepot()) { return false; } // dimensions of the proposed location int tx1 = tile.x; int ty1 = tile.y; int tx2 = tx1 + type.tileWidth(); int ty2 = ty1 + type.tileHeight(); // for each base location for (BWTA::BaseLocation * base : BWTA::getBaseLocations()) { // dimensions of the base location int bx1 = base->getTilePosition().x; int by1 = base->getTilePosition().y; int bx2 = bx1 + BWAPI::Broodwar->self()->getRace().getCenter().tileWidth(); int by2 = by1 + BWAPI::Broodwar->self()->getRace().getCenter().tileHeight(); // conditions for non-overlap are easy bool noOverlap = (tx2 < bx1) || (tx1 > bx2) || (ty2 < by1) || (ty1 > by2); // if the reverse is true, return true if (!noOverlap) { return true; } } // otherwise there is no overlap return false; }
void InformationManager::updateBaseLocationInfo() { _occupiedRegions[_self].clear(); _occupiedRegions[_enemy].clear(); // if we haven't found the enemy main base location yet if (!_mainBaseLocations[_enemy]) { // how many start locations have we explored int exploredStartLocations = 0; bool baseFound = false; // an undexplored base location holder BWTA::BaseLocation * unexplored = nullptr; for (BWTA::BaseLocation * startLocation : BWTA::getStartLocations()) { if (isEnemyBuildingInRegion(BWTA::getRegion(startLocation->getTilePosition()))) { if (Config::Debug::DrawScoutInfo) { BWAPI::Broodwar->printf("Enemy base found by seeing it"); } baseFound = true; _mainBaseLocations[_enemy] = startLocation; updateOccupiedRegions(BWTA::getRegion(startLocation->getTilePosition()), BWAPI::Broodwar->enemy()); } // if it's explored, increment if (BWAPI::Broodwar->isExplored(startLocation->getTilePosition())) { exploredStartLocations++; // otherwise set the unexplored base } else { unexplored = startLocation; } } // if we've explored every start location except one, it's the enemy if (!baseFound && exploredStartLocations == ((int)BWTA::getStartLocations().size() - 1)) { if (Config::Debug::DrawScoutInfo) { BWAPI::Broodwar->printf("Enemy base found by process of elimination"); } _mainBaseLocations[_enemy] = unexplored; updateOccupiedRegions(BWTA::getRegion(unexplored->getTilePosition()), BWAPI::Broodwar->enemy()); } // otherwise we do know it, so push it back } else { updateOccupiedRegions(BWTA::getRegion(_mainBaseLocations[_enemy]->getTilePosition()), BWAPI::Broodwar->enemy()); } // for each enemy unit we know about size_t enemyBaseCount = 0; size_t enemySunkenCount = 0; for (const auto & kv : _unitData[_enemy].getUnits()) { const UnitInfo & ui(kv.second); BWAPI::UnitType type = ui.type; // if the unit is a building if (type.isBuilding()) { // update the enemy occupied regions updateOccupiedRegions(BWTA::getRegion(BWAPI::TilePosition(ui.lastPosition)), BWAPI::Broodwar->enemy()); } if (type.isResourceDepot()) { ++enemyBaseCount; } if (type == BWAPI::UnitTypes::Zerg_Sunken_Colony){ ++enemySunkenCount; } } if (_mainBaseLocations[_enemy]){ if (BWAPI::Broodwar->isExplored(_mainBaseLocations[_enemy]->getTilePosition()) && !_scoutTimer) _scoutTimer = BWAPI::Broodwar->getFrameCount() + 100; } if (enemyBaseCount > 1 && BWAPI::Broodwar->getFrameCount() < _scoutTimer){ _enemyExpand = true; } if (enemySunkenCount > 1){ Config::Micro::UseSparcraftSimulation = true; } // for each of our units for (const auto & kv : _unitData[_self].getUnits()) { const UnitInfo & ui(kv.second); BWAPI::UnitType type = ui.type; // if the unit is a building if (type.isBuilding()) { // update the enemy occupied regions updateOccupiedRegions(BWTA::getRegion(BWAPI::TilePosition(ui.lastPosition)), BWAPI::Broodwar->self()); } } }
// returns an ActionSet of prerequisites for a given action ActionSet calculatePrerequisites(StarcraftAction & action) { ActionSet pre; if (DEBUG_StarcraftData) { printf("DEBUG: Hello\n"); printf("DEBUG: %d \t%s \t%s\n", getAction(action), action.getName().c_str(), actions[getAction(action)].getName().c_str()); } // if it's a UnitType if (action.getType() == StarcraftAction::UnitType) { std::map<BWAPI::UnitType, int> requiredUnits = action.getUnitType().requiredUnits(); BWAPI::UnitType actionType = action.getUnitType(); // if it's a protoss building that isn't a Nexus or Assimilator, we need a pylon (indirectly) if (actionType.getRace() == BWAPI::Races::Protoss && actionType.isBuilding() && !actionType.isResourceDepot() && !(actionType == BWAPI::UnitTypes::Protoss_Pylon) && !(actionType == BWAPI::UnitTypes::Protoss_Assimilator)) { pre.add(getAction(BWAPI::UnitTypes::Protoss_Pylon)); } // for each of the required UnitTypes for (std::map<BWAPI::UnitType, int>::iterator unitIt = requiredUnits.begin(); unitIt != requiredUnits.end(); unitIt++) { if (DEBUG_StarcraftData) printf("\tPRE: %s\n", unitIt->first.getName().c_str()); BWAPI::UnitType type = unitIt->first; // add the action to the ActionSet if it is not a larva if (type != BWAPI::UnitTypes::Zerg_Larva) { //printf("\t\tAdding %s\n", type.getName().c_str()); pre.add(getAction(type)); } } // if there is a TechType required if (action.getUnitType().requiredTech() != BWAPI::TechTypes::None) { if (DEBUG_StarcraftData) printf("\tPRE: %s\n", action.getUnitType().requiredTech().getName().c_str()); // add it to the ActionSet pre.add(getAction(action.getUnitType().requiredTech())); } } // if it's a TechType if (action.getType() == StarcraftAction::TechType) { if (action.getTechType().whatResearches() != BWAPI::UnitTypes::None) { if (DEBUG_StarcraftData) printf("\tPRE: %s\n", action.getTechType().whatResearches().getName().c_str()); // add what researches it pre.add(getAction(action.getTechType().whatResearches())); } } // if it's an UpgradeType if (action.getType() == StarcraftAction::UpgradeType) { if (action.getUpgradeType().whatUpgrades() != BWAPI::UnitTypes::None) { if (DEBUG_StarcraftData) printf("\tPRE: %s\n", action.getUpgradeType().whatUpgrades().getName().c_str()); // add what upgrades it pre.add(getAction(action.getUpgradeType().whatUpgrades())); } } //printf("Finish Prerequisites\n"); return pre; }