Skip to content

Commit

Permalink
replace uint8_t return codes with enum
Browse files Browse the repository at this point in the history
  • Loading branch information
aco4 authored Mar 16, 2024
1 parent 990710b commit a508344
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2703,19 +2703,22 @@ bool IsPlayerDroidLimitReached(int player)
return numDroids >= getMaxDroids(player);
}

// Return codes for the checkHaltOnMaxUnitsReached function
enum ReasonForProductionHalt : uint8_t {
NO_HALT = 0, // no limit reached and no halt
DROID_LIMIT = 1, // unit limit reached
MISSING_RELAY = 2, // can't build commander without command relay center
COMMANDER_LIMIT = 3, // commander unit limit reached
CONSTRUCTION_LIMIT = 4 // construction unit limit reached
};

// Check for max number of units reached and halt production.
// Returns a uint8_t representing the reason production was halted:
// 0 = no limit reached and no halt
// 1 = unit limit reached
// 2 = can't build commander without command relay center
// 3 = commander unit limit reached
// 4 = construction unit limit reached
static uint8_t checkHaltOnMaxUnitsReached(STRUCTURE *psStructure, bool isMission)
static ReasonForProductionHalt checkHaltOnMaxUnitsReached(STRUCTURE *psStructure, bool isMission)
{
CHECK_STRUCTURE(psStructure);

char limitMsg[300];
uint8_t haltReason = 0;
uint8_t haltReason = NO_HALT;
int player = psStructure->player;

DROID_TEMPLATE *templ = psStructure->pFunctionality->factory.psSubject;
Expand All @@ -2724,28 +2727,28 @@ static uint8_t checkHaltOnMaxUnitsReached(STRUCTURE *psStructure, bool isMission
// then put production on hold & return - we need a message to be displayed here !!!!!!!
if (IsPlayerDroidLimitReached(player))
{
haltReason = 1;
haltReason = DROID_LIMIT;
sstrcpy(limitMsg, _("Can't build any more units, Unit Limit Reached — Production Halted"));
}
else switch (droidTemplateType(templ))
{
case DROID_COMMAND:
if (!structureExists(player, REF_COMMAND_CONTROL, true, isMission))
{
haltReason = 2;
haltReason = MISSING_RELAY;
ssprintf(limitMsg, _("Can't build \"%s\" without a Command Relay Center — Production Halted"), templ->name.toUtf8().c_str());
}
else if (getNumCommandDroids(player) >= getMaxCommanders(player))
{
haltReason = 3;
haltReason = COMMANDER_LIMIT;
ssprintf(limitMsg, _("Can't build \"%s\", Commander Limit Reached — Production Halted"), templ->name.toUtf8().c_str());
}
break;
case DROID_CONSTRUCT:
case DROID_CYBORG_CONSTRUCT:
if (getNumConstructorDroids(player) >= getMaxConstructors(player))
{
haltReason = 4;
haltReason = CONSTRUCTION_LIMIT;
ssprintf(limitMsg, _("Can't build any more \"%s\", Construction Unit Limit Reached — Production Halted"), templ->name.toUtf8().c_str());
}
break;
Expand Down

0 comments on commit a508344

Please sign in to comment.