Bazaar developer reference

CvUnit::GetInterceptionDamage(const CvUnit *, bool) const

Defined in
CvUnit.cpp, line 13581
Class
CvUnit
Hook name
CivHooks::CvUnit_GetInterceptionDamage

Hooks

static bool BeforeCvUnit_GetInterceptionDamage(const CvUnit* self, const CvUnit* pAttacker, bool bIncludeRand, int& result);static void AfterCvUnit_GetInterceptionDamage(const CvUnit* self, const CvUnit* pAttacker, bool bIncludeRand, int& result);static int ReplaceCvUnit_GetInterceptionDamage(int (*original)(const CvUnit*, const CvUnit*, bool), const CvUnit* self, const CvUnit* pAttacker, bool bIncludeRand);CivRegisterBefore<CivHooks::CvUnit_GetInterceptionDamage>(host, &BeforeCvUnit_GetInterceptionDamage);CivRegisterAfter<CivHooks::CvUnit_GetInterceptionDamage>(host, &AfterCvUnit_GetInterceptionDamage);CivRegisterReplace<CivHooks::CvUnit_GetInterceptionDamage>(host, &ReplaceCvUnit_GetInterceptionDamage);

Code

13580/// Amount of damage done by this unit when intercepting pAttacker13581int CvUnit::GetInterceptionDamage(const CvUnit* pAttacker, bool bIncludeRand) const13582{13583	int iAttackerStrength = pAttacker->GetMaxRangedCombatStrength(this, /*pCity*/ NULL, true, /*bForRangedAttack*/ false);1358413585	int iInterceptorStrength = 0;13586#if defined(MOD_BUGFIX_INTERCEPTOR_STRENGTH)13587	if (MOD_BUGFIX_INTERCEPTOR_STRENGTH) {13588		switch (getDomainType()) {13589			case DOMAIN_SEA:13590				iInterceptorStrength = GetMaxDefenseStrength(plot(), pAttacker);13591				break;1359213593			case DOMAIN_AIR:13594				iInterceptorStrength = GetMaxRangedCombatStrength(pAttacker, /*pCity*/ NULL, false, /*bForRangedAttack*/ false);13595				break;1359613597			case DOMAIN_LAND:13598				iInterceptorStrength = GetMaxAttackStrength(NULL, NULL, pAttacker);13599				break;1360013601			case DOMAIN_IMMOBILE:13602				iInterceptorStrength = GetMaxAttackStrength(NULL, NULL, pAttacker);13603				break;1360413605			case DOMAIN_HOVER:13606				iInterceptorStrength = GetMaxAttackStrength(NULL, NULL, pAttacker);13607				break;1360813609			default:13610				CvAssert(false);13611				break;13612		}13613	} else {13614#endif13615		// Use Ranged combat value for Interceptor, UNLESS it's a boat13616		if(GetMaxRangedCombatStrength(this, /*pCity*/ NULL, false, false) > 0 && !getDomainType() == DOMAIN_SEA)13617		{13618			iInterceptorStrength = GetMaxRangedCombatStrength(pAttacker, /*pCity*/ NULL, false, /*bForRangedAttack*/ false);13619		}13620		else13621		{13622			iInterceptorStrength = GetMaxDefenseStrength(plot(), pAttacker);13623		}13624#if defined(MOD_BUGFIX_INTERCEPTOR_STRENGTH)13625	}13626	CUSTOMLOG("Interceptor base str for player/unit %i/%i is %i", getOwner(), GetID(), iInterceptorStrength);13627#endif1362813629	// Mod to interceptor strength13630	iInterceptorStrength *= (100 + GetInterceptionCombatModifier());13631	iInterceptorStrength /= 100;1363213633	// The roll will vary damage between 2 and 3 (out of 10) for two units of identical strength1363413635#if defined(MOD_UNITS_MAX_HP)13636	int iInterceptorDamageRatio = GetMaxHitPoints() - getDamage();13637	int iInterceptorDamage = /*400*/ GC.getINTERCEPTION_SAME_STRENGTH_MIN_DAMAGE() * iInterceptorDamageRatio / GetMaxHitPoints();13638#else13639	int iInterceptorDamageRatio = GC.getMAX_HIT_POINTS() - getDamage();13640	int iInterceptorDamage = /*400*/ GC.getINTERCEPTION_SAME_STRENGTH_MIN_DAMAGE() * iInterceptorDamageRatio / GC.getMAX_HIT_POINTS();13641#endif1364213643	int iInterceptorRoll = 0;13644	if(bIncludeRand)13645	{13646		iInterceptorRoll = /*300*/ GC.getGame().getJonRandNum(GC.getINTERCEPTION_SAME_STRENGTH_POSSIBLE_EXTRA_DAMAGE(), "Interception Combat Damage");13647		iInterceptorRoll *= iInterceptorDamageRatio;13648#if defined(MOD_UNITS_MAX_HP)13649		iInterceptorRoll /= GetMaxHitPoints();13650#else13651		iInterceptorRoll /= GC.getMAX_HIT_POINTS();13652#endif13653	}13654	else13655	{13656		iInterceptorRoll = /*300*/ GC.getINTERCEPTION_SAME_STRENGTH_POSSIBLE_EXTRA_DAMAGE();13657		iInterceptorRoll -= 1;	// Subtract 1 here, because this is the amount normally "lost" when doing a rand roll13658		iInterceptorRoll *= iInterceptorDamageRatio;13659#if defined(MOD_UNITS_MAX_HP)13660		iInterceptorRoll /= GetMaxHitPoints();13661#else13662		iInterceptorRoll /= GC.getMAX_HIT_POINTS();13663#endif13664		iInterceptorRoll /= 2;	// The divide by 2 is to provide the average damage13665	}13666	iInterceptorDamage += iInterceptorRoll;1366713668	double fStrengthRatio = (double(iInterceptorStrength) / iAttackerStrength);1366913670	// In case our strength is less than the other guy's, we'll do things in reverse then make the ratio 1 over the result13671	if(iAttackerStrength > iInterceptorStrength)13672	{13673		fStrengthRatio = (double(iAttackerStrength) / iInterceptorStrength);13674	}1367513676	fStrengthRatio = (fStrengthRatio + 3) / 4;13677	fStrengthRatio = pow(fStrengthRatio, 4.0);13678	fStrengthRatio = (fStrengthRatio + 1) / 2;1367913680	if(iAttackerStrength > iInterceptorStrength)13681	{13682		fStrengthRatio = 1 / fStrengthRatio;13683	}1368413685	iInterceptorDamage = int(iInterceptorDamage * fStrengthRatio);1368613687	// Mod to interception damage13688	iInterceptorDamage *= (100 + pAttacker->GetInterceptionDefenseDamageModifier());13689	iInterceptorDamage /= 100;1369013691	// Bring it back out of hundreds13692	iInterceptorDamage /= 100;1369313694	iInterceptorDamage = max(1,iInterceptorDamage);1369513696	CUSTOMLOG("Interceptor damage by player/unit %i/%i is %i", getOwner(), GetID(), iInterceptorDamage);13697	return iInterceptorDamage;13698}

Calls

Called by