|
| 1 | +#include <Ext/Techno/Body.h> |
| 2 | + |
| 3 | +// Hooks that allow harvesters / weeders to work correctly with MovementZone=Subterannean (sic) - Starkku |
| 4 | +#pragma region SubterraneanHarvesters |
| 5 | + |
| 6 | +// Allow scanning for docks in all map zones. |
| 7 | +DEFINE_HOOK(0x4DEFC6, FootClass_FindDock_SubterraneanHarvester, 0x5) |
| 8 | +{ |
| 9 | + GET(TechnoTypeClass*, pTechnoType, EAX); |
| 10 | + |
| 11 | + if (auto const pUnitType = abstract_cast<UnitTypeClass*>(pTechnoType)) |
| 12 | + { |
| 13 | + if ((pUnitType->Harvester || pUnitType->Weeder) && pUnitType->MovementZone == MovementZone::Subterrannean) |
| 14 | + R->ECX(MovementZone::Fly); |
| 15 | + } |
| 16 | + |
| 17 | + return 0; |
| 18 | +} |
| 19 | + |
| 20 | +// Allow scanning for ore in all map zones. |
| 21 | +DEFINE_HOOK(0x4DCF86, FootClass_FindTiberium_SubterraneanHarvester, 0x5) |
| 22 | +{ |
| 23 | + enum { SkipGameCode = 0x4DCF9B }; |
| 24 | + |
| 25 | + GET(MovementZone, mZone, ECX); |
| 26 | + |
| 27 | + if (mZone == MovementZone::Subterrannean) |
| 28 | + R->ECX(MovementZone::Fly); |
| 29 | + |
| 30 | + return 0; |
| 31 | +} |
| 32 | + |
| 33 | +// Allow scanning for weeds in all map zones. |
| 34 | +DEFINE_HOOK(0x4DDB23, FootClass_FindWeeds_SubterraneanHarvester, 0x5) |
| 35 | +{ |
| 36 | + enum { SkipGameCode = 0x4DCF9B }; |
| 37 | + |
| 38 | + GET(MovementZone, mZone, EAX); |
| 39 | + |
| 40 | + if (mZone == MovementZone::Subterrannean) |
| 41 | + R->EAX(MovementZone::Fly); |
| 42 | + |
| 43 | + return 0; |
| 44 | +} |
| 45 | + |
| 46 | +// Set rally point. |
| 47 | +DEFINE_HOOK(0x44459A, BuildingClass_ExitObject_SubterraneanHarvester, 0x5) |
| 48 | +{ |
| 49 | + GET(TechnoClass*, pThis, EDI); |
| 50 | + |
| 51 | + if (auto const pUnit = abstract_cast<UnitClass*>(pThis)) |
| 52 | + { |
| 53 | + auto const pType = pUnit->Type; |
| 54 | + |
| 55 | + if ((pType->Harvester || pType->Weeder) && pType->MovementZone == MovementZone::Subterrannean) |
| 56 | + { |
| 57 | + auto const pExt = TechnoExt::ExtMap.Find(pUnit); |
| 58 | + pExt->SubterraneanHarvFreshFromFactory = true; |
| 59 | + pExt->SubterraneanHarvRallyDest = pUnit->ArchiveTarget; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return 0; |
| 64 | +} |
| 65 | + |
| 66 | +// Handle rally point once idle. |
| 67 | +DEFINE_HOOK(0x7389B1, UnitClass_EnterIdleMode_SubterraneanHarvester, 0x6) |
| 68 | +{ |
| 69 | + enum { ReturnFromFunction = 0x738D21 }; |
| 70 | + |
| 71 | + GET(UnitClass*, pThis, ESI); |
| 72 | + |
| 73 | + auto const pExt = TechnoExt::ExtMap.Find(pThis); |
| 74 | + |
| 75 | + if (pExt->SubterraneanHarvFreshFromFactory) |
| 76 | + { |
| 77 | + pThis->SetArchiveTarget(nullptr); |
| 78 | + pThis->ClearNavQueue(); |
| 79 | + |
| 80 | + if (pThis->Destination && pExt->SubterraneanHarvRallyDest && pThis->Destination != pExt->SubterraneanHarvRallyDest && pThis->DistanceFrom(pThis->Destination) > Unsorted::LeptonsPerCell) |
| 81 | + pThis->SetDestination(pExt->SubterraneanHarvRallyDest, false); |
| 82 | + else |
| 83 | + pThis->SetDestination(nullptr, false); |
| 84 | + |
| 85 | + pExt->SubterraneanHarvFreshFromFactory = false; |
| 86 | + pExt->SubterraneanHarvRallyDest = nullptr; |
| 87 | + |
| 88 | + return ReturnFromFunction; |
| 89 | + } |
| 90 | + |
| 91 | + return 0; |
| 92 | +} |
| 93 | + |
| 94 | +#pragma endregion |
0 commit comments