Skip to content

Commit

Permalink
Let's use enums for groupnumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Feb 14, 2024
1 parent 6a71ad6 commit 6dbcfc2
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/display3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3622,15 +3622,20 @@ static void drawDroidAndStructureSelections()
/// X/Y offset to display the group number at
#define GN_X_OFFSET (8)
#define GN_Y_OFFSET (3)
enum GROUPNUMBER_TYPE
{
GN_NORMAL,
GN_DAMAGED,
GN_FACTORY
};
/// rendering of the unit's group next to the unit itself,
/// or the group that will be assigned to the unit after production in the factory
static void drawGroupNumber(BASE_OBJECT *psObject)
{
UWORD id = UWORD_MAX;
UBYTE groupNumber = UBYTE_MAX;
int32_t x = 0, y = 0;
bool isFactory = false;
bool wentToRepair = false;
GROUPNUMBER_TYPE groupNumberType = GN_NORMAL;

if (auto *psDroid = dynamic_cast<DROID*>(psObject))
{
Expand All @@ -3642,7 +3647,7 @@ static void drawGroupNumber(BASE_OBJECT *psObject)

if (psDroid->repairGroup != UBYTE_MAX) {
groupNumber = psDroid->repairGroup;
wentToRepair = true;
groupNumberType = GN_DAMAGED;
} else {
groupNumber = psDroid->group;
}
Expand All @@ -3660,7 +3665,7 @@ static void drawGroupNumber(BASE_OBJECT *psObject)
y = scrY - GN_Y_OFFSET;

groupNumber = psStruct->productToGroup;
isFactory = true;
groupNumberType = GN_FACTORY;
}

switch (groupNumber)
Expand Down Expand Up @@ -3701,17 +3706,19 @@ static void drawGroupNumber(BASE_OBJECT *psObject)

if (id != UWORD_MAX)
{
if (wentToRepair)
switch (groupNumberType)
{
case GN_NORMAL:
iV_DrawImage(IntImages, id, x, y);
break;
case GN_DAMAGED:
iV_DrawImageTint(IntImages, id, x, y, pal_RGBA(255, 0, 0, 255) /* red */);
}
else if (isFactory)
{
break;
case GN_FACTORY:
iV_DrawImageTint(IntImages, id, x, y, pal_RGBA(255, 220, 115, 255) /* gold */);
}
else
{
iV_DrawImage(IntImages, id, x, y);
break;
default:
break;
}
}
}
Expand Down

0 comments on commit 6dbcfc2

Please sign in to comment.