From da013b79f232035abed004fb7a5bfd6942a7d46d Mon Sep 17 00:00:00 2001 From: Arithyce <108166240+Arithyce@users.noreply.github.com> Date: Thu, 9 May 2024 03:43:50 -0400 Subject: [PATCH] Fix issues Attempts to fix these issues: When a component is made unavailable, any queued units with that component will remain in the production menu and will only be cleared upon re-opening the menu if there is only 1 queued, otherwise the "ghost" template will remain until unqueued. An error is given when the game attempts to produce the unit: "Machinegun Viper Half-tracks : not researched weapon 0", "Wrong template for player 0 factory, type 1". --- src/research.cpp | 2 ++ src/template.cpp | 12 ++++++++++++ src/template.h | 3 +++ src/wzapi.cpp | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/src/research.cpp b/src/research.cpp index 07f03b27e6e..8dc60ecd53a 100644 --- a/src/research.cpp +++ b/src/research.cpp @@ -1184,6 +1184,8 @@ void researchResult(UDWORD researchIndex, UBYTE player, bool bDisplay, STRUCTURE { COMPONENT_TYPE type = pRemArtefact->compType; makeComponentUnavailable(apCompLists[player][type][pRemArtefact->index]); + auto component = (apCompLists[player][type][pRemArtefact->index]); + getTemplateByComponent(player, component); } //Add message to player's list if Major Topic diff --git a/src/template.cpp b/src/template.cpp index c59d3847c62..7dfd5610af1 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -634,6 +634,18 @@ void enumerateTemplates(int player, const std::function psTempla /// Make a duplicate of template given by pointer and store it. Then return pointer to copy. DROID_TEMPLATE *copyTemplate(int player, DROID_TEMPLATE *psTemplate); +// called when a component is made unavailable +DROID_TEMPLATE* getTemplateByComponent(int player, UDWORD component); + void enumerateTemplates(int player, const std::function& func); DROID_TEMPLATE* findPlayerTemplateById(int player, UDWORD templateId); size_t templateCount(int player); diff --git a/src/wzapi.cpp b/src/wzapi.cpp index 83693b2ff8d..6761a4b9020 100644 --- a/src/wzapi.cpp +++ b/src/wzapi.cpp @@ -2954,6 +2954,10 @@ wzapi::no_return_value wzapi::makeComponentUnavailable(WZAPI_PARAMS(std::string { SCRIPT_ASSERT_PLAYER({}, context, player); setComponent(componentName, player, UNAVAILABLE); + COMPONENT_STATS *pComp = getCompStatsFromName(componentName); + COMPONENT_TYPE type = pComp->compType; + auto component = (apCompLists[player][type][pComp->index]); + getTemplateByComponent(player, component); return {}; }