From a1144e3789ce193ea4f03bce353932daa8495067 Mon Sep 17 00:00:00 2001 From: Belonit <54427022+Belonit@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:02:21 +0300 Subject: [PATCH] Fix AllDestroyed TEvent in Ra2Mode --- src/Spawner/Ra2Mode.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Spawner/Ra2Mode.cpp b/src/Spawner/Ra2Mode.cpp index fa394264..8665644a 100644 --- a/src/Spawner/Ra2Mode.cpp +++ b/src/Spawner/Ra2Mode.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include bool Ra2Mode::Enabled = false; @@ -244,3 +245,32 @@ DEFINE_HOOK(0x73E3DB, UnitClass_MissionUnload__CheckPowerBeforeOrePurifier, 0x6) return 0x73E3DB + 0x6; } + +// Additionally check alive infantry in the allied transport +// and also check ActiveAircraftTypes +// https://github.com/CnCNet/cncnet-yr-client-package/issues/349 +DEFINE_HOOK(0x71F1A2, TEventClass_Execute_AllDestroyed, 0x6) +{ + if (!Ra2Mode::IsEnabled()) + return 0; + + if (!SessionClass::IsCampaign()) + return 0; + + enum { AllDestroyed = 0x71F1B1, HasAlive = 0x71F163 }; + GET(HouseClass*, pHouse, ESI); + + if (pHouse->ActiveAircraftTypes.GetTotal() > 0) + return HasAlive; + + if (pHouse->ActiveInfantryTypes.GetTotal() > 0) + return HasAlive; + + for (auto pItem : *InfantryClass::Array) + { + if (pItem->InLimbo && pHouse == pItem->GetOwningHouse() && pHouse->IsAlliedWith(pItem->Transporter)) + return HasAlive; + } + + return AllDestroyed; +}