Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel previous template when producing a new template in factories #4151

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading