Skip to content

Commit

Permalink
FLG Manager: keep all random options sorted at the top of the faction…
Browse files Browse the repository at this point in the history
… list
  • Loading branch information
Vultraz committed Sep 5, 2017
1 parent 138cefe commit d864a89
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/game_initialization/flg_manager.cpp
Expand Up @@ -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;
});
}

Expand Down

1 comment on commit d864a89

@jyrkive
Copy link
Member

@jyrkive jyrkive commented on d864a89 Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is just wrong. It should return true if lhs is a random faction and rhs isn't.

Please sign in to comment.