Fixed a crash with unknown side type.

And switch to an imo better scheme: use side id instead of side type,
and fallback on random side when not provided. So it means that the
switch to get the rebels is no more '--side1=Elvish Captain' but
simply '--side1=Rebels'.
This commit is contained in:
Guillaume Melquiond 2005-01-29 10:05:07 +00:00
parent c92240e5c0
commit 5ff86dbf58

View file

@ -729,20 +729,24 @@ bool game_controller::play_multiplayer_mode()
controller = side_controllers.find(side_num),
algorithm = side_algorithms.find(side_num);
const config* side = type == side_types.end() ? era_cfg->child("multiplayer_side") :
era_cfg->find_child("multiplayer_side","type",type->second);
const config* side = type == side_types.end() ?
era_cfg->find_child("multiplayer_side", "random_faction", "yes") :
era_cfg->find_child("multiplayer_side", "id", type->second);
if((*side)["random_faction"] == "yes") {
if (side == NULL) {
unknown_side_id:
std::string side_name = (type == side_types.end() ? "default" : type->second);
std::cerr << "Could not find side '" << side_name << "' for side " << side_num << "\n";
return false;
}
if ((*side)["random_faction"] == "yes") {
const config::child_list& eras = era_cfg->get_children("multiplayer_side");
for(int i = 0; i != 100 && (*side)["random_faction"] == "yes"; ++i) {
side = eras[rand()%eras.size()];
}
}
if(side == NULL || (*side)["random_faction"] == "yes" || (*side)["type"] == "random") {
std::string side_name = (type == side_types.end() ? "default" : type->second);
std::cerr << "Could not find side '" << side_name << "' for side " << side_num << "\n";
return false;
if ((*side)["random_faction"] == "yes")
goto unknown_side_id;
}
char buf[20];