diff --git a/src/basedef.h b/src/basedef.h index 85151f81e3d..b780c948022 100644 --- a/src/basedef.h +++ b/src/basedef.h @@ -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. diff --git a/src/cmddroid.cpp b/src/cmddroid.cpp index d5d081d9ca9..547c67a807c 100644 --- a/src/cmddroid.cpp +++ b/src/cmddroid.cpp @@ -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) { @@ -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) diff --git a/src/structure.cpp b/src/structure.cpp index fd8da4cd56f..3b4c0f0642f 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -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});