CvCity::rangeCombatDamage(const CvUnit *, CvCity *, bool) const
- Defined in
- CvCity.cpp, line 16299
- Class
- CvCity
- Hook name
CivHooks::CvCity_rangeCombatDamage
Hooks
static bool BeforeCvCity_rangeCombatDamage(const CvCity* self, const CvUnit* pDefender, CvCity* pCity, bool bIncludeRand, int& result);static void AfterCvCity_rangeCombatDamage(const CvCity* self, const CvUnit* pDefender, CvCity* pCity, bool bIncludeRand, int& result);static int ReplaceCvCity_rangeCombatDamage(int (*original)(const CvCity*, const CvUnit*, CvCity*, bool), const CvCity* self, const CvUnit* pDefender, CvCity* pCity, bool bIncludeRand);CivRegisterBefore<CivHooks::CvCity_rangeCombatDamage>(host, &BeforeCvCity_rangeCombatDamage);CivRegisterAfter<CivHooks::CvCity_rangeCombatDamage>(host, &AfterCvCity_rangeCombatDamage);CivRegisterReplace<CivHooks::CvCity_rangeCombatDamage>(host, &ReplaceCvCity_rangeCombatDamage);
Code
16299int CvCity::rangeCombatDamage(const CvUnit* pDefender, CvCity* pCity, bool bIncludeRand) const16300{16301 VALIDATE_OBJECT16302 int iAttackerStrength;1630316304 iAttackerStrength = getStrengthValue(true);1630516306 int iDefenderStrength;1630716308 // No City16309 if(pCity == NULL)16310 {16311 // If this is a defenseless unit, do a fixed amount of damage16312 if(!pDefender->IsCanDefend())16313 {16314 return GC.getNONCOMBAT_UNIT_RANGED_DAMAGE();16315 }1631616317 iDefenderStrength = rangeCombatUnitDefense(pDefender);1631816319 }16320 // City16321 else16322 {16323 iDefenderStrength = pCity->getStrengthValue();16324 }1632516326 // The roll will vary damage between 30 and 40 (out of 100) for two units of identical strength1632716328 int iAttackerDamage = /*250*/ GC.getRANGE_ATTACK_SAME_STRENGTH_MIN_DAMAGE();1632916330 int iAttackerRoll = 0;16331 if(bIncludeRand)16332 {16333 iAttackerRoll = GC.getGame().getJonRandNum(/*300*/ GC.getRANGE_ATTACK_SAME_STRENGTH_POSSIBLE_EXTRA_DAMAGE(), "City Ranged Attack Damage");16334 }16335 else16336 {16337 iAttackerRoll = /*300*/ GC.getRANGE_ATTACK_SAME_STRENGTH_POSSIBLE_EXTRA_DAMAGE();16338 iAttackerRoll -= 1; // Subtract 1 here, because this is the amount normally "lost" when doing a rand roll16339 iAttackerRoll /= 2; // The divide by 2 is to provide the average damage16340 }16341 iAttackerDamage += iAttackerRoll;163421634316344 double fStrengthRatio = (double(iAttackerStrength) / iDefenderStrength);1634516346 // In case our strength is less than the other guy's, we'll do things in reverse then make the ratio 1 over the result16347 if(iDefenderStrength > iAttackerStrength)16348 {16349 fStrengthRatio = (double(iDefenderStrength) / iAttackerStrength);16350 }1635116352 fStrengthRatio = (fStrengthRatio + 3) / 4;16353 fStrengthRatio = pow(fStrengthRatio, 4.0);16354 fStrengthRatio = (fStrengthRatio + 1) / 2;1635516356 if(iDefenderStrength > iAttackerStrength)16357 {16358 fStrengthRatio = 1 / fStrengthRatio;16359 }1636016361 iAttackerDamage = int(iAttackerDamage * fStrengthRatio);1636216363 // Bring it back out of hundreds16364 iAttackerDamage /= 100;1636516366 // Always do at least 1 damage16367 int iMinDamage = /*1*/ GC.getMIN_CITY_STRIKE_DAMAGE();16368 if(iAttackerDamage < iMinDamage)16369 iAttackerDamage = iMinDamage;1637016371 return iAttackerDamage;16372}
Calls
- CvCity::getStrengthValue(bool) const
- CvCity::rangeCombatUnitDefense(const CvUnit *) const
- CvGame::getJonRandNum(int, const char *)
- CvGlobals::getGame()
- CvGlobals::getMIN_CITY_STRIKE_DAMAGE()
- CvGlobals::getNONCOMBAT_UNIT_RANGED_DAMAGE()
- CvGlobals::getRANGE_ATTACK_SAME_STRENGTH_MIN_DAMAGE()
- CvGlobals::getRANGE_ATTACK_SAME_STRENGTH_POSSIBLE_EXTRA_DAMAGE()
- CvUnit::IsCanDefend(const CvPlot *) const
pow