Skip to content

Commit 263f068

Browse files
committed
Improve AI team garrison script behaviour
- They now re-evaluate target immediately if current one becomes ungarrisonable
1 parent 62af2f2 commit 263f068

5 files changed

Lines changed: 52 additions & 35 deletions

File tree

YRpp

docs/Fixed-or-Improved-Logics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
303303
- Fixed vehicles disguised as trees incorrectly displaying veterancy insignia when they shouldn't.
304304
- Fixed the issue where the AI's regular targeting would also target garrisonable buildings.
305305
- Fixed the issue that the move mission of the jumpjet does not end correctly.
306+
- AI team garrison scripts now re-evaluate destination immediately instead of trying to garrison ungarrisonable building before changing target.
306307

307308
## Fixes / interactions with other extensions
308309

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ Vanilla fixes:
601601
- Fixed the bug that techno in attack move will move to target if it cannot attack it (by NetsuNegi)
602602
- Fixed the bug in AI scripts 56 and 57 that forced the launch of superweapons with index numbers 3 and 4 (by FlyStar)
603603
- Buildings with `NeedsEngineer=true` are now considered to have threat value of 0 under ownership of `MultiplayPassive=true` houses regardless of their `ThreatPosed` value (by Starkku)
604+
- AI team garrison scripts now re-evaluate destination immediately instead of trying to garrison ungarrisonable building before changing target (by Starkku)
604605
605606
Phobos fixes:
606607
- Fixed the bug that `AllowAirstrike=no` cannot completely prevent air strikes from being launched against it (by NetsuNegi)

src/Ext/Building/Hooks.Grinding.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -54,40 +54,6 @@ DEFINE_HOOK(0x4D4CD3, FootClass_Mission_Eaten_Grinding, 0x6)
5454
return 0;
5555
}
5656

57-
DEFINE_HOOK(0x4D4B43, FootClass_Mission_Capture_ForbidUnintended, 0x6)
58-
{
59-
GET(InfantryClass*, pThis, EDI);
60-
enum { LosesDestination = 0x4D4BD1 };
61-
62-
if (!pThis || pThis->Target)
63-
return 0;
64-
65-
auto const pBld = specific_cast<BuildingClass*>(pThis->Destination);
66-
if (!pBld)
67-
return 0;
68-
69-
auto const pType = pThis->Type;
70-
71-
if (pType->Engineer)
72-
return 0;
73-
74-
// interaction issues with Ares, no more further checking to make life easier. If someone still try to abuse the bug I won't try to stop them
75-
if (pType->Infiltrate && !pThis->Owner->IsAlliedWith(pBld->Owner))
76-
return 0;
77-
if (pBld->IsStrange())
78-
return 0;
79-
80-
if (pBld->Type->CanBeOccupied && (pType->Occupier || pType->Assaulter))
81-
return 0;
82-
83-
if (pType->C4 || pThis->HasAbility(Ability::C4))
84-
return 0;
85-
86-
// If you can't do any of these then why are you here?
87-
pThis->SetDestination(nullptr, false);
88-
return LosesDestination;
89-
}
90-
9157
DEFINE_HOOK(0x51F0AF, InfantryClass_WhatAction_Grinding, 0x0)
9258
{
9359
enum { Skip = 0x51F05E, ReturnValue = 0x51F17E };

src/Ext/Techno/Hooks.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,3 +1856,52 @@ DEFINE_FUNCTION_JUMP(VTABLE, 0x7F5F30, FootClass_GetThreatValue_Wrapper); // Un
18561856
DEFINE_FUNCTION_JUMP(VTABLE, 0x7E417C, Building_GetThreatValue_Wrapper); // BuildingClass
18571857

18581858
#pragma endregion
1859+
1860+
DEFINE_HOOK(0x4D4B43, FootClass_Mission_Capture, 0x6)
1861+
{
1862+
enum { LosesDestination = 0x4D4BD1 };
1863+
1864+
GET(InfantryClass*, pThis, EDI);
1865+
1866+
if (!pThis || pThis->Target)
1867+
return 0;
1868+
1869+
auto const pBld = specific_cast<BuildingClass*>(pThis->Destination);
1870+
1871+
if (!pBld || pBld->IsStrange())
1872+
return 0;
1873+
1874+
auto const pType = pThis->Type;
1875+
1876+
if (pType->Engineer)
1877+
return 0;
1878+
1879+
// interaction issues with Ares, no more further checking to make life easier. If someone still try to abuse the bug I won't try to stop them
1880+
if (pType->Infiltrate && !pThis->Owner->IsAlliedWith(pBld->Owner))
1881+
return 0;
1882+
1883+
if (pType->C4 || pThis->HasAbility(Ability::C4))
1884+
return 0;
1885+
1886+
auto const pBldType = pBld->Type;
1887+
1888+
if (pBldType->CanBeOccupied && (pType->Occupier || pType->Assaulter))
1889+
{
1890+
// Re-evaluate destination if order to garrison came from TMission.
1891+
if (pType->Occupier && (pThis->ShouldEnterOccupiable || pThis->ShouldGarrisonStructure) && !pBld->CanBeOccupiedBy(pThis))
1892+
{
1893+
if (!(pThis->ShouldEnterOccupiable ? pThis->EnterBattleBunker() : pThis->GarrisonStructure()))
1894+
{
1895+
pThis->SetDestination(nullptr, false);
1896+
return LosesDestination;
1897+
}
1898+
}
1899+
1900+
return 0;
1901+
}
1902+
1903+
// If you can't do any of these then why are you here?
1904+
pThis->SetDestination(nullptr, false);
1905+
1906+
return LosesDestination;
1907+
}

0 commit comments

Comments
 (0)