Skip to content

Commit

Permalink
Finish the previous template to proceed to the new one
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Dec 14, 2024
1 parent 14f1833 commit 0c34ad5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/droiddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct DROID_TEMPLATE : public BASE_STATS
bool prefab; ///< Not player designed, not saved, never delete or change
bool stored; ///< Stored template
bool enabled; ///< Has been enabled
DROID_TEMPLATE* next;
};

static inline DROID_TEMPLATE *castDroidTemplate(BASE_STATS *stats)
Expand Down
5 changes: 4 additions & 1 deletion src/hci/manufacture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ class ManufactureStatsButton: public StatsButton
auto productionRemaining = getProduction(factory, droidTemplate).numRemaining();
if (productionRemaining > 0 && factory && StructureIsManufacturingPending(factory))
{
productionRunSizeLabel->setString(WzString::fromUtf8(astringf("%d", productionRemaining)));
auto manufacture = StructureGetFactory(factory);
productionRunSizeLabel->setString((manufacture->psSubject && manufacture->psSubject->next) ?
WzString::fromUtf8(astringf("1+%d", productionRemaining)) :
WzString::fromUtf8(astringf("%d", productionRemaining)));
productionRunSizeLabel->show();
}
else
Expand Down
35 changes: 21 additions & 14 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6234,6 +6234,21 @@ void doNextProduction(STRUCTURE *psStructure, DROID_TEMPLATE *current, QUEUE_MOD
{
DROID_TEMPLATE *psNextTemplate = factoryProdUpdate(psStructure, current);

if (current)
{
auto it = std::find_if(apsTemplateList.begin(), apsTemplateList.end(), [current](const auto &templ) {
return *templ == *current;
});

if (it == apsTemplateList.end() && current->next)
{
structSetManufacture(psStructure, current->next, ModeImmediate);
// Increase the production counter, because we produced the old template
factoryProdAdjust(psStructure, current->next, true);
return;
}
}

if (psNextTemplate != nullptr)
{
structSetManufacture(psStructure, psNextTemplate, ModeQueue); // ModeQueue instead of mode, since production lists aren't currently synchronised.
Expand Down Expand Up @@ -6329,24 +6344,16 @@ void factoryProdAdjust(STRUCTURE *psStructure, DROID_TEMPLATE *psTemplate, bool
FACTORY *psFactory = &psStructure->pFunctionality->factory;

// the droid template being produced is different from the one we want to make,
// cancel the current production instead of increasing the counter
// update the current production instead of increasing the counter
if (psFactory->psSubject && *psFactory->psSubject != *psTemplate)
{
bool bFound = false;
for (auto templ : apsTemplateList)
{
if (*templ == *psFactory->psSubject)
{
bFound = true;
break;
}
}
auto it = std::find_if(apsTemplateList.begin(), apsTemplateList.end(), [psFactory](const auto &templ) {
return *templ == *psFactory->psSubject;
});

if (!bFound)
if (it == apsTemplateList.end())
{
cancelProduction(psStructure, ModeImmediate, false);
factoryProdAdjust(psStructure, psTemplate, add);
return;
psFactory->psSubject->next = psTemplate;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ DROID_TEMPLATE::DROID_TEMPLATE() // This constructor replaces a memset in scrAs
, prefab(false)
, stored(false)
, enabled(false)
, next(nullptr)
{
std::fill_n(asParts, DROID_MAXCOMP, static_cast<uint8_t>(0));
std::fill_n(asWeaps, MAX_WEAPONS, 0);
Expand Down

0 comments on commit 0c34ad5

Please sign in to comment.