BWAPI
|
#include <UnitGroup.h>
Public Types | |
typedef std::set< Unit >::iterator | iterator |
typedef std::set< Unit > ::const_iterator | const_iterator |
Public Member Functions | |
UnitGroup () | |
int | countCompletedBy (int time) const |
int | ratingDifference (const UnitGroup &other) const |
bool | isWorthEngaging (const UnitGroup &other) const |
Position | getCenter () const |
UnitGroup | getBestFittingToCircle (int circleSize, int inFramesTime=0) const |
Unit | getClosestUnit (Unit unit) const |
Unit | getClosestUnit (Position position) const |
bool | isAnyInRange (const UnitGroup &otherGroup) const |
int | minDistanceBetween (const UnitGroup &otherGroup) const |
int | getBuildScore () const |
int | getAverageTerrainHeight () const |
double | getAverageSpeed () const |
Region | getMajorityRegion () const |
bool | canAttackAir () const |
bool | canAttackGround () const |
bool | canMajorityAttack (const UnitGroup &other) const |
bool | hasDetection () const |
std::set< Unit >::size_type | getCloakedCount () const |
std::set< Unit >::size_type | getFlyingCount () const |
iterator | begin () |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
void | clear () |
std::set< Unit >::size_type | count (Unit const &unit) const |
bool | empty () const |
void | erase (iterator position) |
std::set< Unit >::size_type | erase (Unit const &unit) |
void | erase (iterator first, iterator last) |
iterator | find (Unit const &unit) |
std::set< Unit >::const_iterator | find (Unit const &unit) const |
std::pair< iterator, bool > | insert (Unit const &unit) |
iterator | insert (iterator position, Unit const &unit) |
void | insert (const_iterator first, const_iterator last) |
std::set< Unit >::size_type | size () const |
bool | operator== (const UnitGroup &other) const |
bool | operator!= (const UnitGroup &other) const |
operator std::set< Unit > () const | |
UnitGroup & | operator+= (const UnitGroup &other) |
UnitGroup | operator+ (const UnitGroup &other) const |
Private Attributes | |
std::set< Unit > | mUnits |
Definition at line 8 of file UnitGroup.h.
typedef std::set<Unit>::const_iterator UnitGroup::const_iterator |
Definition at line 46 of file UnitGroup.h.
typedef std::set<Unit>::iterator UnitGroup::iterator |
Definition at line 45 of file UnitGroup.h.
Definition at line 7 of file UnitGroup.cpp.
{ }
std::set< Unit >::iterator UnitGroup::begin | ( | ) |
Definition at line 24 of file UnitGroup.cpp.
References mUnits.
Referenced by TerrainAnaysisClass::createBases(), getCenter(), MineBlockingMineralTask::preUpdate(), UnitTrackerClass::update(), BaseClass::update(), and MineBlockingMineralTask::updateRequirements().
{ return mUnits.begin(); }
std::set< Unit >::const_iterator UnitGroup::begin | ( | ) | const |
bool UnitGroup::canAttackAir | ( | ) | const |
Definition at line 445 of file UnitGroup.cpp.
References mUnits.
Referenced by isWorthEngaging().
bool UnitGroup::canAttackGround | ( | ) | const |
Definition at line 456 of file UnitGroup.cpp.
References mUnits.
bool UnitGroup::canMajorityAttack | ( | const UnitGroup & | other | ) | const |
Definition at line 467 of file UnitGroup.cpp.
References empty(), mUnits, and size().
Referenced by DefaultSquadTask::update().
{ if(empty() || other.empty()) return false; double thisGroupAttackCount = 0.0; for each(Unit thisUnit in mUnits) { for each(Unit otherUnit in other) { if(thisUnit->canAttack(otherUnit)) ++thisGroupAttackCount; } } thisGroupAttackCount /= other.size(); thisGroupAttackCount /= size(); return thisGroupAttackCount > 0.5; }
void UnitGroup::clear | ( | ) |
Definition at line 44 of file UnitGroup.cpp.
References mUnits.
Referenced by BaseClass::update().
{ mUnits.clear(); }
std::set< Unit >::size_type UnitGroup::count | ( | Unit const & | unit | ) | const |
Definition at line 49 of file UnitGroup.cpp.
References mUnits.
Referenced by PylonPowerTrackerClass::onAddPylon(), PylonPowerTrackerClass::onRemovePylon(), AdvancedGroup::update(), ResourceManagerClass::update(), and DefaultSquadTask::updateRequirements().
{ return mUnits.count(unit); }
int UnitGroup::countCompletedBy | ( | int | time | ) | const |
Definition at line 11 of file UnitGroup.cpp.
References BWAPI::Broodwar, BWAPI::Game::getFrameCount(), and mUnits.
{ const int &timeNow = BWAPI::Broodwar->getFrameCount(); int total = 0; for each(Unit unit in mUnits) { if(unit->isCompleted() || unit->getCompletedTime() <= time) ++total; } return total; }
bool UnitGroup::empty | ( | ) | const |
Definition at line 54 of file UnitGroup.cpp.
References mUnits.
Referenced by canMajorityAttack(), BaseClass::drawDebugInfo(), getCenter(), GroupMicroActionBaseClass::hasEnded(), isWorthEngaging(), MineBlockingMineralTask::preUpdate(), ArbiterAction::update(), PsiStormAction::update(), AdvancedGroup::update(), PylonPowerTrackerClass::update(), DefenseSquadTask::update(), DefaultSquadTask::update(), BaseClass::update(), and MineBlockingMineralTask::updateRequirements().
{ return mUnits.empty(); }
std::set< Unit >::iterator UnitGroup::end | ( | ) |
Definition at line 34 of file UnitGroup.cpp.
References mUnits.
Referenced by TerrainAnaysisClass::createBases(), MineBlockingMineralTask::preUpdate(), BaseClass::removeUnit(), UnitTrackerClass::update(), and BaseClass::update().
{ return mUnits.end(); }
std::set< Unit >::const_iterator UnitGroup::end | ( | ) | const |
void UnitGroup::erase | ( | iterator | position | ) |
Referenced by UnitPredictorClass::deletePrediction(), UnitTrackerClass::onDestroy(), UnitTrackerClass::onMorphRenegade(), PylonPowerTrackerClass::onRemovePylon(), MineBlockingMineralTask::preUpdate(), DropAction::removeUnit(), GroupMicroActionBaseClass::removeUnit(), BaseClass::removeUnit(), AdvancedGroup::removeUnits(), DefenseSquadTask::returnUnit(), DefaultSquadTask::returnUnit(), and PsiStormAction::update().
std::set< Unit >::size_type UnitGroup::erase | ( | Unit const & | unit | ) |
void UnitGroup::erase | ( | iterator | first, |
iterator | last | ||
) |
std::set< Unit >::iterator UnitGroup::find | ( | Unit const & | unit | ) |
Definition at line 74 of file UnitGroup.cpp.
References mUnits.
Referenced by BaseClass::removeUnit().
{ return mUnits.find(unit); }
std::set< Unit >::const_iterator UnitGroup::find | ( | Unit const & | unit | ) | const |
double UnitGroup::getAverageSpeed | ( | ) | const |
Definition at line 376 of file UnitGroup.cpp.
References mUnits.
Referenced by isWorthEngaging().
{ double averageSpeed = 0; for each(Unit unit in mUnits) { averageSpeed += unit->getType().topSpeed(); } return averageSpeed / double(mUnits.size()); }
int UnitGroup::getAverageTerrainHeight | ( | ) | const |
Definition at line 365 of file UnitGroup.cpp.
References BWAPI::Broodwar, BWAPI::Game::getGroundHeight(), and mUnits.
{ int height = 0; for each(Unit unit in mUnits) { height += BWAPI::Broodwar->getGroundHeight(unit->getTilePosition()); } return height / mUnits.size(); }
UnitGroup UnitGroup::getBestFittingToCircle | ( | int | circleSize, |
int | inFramesTime = 0 |
||
) | const |
Definition at line 191 of file UnitGroup.cpp.
References getCenter(), and BWAPI::Position::getDistance().
Referenced by ArbiterAction::update(), and PsiStormAction::update().
{ UnitGroup circleUnits(*this); bool removed = false; do { removed = false; Position center = circleUnits.getCenter(); Unit furthestUnit; int furthestDistance = 0; for each(Unit unit in circleUnits) { int distanceToCenter; if(inFramesTime == 0) distanceToCenter = unit->getDistance(center); else distanceToCenter = unit->getDistance(center, inFramesTime); if(distanceToCenter > circleSize && distanceToCenter > furthestDistance) { furthestUnit = unit; furthestDistance = distanceToCenter; } } if(furthestUnit) { circleUnits.erase(furthestUnit); removed = true; } } while(removed); return circleUnits; }
int UnitGroup::getBuildScore | ( | ) | const |
Definition at line 302 of file UnitGroup.cpp.
References mUnits.
Position UnitGroup::getCenter | ( | ) | const |
Definition at line 153 of file UnitGroup.cpp.
References begin(), empty(), mUnits, BWAPI::BulletTypes::None, and size().
Referenced by TerrainAnaysisClass::createBases(), getBestFittingToCircle(), Goal::getPositionForMerge(), PsiStormAction::update(), and ArbiterAction::update().
{ if(empty()) return BWAPI::Positions::None; if(size() == 1) return (*begin())->getPosition(); Vector position; for each(Unit unit in mUnits) { position += Vector(unit->getPosition()); } return position / float(size()); }
std::set< Unit >::size_type UnitGroup::getCloakedCount | ( | ) | const |
Definition at line 421 of file UnitGroup.cpp.
References mUnits.
Referenced by isWorthEngaging().
{ std::set<Unit>::size_type cloakedCount = 0; for each(Unit unit in mUnits) { if(unit->getType().hasPermanentCloak() || unit->isCloaked()) ++cloakedCount; } return cloakedCount; }
Unit UnitGroup::getClosestUnit | ( | Unit | unit | ) | const |
Definition at line 229 of file UnitGroup.cpp.
References mUnits.
Referenced by GoalAction::update(), and AdvancedGroup::update().
{ Unit closestUnit; int closestDistance = std::numeric_limits<int>::max(); for each(Unit groupUnit in mUnits) { int thisDistance = unit->getDistance(groupUnit); if(thisDistance < closestDistance) { closestDistance = thisDistance; closestUnit = groupUnit; } } return closestUnit; }
Unit UnitGroup::getClosestUnit | ( | Position | position | ) | const |
Definition at line 247 of file UnitGroup.cpp.
References mUnits.
std::set< Unit >::size_type UnitGroup::getFlyingCount | ( | ) | const |
Definition at line 433 of file UnitGroup.cpp.
References mUnits.
Referenced by isWorthEngaging().
{ std::set<Unit>::size_type flyingCount = 0; for each(Unit unit in mUnits) { if(unit->getType().isFlyer() || unit->isLifted()) ++flyingCount; } return flyingCount; }
Region UnitGroup::getMajorityRegion | ( | ) | const |
Definition at line 387 of file UnitGroup.cpp.
References Singleton< T >::Instance(), and mUnits.
Referenced by isWorthEngaging().
{ int currentCount = 1; Region currentCandidate; for each(Unit unit in mUnits) { const Region &thisRegion = TerrainAnaysis::Instance().getRegion(unit->getPosition()); if(thisRegion == currentCandidate) ++currentCount; else --currentCount; if(currentCount == 0) { currentCandidate = thisRegion; currentCount = 1; } } return currentCandidate; }
bool UnitGroup::hasDetection | ( | ) | const |
Definition at line 410 of file UnitGroup.cpp.
References mUnits.
Referenced by isWorthEngaging().
std::pair< std::set< Unit >::iterator, bool > UnitGroup::insert | ( | Unit const & | unit | ) |
Definition at line 84 of file UnitGroup.cpp.
References mUnits.
Referenced by AdvancedGroup::addUnit(), DropAction::addUnit(), GroupMicroActionBaseClass::addUnit(), BaseClass::addUnit(), BaseClass::BaseClass(), UnitHelper::getClusters(), TechTask::getFinishedUnits(), TrainTask::getFinishedUnits(), UpgradeTask::getFinishedUnits(), MorphTask::getFinishedUnits(), GatherTask::getFinishedUnits(), ConstructionTask::getFinishedUnits(), MineBlockingMineralTask::getFinishedUnits(), WorkerScoutTask::getFinishedUnits(), ObserverScoutTask::getFinishedUnits(), RequirementGroup::getUnits(), DefenseSquadTask::giveUnit(), DefaultSquadTask::giveUnit(), GroupMicroActionBaseClass::GroupMicroActionBaseClass(), PylonPowerTrackerClass::onAddPylon(), UnitTrackerClass::onDiscover(), UnitTrackerClass::onMorphRenegade(), operator+=(), UnitPredictorClass::savePrediction(), DetectorAction::update(), ArbiterAction::update(), and BaseClass::update().
{ return mUnits.insert(unit); }
iterator UnitGroup::insert | ( | iterator | position, |
Unit const & | unit | ||
) |
void UnitGroup::insert | ( | const_iterator | first, |
const_iterator | last | ||
) |
bool UnitGroup::isAnyInRange | ( | const UnitGroup & | otherGroup | ) | const |
Definition at line 265 of file UnitGroup.cpp.
References mUnits.
Referenced by DefaultSquadTask::update().
{ for each(Unit groupUnit in mUnits) { for each(Unit otherGroupUnit in otherGroup) { if(groupUnit->isInRange(otherGroupUnit)) return true; } } return false; }
bool UnitGroup::isWorthEngaging | ( | const UnitGroup & | other | ) | const |
Definition at line 313 of file UnitGroup.cpp.
References canAttackAir(), empty(), getAverageSpeed(), getCloakedCount(), getFlyingCount(), getMajorityRegion(), hasDetection(), and size().
Referenced by DefaultSquadTask::update().
{ // Don't chase after a faster group double thisAverageSpeed = getAverageSpeed(); double otherAverageSpeed = other.getAverageSpeed(); if(otherAverageSpeed >= thisAverageSpeed) return false; size_t thisFlyingCount = getFlyingCount(); double thisFlyingAverage = 0.0; if(!empty()) thisFlyingAverage = thisFlyingCount / size(); size_t otherFlyingCount = other.getFlyingCount(); double otherFlyingAverage = 0.0; if(!other.empty()) otherFlyingAverage = otherFlyingCount / other.size(); if((thisFlyingAverage + 0.3) < otherFlyingAverage) return false; Region thisRegion = getMajorityRegion(); Region otherRegion = other.getMajorityRegion(); if(thisRegion && thisRegion != otherRegion) { // dont try attacking a group that isnt connected without a majority of flying units if(!otherRegion || thisRegion->isConnected(otherRegion)) { if(thisFlyingAverage > 0.5) return false; } } size_t otherCloakedCount = other.getCloakedCount(); if(!hasDetection() && otherCloakedCount > 0) { size_t thisCloakedCount = getCloakedCount(); if(!other.hasDetection() && thisCloakedCount > 0) { if(thisCloakedCount < otherCloakedCount) return false; } else if(otherCloakedCount > 0) return false; } if(otherFlyingAverage > 0.2 && !canAttackAir()) return false; return true; }
int UnitGroup::minDistanceBetween | ( | const UnitGroup & | otherGroup | ) | const |
Definition at line 279 of file UnitGroup.cpp.
References mUnits.
Referenced by DefaultSquadTask::update().
{ int minDistance = std::numeric_limits<int>::max(); for each(Unit groupUnit in mUnits) { for each(Unit otherGroupUnit in otherGroup) { int thisDistance = otherGroupUnit->getDistance(groupUnit); if(thisDistance < minDistance) minDistance = thisDistance; } } return minDistance; }
UnitGroup::operator std::set< Unit > | ( | ) | const |
Definition at line 104 of file UnitGroup.cpp.
{ return mUnits; }
bool UnitGroup::operator!= | ( | const UnitGroup & | other | ) | const |
Definition at line 294 of file UnitGroup.cpp.
{ UnitGroup ret(*this); ret += other; return ret; }
Definition at line 181 of file UnitGroup.cpp.
References insert().
bool UnitGroup::operator== | ( | const UnitGroup & | other | ) | const |
int UnitGroup::ratingDifference | ( | const UnitGroup & | other | ) | const |
Definition at line 109 of file UnitGroup.cpp.
References mUnits.
Referenced by DefaultSquadTask::update(), and BaseClass::update().
{ // not sure about this, along the right lines with using time to kill as that in turns considers weapon damage, terrain, health etc but bad atm if(mUnits.empty() && other.mUnits.empty()) return 0; else if(mUnits.empty()) return -100; else if(other.mUnits.empty()) return 100; int OtherKillThisTime = 0; int ThisKillOtherTime = 0; for each(Unit thisUnit in mUnits) { for each(Unit otherUnit in other.mUnits) { if(otherUnit->canAttack(thisUnit) && !thisUnit->isUnderDarkSwarm() && otherUnit->getDistance(thisUnit) < 600) { int killTime = otherUnit->getTimeToKill(thisUnit); if(otherUnit->getType().groundWeapon().outerSplashRadius() > 15) killTime /= 2; OtherKillThisTime += std::min(killTime, 500); } else OtherKillThisTime += 500; if(thisUnit->canAttack(otherUnit) && !otherUnit->isUnderDarkSwarm() && thisUnit->getDistance(otherUnit) < 600) ThisKillOtherTime += std::min(thisUnit->getTimeToKill(otherUnit), 500); else ThisKillOtherTime += 500; } } OtherKillThisTime /= other.mUnits.size(); ThisKillOtherTime /= mUnits.size(); int ratingTotal = std::max(OtherKillThisTime, ThisKillOtherTime) - std::min(OtherKillThisTime, ThisKillOtherTime); if(OtherKillThisTime < ThisKillOtherTime) ratingTotal = 0 - ratingTotal; return ratingTotal; }
std::set< Unit >::size_type UnitGroup::size | ( | ) | const |
Definition at line 99 of file UnitGroup.cpp.
References mUnits.
Referenced by canMajorityAttack(), DefenseSquadTask::controlSize(), DefaultSquadTask::controlSize(), BaseClass::drawDebugInfo(), getCenter(), DefenseSquadTask::getPriority(), isWorthEngaging(), PsiStormAction::update(), ArbiterAction::update(), DefaultSquadTask::update(), WorkerScoutTask::update(), BaseClass::update(), and DefenseSquadTask::updateRequirements().
{ return mUnits.size(); }
std::set<Unit> UnitGroup::mUnits [private] |
Definition at line 79 of file UnitGroup.h.
Referenced by begin(), canAttackAir(), canAttackGround(), canMajorityAttack(), clear(), count(), countCompletedBy(), empty(), end(), erase(), find(), getAverageSpeed(), getAverageTerrainHeight(), getBuildScore(), getCenter(), getCloakedCount(), getClosestUnit(), getFlyingCount(), getMajorityRegion(), hasDetection(), insert(), isAnyInRange(), minDistanceBetween(), operator!=(), operator==(), ratingDifference(), and size().