CvUnit::IsUnderEnemyRangedAttack() const
- Defined in
- CvUnit.cpp, line 16979
- Class
- CvUnit
- Hook name
CivHooks::CvUnit_IsUnderEnemyRangedAttack
Hooks
static bool BeforeCvUnit_IsUnderEnemyRangedAttack(const CvUnit* self, bool& result);static void AfterCvUnit_IsUnderEnemyRangedAttack(const CvUnit* self, bool& result);static bool ReplaceCvUnit_IsUnderEnemyRangedAttack(bool (*original)(const CvUnit*), const CvUnit* self);CivRegisterBefore<CivHooks::CvUnit_IsUnderEnemyRangedAttack>(host, &BeforeCvUnit_IsUnderEnemyRangedAttack);CivRegisterAfter<CivHooks::CvUnit_IsUnderEnemyRangedAttack>(host, &AfterCvUnit_IsUnderEnemyRangedAttack);CivRegisterReplace<CivHooks::CvUnit_IsUnderEnemyRangedAttack>(host, &ReplaceCvUnit_IsUnderEnemyRangedAttack);
Code
16978/// Is this Unit under ranged fire from an enemy unit that can do it significant damage?16979bool CvUnit::IsUnderEnemyRangedAttack() const16980{16981 PlayerTypes eLoopPlayer;16982 int iTotalDamage = 0;1698316984 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)16985 {16986 eLoopPlayer = (PlayerTypes) iPlayerLoop;16987 CvPlayer &kPlayer = GET_PLAYER(eLoopPlayer);16988 if(kPlayer.isAlive())16989 {16990 if (atWar(getTeam(), kPlayer.getTeam()))16991 {16992 int iLoop;16993 CvCity *pLoopCity;16994 for(pLoopCity = kPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kPlayer.nextCity(&iLoop))16995 {16996 if(pLoopCity->canRangeStrikeAt(getX(), getY()))16997 {16998 return true;16999 }17000 }1700117002 CvUnit *pLoopUnit;17003 for(pLoopUnit = kPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = kPlayer.nextUnit(&iLoop))17004 {17005 if(pLoopUnit)17006 {17007 if(!pLoopUnit->IsCanAttack())17008 {17009 continue;17010 }1701117012 if(pLoopUnit->IsCanAttackRanged())17013 {17014 // Are we in range?17015 if(plotDistance(pLoopUnit->getX(), pLoopUnit->getY(), getX(), getY()) <= pLoopUnit->GetRange())17016 {17017 // Do we have LOS to the target?17018 if(pLoopUnit->canEverRangeStrikeAt(getX(), getY()))17019 {17020 // Will we do any damage17021 int iExpectedDamage = pLoopUnit->GetRangeCombatDamage(this, NULL, false);17022 iTotalDamage += iExpectedDamage;17023 if (iTotalDamage > healRate(plot()))17024 {17025 return true;17026 }17027 }17028 }17029 }17030 }17031 }17032 }17033 }17034 }1703517036 return false;17037}
Calls
- atWar(TeamTypes, TeamTypes)
- CvCity::canRangeStrikeAt(int, int) const
- CvPlayer::firstCity(int *, bool)
- CvPlayer::firstUnit(int *, bool)
- CvPlayer::getTeam() const
- CvPlayer::isAlive() const
- CvPlayer::nextCity(int *, bool)
- CvPlayer::nextUnit(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvUnit::canEverRangeStrikeAt(int, int, const CvPlot *) const
- CvUnit::GetRange() const
- CvUnit::GetRangeCombatDamage(const CvUnit *, CvCity *, bool, int) const
- CvUnit::getTeam() const
- CvUnit::getX() const
- CvUnit::getY() const
- CvUnit::healRate(const CvPlot *) const
- CvUnit::IsCanAttack() const
- CvUnit::IsCanAttackRanged() const
- CvUnit::plot() const
- plotDistance(int, int, int, int)