BWAPI
|
#include <Base.h>
BaseClass::BaseClass | ( | Region | region, |
std::set< TilePosition > | tiles, | ||
bool | startLocation | ||
) |
Definition at line 11 of file Base.cpp.
: mCenterTilePosition(BWAPI::TilePositions::None) , mCenterPosition(region->getCenter()) , mMinedOut(true) , mRegion(region) , mIsStartLocation(startLocation) , mPlayer(NULL) , mBuildings() , mTiles(tiles) , mIsUnderAttack(false) , mIsContested(false) , mTechBuildings(0) { }
BaseClass::BaseClass | ( | TilePosition | position, |
const UnitGroup & | resources, | ||
Region | region, | ||
std::set< TilePosition > | tiles, | ||
bool | startLocation | ||
) |
Definition at line 26 of file Base.cpp.
References UnitGroup::insert(), mGeysers, mMinerals, and BWAPI::UnitTypes::Resource_Mineral_Field.
: mCenterTilePosition(position) , mCenterPosition(Position(position.x()*32+64, position.y()*32+48)) , mMinedOut(false) , mRegion(region) , mIsStartLocation(startLocation) , mPlayer(NULL) , mBuildings() , mTiles(tiles) , mIsUnderAttack(false) , mIsContested(false) , mTechBuildings(0) { for each(Unit resource in resources) { if(resource->getType() == BWAPI::UnitTypes::Resource_Mineral_Field) mMinerals.insert(resource); else mGeysers.insert(resource); } }
void BaseClass::addUnit | ( | Unit | unit | ) | [private] |
Definition at line 390 of file Base.cpp.
References BWAPI::Broodwar, depotCompare(), UnitGroup::insert(), BWAPI::UnitType::isBuilding(), BWAPI::UnitType::isRefinery(), BWAPI::UnitType::isResourceDepot(), UnitHelper::isStaticDefense(), mBuildings, mGeysers, mPlayerBuildingNumbers, mRefineries, mResourceDepots, mTechBuildings, mTiles, BWAPI::Game::neutral(), BWAPI::UnitTypes::Resource_Vespene_Geyser, BWAPI::UnitType::supplyProvided(), and updatePlayer().
Referenced by onDiscover(), onMorphRenegade(), and update().
{ if(mTiles.count(unit->getTilePosition()) == 0) return; const BWAPI::UnitType &type = unit->getType(); if(type == BWAPI::UnitTypes::Resource_Vespene_Geyser) mGeysers.insert(unit); if(type.isBuilding() && unit->getPlayer() != BWAPI::Broodwar->neutral() && !unit->isLifted()) { mBuildings.insert(unit); ++mPlayerBuildingNumbers[unit->getPlayer()]; if(type.isResourceDepot()) { mResourceDepots.push_front(unit); if(mResourceDepots.size() > 1) std::sort(mResourceDepots.begin(), mResourceDepots.end(), boost::bind<bool>(&BaseClass::depotCompare, this, _1, _2)); } if(!type.isResourceDepot() && type.supplyProvided() == 0 && !UnitHelper::isStaticDefense(type) && !type.isRefinery()) ++mTechBuildings; updatePlayer(); } if(type.isRefinery()) mRefineries.insert(unit); }
bool BaseClass::depotCompare | ( | const Unit & | depotOne, |
const Unit & | depotTwo | ||
) |
Definition at line 195 of file Base.cpp.
References mCenterPosition.
Referenced by addUnit().
{ int thisDistance = depotOne->getPosition().getApproxDistance(mCenterPosition); int currentDistance = depotTwo->getPosition().getApproxDistance(mCenterPosition); return thisDistance < currentDistance; }
void BaseClass::drawDebugInfo | ( | ) | const |
Definition at line 219 of file Base.cpp.
References BWAPI::Colors::Blue, BWAPI::Broodwar, BWAPI::Game::drawCircle(), BWAPI::Game::drawCircleMap(), BWAPI::Game::drawLine(), BWAPI::Game::drawLineMap(), BWAPI::Game::drawTextMap(), UnitGroup::empty(), BWAPI::Player::getColor(), BWAPI::Player::getName(), BWAPI::Colors::Green, isAllyBase(), isEnemyBase(), isMyBase(), mActive, mActiveInFuture, mAllThreats, BWAPI::CoordinateType::Map, mBuildings, mCenterPosition, mGeysers, mIsContested, mIsStartLocation, mIsUnderAttack, mMinedOut, mMinerals, mPlayer, mRefineries, mTechBuildings, BWAPI::Game::neutral(), BWAPI::Colors::Orange, BWAPI::Colors::Red, UnitGroup::size(), BWAPI::Position::x(), and BWAPI::Position::y().
{ if(mPlayer != NULL) BWAPI::Broodwar->drawCircle(BWAPI::CoordinateType::Map, mCenterPosition.x(), mCenterPosition.y(), 78, mPlayer->getColor(), false); else BWAPI::Broodwar->drawCircle(BWAPI::CoordinateType::Map, mCenterPosition.x(), mCenterPosition.y(), 78, BWAPI::Broodwar->neutral()->getColor(), false); bool showtitle = false; int ypos = 30; if(mIsStartLocation) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Start Location"); ypos -= 10; showtitle = true; } if(!mBuildings.empty()) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Buildings: %u", mBuildings.size()); ypos -= 10; showtitle = true; } if(mTechBuildings > 0) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Number of Tech Buildings: %d", mTechBuildings); ypos -= 10; showtitle = true; } if(mPlayer != NULL) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Owner: %s", mPlayer->getName().c_str()); ypos -= 10; showtitle = true; } if(isEnemyBase()) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Is Enemy"); ypos -= 10; showtitle = true; } if(isAllyBase()) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Is Ally"); ypos -= 10; showtitle = true; } if(isMyBase()) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Is Mine"); ypos -= 10; showtitle = true; } if(mIsContested) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Base is Contested"); ypos -= 10; showtitle = true; } if(mIsUnderAttack) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Base is Under Attack"); ypos -= 10; showtitle = true; } if(mActive) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Base is Active"); ypos -= 10; showtitle = true; } else if(mActiveInFuture) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Base is Active In Future"); ypos -= 10; showtitle = true; } if(mMinedOut) { BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - ypos, "Base is mined out"); ypos -= 10; showtitle = true; } if(showtitle) BWAPI::Broodwar->drawTextMap(mCenterPosition.x() + 60, mCenterPosition.y() - 40, "Base Info:"); for each(Unit unit in mAllThreats) { BWAPI::Broodwar->drawLineMap(unit->getPosition().x(), unit->getPosition().y(), mCenterPosition.x(), mCenterPosition.y(), BWAPI::Colors::Red); } for each(Unit building in mBuildings) { BWAPI::Broodwar->drawLine(BWAPI::CoordinateType::Map, building->getPosition().x(), building->getPosition().y(), mCenterPosition.x(), mCenterPosition.y(), building->getPlayer()->getColor()); } for each(Unit mineral in mMinerals) { BWAPI::Broodwar->drawCircleMap(mineral->getPosition().x(), mineral->getPosition().y(), 32, BWAPI::Colors::Blue); BWAPI::Broodwar->drawLineMap(mineral->getPosition().x(), mineral->getPosition().y(), mCenterPosition.x(), mCenterPosition.y(), BWAPI::Colors::Blue); } for each(Unit geyser in mGeysers) { BWAPI::Broodwar->drawCircleMap(geyser->getPosition().x(), geyser->getPosition().y(), 32, BWAPI::Colors::Green); BWAPI::Broodwar->drawLineMap(geyser->getPosition().x(), geyser->getPosition().y(), mCenterPosition.x(), mCenterPosition.y(), BWAPI::Colors::Green); } for each(Unit geyser in mRefineries) { BWAPI::Broodwar->drawCircleMap(geyser->getPosition().x(), geyser->getPosition().y(), 32, BWAPI::Colors::Orange); BWAPI::Broodwar->drawLineMap(geyser->getPosition().x(), geyser->getPosition().y(), mCenterPosition.x(), mCenterPosition.y(), BWAPI::Colors::Green); } }
unsigned int BaseClass::getActivateTime | ( | ) | const [inline] |
const UnitGroup& BaseClass::getBuildings | ( | ) | const [inline] |
TilePosition BaseClass::getCenterBuildLocation | ( | ) | const [inline] |
Definition at line 30 of file Base.h.
References mCenterTilePosition.
{ return mCenterTilePosition; }
Position BaseClass::getCenterLocation | ( | ) | const [inline] |
Definition at line 341 of file Base.cpp.
References BWAPI::Broodwar, and mBuildings.
{ int minDist = std::numeric_limits<int>::max(); Unit bestBuilding; for each(Unit unit in mBuildings) { if(!BWAPI::Broodwar->self()->isEnemy(unit->getPlayer())) continue; int thisDist = pos.getApproxDistance(unit->getPosition()); if(thisDist < minDist) { minDist = thisDist; bestBuilding = unit; } } return bestBuilding; }
const UnitGroup BaseClass::getDefenders | ( | ) | const [inline] |
const UnitGroup& BaseClass::getEnemyThreats | ( | ) | const [inline] |
const UnitGroup& BaseClass::getGeysers | ( | ) | const [inline] |
const UnitGroup& BaseClass::getMinerals | ( | ) | const [inline] |
unsigned int BaseClass::getNumberOfTechBuildings | ( | ) | const [inline] |
Player BaseClass::getPlayer | ( | ) | const [inline] |
Definition at line 49 of file Base.h.
References mPlayer.
Referenced by updatePlayer().
{ return mPlayer; }
const UnitGroup& BaseClass::getRefineries | ( | ) | const [inline] |
Region BaseClass::getRegion | ( | ) | const [inline] |
Unit BaseClass::getResourceDepot | ( | ) | const [inline] |
Definition at line 37 of file Base.h.
References mResourceDepots, and StaticUnits::nullunit.
{ return mResourceDepots.empty() ? StaticUnits::nullunit : mResourceDepots[0]; }
const std::set<TilePosition>& BaseClass::getTiles | ( | ) | const [inline] |
bool BaseClass::isActive | ( | bool | activeInFuture = false | ) | const [inline] |
Definition at line 38 of file Base.h.
References mActive, and mActiveInFuture.
{ return (mActive || (activeInFuture && mActiveInFuture)); }
bool BaseClass::isAllyBase | ( | ) | const [inline] |
Definition at line 63 of file Base.h.
References BWAPI::Broodwar, BWAPI::Player::isAlly(), mPlayer, and BWAPI::Game::self().
Referenced by drawDebugInfo().
{ return BWAPI::Broodwar->self()->isAlly(mPlayer); }
bool BaseClass::isContested | ( | ) | const [inline] |
bool BaseClass::isEnemyBase | ( | ) | const [inline] |
Definition at line 61 of file Base.h.
References BWAPI::Broodwar, BWAPI::Player::isEnemy(), mPlayer, and BWAPI::Game::self().
Referenced by drawDebugInfo().
{ return BWAPI::Broodwar->self()->isEnemy(mPlayer); }
bool BaseClass::isMinedOut | ( | ) | const [inline] |
bool BaseClass::isMyBase | ( | ) | const [inline] |
Definition at line 62 of file Base.h.
References BWAPI::Broodwar, mPlayer, and BWAPI::Game::self().
Referenced by drawDebugInfo().
{ return mPlayer == BWAPI::Broodwar->self(); }
bool BaseClass::isStartLocation | ( | ) | const [inline] |
bool BaseClass::isUnderAttack | ( | ) | const [inline] |
void BaseClass::onDestroy | ( | Unit | unit | ) |
Definition at line 214 of file Base.cpp.
References removeUnit().
{ removeUnit(unit, unit->getPlayer(), unit->getType()); }
void BaseClass::onDiscover | ( | Unit | unit | ) |
void BaseClass::onMorphRenegade | ( | Unit | unit, |
Player | previousPlayer, | ||
BWAPI::UnitType | previousType | ||
) |
Definition at line 208 of file Base.cpp.
References addUnit(), BWAPI::UnitTypes::None, and removeUnit().
{ removeUnit(unit, previousPlayer != NULL ? previousPlayer : unit->getPlayer(), previousType != BWAPI::UnitTypes::None ? previousType : unit->getType()); addUnit(unit); }
void BaseClass::removeUnit | ( | Unit | unit, |
Player | playerToRemove, | ||
BWAPI::UnitType | typeToRemove | ||
) | [private] |
Definition at line 422 of file Base.cpp.
References UnitGroup::end(), UnitGroup::erase(), UnitGroup::find(), BWAPI::UnitType::isRefinery(), BWAPI::UnitType::isResourceDepot(), UnitHelper::isStaticDefense(), mBuildings, mGeysers, mMinerals, mPlayerBuildingNumbers, mRefineries, mResourceDepots, mTechBuildings, BWAPI::UnitType::supplyProvided(), and updatePlayer().
Referenced by onDestroy(), onMorphRenegade(), and update().
{ mRefineries.erase(unit); mGeysers.erase(unit); mMinerals.erase(unit); std::set<Unit>::iterator it = mBuildings.find(unit); if(it != mBuildings.end()) { mBuildings.erase(it); --mPlayerBuildingNumbers[playerToRemove]; if(mPlayerBuildingNumbers[playerToRemove] == 0) mPlayerBuildingNumbers.erase(playerToRemove); mResourceDepots.erase(std::remove(mResourceDepots.begin(), mResourceDepots.end(), unit), mResourceDepots.end()); if(!typeToRemove.isResourceDepot() && typeToRemove.supplyProvided() == 0 && !UnitHelper::isStaticDefense(typeToRemove) && !typeToRemove.isRefinery()) --mTechBuildings; updatePlayer(); } }
void BaseClass::update | ( | ) |
Definition at line 48 of file Base.cpp.
References addUnit(), UnitGroup::begin(), BWAPI::Broodwar, UnitGroup::clear(), UnitGroup::empty(), UnitGroup::end(), UnitGroup::insert(), Singleton< T >::Instance(), UnitHelper::isArmyUnit(), BWAPI::UnitType::isWorker(), AccessTypeDef::Lost, mActivateTime, mActive, mActiveInFuture, mAllDefenders, mAllThreats, mBuildings, mGeysers, mIsUnderAttack, mLiftedBuildings, mMinedOut, mMinerals, mPlayer, mRefineries, mResourceDepots, mThreatTypes, mTiles, UnitGroup::ratingDifference(), removeUnit(), and UnitGroup::size().
{ if(!mMinedOut) { bool noGas = true; for each(Unit geyser in mGeysers) { if(geyser->getResources() > 0) noGas = false; } for each(Unit geyser in mRefineries) { if(geyser->getResources() > 0) noGas = false; } if(mMinerals.empty() && noGas) mMinedOut = true; } for(UnitGroup::iterator it = mBuildings.begin(); it != mBuildings.end();) { if((*it)->isLifted() || (*it)->accessibility() == AccessType::Lost) { Unit unit = *it; ++it; removeUnit(unit, unit->getPlayer(), unit->getType()); } else ++it; } // TODO: Move this to the base manager and make a generic add building and remove building for each(Unit unit in mLiftedBuildings) { if(!unit->isLifted() && unit->exists()) addUnit(unit); } mLiftedBuildings.clear(); for each(Unit unit in UnitTracker::Instance().getAllUnits()) { if(unit->getType().isBuilding() && unit->isLifted()) mLiftedBuildings.insert(unit); } mAllThreats.clear(); mThreatTypes.clear(); mAllDefenders.clear(); int workerCount = 0; if(mPlayer && mPlayer != BWAPI::Broodwar->neutral()) { for each(Unit defender in UnitTracker::Instance().selectAllUnits(mPlayer)) { if(!defender->isCompleted()) continue; const BWAPI::UnitType &type = defender->getType(); if(!UnitHelper::isArmyUnit(type) && !type.isWorker()) continue; if(mTiles.count(defender->getTilePosition()) == 0) continue; if(type.isWorker()) { if(workerCount > 14)//Only count 14 as thats the only amount it will pull from the mineral line continue; else ++workerCount; } mAllDefenders.insert(defender); } for each(Unit enemy in UnitTracker::Instance().selectAllEnemy(mPlayer)) { if(enemy->getType().isBuilding() && !enemy->isLifted()) continue; if(enemy->accessibility() == AccessType::Lost) continue; if(mTiles.count(enemy->getTilePosition()) != 0) { mAllThreats.insert(enemy); mThreatTypes[UnitThreatType::Scout].insert(enemy); } if(enemy->getType().isWorker()) continue; const int maxRange = std::max(48, 24 + std::max(enemy->getGroundWeaponMaxRange(), enemy->getAirWeaponMaxRange())); for each(Unit building in mBuildings) { if(enemy->getDistance(building) <= maxRange) { mAllThreats.insert(enemy); if(enemy->getType().isFlyer() || enemy->isLifted()) { if(enemy->canAttackGround()) mThreatTypes[UnitThreatType::AirToGround].insert(enemy); if(enemy->canAttackAir()) mThreatTypes[UnitThreatType::AirToAir].insert(enemy); } else { if(enemy->canAttackGround()) mThreatTypes[UnitThreatType::GroundToGround].insert(enemy); if(enemy->canAttackAir()) mThreatTypes[UnitThreatType::GroundToAir].insert(enemy); } break; } } } } mActive = false; mActiveInFuture = false; mActivateTime = std::numeric_limits<int>::max(); mIsUnderAttack = !mThreatTypes[UnitThreatType::AirToGround].empty() || !mThreatTypes[UnitThreatType::GroundToGround].empty(); if(!mResourceDepots.empty()) { if(!mMinedOut) { if(!mIsUnderAttack && mResourceDepots[0]->isCompleted()) { mActive = true; mActiveInFuture = true; mActivateTime = 0; } else if(!mIsUnderAttack || (mAllDefenders.size() > 6 && mAllDefenders.ratingDifference(mThreatTypes[UnitThreatType::AirToGround] + mThreatTypes[UnitThreatType::GroundToGround]) >= 150)) { mActiveInFuture = true; mActivateTime = mResourceDepots[0]->getCompletedTime(); } } } //drawDebugInfo(); }
void BaseClass::updatePlayer | ( | ) | [private] |
Definition at line 362 of file Base.cpp.
References getPlayer(), mIsContested, mPlayer, mPlayerBuildingNumbers, and mResourceDepots.
Referenced by addUnit(), and removeUnit().
{ mIsContested = false; if(mPlayerBuildingNumbers.empty()) mPlayer = NULL; else if(mPlayerBuildingNumbers.size() == 1) mPlayer = mPlayerBuildingNumbers.begin()->first; else { mIsContested = true; if(!mResourceDepots.empty()) mPlayer = mResourceDepots[0]->getPlayer(); else { mPlayer = NULL; int number = 0; for each(std::pair<Player, int> pair in mPlayerBuildingNumbers) { if(pair.second > number) { mPlayer = pair.first; number = pair.second; } } } } }
unsigned int BaseClass::mActivateTime [private] |
Definition at line 84 of file Base.h.
Referenced by getActivateTime(), and update().
bool BaseClass::mActive [private] |
Definition at line 82 of file Base.h.
Referenced by drawDebugInfo(), isActive(), and update().
bool BaseClass::mActiveInFuture [private] |
Definition at line 83 of file Base.h.
Referenced by drawDebugInfo(), isActive(), and update().
UnitGroup BaseClass::mAllDefenders [private] |
Definition at line 106 of file Base.h.
Referenced by getDefenders(), and update().
UnitGroup BaseClass::mAllThreats [private] |
Definition at line 103 of file Base.h.
Referenced by drawDebugInfo(), getEnemyThreats(), and update().
UnitGroup BaseClass::mBuildings [private] |
Definition at line 95 of file Base.h.
Referenced by addUnit(), drawDebugInfo(), getBuildings(), getClosestEnemyBuilding(), removeUnit(), and update().
Position BaseClass::mCenterPosition [private] |
Definition at line 75 of file Base.h.
Referenced by depotCompare(), drawDebugInfo(), and getCenterLocation().
TilePosition BaseClass::mCenterTilePosition [private] |
Definition at line 76 of file Base.h.
Referenced by getCenterBuildLocation().
UnitGroup BaseClass::mGeysers [private] |
Definition at line 79 of file Base.h.
Referenced by addUnit(), BaseClass(), drawDebugInfo(), getGeysers(), removeUnit(), and update().
bool BaseClass::mIsContested [private] |
Definition at line 88 of file Base.h.
Referenced by drawDebugInfo(), isContested(), and updatePlayer().
bool BaseClass::mIsStartLocation [private] |
Definition at line 91 of file Base.h.
Referenced by drawDebugInfo(), and isStartLocation().
bool BaseClass::mIsUnderAttack [private] |
Definition at line 87 of file Base.h.
Referenced by drawDebugInfo(), isUnderAttack(), and update().
UnitGroup BaseClass::mLiftedBuildings [private] |
bool BaseClass::mMinedOut [private] |
Definition at line 86 of file Base.h.
Referenced by drawDebugInfo(), isMinedOut(), and update().
UnitGroup BaseClass::mMinerals [private] |
Definition at line 78 of file Base.h.
Referenced by BaseClass(), drawDebugInfo(), getMinerals(), removeUnit(), and update().
Player BaseClass::mPlayer [private] |
Definition at line 93 of file Base.h.
Referenced by drawDebugInfo(), getPlayer(), isAllyBase(), isEnemyBase(), isMyBase(), update(), and updatePlayer().
std::map<Player, int> BaseClass::mPlayerBuildingNumbers [private] |
Definition at line 102 of file Base.h.
Referenced by addUnit(), removeUnit(), and updatePlayer().
UnitGroup BaseClass::mRefineries [private] |
Definition at line 80 of file Base.h.
Referenced by addUnit(), drawDebugInfo(), getRefineries(), removeUnit(), and update().
WeakRegion BaseClass::mRegion [private] |
Definition at line 99 of file Base.h.
Referenced by getRegion().
std::deque<Unit> BaseClass::mResourceDepots [private] |
Definition at line 97 of file Base.h.
Referenced by addUnit(), getResourceDepot(), removeUnit(), update(), and updatePlayer().
unsigned int BaseClass::mTechBuildings [private] |
Definition at line 89 of file Base.h.
Referenced by addUnit(), drawDebugInfo(), getNumberOfTechBuildings(), and removeUnit().
std::map<UnitThreatType, UnitGroup> BaseClass::mThreatTypes [private] |
std::set<TilePosition> BaseClass::mTiles [private] |
Definition at line 100 of file Base.h.
Referenced by addUnit(), getTiles(), and update().