Skip to content

Commit

Permalink
Moved faction sorting from the FLG manager to the connect engine
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vultraz committed May 26, 2018
1 parent 0c3ca19 commit 0504304
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
19 changes: 19 additions & 0 deletions src/game_initialization/connect_engine.cpp
Expand Up @@ -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.
Expand Down
19 changes: 0 additions & 19 deletions src/game_initialization/flg_manager.cpp
Expand Up @@ -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()
Expand Down

0 comments on commit 0504304

Please sign in to comment.