mail[Wesnoth-commits] r33916 - /trunk/src/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on March 20, 2009 - 08:09:
Author: silene
Date: Fri Mar 20 08:09:27 2009
New Revision: 33916

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33916&view=rev
Log:
Removed config::get_children from multiplayer_wait.cpp.

Modified:
    trunk/src/leader_list.cpp
    trunk/src/leader_list.hpp
    trunk/src/multiplayer_connect.cpp
    trunk/src/multiplayer_connect.hpp
    trunk/src/multiplayer_wait.cpp
    trunk/src/multiplayer_wait.hpp

Modified: trunk/src/leader_list.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/leader_list.cpp?rev=33916&r1=33915&r2=33916&view=diff
==============================================================================
--- trunk/src/leader_list.cpp (original)
+++ trunk/src/leader_list.cpp Fri Mar 20 08:09:27 2009
@@ -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_(),

Modified: trunk/src/leader_list.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/leader_list.hpp?rev=33916&r1=33915&r2=33916&view=diff
==============================================================================
--- trunk/src/leader_list.hpp (original)
+++ trunk/src/leader_list.hpp Fri Mar 20 08:09:27 2009
@@ -22,13 +22,14 @@
 
 #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 @@
        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_;

Modified: trunk/src/multiplayer_connect.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_connect.cpp?rev=33916&r1=33915&r2=33916&view=diff
==============================================================================
--- trunk/src/multiplayer_connect.cpp (original)
+++ trunk/src/multiplayer_connect.cpp Fri Mar 20 08:09:27 2009
@@ -295,7 +295,7 @@
                        // 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::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 @@
 
                // 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 @@
                                        
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 @@
        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 @@
        }
        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);
        }
 

Modified: trunk/src/multiplayer_connect.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_connect.hpp?rev=33916&r1=33915&r2=33916&view=diff
==============================================================================
--- trunk/src/multiplayer_connect.hpp (original)
+++ trunk/src/multiplayer_connect.hpp Fri Mar 20 08:09:27 2009
@@ -256,7 +256,7 @@
        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_;

Modified: trunk/src/multiplayer_wait.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_wait.cpp?rev=33916&r1=33915&r2=33916&view=diff
==============================================================================
--- trunk/src/multiplayer_wait.cpp (original)
+++ trunk/src/multiplayer_wait.cpp Fri Mar 20 08:09:27 2009
@@ -38,7 +38,7 @@
 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 @@
        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
                                }
                        }
-               }
-               if (static_cast<size_t>(side_choice) >= sides_list.size()) {
+                       ++nb_sides;
+               }
+               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 @@
                        /** @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 @@
                        }
 
                        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 @@
                        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 @@
        } 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 @@
        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;
                }

Modified: trunk/src/multiplayer_wait.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_wait.hpp?rev=33916&r1=33915&r2=33916&view=diff
==============================================================================
--- trunk/src/multiplayer_wait.hpp (original)
+++ trunk/src/multiplayer_wait.hpp Fri Mar 20 08:09:27 2009
@@ -50,7 +50,7 @@
        {
        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 @@
                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




Related Messages


Powered by MHonArc, Updated Fri Mar 20 11:00:34 2009