CvCity::GetAirStrikeDefenseDamage(const CvUnit *, bool) const
- Defined in
- CvCity.cpp, line 16375
- Class
- CvCity
- Hook name
CivHooks::CvCity_GetAirStrikeDefenseDamage
Hooks
static bool BeforeCvCity_GetAirStrikeDefenseDamage(const CvCity* self, const CvUnit* pAttacker, bool bIncludeRand, int& result);static void AfterCvCity_GetAirStrikeDefenseDamage(const CvCity* self, const CvUnit* pAttacker, bool bIncludeRand, int& result);static int ReplaceCvCity_GetAirStrikeDefenseDamage(int (*original)(const CvCity*, const CvUnit*, bool), const CvCity* self, const CvUnit* pAttacker, bool bIncludeRand);CivRegisterBefore<CivHooks::CvCity_GetAirStrikeDefenseDamage>(host, &BeforeCvCity_GetAirStrikeDefenseDamage);CivRegisterAfter<CivHooks::CvCity_GetAirStrikeDefenseDamage>(host, &AfterCvCity_GetAirStrikeDefenseDamage);CivRegisterReplace<CivHooks::CvCity_GetAirStrikeDefenseDamage>(host, &ReplaceCvCity_GetAirStrikeDefenseDamage);
Code
16375int CvCity::GetAirStrikeDefenseDamage(const CvUnit* pAttacker, bool bIncludeRand) const16376{16377 int iAttackerStrength = pAttacker->GetMaxRangedCombatStrength(NULL, /*pCity*/ NULL, true, false);16378 int iDefenderStrength = getStrengthValue(false);1637916380 // The roll will vary damage between 2 and 3 (out of 10) for two units of identical strength1638116382 int iDefenderDamageRatio = GetMaxHitPoints() - getDamage();16383 int iDefenderDamage = /*200*/ GC.getAIR_STRIKE_SAME_STRENGTH_MIN_DEFENSE_DAMAGE() * iDefenderDamageRatio / GetMaxHitPoints();1638416385 int iDefenderRoll = 0;16386 if(bIncludeRand)16387 {16388 iDefenderRoll = /*200*/ GC.getGame().getJonRandNum(GC.getAIR_STRIKE_SAME_STRENGTH_POSSIBLE_EXTRA_DEFENSE_DAMAGE(), "Unit Air Strike Combat Damage");16389 iDefenderRoll *= iDefenderDamageRatio;16390 iDefenderRoll /= GetMaxHitPoints();16391 }16392 else16393 {16394 iDefenderRoll = /*200*/ GC.getAIR_STRIKE_SAME_STRENGTH_POSSIBLE_EXTRA_DEFENSE_DAMAGE();16395 iDefenderRoll -= 1; // Subtract 1 here, because this is the amount normally "lost" when doing a rand roll16396 iDefenderRoll *= iDefenderDamageRatio;16397 iDefenderRoll /= GetMaxHitPoints();16398 iDefenderRoll /= 2; // The divide by 2 is to provide the average damage16399 }16400 iDefenderDamage += iDefenderRoll;1640116402 double fStrengthRatio = (double(iDefenderStrength) / iAttackerStrength);1640316404 // In case our strength is less than the other guy's, we'll do things in reverse then make the ratio 1 over the result16405 if (iAttackerStrength > iDefenderStrength)16406 {16407 fStrengthRatio = (double(iAttackerStrength) / iDefenderStrength);16408 }1640916410 fStrengthRatio = (fStrengthRatio + 3) / 4;16411 fStrengthRatio = pow(fStrengthRatio, 4.0);16412 fStrengthRatio = (fStrengthRatio + 1) / 2;1641316414 if (iAttackerStrength > iDefenderStrength)16415 {16416 fStrengthRatio = 1 / fStrengthRatio;16417 }1641816419 iDefenderDamage = int(iDefenderDamage * fStrengthRatio);1642016421 // Bring it back out of hundreds16422 iDefenderDamage /= 100;1642316424 // Always do at least 1 damage16425 int iMinDamage = /*1*/ GC.getMIN_CITY_STRIKE_DAMAGE();16426 if(iDefenderDamage < iMinDamage)16427 iDefenderDamage = iMinDamage;1642816429 return iDefenderDamage;16430}
Calls
- CvCity::getDamage() const
- CvCity::GetMaxHitPoints() const
- CvCity::getStrengthValue(bool) const
- CvGame::getJonRandNum(int, const char *)
- CvGlobals::getAIR_STRIKE_SAME_STRENGTH_MIN_DEFENSE_DAMAGE()
- CvGlobals::getAIR_STRIKE_SAME_STRENGTH_POSSIBLE_EXTRA_DEFENSE_DAMAGE()
- CvGlobals::getGame()
- CvGlobals::getMIN_CITY_STRIKE_DAMAGE()
- CvUnit::GetMaxRangedCombatStrength(const CvUnit *, const CvCity *, bool, bool) const
pow