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

game.cpp: Fix loading commander droids without psGroup #3596

Merged
Merged
Changes from all commits
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
12 changes: 11 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5552,10 +5552,16 @@ static bool loadSaveDroid(const char *pFileName, PerPlayerDroidLists& ppsCurrent
// Sort list so transports are loaded first, since they must be loaded before the droids they contain.
std::vector<std::pair<int, WzString>> sortedList;
bool missionList = fName.compare("mdroid");
// This will be set to the largest group ID found throughout the droid file + 1.
//
// This helps to allocate non-conflicting group IDs for commanders which
// happen to lose their group, e.g. when transitioning from an offworld mission.
int nextFreeGroupID = 0;
for (size_t i = 0; i < list.size(); ++i)
{
ini.beginGroup(list[i]);
DROID_TYPE droidType = (DROID_TYPE)ini.value("droidType").toInt();
int aigroup = ini.value("aigroup", -1).toInt();
int priority = 0;
switch (droidType)
{
Expand All @@ -5571,6 +5577,10 @@ static bool loadSaveDroid(const char *pFileName, PerPlayerDroidLists& ppsCurrent
{
++priority;
}
if (aigroup >= 0)
{
nextFreeGroupID = std::max(nextFreeGroupID, aigroup) + 1;
}
default:
break;
}
Expand Down Expand Up @@ -5701,7 +5711,7 @@ static bool loadSaveDroid(const char *pFileName, PerPlayerDroidLists& ppsCurrent
{
if (isTransporter(psDroid) || psDroid->droidType == DROID_COMMAND)
{
DROID_GROUP *psGroup = grpCreate();
DROID_GROUP *psGroup = grpCreate(nextFreeGroupID++);
psGroup->add(psDroid);
}
else
Expand Down
Loading