From d864a89a15ee0159b28b5daec492d3070db31032 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Wed, 6 Sep 2017 10:58:47 +1100 Subject: [PATCH] FLG Manager: keep all random options sorted at the top of the faction list --- src/game_initialization/flg_manager.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/game_initialization/flg_manager.cpp b/src/game_initialization/flg_manager.cpp index 873a70b42c29..d5c7b4d08e70 100644 --- a/src/game_initialization/flg_manager.cpp +++ b/src/game_initialization/flg_manager.cpp @@ -377,12 +377,19 @@ void flg_manager::update_choosable_factions() } } - // Sort alphabetically, but with the 'random' option always first - // TODO: some eras like ageless have multiple random options - // ('any random faction', 'a random default faction', 'a random non-default faction', etc) - // so this code shouldn't assume that there is only one random faction which is on top of the list. - std::sort(choosable_factions_.begin() + 1, choosable_factions_.end(), [](const config* c1, const config* c2) { - return translation::compare((*c1)["name"].str(), (*c2)["name"].str()) < 0; + // 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 false; + } + + return translation::compare(lhs["name"].str(), rhs["name"].str()) < 0; }); }