Adding the ability to choose a random leader in a faction.

This commit is contained in:
Philippe Plantier 2004-09-21 20:35:48 +00:00
parent 062b44d5fa
commit 076ffcfd43
5 changed files with 41 additions and 31 deletions

View file

@ -21,7 +21,7 @@ name= _ "Default"
[multiplayer_side]
name= _ "&random-enemy.png,Random"
type=random
random_faction=yes
[/multiplayer_side]
[multiplayer_side]
@ -102,7 +102,7 @@ name= _ "Classic"
[multiplayer_side]
name= _ "&random-enemy.png,Random"
type=random
random_faction=yes
[/multiplayer_side]
[multiplayer_side]
@ -183,7 +183,7 @@ name= _ "Age of Heroes"
[multiplayer_side]
name= _ "&random-enemy.png,Random"
type=random
random_faction=yes
[/multiplayer_side]
[multiplayer_side]
@ -265,7 +265,7 @@ name= _ "Great War"
[multiplayer_side]
name= _ "&random-enemy.png,Random"
type=random
random_faction=yes
[/multiplayer_side]
[multiplayer_side]

View file

@ -184,7 +184,7 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
if(state.scenario == current_scenario)
state.scenario = (*scenario)["next_scenario"];
scenario = game_config.find_child(type,"id",state.scenario);
scenario = game_config.find_child(type,"id",state.scenario);
//if this isn't the last scenario, then save the game
if(scenario != NULL && save_game_after_scenario) {
@ -707,13 +707,15 @@ bool game_controller::play_multiplayer_mode()
const config* side = type == side_types.end() ? era_cfg->child("multiplayer_side") :
era_cfg->find_child("multiplayer_side","type",type->second);
#if 0
size_t tries = 0;
while(side != NULL && (*side)["type"] == "random" && ++tries < 100) {
const config::child_list& v = era_cfg->get_children("multiplayer_side");
side = v[rand()%v.size()];
}
#endif
if(side == NULL || (*side)["type"] == "random") {
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;

View file

@ -194,24 +194,24 @@ bool gamestatus::next_turn()
player_info read_player(const game_data& data, const config* cfg)
{
player_info res;
player_info res;
res.gold = atoi((*cfg)["gold"].c_str());
res.gold = atoi((*cfg)["gold"].c_str());
const config::child_list& units = cfg->get_children("unit");
for(config::child_list::const_iterator i = units.begin(); i != units.end(); ++i) {
res.available_units.push_back(unit(data,**i));
}
const config::child_list& units = cfg->get_children("unit");
for(config::child_list::const_iterator i = units.begin(); i != units.end(); ++i) {
res.available_units.push_back(unit(data,**i));
}
res.can_recruit.clear();
res.can_recruit.clear();
const std::string& can_recruit_str = (*cfg)["can_recruit"];
if(can_recruit_str != "") {
const std::vector<std::string> can_recruit = config::split(can_recruit_str);
std::copy(can_recruit.begin(),can_recruit.end(),std::inserter(res.can_recruit,res.can_recruit.end()));
}
const std::string& can_recruit_str = (*cfg)["can_recruit"];
if(can_recruit_str != "") {
const std::vector<std::string> can_recruit = config::split(can_recruit_str);
std::copy(can_recruit.begin(),can_recruit.end(),std::inserter(res.can_recruit,res.can_recruit.end()));
}
return res;
return res;
}
game_state read_game(const game_data& data, const config* cfg)

View file

@ -605,7 +605,7 @@ void leader_list_manager::update_leader_list(int side_index)
leaders_.clear();
if(side["type"] == "random") {
if(side["random_faction"] == "yes") {
if(combo_ != NULL) {
std::vector<std::string> dummy;
dummy.push_back("-");
@ -638,7 +638,7 @@ void leader_list_manager::update_leader_list(int side_index)
if (default_index == leaders_.size()) {
leaders_.push_back(default_leader);
}
std::vector<std::string> leader_strings;
for(itor = leaders_.begin(); itor != leaders_.end(); ++itor) {
@ -656,6 +656,10 @@ void leader_list_manager::update_leader_list(int side_index)
}
}
leaders_.push_back("random");
// FIXME: Maybe this should not code into the code.
leader_strings.push_back(_("&random-enemy.png,Random"));
if(combo_ != NULL) {
combo_->set_items(leader_strings);
combo_->set_selected(default_index);

View file

@ -726,20 +726,12 @@ lobby::RESULT mp_connect::process()
for(config::child_iterator side = sides.first; side != sides.second; ++side) {
int ntry = 0;
while((**side)["type"] == "random" && ntry < 1000) {
while((**side)["random_faction"] == "yes" && ntry < 1000) {
const int choice = rand()%real_sides.size();
(**side)["name"] = (*real_sides[choice])["name"];
// Choose a random leader type.
std::vector<std::string> types =
config::split((*real_sides[choice])["leader"]);
if (!types.empty()) {
const int lchoice = rand() % types.size();
(**side)["type"] = types[lchoice];
} else {
(**side)["type"] = (*real_sides[choice])["type"];
}
(**side)["type"] = "random";
(**side)["recruit"] = (*real_sides[choice])["recruit"];
(**side)["music"] = (*real_sides[choice])["music"];
@ -750,6 +742,18 @@ lobby::RESULT mp_connect::process()
++ntry;
}
if ((**side)["type"] == "random" || (**side)["type"].empty()) {
// Choose a random leader type.
std::vector<std::string> types =
config::split((**side)["leader"]);
if (!types.empty()) {
const int lchoice = rand() % types.size();
(**side)["type"] = types[lchoice];
} else {
}
}
}
start_game = true;