BWAPI
|
#include <Unit.h>
UnitClass::UnitClass | ( | BWAPI::Unit * | unit | ) |
Definition at line 15 of file Unit.cpp.
References BWAPI::Broodwar, BWAPI::UnitType::buildTime(), exists(), BWAPI::Unit::getBuildType(), BWAPI::Game::getFrameCount(), BWAPI::Unit::getType(), isCompleted(), BWAPI::Unit::isCompleted(), isMorphing(), BWAPI::Unit::isMorphing(), mStoredCompleted, mStoredCompletedTime, mStoredMorphing, and update().
: mUnit(unit) , mStoredPosition(BWAPI::Positions::Unknown) , mStoredTargetPosition(BWAPI::Positions::None) , mStoredAccessType(AccessType::Full) , mStoredPlayer(BWAPI::Broodwar->neutral()) , mStoredBoolOne(false) , mStoredCompleted(false) , mStoredMorphing(false) , mStoredCompletedTime(0) , mStoredTime(0) , mStoredInt(0) , mStoredExistsTime(Requirement::maxTime) , mStoredHealth(0) , mStoredShield(0) , mLastOrderExecuteTime(0) { if(exists()) { mStoredCompleted = unit->isCompleted(); mStoredMorphing = unit->isMorphing(); } update(); if(exists()) { if(!isCompleted()) mStoredCompletedTime = BWAPI::Broodwar->getFrameCount() + unit->getType().buildTime(); else if(isMorphing()) mStoredCompletedTime = BWAPI::Broodwar->getFrameCount() + unit->getBuildType().buildTime(); } }
UnitClass::UnitClass | ( | Position | pos, |
BWAPI::UnitType | type, | ||
int | completeTime | ||
) |
Definition at line 47 of file Unit.cpp.
: mUnit(NULL) , mStoredPosition(pos) , mStoredTargetPosition(pos) , mStoredType(type) , mStoredAccessType(AccessType::Prediction) , mStoredPlayer(BWAPI::Broodwar->self()) , mStoredBoolOne(false) , mStoredCompleted(false) , mStoredMorphing(false) , mStoredCompletedTime(startTime + type.buildTime()) , mStoredTime(BWAPI::Broodwar->getFrameCount()) , mStoredInt(0) , mStoredExistsTime(startTime) , mStoredHealth(0) , mStoredShield(0) , mLastOrderExecuteTime(0) { }
Definition at line 245 of file Unit.cpp.
References BWAPI::Broodwar, BWAPI::UnitType::canMove(), AccessTypeDef::Dead, BWAPI::Unit::exists(), AccessTypeDef::Full, BWAPI::Unit::getPlayer(), getPlayer(), getTilePosition(), getType(), AccessTypeDef::Guess, MapHelper::isAnyVisible(), BWAPI::Unit::isBurrowed(), BWAPI::Unit::isCloaked(), BWAPI::Unit::isDetected(), BWAPI::UnitType::isFlyingBuilding(), AccessTypeDef::Lost, mStoredAccessType, mUnit, AccessTypeDef::Partial, BWAPI::Game::self(), and BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode.
Referenced by drawUnitPosition(), isCompleted(), and update().
{ if(mUnit) { if(mUnit->exists()) { if(mUnit->getPlayer() == BWAPI::Broodwar->self() || (!mUnit->isCloaked() && !mUnit->isBurrowed()) || mUnit->isDetected()) return AccessType::Full; else return AccessType::Partial; } // If it doesn't exist but its ours it must be dead, is also possible to check if the player has left the game // but in some game modes they don't disappear when player->leftGame() returns true, noticed in protoss champaign if(getPlayer() == BWAPI::Broodwar->self()) return AccessType::Dead; const BWAPI::UnitType &type = getType(); if(MapHelper::isAnyVisible(getTilePosition(), type)) { if(type.canMove() || type.isFlyingBuilding() || type == BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode) mStoredAccessType = AccessType::Lost; else mStoredAccessType = AccessType::Dead; } else if(mStoredAccessType != AccessType::Lost) mStoredAccessType = AccessType::Guess; } return mStoredAccessType; }
void UnitClass::attack | ( | Unit | unit | ) |
Definition at line 700 of file Unit.cpp.
References BWAPI::Unit::attack(), BWAPI::UnitCommandTypes::Attack_Unit, BWAPI::Orders::AttackUnit, BWAPI::Broodwar, exists(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Unit::getOrderTarget(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getTarget(), BWAPI::UnitCommand::getType(), mLastOrderExecuteTime, move(), and mUnit.
{ if(exists() && unit) { if(!unit->exists()) { move(unit->getPosition()); return; } if(mUnit->getOrder() == BWAPI::Orders::AttackUnit) { if(mUnit->getOrderTarget() == unit->mUnit) return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Attack_Unit && mUnit->getLastCommand().getTarget() == unit->mUnit) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->attack(unit->mUnit)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
void UnitClass::attack | ( | Position | target, |
int | accuracy = 8 |
||
) |
Definition at line 727 of file Unit.cpp.
References BWAPI::Unit::attack(), BWAPI::UnitCommandTypes::Attack_Move, BWAPI::Orders::AttackMove, BWAPI::Broodwar, exists(), BWAPI::Position::getApproxDistance(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Unit::getOrderTargetPosition(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getTargetPosition(), BWAPI::UnitCommand::getType(), BWAPI::Orders::Guard, mLastOrderExecuteTime, mUnit, and BWAPI::Orders::PlayerGuard.
{ if(exists()) { if(mUnit->getOrder() == BWAPI::Orders::AttackMove) { if(mUnit->getOrderTargetPosition().getApproxDistance(target) <= accuracy) return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Attack_Move && mUnit->getLastCommand().getTargetPosition().getApproxDistance(target) <= accuracy) { if(mUnit->getOrder() == BWAPI::Orders::Guard || mUnit->getOrder() == BWAPI::Orders::PlayerGuard) return; else if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->attack(target)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
void UnitClass::build | ( | TilePosition | target, |
BWAPI::UnitType | type | ||
) |
Definition at line 534 of file Unit.cpp.
References BWAPI::Broodwar, BWAPI::UnitCommandTypes::Build, BWAPI::Unit::build(), exists(), BWAPI::Unit::getBuildType(), getDistance(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Unit::getOrderTargetPosition(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getTargetTilePosition(), BWAPI::UnitCommand::getType(), BWAPI::UnitCommand::getUnitType(), MapHelper::isAllVisible(), mLastOrderExecuteTime, move(), mUnit, BWAPI::Orders::PlaceBuilding, BWAPI::UnitType::tileHeight(), BWAPI::UnitType::tileWidth(), BWAPI::TilePosition::x(), and BWAPI::TilePosition::y().
{ if(exists()) { const Position targetPosition(target.x()*32+type.tileWidth()*16, target.y()*32+type.tileHeight()*16); if(getDistance(type, targetPosition) > 48 || !MapHelper::isAllVisible(target, type)) { move(targetPosition, 0); return; } if(mUnit->getOrder() == BWAPI::Orders::PlaceBuilding) { if(mUnit->getBuildType() == type && mUnit->getOrderTargetPosition() == targetPosition) return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Build && mUnit->getLastCommand().getUnitType() == type && mUnit->getLastCommand().getTargetTilePosition() == target) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->build(target, type)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); else move(targetPosition, 0); } }
void UnitClass::build | ( | Unit | unit | ) |
Definition at line 564 of file Unit.cpp.
References exists(), mUnit, and BWAPI::Unit::rightClick().
{ if(exists() && unit && unit->exists()) { mUnit->rightClick(unit->mUnit); unit->mUnit->rightClick(mUnit); } }
bool UnitClass::canAttack | ( | Unit | unit | ) |
Definition at line 1018 of file Unit.cpp.
References canAttackAir(), canAttackGround(), BWAPI::Unit::isLockedDown(), BWAPI::Unit::isStasised(), and mUnit.
Referenced by canAttackNow().
{ if(!unit) return false; if(mUnit->isLockedDown() || mUnit->isStasised() || unit->isStasised()) return false; if((unit->isCloaked() || unit->isBurrowed()) && !unit->isDetected()) return false; if(unit->getType().isFlyer() || unit->isLifted()) return canAttackAir(); else return canAttackGround(); }
bool UnitClass::canAttackAir | ( | ) |
Definition at line 1197 of file Unit.cpp.
References BWAPI::UnitType::airWeapon(), getType(), and BWAPI::BulletTypes::None.
Referenced by canAttack().
{ return getType().airWeapon() != BWAPI::WeaponTypes::None; }
bool UnitClass::canAttackGround | ( | ) |
Definition at line 1185 of file Unit.cpp.
References getScarabCount(), getType(), BWAPI::UnitType::groundWeapon(), BWAPI::BulletTypes::None, BWAPI::UnitTypes::Protoss_Reaver, and BWAPI::UnitTypes::Terran_Vulture_Spider_Mine.
Referenced by canAttack().
{ const BWAPI::UnitType &type = getType(); if(type == BWAPI::UnitTypes::Protoss_Reaver) return getScarabCount() != 0; if(type == BWAPI::UnitTypes::Terran_Vulture_Spider_Mine) return true; return type.groundWeapon() != BWAPI::WeaponTypes::None; }
bool UnitClass::canAttackNow | ( | Unit | unit | ) |
bool UnitClass::cancel | ( | int | slot = -2 | ) |
Definition at line 646 of file Unit.cpp.
References BWAPI::Unit::cancelConstruction(), BWAPI::Unit::cancelMorph(), BWAPI::Unit::cancelResearch(), BWAPI::Unit::cancelTrain(), BWAPI::Unit::cancelUpgrade(), exists(), BWAPI::Unit::haltConstruction(), BWAPI::Unit::isBeingConstructed(), BWAPI::Unit::isCompleted(), BWAPI::Unit::isConstructing(), BWAPI::Unit::isMorphing(), BWAPI::Unit::isResearching(), BWAPI::Unit::isTraining(), BWAPI::Unit::isUpgrading(), and mUnit.
Referenced by train().
{ if(exists()) { if(mUnit->isResearching()) mUnit->cancelResearch(); else if(mUnit->isUpgrading()) mUnit->cancelUpgrade(); else if(mUnit->isTraining()) mUnit->cancelTrain(slot); else if(mUnit->isMorphing()) mUnit->cancelMorph(); else if(mUnit->isBeingConstructed() || !mUnit->isCompleted()) mUnit->cancelConstruction(); else if(mUnit->isConstructing()) mUnit->haltConstruction(); else return false; return true; } return false; }
void UnitClass::drawUnitPosition | ( | ) |
Definition at line 277 of file Unit.cpp.
References accessibility(), BWAPI::Colors::Blue, BWAPI::Broodwar, BWAPI::UnitType::buildTime(), BWAPI::UnitType::dimensionDown(), BWAPI::UnitType::dimensionLeft(), BWAPI::UnitType::dimensionRight(), BWAPI::UnitType::dimensionUp(), BWAPI::Game::drawBox(), BWAPI::Game::drawLine(), BWAPI::Game::drawTextMap(), getBuildType(), BWAPI::Player::getColor(), getCompletedTime(), getExistTime(), BWAPI::Game::getFrameCount(), getHealth(), AccessTypeDef::getName(), BWAPI::Player::getName(), getPlayer(), getPosition(), getShield(), getTargetPosition(), getType(), BWAPI::Colors::Green, Singleton< T >::Instance(), isCompleted(), isMorphing(), BWAPI::CoordinateType::Map, BWAPI::UnitType::maxHitPoints(), BWAPI::UnitType::maxShields(), AccessTypeDef::Prediction, BWAPI::Colors::Purple, BWAPI::Colors::Red, SafeEnum< def, inner >::underlying(), BWAPI::Position::x(), and BWAPI::Position::y().
{ const Position &pos = getPosition(); const BWAPI::UnitType &type = getType(); Player player = getPlayer(); const int barHeight = 4; if((!isCompleted() || isMorphing()) && accessibility() != AccessType::Prediction) { double progress = getCompletedTime() - BWAPI::Broodwar->getFrameCount(); if(isMorphing()) progress /= getBuildType().buildTime(); else progress /= type.buildTime(); progress = 1.0 - progress; BWAPI::Color barColour = isMorphing() ? BWAPI::Colors::Red : BWAPI::Colors::Purple; Position bottomLeft(pos.x() - type.dimensionLeft(), pos.y() + type.dimensionDown() + barHeight - 1); DrawingHelper::Instance().drawProgressBar(bottomLeft, type.dimensionLeft()+type.dimensionRight(), barHeight, progress, barColour, player->getColor()); } if(type.maxShields() > 0) { double progress = getShield(); progress /= type.maxShields(); Position bottomLeft(pos.x() - type.dimensionLeft(), pos.y() - type.dimensionUp() - barHeight + 2); DrawingHelper::Instance().drawProgressBar(bottomLeft, type.dimensionLeft()+type.dimensionRight(), barHeight, progress, BWAPI::Colors::Blue, player->getColor()); } if(type.maxHitPoints() > 0) { double progress = getHealth(); progress /= type.maxHitPoints(); Position bottomLeft(pos.x() - type.dimensionLeft(), pos.y() - type.dimensionUp() + 1); DrawingHelper::Instance().drawProgressBar(bottomLeft, type.dimensionLeft()+type.dimensionRight(), barHeight, progress, BWAPI::Colors::Green, player->getColor()); } BWAPI::Broodwar->drawBox(BWAPI::CoordinateType::Map, pos.x() - type.dimensionLeft(), pos.y() - type.dimensionUp(), pos.x() + type.dimensionRight(), pos.y() + type.dimensionDown(), player->getColor()); BWAPI::Broodwar->drawTextMap(pos.x() + type.dimensionRight(), pos.y(), "%s", player->getName().c_str()); AccessType access = accessibility(); BWAPI::Broodwar->drawTextMap(pos.x() + type.dimensionRight(), pos.y()+10, "%s", AccessType::getName(access.underlying()).c_str()); BWAPI::Broodwar->drawTextMap(pos.x() + type.dimensionRight(), pos.y()+20, "%d", (getExistTime() - BWAPI::Broodwar->getFrameCount())); BWAPI::Broodwar->drawTextMap(pos.x() + type.dimensionRight(), pos.y()+30, "%d", (getCompletedTime() - BWAPI::Broodwar->getFrameCount())); if(isMorphing()) BWAPI::Broodwar->drawTextMap(pos.x() + type.dimensionRight(), pos.y()+40, "Morphing"); if(isCompleted()) BWAPI::Broodwar->drawTextMap(pos.x() + type.dimensionRight(), pos.y()+50, "Completed"); Position target = getTargetPosition(); BWAPI::Broodwar->drawLine(BWAPI::CoordinateType::Map, pos.x(), pos.y(), target.x(), target.y(), player->getColor()); }
void UnitClass::drawUnitTilePosition | ( | ) |
Definition at line 343 of file Unit.cpp.
References BWAPI::Broodwar, BWAPI::Game::drawBox(), BWAPI::Player::getColor(), getPlayer(), getTilePosition(), getType(), BWAPI::CoordinateType::Map, BWAPI::UnitType::tileHeight(), BWAPI::UnitType::tileWidth(), BWAPI::TilePosition::x(), and BWAPI::TilePosition::y().
{ TilePosition tile = getTilePosition(); BWAPI::UnitType type = getType(); Player player = getPlayer(); BWAPI::Broodwar->drawBox(BWAPI::CoordinateType::Map, tile.x()*32, tile.y()*32, (tile.x()+type.tileWidth())*32, (tile.y()+type.tileHeight())*32, player->getColor()); }
bool UnitClass::exists | ( | ) |
Definition at line 352 of file Unit.cpp.
References BWAPI::Unit::exists(), and mUnit.
Referenced by attack(), build(), canAttackNow(), cancel(), gather(), getBuildUnit(), getCompletedTime(), getDefenseMatrixPoints(), getEnergy(), getHealth(), getLastCommand(), getLastSeenTime(), getOrder(), getPlayer(), getPosition(), getRemainingAirCooldown(), getRemainingGroundCooldown(), getRemainingResearchTime(), getRemainingTrainTime(), getRemainingUpgradeTime(), getResources(), getScarabCount(), getSecondaryOrder(), getShield(), getSpellCooldown(), getTarget(), getTargetPosition(), getTech(), getTilePosition(), getTrainingQueue(), getType(), getUpgrade(), hasAddon(), hasPath(), isAttackFrame(), isBeingConstructed(), isBeingHealed(), isBurrowed(), isCarryingGas(), isCarryingMinerals(), isCloaked(), isCompleted(), isConstructing(), isDetected(), isHealing(), isLifted(), isLoaded(), isLockedDown(), isMorphing(), isRepairing(), isResearching(), isSelected(), isSieged(), isStasised(), isStuck(), isTraining(), isUnderDarkSwarm(), isUnderStorm(), isUpgrading(), morph(), move(), research(), returnCargo(), stop(), train(), UnitClass(), update(), upgrade(), and useTech().
void UnitClass::gather | ( | Unit | unit | ) |
Definition at line 750 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::UnitCommandTypes::Gather, BWAPI::Unit::gather(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Unit::getOrderTarget(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getTarget(), BWAPI::UnitCommand::getType(), BWAPI::Orders::Harvest1, BWAPI::Orders::HarvestGas, BWAPI::Orders::MiningMinerals, mLastOrderExecuteTime, move(), BWAPI::Orders::MoveToGas, BWAPI::Orders::MoveToMinerals, mUnit, BWAPI::UnitTypes::Resource_Mineral_Field, BWAPI::Orders::WaitForGas, and BWAPI::Orders::WaitForMinerals.
{ if(exists() && unit) { if(!unit->exists()) { move(unit->getPosition()); return; } if(unit->getType() == BWAPI::UnitTypes::Resource_Mineral_Field) { if(mUnit->getOrder() == BWAPI::Orders::MoveToMinerals || mUnit->getOrder() == BWAPI::Orders::WaitForMinerals || mUnit->getOrder() == BWAPI::Orders::MiningMinerals) { if(mUnit->getOrderTarget() == unit->mUnit) return; } } else if(unit->getType().isRefinery()) { if(mUnit->getOrder() == BWAPI::Orders::Harvest1) return; else if(mUnit->getOrder() == BWAPI::Orders::MoveToGas || mUnit->getOrder() == BWAPI::Orders::WaitForGas || mUnit->getOrder() == BWAPI::Orders::HarvestGas) { if(mUnit->getOrderTarget() == unit->mUnit) return; } } else return; if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Gather && mUnit->getLastCommand().getTarget() == unit->mUnit) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->gather(unit->mUnit)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
int UnitClass::getAirWeaponMaxRange | ( | ) |
Definition at line 1060 of file Unit.cpp.
References getPlayer(), getType(), and BWAPI::Player::weaponMaxRange().
Referenced by getWeaponMaxRange().
{ return getPlayer()->weaponMaxRange(getType().airWeapon()); }
Definition at line 587 of file Unit.cpp.
References BWAPI::Unit::exists(), BWAPI::Unit::getBuildType(), mUnit, BWAPI::BulletTypes::None, and BWAPI::BulletTypes::Unknown.
Referenced by drawUnitPosition().
{ if(mUnit) { if(mUnit->exists()) return mUnit->getBuildType(); else return BWAPI::UnitTypes::Unknown; } return BWAPI::UnitTypes::None; }
Definition at line 513 of file Unit.cpp.
References exists(), BWAPI::Unit::getBuildUnit(), Singleton< T >::Instance(), mUnit, and StaticUnits::nullunit.
{ if(exists()) return UnitTracker::Instance().getUnit(mUnit->getBuildUnit()); return StaticUnits::nullunit; }
int UnitClass::getCompletedTime | ( | ) |
Definition at line 406 of file Unit.cpp.
References BWAPI::Broodwar, BWAPI::UnitType::buildTime(), exists(), getExistTime(), BWAPI::Game::getFrameCount(), BWAPI::Unit::getPlayer(), BWAPI::Unit::getRemainingBuildTime(), getType(), isCompleted(), mStoredCompletedTime, mUnit, and BWAPI::Game::self().
Referenced by drawUnitPosition().
{ if(isCompleted()) return BWAPI::Broodwar->getFrameCount(); if(exists()) { if(mUnit->getPlayer() == BWAPI::Broodwar->self()) return BWAPI::Broodwar->getFrameCount() + mUnit->getRemainingBuildTime(); } else { const int existsTime = getExistTime(); const int completeTime = existsTime + getType().buildTime(); if(completeTime < existsTime) return std::numeric_limits<int>::max(); else return completeTime; } return std::max(mStoredCompletedTime, BWAPI::Broodwar->getFrameCount() + 1); }
Definition at line 905 of file Unit.cpp.
References exists(), BWAPI::Unit::getDefenseMatrixPoints(), and mUnit.
Referenced by totalHitPoints().
{ if(exists()) return mUnit->getDefenseMatrixPoints(); return 0; }
int UnitClass::getDistance | ( | BWAPI::UnitType | targType, |
Position | position | ||
) |
Definition at line 1256 of file Unit.cpp.
References getPosition(), and getType().
Referenced by build(), getDistance(), and isInRange().
{ return UnitHelper::getDistance(getPosition(), getType(), position, targType); }
int UnitClass::getDistance | ( | Unit | unit | ) |
Definition at line 1261 of file Unit.cpp.
References getDistance().
{ if(!unit) return 0; return getDistance(unit->getType(), unit->getPosition()); }
int UnitClass::getDistance | ( | Position | position | ) |
Definition at line 1269 of file Unit.cpp.
References getDistance(), getPosition(), and getType().
{ return UnitHelper::getDistance(getPosition(), getType(), position); }
int UnitClass::getDistance | ( | Position | position, |
int | inFramesTime | ||
) |
Definition at line 1274 of file Unit.cpp.
References getDistance(), getPosition(), and getType().
{ return UnitHelper::getDistance(getPosition(inFramesTime), getType(), position); }
int UnitClass::getEnergy | ( | ) |
int UnitClass::getExistTime | ( | ) |
Definition at line 357 of file Unit.cpp.
References BWAPI::Broodwar, BWAPI::Game::getFrameCount(), mStoredExistsTime, and mUnit.
Referenced by drawUnitPosition(), and getCompletedTime().
{ if(mUnit) return BWAPI::Broodwar->getFrameCount(); return std::max(mStoredExistsTime, BWAPI::Broodwar->getFrameCount() + 1); }
Definition at line 1052 of file Unit.cpp.
References getPlayer(), getType(), BWAPI::UnitTypes::Protoss_Reaver, and BWAPI::Player::weaponMaxRange().
Referenced by getWeaponMaxRange().
{ if(getType() == BWAPI::UnitTypes::Protoss_Reaver) return 256; else return getPlayer()->weaponMaxRange(getType().groundWeapon()); }
int UnitClass::getHealth | ( | ) |
Definition at line 889 of file Unit.cpp.
References exists(), BWAPI::Unit::getHitPoints(), mStoredHealth, and mUnit.
Referenced by drawUnitPosition(), and totalHitPoints().
{ if(exists()) return mUnit->getHitPoints(); return mStoredHealth; }
int UnitClass::getID | ( | ) |
Definition at line 1234 of file Unit.cpp.
References exists(), BWAPI::Unit::getLastCommand(), and mUnit.
{ if(exists()) return mUnit->getLastCommand(); return BWAPI::UnitCommand(); }
int UnitClass::getLastSeenTime | ( | ) |
Definition at line 237 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Game::getFrameCount(), and mStoredTime.
{ if(exists()) return BWAPI::Broodwar->getFrameCount(); return mStoredTime; }
Definition at line 189 of file Unit.cpp.
References exists(), BWAPI::Unit::getOrder(), mUnit, and BWAPI::BulletTypes::None.
Referenced by hasOrder().
{ if(exists()) return mUnit->getOrder(); return BWAPI::Orders::None; }
Definition at line 173 of file Unit.cpp.
References exists(), BWAPI::Unit::getPlayer(), mStoredPlayer, and mUnit.
Referenced by accessibility(), drawUnitPosition(), drawUnitTilePosition(), getAirWeaponMaxRange(), getGroundWeaponMaxRange(), and getTimeToKill().
{ if(exists()) return mUnit->getPlayer(); return mStoredPlayer; }
Definition at line 88 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Position::getApproxDistance(), BWAPI::Game::getFrameCount(), BWAPI::Unit::getPosition(), BWAPI::Unit::getTransport(), getType(), BWAPI::Unit::isLoaded(), mStoredPosition, mStoredTargetPosition, mStoredTime, mUnit, and BWAPI::UnitType::topSpeed().
Referenced by drawUnitPosition(), getDistance(), getPosition(), getTilePosition(), hasPath(), and move().
{ if(exists()) { if(mUnit->isLoaded()) return mUnit->getTransport()->getPosition(); else return mUnit->getPosition(); } const BWAPI::UnitType &type = getType(); if(type.topSpeed() != 0.0) { int travelTime = int(mStoredPosition.getApproxDistance(mStoredTargetPosition) / type.topSpeed()); int timeDifference = BWAPI::Broodwar->getFrameCount() - mStoredTime; if(timeDifference > travelTime) return mStoredTargetPosition; if(travelTime != 0) { float traveled = float(timeDifference) / float(travelTime); Vector currentPosition = mStoredTargetPosition - mStoredPosition; currentPosition *= traveled; currentPosition += Vector(mStoredPosition); return currentPosition; } } return mStoredPosition; }
Position UnitClass::getPosition | ( | int | inFramesTime | ) |
Definition at line 124 of file Unit.cpp.
References BWAPI::Position::getApproxDistance(), getPosition(), getTargetPosition(), getType(), mStoredPosition, and BWAPI::UnitType::topSpeed().
{ const Position ¤tPosition = getPosition(); const BWAPI::UnitType &type = getType(); if(type.topSpeed() != 0.0) { const Position &targetPosition = getTargetPosition(); int travelTime = int(currentPosition.getApproxDistance(targetPosition) / type.topSpeed()); if(inFramesTime > travelTime) return targetPosition; if(travelTime != 0) { float traveled = float(inFramesTime) / float(travelTime); Vector direction = targetPosition - currentPosition; direction *= traveled; direction += Vector(mStoredPosition); return direction; } } return currentPosition; }
Definition at line 1120 of file Unit.cpp.
References exists(), BWAPI::Unit::getAirWeaponCooldown(), and mUnit.
Referenced by getRemainingCooldown().
{ if(exists()) return mUnit->getAirWeaponCooldown(); return 0; }
int UnitClass::getRemainingCooldown | ( | Unit | unit | ) |
Definition at line 1101 of file Unit.cpp.
References getRemainingAirCooldown(), and getRemainingGroundCooldown().
{ if(!unit) return 0; if(unit->getType().isFlyer() || unit->isLifted()) return getRemainingAirCooldown(); else return getRemainingGroundCooldown(); }
Definition at line 1112 of file Unit.cpp.
References exists(), BWAPI::Unit::getGroundWeaponCooldown(), and mUnit.
Referenced by getRemainingCooldown().
{ if(exists()) return mUnit->getGroundWeaponCooldown(); return 0; }
Definition at line 478 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Unit::getPlayer(), BWAPI::Unit::getRemainingResearchTime(), mUnit, and BWAPI::Game::self().
{ if(exists() && mUnit->getPlayer() == BWAPI::Broodwar->self()) return mUnit->getRemainingResearchTime(); return 0; }
int UnitClass::getRemainingTrainTime | ( | ) |
Definition at line 462 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Unit::getPlayer(), BWAPI::Unit::getRemainingTrainTime(), mUnit, and BWAPI::Game::self().
{ if(exists() && mUnit->getPlayer() == BWAPI::Broodwar->self()) return mUnit->getRemainingTrainTime(); return 0; }
Definition at line 470 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Unit::getPlayer(), BWAPI::Unit::getRemainingUpgradeTime(), mUnit, and BWAPI::Game::self().
{ if(exists() && mUnit->getPlayer() == BWAPI::Broodwar->self()) return mUnit->getRemainingUpgradeTime(); return 0; }
int UnitClass::getResources | ( | ) |
Definition at line 608 of file Unit.cpp.
References exists(), BWAPI::Unit::getResources(), mStoredInt, and mUnit.
{ if(exists()) return mUnit->getResources(); return mStoredInt; }
int UnitClass::getScarabCount | ( | ) |
Definition at line 1210 of file Unit.cpp.
References exists(), BWAPI::Unit::getScarabCount(), and mUnit.
Referenced by canAttackGround().
{ if(exists()) return mUnit->getScarabCount(); return 0; }
Definition at line 197 of file Unit.cpp.
References exists(), BWAPI::Unit::getSecondaryOrder(), mUnit, and BWAPI::BulletTypes::None.
Referenced by hasOrder().
{ if(exists()) return mUnit->getSecondaryOrder(); return BWAPI::Orders::None; }
int UnitClass::getShield | ( | ) |
Definition at line 897 of file Unit.cpp.
References exists(), BWAPI::Unit::getShields(), mStoredShield, and mUnit.
Referenced by drawUnitPosition(), and totalHitPoints().
{ if(exists()) return mUnit->getShields(); return mStoredShield; }
int UnitClass::getSpellCooldown | ( | ) |
Definition at line 1128 of file Unit.cpp.
References exists(), BWAPI::Unit::getSpellCooldown(), and mUnit.
{ if(exists()) return mUnit->getSpellCooldown(); return 0; }
Definition at line 521 of file Unit.cpp.
References exists(), BWAPI::Unit::getOrderTarget(), BWAPI::Unit::getTarget(), Singleton< T >::Instance(), mUnit, and StaticUnits::nullunit.
{ if(exists()) { if(mUnit->getOrderTarget()) return UnitTracker::Instance().getUnit(mUnit->getOrderTarget()); else return UnitTracker::Instance().getUnit(mUnit->getTarget()); } return StaticUnits::nullunit; }
Definition at line 154 of file Unit.cpp.
References BWAPI::UnitType::canMove(), exists(), BWAPI::Unit::getPosition(), BWAPI::Unit::getTargetPosition(), BWAPI::Unit::getTransport(), getType(), BWAPI::UnitType::isFlyingBuilding(), BWAPI::Unit::isLoaded(), mStoredTargetPosition, and mUnit.
Referenced by drawUnitPosition(), and getPosition().
{ if(exists()) { const BWAPI::UnitType &type = getType(); if(type.canMove() || type.isFlyingBuilding()) { if(mUnit->isLoaded()) return mUnit->getTransport()->getTargetPosition(); else return mUnit->getTargetPosition(); } else return mUnit->getPosition(); } return mStoredTargetPosition; }
Definition at line 638 of file Unit.cpp.
References exists(), BWAPI::Unit::getTech(), mUnit, and BWAPI::BulletTypes::None.
{ if(exists()) return mUnit->getTech(); return BWAPI::TechTypes::None; }
Definition at line 72 of file Unit.cpp.
References exists(), getPosition(), BWAPI::Unit::getTilePosition(), BWAPI::Unit::getTransport(), getType(), BWAPI::Unit::isLoaded(), mUnit, BWAPI::UnitType::tileHeight(), BWAPI::UnitType::tileWidth(), BWAPI::Position::x(), and BWAPI::Position::y().
Referenced by accessibility(), drawUnitTilePosition(), and getTimeToKill().
{ if(exists()) { if(mUnit->isLoaded()) return mUnit->getTransport()->getTilePosition(); else return mUnit->getTilePosition(); } const BWAPI::UnitType &type = getType(); const Position &pos = getPosition(); return TilePosition(Position(pos.x() - (type.tileWidth() * 16), pos.y() - (type.tileHeight() * 16))); }
int UnitClass::getTimeToKill | ( | Unit | unit | ) |
Definition at line 1136 of file Unit.cpp.
References BWAPI::Broodwar, BWAPI::DamageTypes::Concussive, BWAPI::WeaponType::damageAmount(), BWAPI::WeaponType::damageCooldown(), BWAPI::WeaponType::damageFactor(), BWAPI::WeaponType::damageType(), BWAPI::DamageTypes::Explosive, getPlayer(), getTilePosition(), BWAPI::Player::getUpgradeLevel(), getWeapon(), BWAPI::UnitSizeTypes::Large, BWAPI::UnitSizeTypes::Medium, BWAPI::UnitSizeTypes::Small, and BWAPI::WeaponType::upgradeType().
{ int health = unit->totalHitPoints(); BWAPI::WeaponType weapon = getWeapon(unit); int weaponDamage = weapon.damageAmount() + (weapon.damageFactor() * getPlayer()->getUpgradeLevel(weapon.upgradeType())); if(weaponDamage == 0) return 5000; int thisNumberOfShots = health / weaponDamage; if(weapon.damageType() == BWAPI::DamageTypes::Concussive) { if(unit->getType().size() == BWAPI::UnitSizeTypes::Large) thisNumberOfShots *= 4; else if(unit->getType().size() == BWAPI::UnitSizeTypes::Medium) thisNumberOfShots += thisNumberOfShots; } else if(weapon.damageType() == BWAPI::DamageTypes::Explosive) { if(unit->getType().size() == BWAPI::UnitSizeTypes::Small) thisNumberOfShots += thisNumberOfShots; else if(unit->getType().size() == BWAPI::UnitSizeTypes::Medium) thisNumberOfShots += thisNumberOfShots / 2; } if((BWAPI::Broodwar->getGroundHeight(getTilePosition()) - BWAPI::Broodwar->getGroundHeight(unit->getTilePosition())) < 0) thisNumberOfShots += thisNumberOfShots; return thisNumberOfShots * weapon.damageCooldown(); }
std::list< BWAPI::UnitType > UnitClass::getTrainingQueue | ( | ) |
Definition at line 1279 of file Unit.cpp.
References exists(), BWAPI::Unit::getTrainingQueue(), and mUnit.
{ if(exists()) return mUnit->getTrainingQueue(); return std::list<BWAPI::UnitType>(); }
Definition at line 181 of file Unit.cpp.
References exists(), BWAPI::Unit::getType(), mStoredType, and mUnit.
Referenced by accessibility(), canAttackAir(), canAttackGround(), drawUnitPosition(), drawUnitTilePosition(), getAirWeaponMaxRange(), getCompletedTime(), getDistance(), getGroundWeaponMaxRange(), getPosition(), getTargetPosition(), getTilePosition(), getWeapon(), getWeaponCooldown(), getWeaponMinRange(), isLifted(), isSieged(), setBuildTime(), and totalHitPointFraction().
{ if(exists()) return mUnit->getType(); return mStoredType; }
Definition at line 624 of file Unit.cpp.
References exists(), BWAPI::Unit::getUpgrade(), mUnit, and BWAPI::BulletTypes::None.
{ if(exists()) return mUnit->getUpgrade(); return BWAPI::UpgradeTypes::None; }
Definition at line 1169 of file Unit.cpp.
References BWAPI::UnitType::airWeapon(), getType(), BWAPI::UnitType::groundWeapon(), BWAPI::BulletTypes::None, BWAPI::UnitTypes::Protoss_Reaver, and BWAPI::WeaponTypes::Scarab.
Referenced by getTimeToKill().
{ if(!unit) return BWAPI::WeaponTypes::None; if(unit->getType().isFlyer() || unit->isLifted()) return getType().airWeapon(); else { if(getType() == BWAPI::UnitTypes::Protoss_Reaver) return BWAPI::WeaponTypes::Scarab; else return getType().groundWeapon(); } }
int UnitClass::getWeaponCooldown | ( | Unit | unit | ) |
Definition at line 1087 of file Unit.cpp.
References BWAPI::UnitType::airWeapon(), BWAPI::WeaponType::damageCooldown(), getType(), BWAPI::UnitType::groundWeapon(), and BWAPI::UnitTypes::Protoss_Reaver.
{ if(!unit) return 0; if(getType() == BWAPI::UnitTypes::Protoss_Reaver) return 60; if(unit->getType().isFlyer() || unit->isLifted()) return getType().airWeapon().damageCooldown(); else return getType().groundWeapon().damageCooldown(); }
int UnitClass::getWeaponMaxRange | ( | Unit | unit | ) |
Definition at line 1065 of file Unit.cpp.
References getAirWeaponMaxRange(), and getGroundWeaponMaxRange().
Referenced by isInRange().
{ if(!unit) return 0; if(unit->getType().isFlyer() || unit->isLifted()) return getAirWeaponMaxRange(); else return getGroundWeaponMaxRange(); }
int UnitClass::getWeaponMinRange | ( | Unit | unit | ) |
Definition at line 1076 of file Unit.cpp.
References BWAPI::UnitType::airWeapon(), getType(), BWAPI::UnitType::groundWeapon(), and BWAPI::WeaponType::minRange().
Referenced by isInRange().
{ if(!unit) return 0; if(unit->getType().isFlyer() || unit->isLifted()) return getType().airWeapon().minRange(); else return getType().groundWeapon().minRange(); }
bool UnitClass::hasAddon | ( | ) |
bool UnitClass::hasOrder | ( | BWAPI::Order | order | ) |
Definition at line 1357 of file Unit.cpp.
References getOrder(), and getSecondaryOrder().
{ if(getOrder() == order) return true; else if(getSecondaryOrder() == order) return true; else return false; }
bool UnitClass::hasPath | ( | Position | position | ) |
Definition at line 927 of file Unit.cpp.
References BWAPI::Broodwar, exists(), getPosition(), BWAPI::Unit::hasPath(), BWAPI::Game::hasPath(), and mUnit.
{ if(exists()) return mUnit->hasPath(position); return BWAPI::Broodwar->hasPath(getPosition(), position); }
bool UnitClass::isAttackFrame | ( | ) |
Definition at line 1202 of file Unit.cpp.
References exists(), BWAPI::Unit::isAttackFrame(), and mUnit.
{ if(exists()) return mUnit->isAttackFrame(); return false; }
bool UnitClass::isBeingConstructed | ( | ) |
Definition at line 454 of file Unit.cpp.
References exists(), BWAPI::Unit::isBeingConstructed(), and mUnit.
{ if(exists()) return mUnit->isBeingConstructed(); return false; }
bool UnitClass::isBeingHealed | ( | ) |
Definition at line 1242 of file Unit.cpp.
References exists(), BWAPI::Unit::isBeingHealed(), and mUnit.
{ if(exists()) return mUnit->isBeingHealed(); return false; }
bool UnitClass::isBeingRepaired | ( | ) |
bool UnitClass::isBurrowed | ( | ) |
Definition at line 960 of file Unit.cpp.
References exists(), BWAPI::Unit::isBurrowed(), and mUnit.
{ if(exists()) return mUnit->isBurrowed(); return false; }
bool UnitClass::isCarryingGas | ( | ) |
Definition at line 221 of file Unit.cpp.
References exists(), BWAPI::Unit::isCarryingGas(), and mUnit.
{ if(exists()) return mUnit->isCarryingGas(); return false; }
bool UnitClass::isCarryingMinerals | ( | ) |
Definition at line 229 of file Unit.cpp.
References exists(), BWAPI::Unit::isCarryingMinerals(), and mUnit.
{ if(exists()) return mUnit->isCarryingMinerals(); return false; }
bool UnitClass::isCloaked | ( | ) |
bool UnitClass::isCompleted | ( | ) |
Definition at line 384 of file Unit.cpp.
References accessibility(), BWAPI::Broodwar, exists(), BWAPI::Game::getFrameCount(), BWAPI::Unit::getPlayer(), BWAPI::Unit::getRemainingBuildTime(), BWAPI::Unit::isCompleted(), mStoredCompleted, mStoredCompletedTime, mUnit, AccessTypeDef::Prediction, and BWAPI::Game::self().
Referenced by drawUnitPosition(), getCompletedTime(), and UnitClass().
{ if(exists()) { if(mUnit->isCompleted()) return true; if(mUnit->getPlayer() == BWAPI::Broodwar->self()) return mUnit->getRemainingBuildTime() == 0; return false; } if(accessibility() == AccessType::Prediction) return false; if(mStoredCompleted) return true; return mStoredCompletedTime <= BWAPI::Broodwar->getFrameCount(); }
bool UnitClass::isConstructing | ( | ) |
Definition at line 446 of file Unit.cpp.
References exists(), BWAPI::Unit::isConstructing(), and mUnit.
{ if(exists()) return mUnit->isConstructing(); return false; }
bool UnitClass::isDetected | ( | ) |
Definition at line 968 of file Unit.cpp.
References exists(), BWAPI::Unit::isDetected(), and mUnit.
{ if(exists()) return mUnit->isDetected(); return false; }
bool UnitClass::isHealing | ( | ) |
Definition at line 1226 of file Unit.cpp.
References exists(), BWAPI::Unit::getOrder(), BWAPI::Orders::MedicHeal1, BWAPI::Orders::MedicHeal2, and mUnit.
{ if(exists()) return mUnit->getOrder() == BWAPI::Orders::MedicHeal1 || mUnit->getOrder() == BWAPI::Orders::MedicHeal2; return false; }
bool UnitClass::isInRange | ( | Unit | unit | ) |
Definition at line 1035 of file Unit.cpp.
References getDistance(), getWeaponMaxRange(), and getWeaponMinRange().
{ int weaponMaxRange = getWeaponMaxRange(unit); if(weaponMaxRange <= 0) return false; int distance = getDistance(unit); int weaponMinRange = getWeaponMinRange(unit); if(weaponMinRange != 0 && distance <= weaponMinRange) return false; return weaponMaxRange >= distance; }
bool UnitClass::isLifted | ( | ) |
Definition at line 205 of file Unit.cpp.
References exists(), getType(), BWAPI::UnitType::isFlyingBuilding(), BWAPI::Unit::isLifted(), mStoredBoolOne, and mUnit.
{ if(exists()) return mUnit->isLifted(); return getType().isFlyingBuilding() && mStoredBoolOne; }
bool UnitClass::isLoaded | ( | ) |
bool UnitClass::isLockedDown | ( | ) |
Definition at line 944 of file Unit.cpp.
References exists(), BWAPI::Unit::isLockedDown(), and mUnit.
{ if(exists()) return mUnit->isLockedDown(); return false; }
bool UnitClass::isMorphing | ( | ) |
Definition at line 365 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Game::getFrameCount(), BWAPI::Unit::getPlayer(), BWAPI::Unit::getRemainingBuildTime(), BWAPI::Unit::isMorphing(), mStoredCompletedTime, mStoredMorphing, mUnit, and BWAPI::Game::self().
Referenced by drawUnitPosition(), and UnitClass().
{ if(exists()) { if(!mUnit->isMorphing()) return false; if(mUnit->getPlayer() == BWAPI::Broodwar->self()) return mUnit->getRemainingBuildTime() > 0; return true; } if(!mStoredMorphing) return false; return mStoredCompletedTime > BWAPI::Broodwar->getFrameCount(); }
bool UnitClass::isRepairing | ( | ) |
Definition at line 1218 of file Unit.cpp.
References exists(), BWAPI::Unit::isRepairing(), and mUnit.
{ if(exists()) return mUnit->isRepairing(); return false; }
bool UnitClass::isResearching | ( | ) |
Definition at line 438 of file Unit.cpp.
References exists(), BWAPI::Unit::isResearching(), and mUnit.
{ if(exists()) return mUnit->isResearching(); return false; }
bool UnitClass::isSelected | ( | ) |
Definition at line 919 of file Unit.cpp.
References exists(), BWAPI::Unit::isSelected(), and mUnit.
{ if(exists()) return mUnit->isSelected(); return false; }
bool UnitClass::isSieged | ( | ) |
Definition at line 213 of file Unit.cpp.
References exists(), getType(), BWAPI::Unit::isSieged(), mStoredBoolOne, mUnit, BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode, and BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode.
{ if(exists()) return mUnit->isSieged(); return (getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode || getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode) && mStoredBoolOne; }
bool UnitClass::isStasised | ( | ) |
Definition at line 935 of file Unit.cpp.
References exists(), Singleton< T >::Instance(), BWAPI::Unit::isStasised(), and mUnit.
{ if(exists()) if(mUnit->isStasised()) return true; return LatencyTracker::Instance().isStasisInRange(shared_from_this()); }
bool UnitClass::isStuck | ( | ) |
bool UnitClass::isTraining | ( | ) |
Definition at line 430 of file Unit.cpp.
References exists(), BWAPI::Unit::isTraining(), and mUnit.
{ if(exists()) return mUnit->isTraining(); return false; }
bool UnitClass::isUnderDarkSwarm | ( | ) |
Definition at line 993 of file Unit.cpp.
References exists(), BWAPI::Unit::isUnderDarkSwarm(), and mUnit.
{ if(exists()) if(mUnit->isUnderDarkSwarm()) return true; return false; }
bool UnitClass::isUnderStorm | ( | ) |
Definition at line 984 of file Unit.cpp.
References exists(), Singleton< T >::Instance(), BWAPI::Unit::isUnderStorm(), and mUnit.
{ if(exists()) if(mUnit->isUnderStorm()) return true; return LatencyTracker::Instance().isStormInRange(shared_from_this()); }
bool UnitClass::isUpgrading | ( | ) |
Definition at line 616 of file Unit.cpp.
References exists(), BWAPI::Unit::isUpgrading(), and mUnit.
{ if(exists()) return mUnit->isUpgrading(); return false; }
void UnitClass::morph | ( | BWAPI::UnitType | type | ) |
void UnitClass::move | ( | Position | target, |
int | accuracy = 8 |
||
) |
Definition at line 677 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Position::getApproxDistance(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Unit::getOrderTargetPosition(), getPosition(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getTargetPosition(), BWAPI::UnitCommand::getType(), BWAPI::Orders::Guard, mLastOrderExecuteTime, BWAPI::Orders::Move, BWAPI::UnitCommandTypes::Move, BWAPI::Unit::move(), mUnit, and BWAPI::Orders::PlayerGuard.
Referenced by attack(), build(), gather(), returnCargo(), and useTech().
{ if(exists()) { if(mUnit->getOrder() == BWAPI::Orders::Move) { if(mUnit->getOrderTargetPosition().getApproxDistance(target) <= accuracy) return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Move && mUnit->getLastCommand().getTargetPosition().getApproxDistance(target) <= accuracy) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; else if((mUnit->getOrder() == BWAPI::Orders::Guard || mUnit->getOrder() == BWAPI::Orders::PlayerGuard) && getPosition().getApproxDistance(target) <= accuracy*4) return; } if(mUnit->move(target)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
void UnitClass::onDestroy | ( | ) |
Definition at line 67 of file Unit.cpp.
References AccessTypeDef::Dead, and mStoredAccessType.
void UnitClass::promote | ( | BWAPI::Unit * | unit | ) |
Definition at line 861 of file Unit.cpp.
References AccessTypeDef::Full, mStoredAccessType, mUnit, and update().
{ mUnit = unit; mStoredAccessType = AccessType::Full; update(); }
void UnitClass::research | ( | BWAPI::TechType | mType | ) |
void UnitClass::returnCargo | ( | ) |
Definition at line 792 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getType(), mLastOrderExecuteTime, mUnit, BWAPI::UnitCommandTypes::Return_Cargo, BWAPI::Unit::returnCargo(), BWAPI::Orders::ReturnGas, and BWAPI::Orders::ReturnMinerals.
{ if(exists()) { if(mUnit->getOrder() == BWAPI::Orders::ReturnGas || mUnit->getOrder() == BWAPI::Orders::ReturnMinerals) return; if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Return_Cargo) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->returnCargo()) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
void UnitClass::returnCargo | ( | Unit | unit | ) |
Definition at line 810 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Unit::getOrderTarget(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getTarget(), BWAPI::UnitCommand::getType(), mLastOrderExecuteTime, move(), mUnit, BWAPI::Orders::ResetCollision, BWAPI::Orders::ReturnGas, BWAPI::Orders::ReturnMinerals, BWAPI::UnitCommandTypes::Right_Click_Unit, and BWAPI::Unit::rightClick().
{ if(!unit) return; if(!unit->exists() || !unit->isCompleted()) { move(unit->getPosition()); return; } if(exists()) { if(mUnit->getOrder() == BWAPI::Orders::ResetCollision) return; if(mUnit->getOrder() == BWAPI::Orders::ReturnGas || mUnit->getOrder() == BWAPI::Orders::ReturnMinerals) { if(mUnit->getOrderTarget() == unit->mUnit) return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Right_Click_Unit && mUnit->getLastCommand().getTarget() == unit->mUnit) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->rightClick(unit->mUnit)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
void UnitClass::setBuildTime | ( | int | time | ) |
Definition at line 868 of file Unit.cpp.
References BWAPI::UnitType::buildTime(), getType(), mStoredCompletedTime, and mStoredExistsTime.
{ mStoredExistsTime = time; mStoredCompletedTime = time + getType().buildTime(); if(mStoredCompletedTime < time) mStoredCompletedTime = std::numeric_limits<int>::max(); }
void UnitClass::setPosition | ( | Position | position | ) |
Definition at line 913 of file Unit.cpp.
References mStoredPosition, and mStoredTargetPosition.
{ mStoredPosition = position; mStoredTargetPosition = position; }
void UnitClass::stop | ( | ) |
Definition at line 843 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getType(), mLastOrderExecuteTime, mUnit, BWAPI::Orders::Stop, and BWAPI::Unit::stop().
{ if(exists()) { if(mUnit->getOrder() == BWAPI::Orders::Stop) return; if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Stop) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->stop()) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
double UnitClass::totalHitPointFraction | ( | ) |
Definition at line 877 of file Unit.cpp.
References getType(), and totalHitPoints().
{ double currentHealth = totalHitPoints(); return currentHealth / double(getType().maxHitPoints() + getType().maxShields()); }
int UnitClass::totalHitPoints | ( | ) |
Definition at line 884 of file Unit.cpp.
References getDefenseMatrixPoints(), getHealth(), and getShield().
Referenced by totalHitPointFraction().
{ return getHealth() + getShield() + getDefenseMatrixPoints(); }
void UnitClass::train | ( | BWAPI::UnitType | type | ) |
Definition at line 486 of file Unit.cpp.
References BWAPI::Broodwar, cancel(), exists(), BWAPI::Unit::getLastCommand(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::Unit::getSecondaryOrder(), BWAPI::Unit::getTrainingQueue(), BWAPI::UnitCommand::getType(), BWAPI::UnitCommand::getUnitType(), mLastOrderExecuteTime, mUnit, BWAPI::UnitCommandTypes::Train, BWAPI::Orders::Train, and BWAPI::Unit::train().
{ if(exists()) { if(mUnit->getSecondaryOrder() == BWAPI::Orders::Train) { const std::list<BWAPI::UnitType> &queue = mUnit->getTrainingQueue(); if(queue.size() > 1 || (queue.size() == 1 && *queue.begin() != type)) { cancel(); return; } return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Train && mUnit->getLastCommand().getUnitType() == type) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->train(type)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
void UnitClass::update | ( | ) |
Definition at line 1367 of file Unit.cpp.
References accessibility(), BWAPI::Broodwar, BWAPI::UnitType::buildTime(), exists(), BWAPI::Unit::getBuildType(), BWAPI::Game::getFrameCount(), BWAPI::Unit::getHitPoints(), BWAPI::Unit::getPlayer(), BWAPI::Unit::getPosition(), BWAPI::Unit::getRemainingBuildTime(), BWAPI::Unit::getResources(), BWAPI::Unit::getShields(), BWAPI::Unit::getTargetPosition(), BWAPI::Unit::getType(), BWAPI::Unit::isCompleted(), BWAPI::UnitType::isFlyingBuilding(), BWAPI::Unit::isLifted(), BWAPI::Unit::isMorphing(), BWAPI::Unit::isSieged(), mStoredAccessType, mStoredBoolOne, mStoredCompleted, mStoredCompletedTime, mStoredHealth, mStoredInt, mStoredMorphing, mStoredPlayer, mStoredPosition, mStoredShield, mStoredTargetPosition, mStoredTime, mStoredType, mUnit, BWAPI::Game::self(), BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode, and BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode.
Referenced by promote(), and UnitClass().
{ if(exists()) { mStoredTime = BWAPI::Broodwar->getFrameCount(); mStoredPosition = mUnit->getPosition(); mStoredType = mUnit->getType(); mStoredPlayer = mUnit->getPlayer(); mStoredInt = mUnit->getResources(); if(mStoredCompleted && !mUnit->isCompleted()) mStoredCompletedTime = BWAPI::Broodwar->getFrameCount() + mUnit->getType().buildTime(); mStoredCompleted = mUnit->isCompleted(); if(!mStoredMorphing && mUnit->isMorphing()) mStoredCompletedTime = BWAPI::Broodwar->getFrameCount() + mUnit->getBuildType().buildTime(); mStoredMorphing = mUnit->isMorphing(); if(mUnit->getPlayer() == BWAPI::Broodwar->self()) mStoredCompletedTime = BWAPI::Broodwar->getFrameCount() + mUnit->getRemainingBuildTime(); else if(mUnit->isCompleted() && !mUnit->isMorphing()) mStoredCompletedTime = BWAPI::Broodwar->getFrameCount(); mStoredTargetPosition = mUnit->getTargetPosition(); mStoredHealth = mUnit->getHitPoints(); mStoredShield = mUnit->getShields(); if(mUnit->getType().isFlyingBuilding()) mStoredBoolOne = mUnit->isLifted(); else if(mUnit->getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode || mUnit->getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode) mStoredBoolOne = mUnit->isSieged(); mStoredAccessType = accessibility(); } }
void UnitClass::upgrade | ( | BWAPI::UpgradeType | type | ) |
void UnitClass::useTech | ( | BWAPI::TechType | tech, |
BWAPI::Position | target | ||
) |
Definition at line 1309 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Unit::getOrderTargetPosition(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getTargetPosition(), getTechCastOrder(), BWAPI::UnitCommand::getTechType(), BWAPI::UnitCommand::getType(), mLastOrderExecuteTime, mUnit, BWAPI::UnitCommandTypes::Use_Tech_Position, and BWAPI::Unit::useTech().
{ if(exists()) { if(mUnit->getOrder() == getTechCastOrder(tech)) { if(mUnit->getOrderTargetPosition() == target) return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Use_Tech_Position && mUnit->getLastCommand().getTechType() == tech && mUnit->getLastCommand().getTargetPosition() == target) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->useTech(tech, target)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
void UnitClass::useTech | ( | BWAPI::TechType | tech, |
Unit | target | ||
) |
Definition at line 1330 of file Unit.cpp.
References BWAPI::Broodwar, exists(), BWAPI::Unit::getLastCommand(), BWAPI::Unit::getOrder(), BWAPI::Unit::getOrderTarget(), BWAPI::Game::getRemainingLatencyFrames(), BWAPI::UnitCommand::getTarget(), getTechCastOrder(), BWAPI::UnitCommand::getTechType(), BWAPI::UnitCommand::getType(), mLastOrderExecuteTime, move(), mUnit, BWAPI::UnitCommandTypes::Use_Tech_Unit, and BWAPI::Unit::useTech().
{ if(exists() && target) { if(!target->exists()) { move(target->getPosition()); return; } if(mUnit->getOrder() == getTechCastOrder(tech))//TODO: in latest revision, the tech knows the relating order { if(mUnit->getOrderTarget() == target->mUnit) return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Use_Tech_Unit && mUnit->getLastCommand().getTechType() == tech && mUnit->getLastCommand().getTarget() == target->mUnit) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->useTech(tech, target->mUnit)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
int UnitClass::mDeleteTimer [private] |
int UnitClass::mLastOrderExecuteTime [private] |
AccessType UnitClass::mStoredAccessType [private] |
Definition at line 213 of file Unit.h.
Referenced by accessibility(), onDestroy(), promote(), and update().
bool UnitClass::mStoredBoolOne [private] |
Definition at line 211 of file Unit.h.
Referenced by isLifted(), isSieged(), and update().
bool UnitClass::mStoredCompleted [private] |
Definition at line 197 of file Unit.h.
Referenced by isCompleted(), UnitClass(), and update().
int UnitClass::mStoredCompletedTime [private] |
Definition at line 201 of file Unit.h.
Referenced by getCompletedTime(), isCompleted(), isMorphing(), setBuildTime(), UnitClass(), and update().
int UnitClass::mStoredExistsTime [private] |
Definition at line 202 of file Unit.h.
Referenced by getExistTime(), and setBuildTime().
int UnitClass::mStoredHealth [private] |
Definition at line 204 of file Unit.h.
Referenced by getHealth(), and update().
int UnitClass::mStoredInt [private] |
Definition at line 208 of file Unit.h.
Referenced by getResources(), and update().
bool UnitClass::mStoredMorphing [private] |
Definition at line 198 of file Unit.h.
Referenced by isMorphing(), UnitClass(), and update().
Player UnitClass::mStoredPlayer [private] |
Definition at line 196 of file Unit.h.
Referenced by getPlayer(), and update().
Position UnitClass::mStoredPosition [private] |
Definition at line 193 of file Unit.h.
Referenced by getPosition(), setPosition(), and update().
int UnitClass::mStoredShield [private] |
Definition at line 205 of file Unit.h.
Referenced by getShield(), and update().
Position UnitClass::mStoredTargetPosition [private] |
Definition at line 194 of file Unit.h.
Referenced by getPosition(), getTargetPosition(), setPosition(), and update().
int UnitClass::mStoredTime [private] |
Definition at line 199 of file Unit.h.
Referenced by getLastSeenTime(), getPosition(), and update().
BWAPI::UnitType UnitClass::mStoredType [private] |
BWAPI::Unit* UnitClass::mUnit [private] |
Definition at line 191 of file Unit.h.
Referenced by accessibility(), attack(), build(), canAttack(), cancel(), exists(), gather(), getBuildType(), getBuildUnit(), getCompletedTime(), getDefenseMatrixPoints(), getEnergy(), getExistTime(), getHealth(), getID(), getLastCommand(), getOrder(), getPlayer(), getPosition(), getRemainingAirCooldown(), getRemainingGroundCooldown(), getRemainingResearchTime(), getRemainingTrainTime(), getRemainingUpgradeTime(), getResources(), getScarabCount(), getSecondaryOrder(), getShield(), getSpellCooldown(), getTarget(), getTargetPosition(), getTech(), getTilePosition(), getTrainingQueue(), getType(), getUpgrade(), hasAddon(), hasPath(), isAttackFrame(), isBeingConstructed(), isBeingHealed(), isBurrowed(), isCarryingGas(), isCarryingMinerals(), isCloaked(), isCompleted(), isConstructing(), isDetected(), isHealing(), isLifted(), isLoaded(), isLockedDown(), isMorphing(), isRepairing(), isResearching(), isSelected(), isSieged(), isStasised(), isStuck(), isTraining(), isUnderDarkSwarm(), isUnderStorm(), isUpgrading(), morph(), move(), promote(), research(), returnCargo(), stop(), train(), update(), upgrade(), and useTech().