CvDiplomacyAI::DoUpdateWarDamageLevel()
- Defined in
- CvDiplomacyAI.cpp, line 8995
- Class
- CvDiplomacyAI
- Hook name
CivHooks::CvDiplomacyAI_DoUpdateWarDamageLevel
Hooks
static bool BeforeCvDiplomacyAI_DoUpdateWarDamageLevel(CvDiplomacyAI* self);static void AfterCvDiplomacyAI_DoUpdateWarDamageLevel(CvDiplomacyAI* self);static void ReplaceCvDiplomacyAI_DoUpdateWarDamageLevel(void (*original)(CvDiplomacyAI*), CvDiplomacyAI* self);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateWarDamageLevel>(host, &BeforeCvDiplomacyAI_DoUpdateWarDamageLevel);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateWarDamageLevel>(host, &AfterCvDiplomacyAI_DoUpdateWarDamageLevel);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateWarDamageLevel>(host, &ReplaceCvDiplomacyAI_DoUpdateWarDamageLevel);
Code
8994/// Updates how much damage have we taken in a war against all Players8995void CvDiplomacyAI::DoUpdateWarDamageLevel()8996{8997 PlayerTypes eLoopPlayer;89988999 WarDamageLevelTypes eWarDamageLevel;90009001 int iValueLost;9002 int iCurrentValue;9003 int iValueLostRatio;90049005 CvCity* pLoopCity;9006 CvUnit* pLoopUnit;9007 int iValueLoop;90089009 // Calculate the value of what we have currently9010 // This is invariant so we will just do it once9011 iCurrentValue = 0;90129013 int iTypicalPower = m_pPlayer->GetMilitaryAI()->GetPowerOfStrongestBuildableUnit(DOMAIN_LAND);9014 // City value9015 for(pLoopCity = GetPlayer()->firstCity(&iValueLoop); pLoopCity != NULL; pLoopCity = GetPlayer()->nextCity(&iValueLoop))9016 {9017 iCurrentValue += (pLoopCity->getPopulation() * /*150*/ GC.getWAR_DAMAGE_LEVEL_INVOLVED_CITY_POP_MULTIPLIER());9018 if (pLoopCity->IsOriginalCapital()) // anybody's9019 {9020 iCurrentValue *= 3;9021 iCurrentValue /= 2;9022 }9023 }90249025 // Unit value9026 for(pLoopUnit = GetPlayer()->firstUnit(&iValueLoop); pLoopUnit != NULL; pLoopUnit = GetPlayer()->nextUnit(&iValueLoop))9027 {9028 CvUnitEntry* pkUnitInfo = GC.getUnitInfo(pLoopUnit->getUnitType());9029 if(pkUnitInfo)9030 {9031 int iUnitValue = pkUnitInfo->GetPower();9032 if(iTypicalPower > 0)9033 {9034 iUnitValue = iUnitValue* /*100*/ GC.getDEFAULT_WAR_VALUE_FOR_UNIT() / iTypicalPower;9035 }9036 else9037 {9038 iUnitValue = /*100*/ GC.getDEFAULT_WAR_VALUE_FOR_UNIT();9039 }9040 iCurrentValue += iUnitValue;9041 }9042 }90439044 // Loop through all (known) Players9045 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)9046 {9047 eLoopPlayer = (PlayerTypes) iPlayerLoop;90489049 if(IsPlayerValid(eLoopPlayer))9050 {9051 eWarDamageLevel = WAR_DAMAGE_LEVEL_NONE;90529053 iValueLost = GetWarValueLost(eLoopPlayer);90549055 if(iValueLost > 0)9056 {9057 // Total original value is the current value plus the amount lost, so compute the percentage on that9058 if(iCurrentValue > 0)9059 iValueLostRatio = iValueLost * 100 / (iCurrentValue + iValueLost);9060 else9061 iValueLostRatio = iValueLost;90629063 if(iValueLostRatio >= /*67*/ GC.getWAR_DAMAGE_LEVEL_THRESHOLD_CRIPPLED())9064 eWarDamageLevel = WAR_DAMAGE_LEVEL_CRIPPLED;9065 else if(iValueLostRatio >= /*50*/ GC.getWAR_DAMAGE_LEVEL_THRESHOLD_SERIOUS())9066 eWarDamageLevel = WAR_DAMAGE_LEVEL_SERIOUS;9067 else if(iValueLostRatio >= /*25*/ GC.getWAR_DAMAGE_LEVEL_THRESHOLD_MAJOR())9068 eWarDamageLevel = WAR_DAMAGE_LEVEL_MAJOR;9069 else if(iValueLostRatio >= /*10*/ GC.getWAR_DAMAGE_LEVEL_THRESHOLD_MINOR())9070 eWarDamageLevel = WAR_DAMAGE_LEVEL_MINOR;9071 }90729073 SetWarDamageLevel(eLoopPlayer, eWarDamageLevel);9074 }9075 }9076}
Calls
- CvCity::getPopulation(bool) const
- CvCity::IsOriginalCapital() const
- CvDiplomacyAI::GetPlayer()
- CvDiplomacyAI::GetWarValueLost(PlayerTypes) const
- CvDiplomacyAI::IsPlayerValid(PlayerTypes, bool)
- CvDiplomacyAI::SetWarDamageLevel(PlayerTypes, WarDamageLevelTypes)
- CvGlobals::getDEFAULT_WAR_VALUE_FOR_UNIT()
- CvGlobals::getUnitInfo(UnitTypes)
- CvGlobals::getWAR_DAMAGE_LEVEL_INVOLVED_CITY_POP_MULTIPLIER()
- CvGlobals::getWAR_DAMAGE_LEVEL_THRESHOLD_CRIPPLED()
- CvGlobals::getWAR_DAMAGE_LEVEL_THRESHOLD_MAJOR()
- CvGlobals::getWAR_DAMAGE_LEVEL_THRESHOLD_MINOR()
- CvGlobals::getWAR_DAMAGE_LEVEL_THRESHOLD_SERIOUS()
- CvMilitaryAI::GetPowerOfStrongestBuildableUnit(DomainTypes)
- CvPlayer::firstCity(int *, bool)
- CvPlayer::firstUnit(int *, bool)
- CvPlayer::GetMilitaryAI() const
- CvPlayer::nextCity(int *, bool)
- CvPlayer::nextUnit(int *, bool)
- CvUnit::getUnitType() const
- CvUnitEntry::GetPower() const