Skip to content

Commit 69d45d1

Browse files
authored
[Minor] Fix an issue related to construction (#1933)
Fix the issue where AI cannot repair construction yard when using `AIForbidConyard`. Optimize and remove some useless checks related to abandon construction.
1 parent 6ce2f4e commit 69d45d1

File tree

2 files changed

+14
-47
lines changed

2 files changed

+14
-47
lines changed

src/Ext/Building/Hooks.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -631,45 +631,32 @@ DEFINE_HOOK(0x4C9C7B, FactoryClass_QueueProduction_ForceCheckBuilding, 0x7)
631631
return RulesExt::Global()->BuildingProductionQueue ? SkipGameCode : 0;
632632
}
633633

634+
DEFINE_JUMP(LJMP, 0x4FABEE, 0x4FAB3D)
635+
634636
DEFINE_HOOK(0x4FAAD8, HouseClass_AbandonProduction_RewriteForBuilding, 0x8)
635637
{
636-
enum { CheckSame = 0x4FAB3D, SkipCheck = 0x4FAB64, Return = 0x4FAC9B };
638+
enum { CheckSame = 0x4FAB3D, Return = 0x4FAC9B };
637639

638640
GET_STACK(const bool, all, STACK_OFFSET(0x18, 0x10));
639641
GET(const int, index, EBX);
640-
GET(const BuildCat, buildCat, ECX);
641642
GET(const AbstractType, absType, EBP);
642643
GET(FactoryClass* const, pFactory, ESI);
643644

644-
if (buildCat == BuildCat::DontCare || all)
645-
{
646-
const auto pType = TechnoTypeClass::GetByTypeAndIndex(absType, index);
647-
const auto firstRemoved = pFactory->RemoveOneFromQueue(pType);
645+
const auto pType = TechnoTypeClass::GetByTypeAndIndex(absType, index);
646+
const auto firstRemoved = pFactory->RemoveOneFromQueue(pType);
648647

649-
if (firstRemoved)
650-
{
651-
SidebarClass::Instance.SidebarBackgroundNeedsRedraw = true; // Added, force redraw strip
652-
SidebarClass::Instance.RepaintSidebar(SidebarClass::GetObjectTabIdx(absType, index, 0));
653-
654-
if (all)
655-
while (pFactory->RemoveOneFromQueue(pType));
656-
else
657-
return Return;
658-
}
648+
if (firstRemoved)
649+
{
650+
SidebarClass::Instance.SidebarBackgroundNeedsRedraw = true; // Added, force redraw strip
651+
SidebarClass::Instance.RepaintSidebar(SidebarClass::GetObjectTabIdx(absType, index, 0));
659652

660-
return CheckSame;
653+
if (all)
654+
while (pFactory->RemoveOneFromQueue(pType));
655+
else
656+
return Return;
661657
}
662658

663-
if (!pFactory->Object)
664-
return SkipCheck;
665-
666-
if (!pFactory->RemoveOneFromQueue(TechnoTypeClass::GetByTypeAndIndex(absType, index)))
667-
return CheckSame;
668-
669-
SidebarClass::Instance.SidebarBackgroundNeedsRedraw = true; // Added, force redraw strip
670-
SidebarClass::Instance.RepaintSidebar(SidebarClass::GetObjectTabIdx(absType, index, 0));
671-
672-
return Return;
659+
return CheckSame;
673660
}
674661

675662
DEFINE_HOOK(0x6A9C54, StripClass_DrawStrip_FindFactoryDehardCode, 0x6)

src/Ext/BuildingType/Hooks.Placing.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,6 @@ DEFINE_HOOK(0x42EB8E, BaseClass_GetBaseNodeIndex_CheckValidBaseNode, 0x6)
138138
return reinterpret_cast<bool(__thiscall*)(HouseClass*, BaseNodeClass*)>(0x50CAD0)(pBase->Owner, pBaseNode) ? Valid : Invalid;
139139
}
140140

141-
// AIConstructionYard Hook #4-3 -> sub_7393C0 - Prohibit AI from building construction yard.
142-
DEFINE_HOOK(0x7397F4, UnitClass_TryToDeploy_SkipSetShouldRebuild, 0x7)
143-
{
144-
enum { SkipRebuildFlag = 0x7397FB };
145-
146-
GET(BuildingClass* const, pBuilding, EBX);
147-
148-
return (pBuilding->Type->ConstructionYard && RulesExt::Global()->AIForbidConYard) ? SkipRebuildFlag : 0;
149-
}
150-
151-
// AIConstructionYard Hook #4-4 -> sub_440580 - Prohibit AI from building construction yard.
152-
DEFINE_HOOK(0x440B7A, BuildingClass_Unlimbo_SkipSetShouldRebuild, 0x7)
153-
{
154-
enum { SkipRebuildFlag = 0x440B81 };
155-
156-
GET(BuildingClass* const, pBuilding, ESI);
157-
158-
return (pBuilding->Type->ConstructionYard && RulesExt::Global()->AIForbidConYard) ? SkipRebuildFlag : 0;
159-
}
160-
161141
// AIConstructionYard Hook #5-1 -> sub_588570 - Only expand walls on nodes.
162142
DEFINE_HOOK(0x5885D1, MapClass_BuildingToFirestormWall_SkipExtraWalls, 0x6)
163143
{

0 commit comments

Comments
 (0)