|
| 1 | +#include <Helpers/Macro.h> |
| 2 | +#include <TunnelLocomotionClass.h> |
| 3 | + |
| 4 | +#include <Ext/TechnoType/Body.h> |
| 5 | + |
| 6 | +namespace UnitUnloadTemp |
| 7 | +{ |
| 8 | + TechnoTypeExt::ExtData* TypeExtData = nullptr; |
| 9 | +} |
| 10 | + |
| 11 | +// Prevent subterranean units from deploying while underground. |
| 12 | +DEFINE_HOOK(0x73D63B, UnitClass_Mi_Unload_Subterranean, 0x6) |
| 13 | +{ |
| 14 | + enum { ReturnFromFunction = 0x73DFB0, SkipHarvester = 0x73D694, SkipPassengers = 0x73DCD3, Harvester = 0x73DEE7, Continue = 0x73D6EC }; |
| 15 | + |
| 16 | + GET(UnitClass* const, pThis, ESI); |
| 17 | + |
| 18 | + if (auto const pLoco = locomotion_cast<TunnelLocomotionClass*>(pThis->Locomotor)) |
| 19 | + { |
| 20 | + if (pLoco->State != TunnelLocomotionClass::State::Idle) |
| 21 | + return ReturnFromFunction; |
| 22 | + } |
| 23 | + |
| 24 | + auto const pType = pThis->Type; |
| 25 | + auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType); |
| 26 | + UnitUnloadTemp::TypeExtData = pTypeExt; |
| 27 | + |
| 28 | + // It should be the highest priority. |
| 29 | + if (pThis->BunkerLinkedItem) |
| 30 | + { |
| 31 | + if (auto const pBuilding = pThis->GetCell()->GetBuilding()) |
| 32 | + pBuilding->EmptyBunker(); |
| 33 | + |
| 34 | + // It can fix the issue where mining carts cannot move. |
| 35 | + R->EAX(pType); |
| 36 | + return SkipHarvester; |
| 37 | + } |
| 38 | + |
| 39 | + // Miners should not be hindered by other deployment actions while unloading minerals. |
| 40 | + if (pType->Harvester || pType->Weeder) |
| 41 | + { |
| 42 | + const bool hasAnyLink = pThis->HasAnyLink(); |
| 43 | + |
| 44 | + if (hasAnyLink || pThis->Unloading) |
| 45 | + { |
| 46 | + R->AL(hasAnyLink); |
| 47 | + return Harvester; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + R->EAX(pType); |
| 52 | + |
| 53 | + if (pTypeExt->Deploy_SkipPassengerUnload) |
| 54 | + return SkipPassengers; |
| 55 | + else if (pTypeExt->Deploy_NoPassenger && pThis->Passengers.NumPassengers <= 0 && pThis->MissionStatus == 0) |
| 56 | + return SkipPassengers; |
| 57 | + |
| 58 | + return Continue; |
| 59 | +} |
| 60 | + |
| 61 | +DEFINE_HOOK(0x73DEEB, UnitClass_Mi_Unload_SkipHarvester, 0x5) |
| 62 | +{ |
| 63 | + GET(UnitClass* const, pThis, ESI); |
| 64 | + enum { SkipHarvester = 0x73D694 }; |
| 65 | + |
| 66 | + auto const pTypeExt = UnitUnloadTemp::TypeExtData; |
| 67 | + |
| 68 | + if (!pThis->Unloading && (!pTypeExt->Deploy_NoTiberium || pThis->Tiberium.GetTotalValue() == 0)) |
| 69 | + { |
| 70 | + R->EAX(pThis->Type); |
| 71 | + return SkipHarvester; |
| 72 | + } |
| 73 | + |
| 74 | + return 0; |
| 75 | +} |
| 76 | + |
| 77 | +DEFINE_HOOK(0x740015, UnitClass_MouseOverObject_SkipPassengers, 0x6) |
| 78 | +{ |
| 79 | + enum { SkipPassengers = 0x7400F0 }; |
| 80 | + |
| 81 | + GET(UnitClass* const, pThis, ESI); |
| 82 | + GET(UnitTypeClass* const, pType, EAX); |
| 83 | + |
| 84 | + auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType); |
| 85 | + |
| 86 | + return pTypeExt->Deploy_SkipPassengerUnload |
| 87 | + || (pTypeExt->Deploy_NoPassenger && pThis->Passengers.NumPassengers <= 0) |
| 88 | + ? SkipPassengers : 0; |
| 89 | +} |
0 commit comments