Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic assignment of units produced in factories to groups #3628

Merged
merged 18 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implemented fallback group for commanders
Monsterovich authored and past-due committed May 3, 2024
commit 6108634851cec9e95efa5feced924f6f8a77e121
1 change: 1 addition & 0 deletions src/basedef.h
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions src/cmddroid.cpp
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 11 additions & 4 deletions src/structure.cpp
Original file line number Diff line number Diff line change
@@ -2479,11 +2479,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});