Removed config::get_children from multiplayer_wait.cpp.

This commit is contained in:
Guillaume Melquiond 2009-03-20 07:09:27 +00:00
parent 5ec4fc7b82
commit cacf765f3c
6 changed files with 62 additions and 57 deletions

View File

@ -26,7 +26,7 @@
const std::string leader_list_manager::random_enemy_picture("units/random-dice.png");
leader_list_manager::leader_list_manager(const config::child_list& side_list,
leader_list_manager::leader_list_manager(const std::vector<const config *> &side_list,
gui::combo* leader_combo , gui::combo* gender_combo):
leaders_(),
genders_(),

View File

@ -22,13 +22,14 @@ namespace gui { class combo; }
#include "unit_types.hpp"
#include <string>
#include <vector>
class leader_list_manager
{
public:
static const std::string random_enemy_picture;
leader_list_manager(const config::child_list& side_list,
leader_list_manager(const std::vector<const config *> &side_list,
gui::combo* leader_combo = NULL, gui::combo* gender_combo = NULL);
void set_leader_combo(gui::combo* combo);
@ -47,7 +48,7 @@ private:
std::vector<std::string> leaders_;
std::vector<std::string> genders_;
std::vector<std::string> gender_ids_;
config::child_list side_list_;
std::vector<const config *> side_list_;
gui::combo* leader_combo_;
gui::combo* gender_combo_;
int colour_;

View File

@ -295,7 +295,7 @@ connect::side::side(connect& parent, const config& cfg, int index) :
// Pick the first faction with the greater amount of data matching the criteria
int faction_index = 0;
int best_score = 0;
std::vector<config*>::const_iterator faction = parent.era_sides_.begin();
std::vector<const config*>::const_iterator faction = parent.era_sides_.begin();
while(faction != parent.era_sides_.end()) {
int faction_score = 0;
const config& side = (**faction);
@ -575,12 +575,12 @@ void connect::side::init_ai_algorithm_combo()
void connect::side::update_faction_combo()
{
std::vector<std::string> factions;
for(std::vector<config*>::const_iterator faction = parent_->era_sides_.begin();
faction != parent_->era_sides_.end(); ++faction) {
const std::string& name = (**faction)["name"];
const std::string& icon = (**faction)["image"];
foreach (const config *faction, parent_->era_sides_)
{
const std::string& name = (*faction)["name"];
const std::string& icon = (*faction)["image"];
if (!icon.empty()) {
std::string rgb = (**faction)["flag_rgb"];
std::string rgb = (*faction)["flag_rgb"];
if (rgb.empty())
rgb = "magenta";
@ -906,11 +906,12 @@ void connect::side::resolve_random()
// Builds the list of sides eligible for choice (nonrandom factions)
std::vector<int> nonrandom_sides;
for (config::child_list::iterator itor = parent_->era_sides_.begin(),
itor_end = parent_->era_sides_.end(); itor != itor_end; ++itor)
int num = -1;
foreach (const config *i, parent_->era_sides_)
{
if((**itor)["random_faction"] != "yes") {
const std::string& faction_id = (**itor)["id"];
++num;
if ((*i)["random_faction"] != "yes") {
const std::string& faction_id = (*i)["id"];
if (
!faction_choices.empty() &&
std::find(faction_choices.begin(),faction_choices.end(),faction_id) == faction_choices.end()
@ -921,7 +922,7 @@ void connect::side::resolve_random()
std::find(faction_excepts.begin(),faction_excepts.end(),faction_id) != faction_excepts.end()
)
continue;
nonrandom_sides.push_back(itor - parent_->era_sides_.begin());
nonrandom_sides.push_back(num);
}
}
@ -1423,10 +1424,8 @@ void connect::lists_init()
player_types_.push_back(_("Computer Player"));
player_types_.push_back(_("Empty"));
for(std::vector<config*>::const_iterator faction = era_sides_.begin();
faction != era_sides_.end();
++faction) {
player_factions_.push_back((**faction)["name"]);
foreach (const config *faction, era_sides_) {
player_factions_.push_back((*faction)["name"]);
}
// AI algorithms
@ -1676,7 +1675,10 @@ void connect::load_game()
}
if (era_cfg)
{
era_sides_ = era_cfg->get_children("multiplayer_side");
era_sides_.clear();
foreach (const config &e, era_cfg->child_range("multiplayer_side")) {
era_sides_.push_back(&e);
}
level_.add_child("era", *era_cfg);
}

View File

@ -256,7 +256,7 @@ private:
create::parameters params_;
/** The list of available sides for the current era. */
config::child_list era_sides_;
std::vector<const config *> era_sides_;
// Lists used for combos
std::vector<std::string> player_types_;

View File

@ -38,7 +38,7 @@ const int leader_pane_border = 10;
namespace mp {
wait::leader_preview_pane::leader_preview_pane(game_display& disp,
const config::child_list& side_list, int color) :
const std::vector<const config *> &side_list, int color) :
gui::preview_pane(disp.video()),
side_list_(side_list),
color_(color),
@ -222,34 +222,40 @@ void wait::join_game(bool observe)
append_to_title(": " + level_["name"]);
if (!observe) {
const config::child_list& sides_list = level_.get_children("side");
//search for an appropriate vacant slot. If a description is set
//(i.e. we're loading from a saved game), then prefer to get the side
//with the same description as our login. Otherwise just choose the first
//available side.
int side_choice = -1;
for(config::child_list::const_iterator s = sides_list.begin(); s != sides_list.end(); ++s) {
if((**s)["controller"] == "reserved" && (**s)["current_player"] == preferences::login())
const config *side_choice = NULL;
int side_num = -1, nb_sides = 0;
foreach (const config &sd, level_.child_range("side"))
{
if (sd["controller"] == "reserved" && sd["current_player"] == preferences::login())
{
side_choice = s - sides_list.begin();
side_choice = &sd;
side_num = nb_sides;
break;
}
if((**s)["controller"] == "network" && (**s)["id"].empty()) {
if (side_choice < 0) // found the first empty side
side_choice = s - sides_list.begin();
if((**s)["current_player"] == preferences::login()) {
side_choice = s - sides_list.begin();
if (sd["controller"] == "network" && sd["id"].empty())
{
if (!side_choice) { // found the first empty side
side_choice = &sd;
side_num = nb_sides;
}
if (sd["current_player"] == preferences::login()) {
side_choice = &sd;
side_num = nb_sides;
break; // found the prefered one
}
}
++nb_sides;
}
if (static_cast<size_t>(side_choice) >= sides_list.size()) {
if (!side_choice) {
set_result(QUIT);
return;
}
const bool allow_changes = (*sides_list[side_choice])["allow_changes"] != "no";
const bool allow_changes = (*side_choice)["allow_changes"] != "no";
//if the client is allowed to choose their team, instead of having
//it set by the server, do that here.
@ -263,29 +269,28 @@ void wait::join_game(bool observe)
/** @todo Check whether we have the era. If we don't inform the user. */
if(era == NULL)
throw config::error(_("No era information found."));
const config::child_list& possible_sides =
era->get_children("multiplayer_side");
if(possible_sides.empty()) {
config::const_child_itors possible_sides = era->child_range("multiplayer_side");
if (possible_sides.first == possible_sides.second) {
set_result(QUIT);
throw config::error(_("No multiplayer sides found"));
return;
}
int color = side_choice;
const std::string color_str = (*sides_list[side_choice])["colour"];
int color = side_num;
const std::string color_str = (*side_choice)["colour"];
if (!color_str.empty())
color = game_config::color_info(color_str).index() - 1;
std::vector<std::string> choices;
for(config::child_list::const_iterator side =
possible_sides.begin(); side !=
possible_sides.end(); ++side)
std::vector<const config *> leader_sides;
foreach (const config &side, possible_sides)
{
const std::string& name = (**side)["name"];
const std::string& icon = (**side)["image"];
const std::string &name = side["name"];
const std::string &icon = side["image"];
leader_sides.push_back(&side);
if (!icon.empty()) {
std::string rgb = (**side)["flag_rgb"];
std::string rgb = side["flag_rgb"];
if (rgb.empty())
rgb = "magenta";
@ -297,11 +302,10 @@ void wait::join_game(bool observe)
}
std::vector<gui::preview_pane* > preview_panes;
leader_preview_pane leader_selector(disp(),
possible_sides, color);
leader_preview_pane leader_selector(disp(), leader_sides, color);
preview_panes.push_back(&leader_selector);
const int res = gui::show_dialog(disp(), NULL, _("Choose your faction:"), _("Starting position: ") + lexical_cast<std::string>(side_choice+1),
const int res = gui::show_dialog(disp(), NULL, _("Choose your faction:"), _("Starting position: ") + lexical_cast<std::string>(side_num + 1),
gui::OK_CANCEL, &choices, &preview_panes);
if(res < 0) {
set_result(QUIT);
@ -311,7 +315,7 @@ void wait::join_game(bool observe)
leader_choice = leader_selector.get_selected_leader();
gender_choice = leader_selector.get_selected_gender();
assert(faction_choice < possible_sides.size());
assert(faction_choice < leader_sides.size());
config faction;
config& change = faction.add_child("change_faction");
@ -429,8 +433,8 @@ void wait::process_network_data(const config& data, const network::connection so
} else if(data.child("side")) {
level_ = data;
LOG_NW << "got some sides. Current number of sides = "
<< level_.get_children("side").size() << ","
<< data.get_children("side").size() << "\n";
<< level_.child_count("side") << ','
<< data.child_count("side") << '\n';
generate_menu();
}
}
@ -443,10 +447,8 @@ void wait::generate_menu()
std::vector<std::string> details;
std::vector<std::string> playerlist;
const config::child_list& sides = level_.get_children("side");
for(config::child_list::const_iterator s = sides.begin(); s != sides.end(); ++s) {
const config& sd = **s;
foreach (const config &sd, level_.child_range("side"))
{
if(sd["allow_player"] == "no") {
continue;
}

View File

@ -50,7 +50,7 @@ private:
{
public:
leader_preview_pane(game_display& disp,
const config::child_list& side_list, int color);
const std::vector<const config *> &side_list, int color);
bool show_above() const;
bool left_side() const;
@ -63,7 +63,7 @@ private:
virtual void draw_contents();
virtual void process_event();
const config::child_list side_list_;
std::vector<const config *> side_list_;
const int color_;
gui::combo leader_combo_; // Must appear before the leader_list_manager
gui::combo gender_combo_; // Must appear before the leader_list_manager