Hooks
static bool BeforeCvUnit_GetParadropInterceptionDamage(const CvUnit* self, const CvUnit* pAttacker, bool bIncludeRand, int& result);static void AfterCvUnit_GetParadropInterceptionDamage(const CvUnit* self, const CvUnit* pAttacker, bool bIncludeRand, int& result);static int ReplaceCvUnit_GetParadropInterceptionDamage(int (*original)(const CvUnit*, const CvUnit*, bool), const CvUnit* self, const CvUnit* pAttacker, bool bIncludeRand);CivRegisterBefore<CivHooks::CvUnit_GetParadropInterceptionDamage>(host, &BeforeCvUnit_GetParadropInterceptionDamage);CivRegisterAfter<CivHooks::CvUnit_GetParadropInterceptionDamage>(host, &AfterCvUnit_GetParadropInterceptionDamage);CivRegisterReplace<CivHooks::CvUnit_GetParadropInterceptionDamage>(host, &ReplaceCvUnit_GetParadropInterceptionDamage);
Code
13700#if defined(MOD_GLOBAL_PARATROOPS_AA_DAMAGE)13701/// Amount of damage done by this unit when intercepting a paratrooper13702// (This code is basically the same as GetInterceptionDamage() except it uses the attacker's defensive strength)13703int CvUnit::GetParadropInterceptionDamage(const CvUnit* pAttacker, bool bIncludeRand) const13704{13705 int iAttackerStrength = pAttacker->GetMaxDefenseStrength(plot(), this);1370613707 int iInterceptorStrength = 0;1370813709#if defined(MOD_BUGFIX_INTERCEPTOR_STRENGTH)13710 if (MOD_BUGFIX_INTERCEPTOR_STRENGTH) {13711 switch (getDomainType()) {13712 case DOMAIN_SEA:13713 iInterceptorStrength = GetMaxDefenseStrength(plot(), pAttacker);13714 break;1371513716 case DOMAIN_AIR:13717 iInterceptorStrength = GetMaxRangedCombatStrength(pAttacker, /*pCity*/ NULL, false, /*bForRangedAttack*/ false);13718 break;1371913720 case DOMAIN_LAND:13721 iInterceptorStrength = GetMaxAttackStrength(NULL, NULL, pAttacker);13722 break;1372313724 case DOMAIN_IMMOBILE:13725 iInterceptorStrength = GetMaxAttackStrength(NULL, NULL, pAttacker);13726 break;1372713728 default:13729 CvAssert(false);13730 break;13731 }13732 } else {13733#else13734 // Use Ranged combat value for Interceptor, UNLESS it's a boat13735 if(GetMaxRangedCombatStrength(this, /*pCity*/ NULL, false, false) > 0 && !getDomainType() == DOMAIN_SEA)13736 {13737 iInterceptorStrength = GetMaxRangedCombatStrength(pAttacker, /*pCity*/ NULL, false, /*bForRangedAttack*/ false);13738 }13739 else13740 {13741 iInterceptorStrength = GetMaxDefenseStrength(plot(), pAttacker);13742 }13743#endif13744#if defined(MOD_BUGFIX_INTERCEPTOR_STRENGTH)13745 }13746 // CUSTOMLOG("Interceptor base str against paradrop for player/unit %i/%i is %i", getOwner(), GetID(), iInterceptorStrength);13747#endif1374813749 // Mod to interceptor strength13750 iInterceptorStrength *= (100 + GetInterceptionCombatModifier());13751 iInterceptorStrength /= 100;13752 // CUSTOMLOG("ParadropIntercept: Paratrooper str=%i, Interceptor str=%i", iAttackerStrength, iInterceptorStrength)1375313754 // The roll will vary damage between 2 and 3 (out of 10) for two units of identical strength1375513756#if defined(MOD_UNITS_MAX_HP)13757 int iInterceptorDamageRatio = GetMaxHitPoints() - getDamage();13758 int iInterceptorDamage = /*400*/ GC.getINTERCEPTION_SAME_STRENGTH_MIN_DAMAGE() * iInterceptorDamageRatio / GetMaxHitPoints();13759#else13760 int iInterceptorDamageRatio = GC.getMAX_HIT_POINTS() - getDamage();13761 int iInterceptorDamage = /*400*/ GC.getINTERCEPTION_SAME_STRENGTH_MIN_DAMAGE() * iInterceptorDamageRatio / GC.getMAX_HIT_POINTS();13762#endif1376313764 int iInterceptorRoll = 0;13765 if(bIncludeRand)13766 {13767 iInterceptorRoll = /*300*/ GC.getGame().getJonRandNum(GC.getINTERCEPTION_SAME_STRENGTH_POSSIBLE_EXTRA_DAMAGE(), "Interception Combat Damage");13768 iInterceptorRoll *= iInterceptorDamageRatio;13769#if defined(MOD_UNITS_MAX_HP)13770 iInterceptorRoll /= GetMaxHitPoints();13771#else13772 iInterceptorRoll /= GC.getMAX_HIT_POINTS();13773#endif13774 }13775 else13776 {13777 iInterceptorRoll = /*300*/ GC.getINTERCEPTION_SAME_STRENGTH_POSSIBLE_EXTRA_DAMAGE();13778 iInterceptorRoll -= 1; // Subtract 1 here, because this is the amount normally "lost" when doing a rand roll13779 iInterceptorRoll *= iInterceptorDamageRatio;13780#if defined(MOD_UNITS_MAX_HP)13781 iInterceptorRoll /= GetMaxHitPoints();13782#else13783 iInterceptorRoll /= GC.getMAX_HIT_POINTS();13784#endif13785 iInterceptorRoll /= 2; // The divide by 2 is to provide the average damage13786 }13787 iInterceptorDamage += iInterceptorRoll;1378813789 double fStrengthRatio = (double(iInterceptorStrength) / iAttackerStrength);1379013791 // In case our strength is less than the other guy's, we'll do things in reverse then make the ratio 1 over the result13792 if(iAttackerStrength > iInterceptorStrength)13793 {13794 fStrengthRatio = (double(iAttackerStrength) / iInterceptorStrength);13795 }1379613797 fStrengthRatio = (fStrengthRatio + 3) / 4;13798 fStrengthRatio = pow(fStrengthRatio, 4.0);13799 fStrengthRatio = (fStrengthRatio + 1) / 2;1380013801 if(iAttackerStrength > iInterceptorStrength)13802 {13803 fStrengthRatio = 1 / fStrengthRatio;13804 }1380513806 iInterceptorDamage = int(iInterceptorDamage * fStrengthRatio);1380713808 // Mod to interception damage13809 iInterceptorDamage *= (100 + pAttacker->GetInterceptionDefenseDamageModifier());13810 iInterceptorDamage /= 100;1381113812 // Bring it back out of hundreds13813 iInterceptorDamage /= 100;1381413815 iInterceptorDamage = max(1,iInterceptorDamage);1381613817 return iInterceptorDamage;13818}