Fix the [multiplayer_side]type=random crash for no-gui games

(related to patch #2642)
This commit is contained in:
Alexander van Gessel 2012-04-08 16:31:07 +01:00
parent 91c9246ff1
commit 2316d75f6b

View file

@ -859,7 +859,21 @@ protected:
// If this side tag describes the leader of the side
if (!side_cfg_["no_leader"].to_bool() && side_cfg_["controller"] != "null") {
handle_leader(side_cfg_);
if (side_cfg_["type"] == "random") {
std::vector<std::string> types = utils::split(side_cfg_["random_leader"]);
if (types.empty())
types = utils::split(side_cfg_["leader"]);
if (types.empty()) {
utils::string_map i18n_symbols;
i18n_symbols["faction"] = side_cfg_["name"];
throw config::error(vgettext("Unable to find a leader type for faction $faction", i18n_symbols));
}
const int choice = rand() % types.size();
config leader = side_cfg_;
leader["type"] = types[choice];
handle_leader(leader);
} else
handle_leader(side_cfg_);
}
foreach (const config &l, side_cfg_.child_range("leader")) {
handle_leader(l);