Skip to content

Commit 57a1c58

Browse files
authored
[Minor] Notify the completed building in building production queue (#1517)
If enable the building production queue, when a building is fully completed, the remaining buildings will be turned into gray cameo as before. Also simplified the code of recheck cameo.
1 parent b9569c4 commit 57a1c58

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/Ext/Building/Hooks.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,24 @@ DEFINE_HOOK(0x6A9789, StripClass_DrawStrip_NoGreyCameo, 0x6)
601601
GET(TechnoTypeClass* const, pType, EBX);
602602
GET_STACK(bool, clicked, STACK_OFFSET(0x48C, -0x475));
603603

604-
return (!RulesExt::Global()->BuildingProductionQueue && pType->WhatAmI() == AbstractType::BuildingType && clicked) ? SkipGameCode : ContinueCheck;
604+
if (!RulesExt::Global()->BuildingProductionQueue)
605+
{
606+
if (pType->WhatAmI() == AbstractType::BuildingType && clicked)
607+
return SkipGameCode;
608+
}
609+
else if (const auto pBuildingType = abstract_cast<BuildingTypeClass*>(pType))
610+
{
611+
if (const auto pFactory = HouseClass::CurrentPlayer->GetPrimaryFactory(AbstractType::BuildingType, pType->Naval, pBuildingType->BuildCat))
612+
{
613+
if (const auto pProduct = abstract_cast<BuildingClass*>(pFactory->Object))
614+
{
615+
if (pFactory->IsDone() && pProduct->Type != pType && ((pProduct->Type->BuildCat != BuildCat::Combat) ^ (pBuildingType->BuildCat == BuildCat::Combat)))
616+
return SkipGameCode;
617+
}
618+
}
619+
}
620+
621+
return ContinueCheck;
605622
}
606623

607624
DEFINE_HOOK(0x6AA88D, StripClass_RecheckCameo_FindFactoryDehardCode, 0x6)

src/Ext/Sidebar/Body.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool __stdcall SidebarExt::AresTabCameo_RemoveCameo(BuildType* pItem)
2929
{
3030
const auto pFactory = pTechnoType->FindFactory(true, false, false, pCurrent);
3131

32-
if (pFactory && pFactory->Owner->CanBuild(pTechnoType, false, true) != CanBuildResult::Unbuildable)
32+
if (pFactory && pCurrent->CanBuild(pTechnoType, false, true) != CanBuildResult::Unbuildable)
3333
return false;
3434
}
3535
else
@@ -40,32 +40,27 @@ bool __stdcall SidebarExt::AresTabCameo_RemoveCameo(BuildType* pItem)
4040
return false;
4141
}
4242

43-
if (pItem->CurrentFactory)
43+
// Here we just raise AbandonAll without find factory, rather than check factory and Abandon then find factory and AbandonAll
44+
if (pTechnoType)
4445
{
45-
EventClass event = EventClass(pCurrent->ArrayIndex, EventType::Abandon, static_cast<int>(pItem->ItemType), pItem->ItemIndex, pTechnoType && pTechnoType->Naval);
46+
const EventClass event
47+
(
48+
pCurrent->ArrayIndex,
49+
EventType::AbandonAll,
50+
static_cast<int>(pItem->ItemType),
51+
pItem->ItemIndex,
52+
pTechnoType->Naval
53+
);
4654
EventClass::AddEvent(event);
4755
}
4856

4957
if (pItem->ItemType == AbstractType::BuildingType || pItem->ItemType == AbstractType::Building)
5058
{
51-
DisplayClass::Instance->CurrentBuilding = nullptr;
52-
DisplayClass::Instance->CurrentBuildingType = nullptr;
53-
DisplayClass::Instance->CurrentBuildingOwnerArrayIndex = -1;
54-
DisplayClass::Instance->SetActiveFoundation(nullptr);
55-
}
56-
57-
if (pTechnoType)
58-
{
59-
const auto absType = pTechnoType->WhatAmI();
60-
61-
// Here we make correction to the hardcoded BuildCat::DontCare
62-
const auto buildCat = absType == AbstractType::BuildingType ? static_cast<BuildingTypeClass*>(pTechnoType)->BuildCat : BuildCat::DontCare;
63-
64-
if (pCurrent->GetPrimaryFactory(absType, pTechnoType->Naval, buildCat))
65-
{
66-
EventClass event = EventClass(pCurrent->ArrayIndex, EventType::AbandonAll, static_cast<int>(pItem->ItemType), pItem->ItemIndex, pTechnoType->Naval);
67-
EventClass::AddEvent(event);
68-
}
59+
const auto pDisplay = DisplayClass::Instance();
60+
pDisplay->SetActiveFoundation(nullptr);
61+
pDisplay->CurrentBuilding = nullptr;
62+
pDisplay->CurrentBuildingType = nullptr;
63+
pDisplay->CurrentBuildingOwnerArrayIndex = -1;
6964
}
7065

7166
return true;

0 commit comments

Comments
 (0)