Hooks
static bool BeforeCvUnitCombat_ParadropIntercept(CvUnit& pParaUnit, CvPlot& pDropPlot, bool& result);static void AfterCvUnitCombat_ParadropIntercept(CvUnit& pParaUnit, CvPlot& pDropPlot, bool& result);static bool ReplaceCvUnitCombat_ParadropIntercept(bool (*original)(CvUnit&, CvPlot&), CvUnit& pParaUnit, CvPlot& pDropPlot);CivRegisterBefore<CivHooks::CvUnitCombat_ParadropIntercept>(host, &BeforeCvUnitCombat_ParadropIntercept);CivRegisterAfter<CivHooks::CvUnitCombat_ParadropIntercept>(host, &AfterCvUnitCombat_ParadropIntercept);CivRegisterReplace<CivHooks::CvUnitCombat_ParadropIntercept>(host, &ReplaceCvUnitCombat_ParadropIntercept);
Code
2812bool CvUnitCombat::ParadropIntercept(CvUnit& pParaUnit, CvPlot& pDropPlot) {2813 CvAssertMsg(!pParaUnit.isDelayedDeath(), "Trying to paradrop and the unit is already dead!");2814 CvAssert(pParaUnit.getCombatTimer() == 0);2815 2816 // Any interception to be done?2817 CvUnit* pInterceptor = pParaUnit.GetBestInterceptor(pDropPlot, NULL);2818 if (pInterceptor) {2819 uint uiParentEventID = 0;2820 int iInterceptionDamage = 0;28212822 // Is the interception successful?2823 if(GC.getGame().getJonRandNum(100, "Intercept Rand (Paradrop)") < pInterceptor->currInterceptionProbability())2824 {2825 iInterceptionDamage = pInterceptor->GetParadropInterceptionDamage(&pParaUnit);2826 }2827 2828 if (iInterceptionDamage > 0) {2829#if defined(MOD_EVENTS_BATTLES)2830 if (MOD_EVENTS_BATTLES) {2831 BATTLE_STARTED(BATTLE_TYPE_PARADROP, pDropPlot);2832 BATTLE_JOINED(&pParaUnit, BATTLE_UNIT_ATTACKER, false);2833 BATTLE_JOINED(pInterceptor, BATTLE_UNIT_INTERCEPTOR, false);28342835 if (MOD_EVENTS_BATTLES_DAMAGE) {2836 int iValue = 0;2837 if (GAMEEVENTINVOKE_VALUE(iValue, GAMEEVENT_BattleDamageDelta, BATTLE_UNIT_INTERCEPTOR, iInterceptionDamage) == GAMEEVENTRETURN_VALUE) {2838 if (iValue != 0) {2839 if (iValue < 0) {2840 // Decreasing the amount of damage, in which case it can't be more than the amount inflicted (as that's called 'healing'!)2841 if (iInterceptionDamage + iValue < 0) {2842 iValue = -iInterceptionDamage;2843 }2844 } else {2845 // Increasing the amount of damage, in which case we can't exceed unit's hit points2846 if (iInterceptionDamage + iValue > pParaUnit.GetCurrHitPoints()) {2847 iValue = pParaUnit.GetCurrHitPoints() - iInterceptionDamage;2848 }2849 }2850 2851 iInterceptionDamage += iValue;2852 }2853 }2854 }2855 }2856#endif28572858 CUSTOMLOG("Paradrop: hostile AA did %i damage", iInterceptionDamage);2859 // Play the AA animations here ... but without an air attacker it's just not possible!!!2860 // if (!CvPreGame::quickCombat()) {2861 // Center camera here (pDropPlot MUST be visible or couldn't drop onto it!)2862 // auto_ptr<ICvPlot1> pDllTargetPlot = GC.WrapPlotPointer(&pDropPlot);2863 // GC.GetEngineUserInterface()->lookAt(pDllTargetPlot.get(), CAMERALOOKAT_NORMAL);2864 // kCombatInfo.setVisualizeCombat(true);28652866 // auto_ptr<ICvCombatInfo1> pDllCombatInfo(new CvDllCombatInfo(&kCombatInfo));2867 // uiParentEventID = gDLL->GameplayUnitCombat(pDllCombatInfo.get());28682869 // Set the combat units so that other missions do not continue until combat is over.2870 // pInterceptor->setCombatUnit(&pParaUnit, false);2871 // }28722873 pInterceptor->setMadeInterception(true);2874 pInterceptor->setCombatUnit(NULL);28752876 // Killing the unit during the drop is a really bad idea, the game crashes at random after the drop2877 int iHealth = pParaUnit.GetMaxHitPoints() - pParaUnit.GetCurrHitPoints();2878#if defined(MOD_API_UNIT_STATS)2879 pParaUnit.changeDamage(std::min(iHealth - 1, iInterceptionDamage), pInterceptor->getOwner(), pInterceptor->GetID());2880#else2881 pParaUnit.changeDamage(std::min(iHealth - 1, iInterceptionDamage), pInterceptor->getOwner());2882#endif28832884 if (GC.getGame().getActivePlayer() == pParaUnit.getOwner()) {2885 CvString strBuffer;2886 if (pParaUnit.IsDead()) {2887 strBuffer = GetLocalizedText("TXT_KEY_PARADROP_AA_KILLED", pParaUnit.getNameKey(), pInterceptor->getNameKey());2888 } else {2889 strBuffer = GetLocalizedText("TXT_KEY_PARADROP_AA_DAMAGED", pParaUnit.getNameKey(), pInterceptor->getNameKey(), iInterceptionDamage);2890 }2891 GC.GetEngineUserInterface()->AddMessage(uiParentEventID, pParaUnit.getOwner(), true, GC.getEVENT_MESSAGE_TIME(), strBuffer);2892 MILITARYLOG(pParaUnit.getOwner(), strBuffer.c_str(), pParaUnit.plot(), pInterceptor->getOwner());2893 }2894 2895 BATTLE_FINISHED();2896 }2897 }2898 2899 return pParaUnit.IsDead();2900}