mail[Wesnoth-commits] r40482 - in /trunk/src: play_controller.cpp play_controller.hpp team.cpp team.hpp


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

Header


Content

Posted by guillaume . melquiond on December 31, 2009 - 14:28:
Author: silene
Date: Thu Dec 31 14:28:45 2009
New Revision: 40482

URL: http://svn.gna.org/viewcvs/wesnoth?rev=40482&view=rev
Log:
Removed usage of deprecated config::child_list.

Modified:
    trunk/src/play_controller.cpp
    trunk/src/play_controller.hpp
    trunk/src/team.cpp
    trunk/src/team.hpp

Modified: trunk/src/play_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/play_controller.cpp?rev=40482&r1=40481&r2=40482&view=diff
==============================================================================
--- trunk/src/play_controller.cpp (original)
+++ trunk/src/play_controller.cpp Thu Dec 31 14:28:45 2009
@@ -139,12 +139,11 @@
        }
        recorder.set_skip(false);
 
-       const config::child_list& unit_cfg = level_.get_children("side");
        const bool snapshot = utils::string_bool(level_["snapshot"]);
 
        if(utils::string_bool(level_["modify_placing"])) {
                LOG_NG << "modifying placing...\n";
-               place_sides_in_preferred_locations(map_,unit_cfg);
+               place_sides_in_preferred_locations();
        }
 
        foreach (const config &t, level_.child_range("time_area")) {
@@ -161,14 +160,23 @@
 
        std::set<std::string> seen_save_ids;
 
-       for(config::child_list::const_iterator ui = unit_cfg.begin(); ui != 
unit_cfg.end(); ++ui) {
-               std::string save_id = get_unique_saveid(**ui, seen_save_ids);
+       int team_num = 0;
+       foreach (const config &side, level_.child_range("side"))
+       {
+               std::string save_id = get_unique_saveid(side, seen_save_ids);
                seen_save_ids.insert(save_id);
-               if (first_human_team_ == -1){
-                       first_human_team_ = 
team_manager_.get_first_human_team(ui, unit_cfg, preferences::client_type(), 
preferences::login());
-               }
-               gamestate_.build_team(**ui, save_id, teams_, level_, map_
+               if (first_human_team_ == -1) {
+                       const std::string &controller = side["controller"];
+                       if (controller == preferences::client_type() &&
+                           side["id"] == preferences::login()) {
+                               first_human_team_ = team_num;
+                       } else if (controller == "human") {
+                               first_human_team_ = team_num;
+                       }
+               }
+               gamestate_.build_team(side, save_id, teams_, level_, map_
                                , units_, snapshot);
+               ++team_num;
        }
 
        // mouse_handler expects at least one team for linger mode to work.
@@ -280,34 +288,36 @@
 
 static bool operator<(const placing_info& a, const placing_info& b) { return 
a.score > b.score; }
 
-void play_controller::place_sides_in_preferred_locations(gamemap& map, const 
config::child_list& sides)
+void play_controller::place_sides_in_preferred_locations()
 {
        std::vector<placing_info> placings;
 
-       const int num_pos = map.num_valid_starting_positions();
-
-       for(config::child_list::const_iterator s = sides.begin(); s != 
sides.end(); ++s) {
-               const int side_num = s - sides.begin() + 1;
+       int num_pos = map_.num_valid_starting_positions();
+
+       int side_num = 1;
+       foreach (const config &side, level_.child_range("side"))
+       {
                for(int p = 1; p <= num_pos; ++p) {
-                       const map_location& pos = map.starting_position(p);
-                       const int score = placing_score(**s,map,pos);
+                       const map_location& pos = map_.starting_position(p);
+                       int score = placing_score(side, map_, pos);
                        placing_info obj;
                        obj.side = side_num;
                        obj.score = score;
                        obj.pos = pos;
                        placings.push_back(obj);
                }
+               ++side_num;
        }
 
        std::sort(placings.begin(),placings.end());
        std::set<int> placed;
        std::set<map_location> positions_taken;
 
-       for(std::vector<placing_info>::const_iterator i = placings.begin(); i 
!= placings.end() && placed.size() != sides.size(); ++i) {
+       for (std::vector<placing_info>::const_iterator i = placings.begin(); 
i != placings.end() && int(placed.size()) != side_num - 1; ++i) {
                if(placed.count(i->side) == 0 && 
positions_taken.count(i->pos) == 0) {
                        placed.insert(i->side);
                        positions_taken.insert(i->pos);
-                       map.set_starting_position(i->side,i->pos);
+                       map_.set_starting_position(i->side,i->pos);
                        LOG_NG << "placing side " << i->side << " at " << 
i->pos << '\n';
                }
        }

Modified: trunk/src/play_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/play_controller.hpp?rev=40482&r1=40481&r2=40482&view=diff
==============================================================================
--- trunk/src/play_controller.hpp (original)
+++ trunk/src/play_controller.hpp Thu Dec 31 14:28:45 2009
@@ -169,7 +169,7 @@
        void fire_start(bool execute);
        virtual void init_gui();
        virtual void init_side(const unsigned int team_index, bool is_replay 
= false);
-       void place_sides_in_preferred_locations(gamemap& map, const 
config::child_list& sides);
+       void place_sides_in_preferred_locations();
        virtual void finish_side_turn();
        void finish_turn();
        bool clear_shroud();

Modified: trunk/src/team.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/team.cpp?rev=40482&r1=40481&r2=40482&view=diff
==============================================================================
--- trunk/src/team.cpp (original)
+++ trunk/src/team.cpp Thu Dec 31 14:28:45 2009
@@ -56,19 +56,6 @@
 {
        assert(teams);
        return *teams;
-}
-
-int teams_manager::get_first_human_team(const 
config::child_list::const_iterator& cfg, const config::child_list& unit_cfg,
-                                               const std::string& 
client_type, const std::string& login)
-{
-       int result = -1;
-       const std::string& controller = (**cfg)["controller"];
-       if (controller == client_type && (**cfg)["id"] == login) {
-               result = cfg - unit_cfg.begin();
-       } else if((**cfg)["controller"] == "human") {
-               result = cfg - unit_cfg.begin();
-       }
-       return result;
 }
 
 team::team_info::team_info(const config& cfg) :

Modified: trunk/src/team.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/team.hpp?rev=40482&r1=40481&r2=40482&view=diff
==============================================================================
--- trunk/src/team.hpp (original)
+++ trunk/src/team.hpp Thu Dec 31 14:28:45 2009
@@ -310,7 +310,6 @@
        ~teams_manager();
 
        static const std::vector<team>& get_teams();
-       int get_first_human_team(const config::child_list::const_iterator& 
cfg, const config::child_list& unit_cfg, const std::string& client_type, 
const std::string& login);
 };
 
 namespace player_teams {




Related Messages


Powered by MHonArc, Updated Thu Dec 31 14:40:12 2009