Skip to content

Commit

Permalink
Do not halt production on template becoming redundant.
Browse files Browse the repository at this point in the history
Production would halt until the redundant tank was manually removed from the build order.
  • Loading branch information
Cyp committed Jun 29, 2012
1 parent 134c51c commit 7621581
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/structure.cpp
Expand Up @@ -1008,7 +1008,7 @@ bool structSetManufacture(STRUCTURE *psStruct, DROID_TEMPLATE *psTempl, QUEUE_MO
(int)psStruct->pStructureType->type);
/* psTempl might be NULL if the build is being cancelled in the middle */

ASSERT_OR_RETURN(false, (validTemplateForFactory(psTempl, psStruct) && researchedTemplate(psTempl, psStruct->player)) || psStruct->player == scavengerPlayer() || !bMultiPlayer, "Wrong template for player %d factory, type %d.", psStruct->player, psStruct->pStructureType->type);
ASSERT_OR_RETURN(false, (validTemplateForFactory(psTempl, psStruct) && researchedTemplate(psTempl, psStruct->player, true)) || psStruct->player == scavengerPlayer() || !bMultiPlayer, "Wrong template for player %d factory, type %d.", psStruct->player, psStruct->pStructureType->type);

psFact = &psStruct->pFunctionality->factory;

Expand Down
48 changes: 34 additions & 14 deletions src/template.cpp
Expand Up @@ -60,7 +60,27 @@ static const StringToEnum<DROID_TYPE> map_DROID_TYPE[] =
{"DROID", DROID_DEFAULT },
};

bool researchedTemplate(DROID_TEMPLATE *psCurr, int player)
static bool researchedItem(DROID_TEMPLATE *psCurr, int player, COMPONENT_TYPE partIndex, int part, bool allowZero, bool allowRedundant)
{
if (allowZero && part <= 0)
{
return true;
}
int availability = apCompLists[player][partIndex][part];
return availability == AVAILABLE || (allowRedundant && availability == REDUNDANT);
}

static bool researchedPart(DROID_TEMPLATE *psCurr, int player, COMPONENT_TYPE partIndex, bool allowZero, bool allowRedundant)
{
return researchedItem(psCurr, player, partIndex, psCurr->asParts[partIndex], allowZero, allowRedundant);
}

static bool researchedWeap(DROID_TEMPLATE *psCurr, int player, int weapIndex, bool allowRedundant)
{
return researchedItem(psCurr, player, COMP_WEAPON, psCurr->asWeaps[weapIndex], false, allowRedundant);
}

bool researchedTemplate(DROID_TEMPLATE *psCurr, int player, bool allowRedundant)
{
// super hack -- cyborgs and transports are special, only check their body
switch (psCurr->droidType)
Expand All @@ -72,25 +92,25 @@ bool researchedTemplate(DROID_TEMPLATE *psCurr, int player)
case DROID_CYBORG_REPAIR:
case DROID_TRANSPORTER:
case DROID_SUPERTRANSPORTER:
return (apCompLists[player][COMP_BODY][psCurr->asParts[COMP_BODY]] == AVAILABLE);
return researchedPart(psCurr, player, COMP_BODY, false, allowRedundant);
default:
break; // now proceed to normal droids...
}
// Note the ugly special case for commanders - their weapon is unavailable
// NOTE: This is one ugly & hard to debug if statement.
if (apCompLists[player][COMP_BODY][psCurr->asParts[COMP_BODY]] != AVAILABLE
|| (psCurr->asParts[COMP_BRAIN] > 0 && apCompLists[player][COMP_BRAIN][psCurr->asParts[COMP_BRAIN]] != AVAILABLE)
|| apCompLists[player][COMP_PROPULSION][psCurr->asParts[COMP_PROPULSION]] != AVAILABLE
|| (psCurr->asParts[COMP_SENSOR] > 0 && apCompLists[player][COMP_SENSOR][psCurr->asParts[COMP_SENSOR]] != AVAILABLE)
|| (psCurr->asParts[COMP_ECM] > 0 && apCompLists[player][COMP_ECM][psCurr->asParts[COMP_ECM]] != AVAILABLE)
|| (psCurr->asParts[COMP_REPAIRUNIT] > 0 && apCompLists[player][COMP_REPAIRUNIT][psCurr->asParts[COMP_REPAIRUNIT]] != AVAILABLE)
|| (psCurr->asParts[COMP_CONSTRUCT] > 0 && apCompLists[player][COMP_CONSTRUCT][psCurr->asParts[COMP_CONSTRUCT]] != AVAILABLE)
|| (psCurr->asParts[COMP_BRAIN] == 0 && psCurr->numWeaps > 0 && apCompLists[player][COMP_WEAPON][psCurr->asWeaps[0]] != AVAILABLE)
|| (psCurr->numWeaps > 1 && apCompLists[player][COMP_WEAPON][psCurr->asWeaps[1]] != AVAILABLE))
// NOTE: This was one ugly & hard to debug if statement.
bool researchedEverything = researchedPart(psCurr, player, COMP_BODY, false, allowRedundant)
&& researchedPart(psCurr, player, COMP_BRAIN, true, allowRedundant)
&& researchedPart(psCurr, player, COMP_PROPULSION, false, allowRedundant)
&& researchedPart(psCurr, player, COMP_SENSOR, true, allowRedundant)
&& researchedPart(psCurr, player, COMP_ECM, true, allowRedundant)
&& researchedPart(psCurr, player, COMP_REPAIRUNIT, true, allowRedundant)
&& researchedPart(psCurr, player, COMP_CONSTRUCT, true, allowRedundant);
unsigned ignoreFirstWeapon = psCurr->asParts[COMP_BRAIN] != 0? 1 : 0;
for (unsigned weapIndex = ignoreFirstWeapon; weapIndex < psCurr->numWeaps && researchedEverything; ++weapIndex)
{
return false;
researchedEverything = researchedWeap(psCurr, player, weapIndex, allowRedundant);
}
return true;
return researchedEverything;
}

bool initTemplates()
Expand Down
2 changes: 1 addition & 1 deletion src/template.h
Expand Up @@ -35,6 +35,6 @@ a string ID or something the user types in*/
const char* getTemplateName(const DROID_TEMPLATE *psTemplate);

/// Have we researched the components of this template?
bool researchedTemplate(DROID_TEMPLATE *psCurr, int player);
bool researchedTemplate(DROID_TEMPLATE *psCurr, int player, bool allowRedundant = false);

#endif // TEMPLATE_H

0 comments on commit 7621581

Please sign in to comment.