Skip to content

Commit

Permalink
Cancel previous template when producing a new template in factories
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Dec 13, 2024
1 parent 96ce8bf commit 14f1833
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/droiddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ typedef std::vector<DROID_ORDER_DATA> OrderList;
struct DROID_TEMPLATE : public BASE_STATS
{
DROID_TEMPLATE();
bool operator==(const DROID_TEMPLATE& other) const;
bool operator!=(const DROID_TEMPLATE& other) const;

BODY_STATS* getBodyStats() const;
BRAIN_STATS* getBrainStats() const;
Expand Down
23 changes: 23 additions & 0 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6327,6 +6327,29 @@ void factoryProdAdjust(STRUCTURE *psStructure, DROID_TEMPLATE *psTemplate, bool
ASSERT_OR_RETURN(, psTemplate != nullptr, "NULL template");

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
if (psFactory->psSubject && *psFactory->psSubject != *psTemplate)
{
bool bFound = false;
for (auto templ : apsTemplateList)
{
if (*templ == *psFactory->psSubject)
{
bFound = true;
break;
}
}

if (!bFound)
{
cancelProduction(psStructure, ModeImmediate, false);
factoryProdAdjust(psStructure, psTemplate, add);
return;
}
}

if (psFactory->psAssemblyPoint->factoryInc >= asProductionRun[psFactory->psAssemblyPoint->factoryType].size())
{
asProductionRun[psFactory->psAssemblyPoint->factoryType].resize(psFactory->psAssemblyPoint->factoryInc + 1); // Don't have a production list, create it.
Expand Down
16 changes: 16 additions & 0 deletions src/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,22 @@ DROID_TEMPLATE::DROID_TEMPLATE() // This constructor replaces a memset in scrAs
std::fill_n(asWeaps, MAX_WEAPONS, 0);
}

bool DROID_TEMPLATE::operator==(const DROID_TEMPLATE &other) const
{
return numWeaps == other.numWeaps &&
droidType == other.droidType &&
multiPlayerID == other.multiPlayerID &&
prefab == other.prefab &&
enabled == other.enabled &&
std::equal(std::begin(asParts), std::end(asParts), std::begin(other.asParts)) &&
std::equal(std::begin(asWeaps), std::end(asWeaps), std::begin(other.asWeaps));
}

bool DROID_TEMPLATE::operator!=(const DROID_TEMPLATE &other) const
{
return !(*this == other);
}

BODY_STATS* DROID_TEMPLATE::getBodyStats() const
{
return &asBodyStats[asParts[COMP_BODY]];
Expand Down

0 comments on commit 14f1833

Please sign in to comment.