mail[Wesnoth-commits] r13414 - in /branches/1.2/src: playturn.cpp server/game.cpp team.cpp team.hpp


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

Header


Content

Posted by joerg . hinrichs on September 05, 2006 - 21:59:
Author: jhinrichs
Date: Tue Sep  5 21:59:12 2006
New Revision: 13414

URL: http://svn.gna.org/viewcvs/wesnoth?rev=13414&view=rev
Log:
fixes bug #6390 (AI temporarily takes control of a side that the host wants 
to reassign via the command line). This implements to transfer control to 
allies.

Modified:
    branches/1.2/src/playturn.cpp
    branches/1.2/src/server/game.cpp
    branches/1.2/src/team.cpp
    branches/1.2/src/team.hpp

Modified: branches/1.2/src/playturn.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/playturn.cpp?rev=13414&r1=13413&r2=13414&view=diff
==============================================================================
--- branches/1.2/src/playturn.cpp (original)
+++ branches/1.2/src/playturn.cpp Tue Sep  5 21:59:12 2006
@@ -139,14 +139,16 @@
                const size_t index = static_cast<size_t>(side-1);
 
                const std::string& controller = (*change)["controller"];
+               const std::string& player = (*change)["player"];
 
                if(index < teams_.size()) {
-                       if(controller == "human") {
+                       teams_[index].set_current_player(player);
+                       if ( (controller == "human") && 
(!teams_[index].is_human()) ) {
                                teams_[index].make_human();
                                gui_.set_team(index);
-                       } else if(controller == "network") {
+                       } else if ( (controller == "network") && 
(!teams_[index].is_network()) ){
                                teams_[index].make_network();
-                       } else if(controller == "ai") {
+                       } else if ( (controller == "ai") && 
(!teams_[index].is_ai()) ) {
                                teams_[index].make_ai();
                        }
 
@@ -165,20 +167,32 @@
                int action = 0;
 
                std::vector<std::string> observers;
+               std::vector<team*> allies;
+               std::vector<std::string> options;
 
                //see if the side still has a leader alive. If they have
                //no leader, we assume they just want to be replaced by
                //the AI.
                const unit_map::const_iterator leader = 
find_leader(units_,side+1);
                if(leader != units_.end()) {
-                       std::vector<std::string> options;
                        options.push_back(_("Replace with AI"));
                        options.push_back(_("Replace with local player"));
                        options.push_back(_("Abort game"));
 
+                       //get all observers in as options to transfer control
                        for(std::set<std::string>::const_iterator ob = 
gui_.observers().begin(); ob != gui_.observers().end(); ++ob) {
                                options.push_back(_("Replace with ") + *ob);
                                observers.push_back(*ob);
+                       }
+
+                       for (std::vector<team>::iterator team = 
teams_.begin(); team != teams_.end(); team++){
+                               if ( (!team->is_enemy(side + 1)) && 
(!team->is_human()) 
+                                       && (team->current_player() != 
teams_[side].current_player()) ){
+                                       //if this is an ally of the dropping 
side and it is not us (choose local player
+                                       //if you want that) and if it is not 
the dropping side itself, get this team in as well
+                                       options.push_back(_("Replace with ") 
+ team->save_id());
+                                       allies.push_back(team);
+                               }
                        }
 
                        const std::string msg = leader->second.description() 
+ " " + _("has left the game. What do you want to do?");
@@ -201,6 +215,9 @@
                                        if (index < observers.size()) {
                                                teams_[side].make_network();
                                                
change_side_controller(cfg["side_drop"], observers[index], false /*not our 
own side*/);
+                                       } else if (index < options.size() - 
1) {
+                                               allies[index - 
observers.size()]->make_network();
+                                               
change_side_controller(cfg["side_drop"], allies[index - 
observers.size()]->save_id(), false /*not our own side*/);
                                        } else {
                                                teams_[side].make_ai();
                                        }

Modified: branches/1.2/src/server/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/server/game.cpp?rev=13414&r1=13413&r2=13414&view=diff
==============================================================================
--- branches/1.2/src/server/game.cpp (original)
+++ branches/1.2/src/server/game.cpp Tue Sep  5 21:59:12 2006
@@ -425,9 +425,10 @@
        config& change = response.add_child("change_controller");
 
        change["side"] = side;
+       change["player"] = player;
 
        change["controller"] = "network";
-       network::queue_data(response,players_.front());
+       network::send_data(response,players_.front());
 
        change["controller"] = "human";
        network::queue_data(response, sock_entering);

Modified: branches/1.2/src/team.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/team.cpp?rev=13414&r1=13413&r2=13414&view=diff
==============================================================================
--- branches/1.2/src/team.cpp (original)
+++ branches/1.2/src/team.cpp Tue Sep  5 21:59:12 2006
@@ -102,6 +102,10 @@
        if(save_id.empty()) {
                save_id = cfg["description"];
        }
+       current_player = cfg["current_player"];
+       if (current_player.empty()) {
+               current_player = save_id;
+       }
 
        countdown_time = cfg["countdown_time"];
 
@@ -254,6 +258,7 @@
        cfg["name"] = name;
        cfg["team_name"] = team_name;
        cfg["save_id"] = save_id;
+       cfg["current_player"] = current_player;
        cfg["flag"] = flag;
        cfg["description"] = description;
        cfg["objectives"] = objectives;
@@ -480,6 +485,10 @@
        action_bonus_count_=count;
 }
 
+void team::set_current_player(const std::string player){
+       info_.current_player = player;
+}
+
 const std::set<std::string>& team::recruits() const
 {
        return info_.can_recruit;
@@ -597,6 +606,10 @@
 const std::string& team::save_id() const
 {
        return info_.save_id;
+}
+
+const std::string& team::current_player() const{
+       return info_.current_player;
 }
 
 void team::set_objectives(const t_string& new_objectives, bool silently)

Modified: branches/1.2/src/team.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/team.hpp?rev=13414&r1=13413&r2=13414&view=diff
==============================================================================
--- branches/1.2/src/team.hpp (original)
+++ branches/1.2/src/team.hpp Tue Sep  5 21:59:12 2006
@@ -73,6 +73,7 @@
                std::vector<int> enemies;
                std::string team_name;
                std::string save_id;
+               std::string current_player;
                std::string countdown_time;
                int action_bonus_count;
 
@@ -129,12 +130,14 @@
        void set_countdown_time(int amount);
        int action_bonus_count() const;
        void set_action_bonus_count(int count);
+       void set_current_player(const std::string player);
 
        const std::set<std::string>& recruits() const;
        std::set<std::string>& recruits();
        const std::vector<std::string>& recruitment_pattern() const;
        const std::string& name() const;
        const std::string& save_id() const;
+       const std::string& current_player() const;
 
        void set_objectives(const t_string& new_objectives, bool 
silently=false);
        void reset_objectives_changed();




Related Messages


Powered by MHonArc, Updated Tue Sep 05 22:20:19 2006