Skip to content

Improve subterranean harvester pathfinding #1535

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ This page lists all the individual contributions to the project by their author.
- Vehicles keeping target on move command
- `IsSonic` wave drawing crash fix
- Customizable electric bolt duration and electric bolt-related fixes
- Subterranean harvester pathfinding fix
- **Morton (MortonPL)**:
- `XDrawOffset` for animations
- Shield passthrough & absorption
Expand Down
1 change: 1 addition & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<ClCompile Include="src\Ext\TEvent\Body.cpp" />
<ClCompile Include="src\Ext\Trigger\Hooks.cpp" />
<ClCompile Include="src\Ext\Unit\Hooks.Crushing.cpp" />
<ClCompile Include="src\Ext\Unit\Hooks.Harvester.cpp" />
<ClCompile Include="src\Locomotion\TestLocomotionClass.cpp" />
<ClCompile Include="src\Misc\Hooks.Gamespeed.cpp" />
<ClCompile Include="src\Misc\Hooks.Ares.cpp" />
Expand Down
1 change: 1 addition & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- Fixed an issue that MCV will self-destruct when using trigger 107 to teleport
- Fixed an issue that moving MCV with Teleport locomotion will cause reconnection error
- Fixed wrong shadow when a vehicle has hover locomotor and is being lifted by `IsLocomotor=yes` warhead
- Fixed `MovementZone=Subterannean` harvesters being unable to find docks if in area enclosed by water, cliffs etc.

## Fixes / interactions with other extensions

Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ Vanilla fixes:
- Fixed an issue that teleport units board transport vehicles on the bridge will create an impassable invisible barrier, which may cause the game to freeze or even crash (by NetsuNegi)
- Fixed an issue that moving MCV with Teleport locomotion will cause reconnection error (by CrimRecya)
- Fixed wrong shadow when a vehicle has hover locomotor and is being lifted by `IsLocomotor=yes` warhead (by NetsuNegi)
- Fixed `MovementZone=Subterannean` harvesters being unable to find docks if in area enclosed by water, cliffs etc.

Phobos fixes:
- Fixed an issue that MCV will self-destruct when using trigger 107 to teleport (by CrimRecya)
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/Techno/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ void TechnoExt::ExtData::Serialize(T& Stm)
.Process(this->AE)
.Process(this->PreviousType)
.Process(this->AnimRefCount)
.Process(this->SubterraneanHarvFreshFromFactory)
.Process(this->SubterraneanHarvRallyDest)
.Process(this->ReceiveDamage)
.Process(this->PassengerDeletionTimer)
.Process(this->CurrentShieldType)
Expand Down
4 changes: 4 additions & 0 deletions src/Ext/Techno/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class TechnoExt
TechnoTypeClass* PreviousType; // Type change registered in TechnoClass::AI on current frame and used in FootClass::AI on same frame and reset after.
std::vector<EBolt*> ElectricBolts; // EBolts are not serialized so do not serialize this either.
int AnimRefCount; // Used to keep track of how many times this techno is referenced in anims f.ex Invoker, ParentBuilding etc., for pointer invalidation.
bool SubterraneanHarvFreshFromFactory;
AbstractClass* SubterraneanHarvRallyDest;
bool ReceiveDamage;
bool LastKillWasTeamTarget;
CDTimerClass PassengerDeletionTimer;
Expand Down Expand Up @@ -77,6 +79,8 @@ class TechnoExt
, PreviousType { nullptr }
, ElectricBolts {}
, AnimRefCount { 0 }
, SubterraneanHarvFreshFromFactory { false }
, SubterraneanHarvRallyDest { nullptr }
, ReceiveDamage { false }
, LastKillWasTeamTarget { false }
, PassengerDeletionTimer {}
Expand Down
30 changes: 30 additions & 0 deletions src/Ext/Techno/Hooks.Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,4 +752,34 @@ DEFINE_HOOK(0x70FB73, FootClass_IsBunkerableNow_Dehardcode, 0x6)
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType);
return pTypeExt->BunkerableAnyway ? CanEnter : 0;
}

#pragma endregion

// issue #112 Make FireOnce=yes work on other TechnoTypes
// Author: Starkku
DEFINE_HOOK(0x4C7512, EventClass_Execute_StopCommand, 0x6)
{
GET(TechnoClass* const, pThis, ESI);

if (auto const pUnit = abstract_cast<UnitClass*>(pThis))
{
// Reset target for deploy weapons.
if (pUnit->CurrentMission == Mission::Unload && pUnit->Type->DeployFire && !pUnit->Type->IsSimpleDeployer)
{
pUnit->SetTarget(nullptr);
pThis->QueueMission(Mission::Guard, true);
}

auto const pType = pUnit->Type;

// Reset subterranean harvester rally point info.
if ((pType->Harvester || pType->Weeder) && pType->MovementZone == MovementZone::Subterrannean)
{
auto const pExt = TechnoExt::ExtMap.Find(pUnit);
pExt->SubterraneanHarvFreshFromFactory = false;
pExt->SubterraneanHarvRallyDest = nullptr;
}
}

return 0;
}
18 changes: 1 addition & 17 deletions src/Ext/Unit/Hooks.DeployFire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,7 @@
#include <Ext/Techno/Body.h>
#include <Utilities/Macro.h>

// issue #112 Make FireOnce=yes work on other TechnoTypes
// Author: Starkku
DEFINE_HOOK(0x4C7512, EventClass_Execute_StopUnitDeployFire, 0x6)
{
GET(TechnoClass* const, pThis, ESI);

auto const pUnit = abstract_cast<UnitClass*>(pThis);
if (pUnit && pUnit->CurrentMission == Mission::Unload && pUnit->Type->DeployFire && !pUnit->Type->IsSimpleDeployer)
{
pUnit->SetTarget(nullptr);
pThis->QueueMission(Mission::Guard, true);
}

return 0;
}

DEFINE_HOOK(0x4C77E4, EventClass_Execute_UnitDeployFire, 0x6)
DEFINE_HOOK(0x4C77E4, EventClass_Execute_DeployCommand, 0x6)
{
enum { DoNotExecute = 0x4C8109 };

Expand Down
145 changes: 145 additions & 0 deletions src/Ext/Unit/Hooks.Harvester.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#include <Ext/Techno/Body.h>

// Hooks that allow harvesters / weeders to work correctly with MovementZone=Subterannean (sic) - Starkku
#pragma region SubterraneanHarvesters

// Allow scanning for docks in all map zones.
DEFINE_HOOK(0x4DEFC6, FootClass_FindDock_SubterraneanHarvester, 0x5)
{
GET(TechnoTypeClass*, pTechnoType, EAX);

if (auto const pUnitType = abstract_cast<UnitTypeClass*>(pTechnoType))
{
if ((pUnitType->Harvester || pUnitType->Weeder) && pUnitType->MovementZone == MovementZone::Subterrannean)
R->ECX(MovementZone::Fly);
}

return 0;
}

// Allow scanning for ore in all map zones.
DEFINE_HOOK(0x4DCF86, FootClass_FindTiberium_SubterraneanHarvester, 0x5)
{
enum { SkipGameCode = 0x4DCF9B };

GET(MovementZone, mZone, ECX);

if (mZone == MovementZone::Subterrannean)
R->ECX(MovementZone::Fly);

return 0;
}

// Allow scanning for weeds in all map zones.
DEFINE_HOOK(0x4DDB23, FootClass_FindWeeds_SubterraneanHarvester, 0x5)
{
enum { SkipGameCode = 0x4DCF9B };

GET(MovementZone, mZone, EAX);

if (mZone == MovementZone::Subterrannean)
R->EAX(MovementZone::Fly);

return 0;
}

// Set rally point.
DEFINE_HOOK(0x44459A, BuildingClass_ExitObject_SubterraneanHarvester, 0x5)
{
GET(TechnoClass*, pThis, EDI);

if (auto const pUnit = abstract_cast<UnitClass*>(pThis))
{
auto const pType = pUnit->Type;

if ((pType->Harvester || pType->Weeder) && pType->MovementZone == MovementZone::Subterrannean)
{
auto const pExt = TechnoExt::ExtMap.Find(pUnit);
pExt->SubterraneanHarvFreshFromFactory = true;
pExt->SubterraneanHarvRallyDest = pUnit->ArchiveTarget;
}
}

return 0;
}

// Handle rally point once idle.
DEFINE_HOOK(0x7389B1, UnitClass_EnterIdleMode_SubterraneanHarvester, 0x6)
{
enum { ReturnFromFunction = 0x738D21 };

GET(UnitClass*, pThis, ESI);

auto const pExt = TechnoExt::ExtMap.Find(pThis);

if (pExt->SubterraneanHarvFreshFromFactory)
{
pThis->SetArchiveTarget(nullptr);
pThis->ClearNavigationList();
pThis->SetDestination(pExt->SubterraneanHarvRallyDest, false);
pExt->SubterraneanHarvFreshFromFactory = false;
pExt->SubterraneanHarvRallyDest = nullptr;

return ReturnFromFunction;
}

return 0;
}

#pragma endregion

DEFINE_HOOK(0x740943, UnitClass_Mission_Guard_PlayerHarvester, 0x6)
{
enum { SkipGameCode = 0x7408C7, ReturnFromFunction = 0x7409EF };

GET(UnitClass*, pThis, ESI);

if (pThis->Type->Teleporter || pThis->Type->MovementZone == MovementZone::Subterrannean)
{
auto const pCell = pThis->GetCell();
int cellIndex = 0;

while (true)
{
auto const pAdjCell = pCell->GetNeighbourCell((FacingType)cellIndex);
auto const pBuilding = pAdjCell->GetBuilding();

if (pBuilding)
{
if (pBuilding->Type->Refinery && pBuilding->Owner == pThis->Owner)
{
pThis->QueueMission(Mission::Harvest, false);
return ReturnFromFunction;
}
}

if (++cellIndex >= (int)FacingType::Count)
{
double percentage = pThis->GetStoragePercentage();

if (pThis->ArchiveTarget && percentage > 0.0)
{
pThis->QueueMission(Mission::Harvest, false);
return ReturnFromFunction;
}
else if (percentage != 1.0 && percentage > 0.0)
{
return SkipGameCode;
}
else if (percentage == 0.0)
{
return SkipGameCode;
}

if (!pThis->Locomotor->Is_Moving())
return SkipGameCode;

pThis->QueueMission(Mission::Harvest, false);
return ReturnFromFunction;
}
}
}

return SkipGameCode;
}

Loading