Skip to content

Commit

Permalink
Implemented fallback group for commanders
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Mar 11, 2024
1 parent d48322b commit 7598416
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/basedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct BASE_OBJECT : public SIMPLE_OBJECT
SCREEN_DISP_DATA sDisplay; ///< screen coordinate details
UBYTE group = 0; ///< Which group selection is the droid currently in?
UBYTE repairGroup = UBYTE_MAX; ///< Group to be set when the unit has been repaired
UBYTE fallbackGroup = UBYTE_MAX; ///< Group to revert if the commander capacity is full
UBYTE selected; ///< Whether the object is selected (might want this elsewhere)
UBYTE visible[MAX_PLAYERS]; ///< Whether object is visible to specific player
UBYTE seenThisTick[MAX_PLAYERS]; ///< Whether object has been seen this tick by the specific player.
Expand Down
8 changes: 8 additions & 0 deletions src/cmddroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ bool cmdDroidAddDroid(DROID *psCommander, DROID *psDroid)
ASSERT_OR_RETURN(false, psDroid != nullptr, "psDroid is null?");

auto initialDroidGroup = psDroid->group;
auto fallbackDroidGroup = initialDroidGroup != UBYTE_MAX ? initialDroidGroup : psDroid->fallbackGroup;

if (psCommander->psGroup == nullptr)
{
Expand Down Expand Up @@ -123,6 +124,13 @@ bool cmdDroidAddDroid(DROID *psCommander, DROID *psDroid)
addConsoleMessage(_("Commander needs a higher level to command more units"), DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
lastMaxCmdLimitMsgTime = gameTime;
}

if (fallbackDroidGroup != UBYTE_MAX)
{
psDroid->group = fallbackDroidGroup;
psDroid->fallbackGroup = UBYTE_MAX;
// fixme: SelectNewDroid doesn't work here for some reason
}
}

if (initialDroidGroup != psDroid->group)
Expand Down
15 changes: 11 additions & 4 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2486,11 +2486,18 @@ static bool structPlaceDroid(STRUCTURE *psStructure, DROID_TEMPLATE *psTempl, DR
bool hasCommander = psFact->psCommander != nullptr && myResponsibility(psStructure->player);
// assign a group to the manufactured droid
// if a commander is assigned, ignore this behavior (except for builders)
if (psStructure->productToGroup != UBYTE_MAX && (!hasCommander || isConstructionDroid(psNewDroid)))
if (psStructure->productToGroup != UBYTE_MAX)
{
psNewDroid->group = psStructure->productToGroup;
intGroupsChanged(psNewDroid->group); // update groups UI
SelectNewDroid(psNewDroid);
if (!hasCommander || isConstructionDroid(psNewDroid))
{
psNewDroid->group = psStructure->productToGroup;
intGroupsChanged(psNewDroid->group); // update groups UI
SelectNewDroid(psNewDroid);
}
else
{
psNewDroid->fallbackGroup = psStructure->productToGroup;
}
}
setFactorySecondaryState(psNewDroid, psStructure);
const auto mapCoord = map_coord({x, y});
Expand Down

0 comments on commit 7598416

Please sign in to comment.