From 050430460adb5dc1ed3968a737e3be46dc216bf5 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sun, 27 May 2018 03:00:25 +1100 Subject: [PATCH] Moved faction sorting from the FLG manager to the connect engine This list in the connect engine was passed to each of its side engine's flg managers, where it was then sorted by update_choosable_factions(). Basically, a whole bunch of unnecessary sorting. This makes it so the list is already sorted when it's passed to each side engine. None of the post-processing of the faction list (in populating available_leaders_) should mess with the order, as far as I can tell. --- src/game_initialization/connect_engine.cpp | 19 +++++++++++++++++++ src/game_initialization/flg_manager.cpp | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/game_initialization/connect_engine.cpp b/src/game_initialization/connect_engine.cpp index 2639bcba7426..b190d63cbc3e 100644 --- a/src/game_initialization/connect_engine.cpp +++ b/src/game_initialization/connect_engine.cpp @@ -178,6 +178,25 @@ connect_engine::connect_engine(saved_game& state, const bool first_scenario, mp_ era_factions_.push_back(&era); } + // Sort alphabetically, but with the random faction options always first. + // Since some eras have multiple random options we can't just assume there is + // only one random faction on top of the list. + std::sort(era_factions_.begin(), era_factions_.end(), [](const config* c1, const config* c2) { + const config& lhs = *c1; + const config& rhs = *c2; + + // Random factions always first. + if(lhs["random_faction"].to_bool() && !rhs["random_faction"].to_bool()) { + return true; + } + + if(!lhs["random_faction"].to_bool() && rhs["random_faction"].to_bool()) { + return false; + } + + return translation::compare(lhs["name"].str(), rhs["name"].str()) < 0; + }); + game_config::add_color_info(scenario()); // Create side engines. diff --git a/src/game_initialization/flg_manager.cpp b/src/game_initialization/flg_manager.cpp index 4f4472a82484..57eda15f81ed 100644 --- a/src/game_initialization/flg_manager.cpp +++ b/src/game_initialization/flg_manager.cpp @@ -381,25 +381,6 @@ void flg_manager::update_choosable_factions() choosable_factions_.push_back(faction); } } - - // Sort alphabetically, but with the random faction options always first. - // Since some eras have multiple random options we can't just assume there is - // only one random faction on top of the list. - std::sort(choosable_factions_.begin(), choosable_factions_.end(), [](const config* c1, const config* c2) { - const config& lhs = *c1; - const config& rhs = *c2; - - // Random factions always first. - if(lhs["random_faction"].to_bool() && !rhs["random_faction"].to_bool()) { - return true; - } - - if(!lhs["random_faction"].to_bool() && rhs["random_faction"].to_bool()) { - return false; - } - - return translation::compare(lhs["name"].str(), rhs["name"].str()) < 0; - }); } void flg_manager::update_choosable_leaders()