|
1 | 1 | #include "Body.h" |
2 | 2 |
|
| 3 | +#include <EventClass.h> |
3 | 4 | #include <SpawnManagerClass.h> |
4 | 5 | #include <TunnelLocomotionClass.h> |
5 | 6 | #include <JumpjetLocomotionClass.h> |
@@ -846,13 +847,78 @@ DEFINE_HOOK(0x73D6E6, UnitClass_Unload_Subterranean, 0x6) |
846 | 847 |
|
847 | 848 | GET(UnitClass*, pThis, ESI); |
848 | 849 |
|
849 | | - if (pThis->Type->Locomotor == LocomotionClass::CLSIDs::Tunnel) |
| 850 | + if (auto const pLoco = locomotion_cast<TunnelLocomotionClass*>(pThis->Locomotor)) |
850 | 851 | { |
851 | | - auto const pLoco = static_cast<TunnelLocomotionClass*>(pThis->Locomotor.GetInterfacePtr()); |
852 | | - |
853 | 852 | if (pLoco->State != TunnelLocomotionClass::State::Idle) |
854 | 853 | return ReturnFromFunction; |
855 | 854 | } |
856 | 855 |
|
857 | 856 | return 0; |
858 | 857 | } |
| 858 | + |
| 859 | +#pragma region Events |
| 860 | + |
| 861 | +DEFINE_HOOK(0x4C7512, EventClass_Execute_StopCommand, 0x6) |
| 862 | +{ |
| 863 | + GET(TechnoClass* const, pThis, ESI); |
| 864 | + |
| 865 | + if (auto const pUnit = abstract_cast<UnitClass*>(pThis)) |
| 866 | + { |
| 867 | + // issue #112 Make FireOnce=yes work on other TechnoType |
| 868 | + // Author: Starkku |
| 869 | + if (pUnit->CurrentMission == Mission::Unload && pUnit->Type->DeployFire && !pUnit->Type->IsSimpleDeployer) |
| 870 | + { |
| 871 | + pUnit->SetTarget(nullptr); |
| 872 | + pThis->QueueMission(Mission::Guard, true); |
| 873 | + } |
| 874 | + |
| 875 | + // Explicit stop command should reset subterranean harvester state machine. |
| 876 | + auto const pExt = TechnoExt::ExtMap.Find(pUnit); |
| 877 | + pExt->SubterraneanHarvStatus = 0; |
| 878 | + pExt->SubterraneanHarvRallyPoint = nullptr; |
| 879 | + } |
| 880 | + |
| 881 | + return 0; |
| 882 | +} |
| 883 | + |
| 884 | +DEFINE_HOOK(0x4C7462, EventClass_Execute_MegaMission_MoveCommand, 0x5) |
| 885 | +{ |
| 886 | + enum { SkipGameCode = 0x4C74C0 }; |
| 887 | + |
| 888 | + GET(TechnoClass*, pTechno, EDI); |
| 889 | + |
| 890 | + if (pTechno->WhatAmI() != AbstractType::Unit) |
| 891 | + return 0; |
| 892 | + |
| 893 | + GET(EventClass*, pThis, ESI); |
| 894 | + auto const mission = static_cast<Mission>(pThis->MegaMission.Mission); |
| 895 | + auto const pExt = TechnoExt::ExtMap.Find(pTechno); |
| 896 | + |
| 897 | + if (mission == Mission::Move) |
| 898 | + { |
| 899 | + // Explicitly reset subterranean harvester state machine. |
| 900 | + pExt->SubterraneanHarvStatus = 0; |
| 901 | + pExt->SubterraneanHarvRallyPoint = nullptr; |
| 902 | + |
| 903 | + // Do not explicitly reset target for KeepTargetOnMove vehicles when issued move command. |
| 904 | + if (pExt->TypeExtData->KeepTargetOnMove && pTechno->Target) |
| 905 | + { |
| 906 | + GET(AbstractClass*, pTarget, EBX); |
| 907 | + |
| 908 | + if (!pTarget && pTechno->IsCloseEnoughToAttack(pTechno->Target)) |
| 909 | + { |
| 910 | + auto const pDestination = pThis->MegaMission.Destination.As_Abstract(); |
| 911 | + pTechno->SetDestination(pDestination, true); |
| 912 | + pExt->KeepTargetOnMove = true; |
| 913 | + |
| 914 | + return SkipGameCode; |
| 915 | + } |
| 916 | + } |
| 917 | + } |
| 918 | + |
| 919 | + pExt->KeepTargetOnMove = false; |
| 920 | + |
| 921 | + return 0; |
| 922 | +} |
| 923 | + |
| 924 | +#pragma endregion |
0 commit comments