Skip to content

Commit

Permalink
Enforce commander production limits if no command relay is built.
Browse files Browse the repository at this point in the history
Refs ticket 1661.
  • Loading branch information
KJeff01 committed Dec 30, 2018
1 parent fbeae27 commit 7d0a911
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/structure.cpp
Expand Up @@ -2413,6 +2413,22 @@ static bool IsFactoryCommanderGroupFull(const FACTORY *psFactory)
return true;
}

// Check if a player has built a command relay.
bool hasBuiltCommandRelay(bool isMission, int player)
{
bool hasRelay = false;

for (STRUCTURE *psCurr = isMission ? mission.apsStructLists[player] : apsStructLists[player]; psCurr; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_COMMAND_CONTROL && psCurr->status == SS_BUILT)
{
hasRelay = true;
break;
}
}

return hasRelay;
}

// Disallow manufacture of units once these limits are reached,
// doesn't mean that these numbers can't be exceeded if units are
Expand Down Expand Up @@ -2455,35 +2471,35 @@ bool IsPlayerDroidLimitReached(int player)
}

// Check for max number of units reached and halt production.
//
static bool checkHaltOnMaxUnitsReached(STRUCTURE *psStructure)
static bool checkHaltOnMaxUnitsReached(STRUCTURE *psStructure, bool isMission)
{
CHECK_STRUCTURE(psStructure);

char limitMsg[300];
bool isLimit = false;
int player = psStructure->player;

DROID_TEMPLATE *templ = psStructure->pFunctionality->factory.psSubject;

// if the players that owns the factory has reached his (or hers) droid limit
// then put production on hold & return - we need a message to be displayed here !!!!!!!
if (IsPlayerDroidLimitReached(psStructure->player))
if (IsPlayerDroidLimitReached(player))
{
isLimit = true;
sstrcpy(limitMsg, _("Can't build anymore units, Unit Limit Reached — Production Halted"));
}
else switch (droidTemplateType(templ))
{
case DROID_COMMAND:
if (getNumCommandDroids(psStructure->player) >= getMaxCommanders(psStructure->player))
if (!hasBuiltCommandRelay(isMission, player) || getNumCommandDroids(player) >= getMaxCommanders(player))
{
isLimit = true;
ssprintf(limitMsg, _("Can't build anymore \"%s\", Command Control Limit Reached — Production Halted"), templ->name.toUtf8().c_str());
}
break;
case DROID_CONSTRUCT:
case DROID_CYBORG_CONSTRUCT:
if (getNumConstructorDroids(psStructure->player) >= getMaxConstructors(psStructure->player))
if (getNumConstructorDroids(player) >= getMaxConstructors(player))
{
isLimit = true;
ssprintf(limitMsg, _("Can't build anymore \"%s\", Construction Unit Limit Reached — Production Halted"), templ->name.toUtf8().c_str());
Expand All @@ -2493,7 +2509,7 @@ static bool checkHaltOnMaxUnitsReached(STRUCTURE *psStructure)
break;
}

if (isLimit && psStructure->player == selectedPlayer && lastMaxUnitMessage + MAX_UNIT_MESSAGE_PAUSE < gameTime)
if (isLimit && player == selectedPlayer && lastMaxUnitMessage + MAX_UNIT_MESSAGE_PAUSE < gameTime)
{
addConsoleMessage(limitMsg, DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
lastMaxUnitMessage = gameTime;
Expand Down Expand Up @@ -3137,7 +3153,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
// also need to check if a command droid's group is full

// If the factory commanders group is full - return
if (IsFactoryCommanderGroupFull(psFactory) || checkHaltOnMaxUnitsReached(psStructure))
if (IsFactoryCommanderGroupFull(psFactory) || checkHaltOnMaxUnitsReached(psStructure, isMission))
{
return;
}
Expand All @@ -3162,7 +3178,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
}

//check for manufacture to be complete
if (psFactory->buildPointsRemaining <= 0 && !IsFactoryCommanderGroupFull(psFactory) && !checkHaltOnMaxUnitsReached(psStructure))
if (psFactory->buildPointsRemaining <= 0 && !IsFactoryCommanderGroupFull(psFactory) && !checkHaltOnMaxUnitsReached(psStructure, isMission))
{
if (isMission)
{
Expand Down
2 changes: 2 additions & 0 deletions src/structure.h
Expand Up @@ -78,6 +78,8 @@ void setMaxDroids(int player, int value);
void setMaxCommanders(int player, int value);
void setMaxConstructors(int player, int value);

bool hasBuiltCommandRelay(bool isMission, int player);

bool IsPlayerDroidLimitReached(int player);

bool loadStructureStats(WzConfig &ini);
Expand Down

0 comments on commit 7d0a911

Please sign in to comment.