From 9423ce1482820a4099ad70f84fc6a6cc6197d9ab Mon Sep 17 00:00:00 2001 From: Dylan <28832631+DARwins1@users.noreply.github.com> Date: Tue, 10 Oct 2023 00:59:42 -0700 Subject: [PATCH] Prevent Commander list scrambling on save-load Prevents the list of commanders in the command tab from being jumbled up when loading a save by sorting the list by droid ID. --- src/hci/commander.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hci/commander.cpp b/src/hci/commander.cpp index b2eda0d6763..7e5723c268a 100644 --- a/src/hci/commander.cpp +++ b/src/hci/commander.cpp @@ -46,7 +46,10 @@ void CommanderController::updateCommandersList() } } - std::reverse(commanders.begin(), commanders.end()); + // Sort the list of commanders from lowest to highest id (using a lambda function defined within the sort call) + std::sort(commanders.begin(), commanders.end(), [](DROID *droid1, DROID *droid2) { + return droid1->id < droid2->id; + }); } STRUCTURE_STATS *CommanderController::getObjectStatsAt(size_t objectIndex) const