CvCombatInfo::getDamageInflicted(BattleUnitTypes) const
- Defined in
- CvStructs.cpp, line 345
- Class
- CvCombatInfo
- Hook name
CivHooks::CvCombatInfo_getDamageInflicted- Lua events
GameEvents.BattleDamageDelta
Hooks
static bool BeforeCvCombatInfo_getDamageInflicted(const CvCombatInfo* self, BattleUnitTypes unitType, int& result);static void AfterCvCombatInfo_getDamageInflicted(const CvCombatInfo* self, BattleUnitTypes unitType, int& result);static int ReplaceCvCombatInfo_getDamageInflicted(int (*original)(const CvCombatInfo*, BattleUnitTypes), const CvCombatInfo* self, BattleUnitTypes unitType);CivRegisterBefore<CivHooks::CvCombatInfo_getDamageInflicted>(host, &BeforeCvCombatInfo_getDamageInflicted);CivRegisterAfter<CivHooks::CvCombatInfo_getDamageInflicted>(host, &AfterCvCombatInfo_getDamageInflicted);CivRegisterReplace<CivHooks::CvCombatInfo_getDamageInflicted>(host, &ReplaceCvCombatInfo_getDamageInflicted);
Code
345int CvCombatInfo::getDamageInflicted(BattleUnitTypes unitType) const346{347 checkBattleUnitType(unitType);348#if defined(MOD_EVENTS_BATTLES)349 int iDamage = m_iDamageInflicted[unitType];350351 if (MOD_EVENTS_BATTLES_DAMAGE) {352 int iValue = 0;353 if (GAMEEVENTINVOKE_VALUE(iValue, GAMEEVENT_BattleDamageDelta, unitType, iDamage) == GAMEEVENTRETURN_VALUE) {354 if (iValue != 0) {355 if (iValue < 0) {356 // Decreasing the amount of damage, in which case it can't be more than the amount inflicted (as that's called 'healing'!)357 if (iDamage + iValue < 0) {358 iValue = -iDamage;359 }360 } else {361 // Increasing the amount of damage, in which case we can't exceed unit/city hit points362 CvCity* pCity = m_pCities[unitType];363 if (pCity)364 {365 if (iDamage + iValue + pCity->getDamage() > pCity->GetMaxHitPoints())366 {367 iValue = pCity->GetMaxHitPoints() - pCity->getDamage() - iDamage;368 }369 }370 else371 {372 if (iDamage + iValue > m_pUnits[unitType]->GetCurrHitPoints())373 {374 iValue = m_pUnits[unitType]->GetCurrHitPoints() - iDamage;375 }376 }377 }378 379 iDamage += iValue;380 381// Fuck fucking C const, it should have been fucking banned fucking years ago!382// if (unitType == BATTLE_UNIT_ATTACKER) {383// m_iFinalDamage[BATTLE_UNIT_DEFENDER] += iValue;384// } else {385// m_iFinalDamage[BATTLE_UNIT_ATTACKER] += iValue;386// }387 }388 }389 }390391 return iDamage;392#else393 return m_iDamageInflicted[unitType];394#endif395}
Calls
Called by
- CvDllCombatInfo::GetDamageInflicted(BattleUnitTypes) const
- CvUnitCombat::ResolveAirSweep(const CvCombatInfo &, uint)
- CvUnitCombat::ResolveAirUnitVsCombat(const CvCombatInfo &, uint)
- CvUnitCombat::ResolveCityMeleeCombat(const CvCombatInfo &, uint)
- CvUnitCombat::ResolveMeleeCombat(const CvCombatInfo &, uint)
- CvUnitCombat::ResolveRangedCityVsUnitCombat(const CvCombatInfo &, uint)
- CvUnitCombat::ResolveRangedUnitVsCombat(const CvCombatInfo &, uint)