Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
Arithyce committed May 9, 2024
1 parent 9dcf2bb commit da013b7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,18 @@ void enumerateTemplates(int player, const std::function<bool (DROID_TEMPLATE* ps
}
}

// called when a component is made unavailable
DROID_TEMPLATE* getTemplateByComponent(int player, UDWORD component)
{
auto it = droidTemplates[player].find(component);
if (it != droidTemplates[player].end())
{
auto templ = it;
deleteTemplateFromProduction(templ, player, ModeQueue);
}
return 0;
}

DROID_TEMPLATE* findPlayerTemplateById(int player, UDWORD templateId)
{
ASSERT_PLAYER_OR_RETURN(nullptr, player);
Expand Down
3 changes: 3 additions & 0 deletions src/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ DROID_TEMPLATE* addTemplate(int player, std::unique_ptr<DROID_TEMPLATE> 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<bool (DROID_TEMPLATE* psTemplate)>& func);
DROID_TEMPLATE* findPlayerTemplateById(int player, UDWORD templateId);
size_t templateCount(int player);
Expand Down
4 changes: 4 additions & 0 deletions src/wzapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}

Expand Down

0 comments on commit da013b7

Please sign in to comment.