Author: sapient
Date: Thu Apr 19 03:45:06 2007
New Revision: 16926

URL: http://svn.gna.org/viewcvs/wesnoth?rev=16926&view=rev
Log:
using 'goto' is considered poor style when do/while would have the same effect

Modified:
    trunk/src/playmp_controller.cpp
    trunk/src/playsingle_controller.cpp

Modified: trunk/src/playmp_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playmp_controller.cpp?rev=16926&r1=16925&r2=16926&view=diff
==============================================================================
--- trunk/src/playmp_controller.cpp (original)
+++ trunk/src/playmp_controller.cpp Thu Apr 19 03:45:06 2007
@@ -54,46 +54,43 @@
 }
 
 void playmp_controller::play_side(const unsigned int team_index, bool save){
-//goto this label if the type of a team (human/ai/networked) has changed 
mid-turn
-redo_turn:
-       player_type_changed_ = false;
-       end_turn_ = false;
-
-       // we can't call playsingle_controller::play_side because
-       // we need to catch exception here
-       if(current_team().is_human()) {
-               LOG_NG << "is human...\n";
-               try{
-                       before_human_turn(save);
-                       play_human_turn();
-                       after_human_turn();
-               } catch(end_turn_exception& end_turn) {
-                       if (end_turn.redo == team_index) {
-                               player_type_changed_ = true;
-                               // if new controller is not human,
-                               // reset gui to prev human one
-                               if (!teams_[team_index-1].is_human()) {
-                                       int t = 
find_human_team_before(team_index);
-                                       if (t > 0) {
-                                               gui_->set_team(t-1);
-                                               gui_->recalculate_minimap();
-                                               gui_->invalidate_all();
-                                               gui_->draw();
-                                               gui_->update_display();
+       do {
+               player_type_changed_ = false;
+               end_turn_ = false;
+
+               // we can't call playsingle_controller::play_side because
+               // we need to catch exception here
+               if(current_team().is_human()) {
+                       LOG_NG << "is human...\n";
+                       try{
+                               before_human_turn(save);
+                               play_human_turn();
+                               after_human_turn();
+                       } catch(end_turn_exception& end_turn) {
+                               if (end_turn.redo == team_index) {
+                                       player_type_changed_ = true;
+                                       // if new controller is not human,
+                                       // reset gui to prev human one
+                                       if (!teams_[team_index-1].is_human()) {
+                                               int t = 
find_human_team_before(team_index);
+                                               if (t > 0) {
+                                                       gui_->set_team(t-1);
+                                                       
gui_->recalculate_minimap();
+                                                       gui_->invalidate_all();
+                                                       gui_->draw();
+                                                       gui_->update_display();
+                                               }
                                        }
                                }
                        }
-               }
-               LOG_NG << "human finished turn...\n";
-       } else if(current_team().is_ai()) {
-               play_ai_turn();
-       } else if(current_team().is_network()) {
-               play_network_turn();
-       }
-
-       if (player_type_changed_) {
-               goto redo_turn;
-       }
+                       LOG_NG << "human finished turn...\n";
+               } else if(current_team().is_ai()) {
+                       play_ai_turn();
+               } else if(current_team().is_network()) {
+                       play_network_turn();
+               }
+       } while (player_type_changed_);
+       //keep looping if the type of a team (human/ai/networked) has changed 
mid-turn
 }
 
 void playmp_controller::before_human_turn(bool save){

Modified: trunk/src/playsingle_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playsingle_controller.cpp?rev=16926&r1=16925&r2=16926&view=diff
==============================================================================
--- trunk/src/playsingle_controller.cpp (original)
+++ trunk/src/playsingle_controller.cpp Thu Apr 19 03:45:06 2007
@@ -412,46 +412,45 @@
 
 void playsingle_controller::play_side(const unsigned int team_index, bool save)
 {
-//goto this label if the type of a team (human/ai/networked) has changed 
mid-turn
-redo_turn:
-       //although this flag is used only in this method it has to be a class 
member
-       //since derived classes rely on it
-       player_type_changed_ = false;
-       end_turn_ = false;
-
-       if(current_team().is_human()) {
-               LOG_NG << "is human...\n";
-               try{
-                       before_human_turn(save);
-                       play_human_turn();
-                       after_human_turn();
-               } catch(end_turn_exception& end_turn) {
-                       if (end_turn.redo == team_index) {
-                               player_type_changed_ = true;
-                               // if new controller is not human,
-                               // reset gui to prev human one
-                               if (!teams_[team_index-1].is_human()) {
-                                       int t = 
find_human_team_before(team_index);
-                                       if (t > 0) {
-                                               gui_->set_team(t-1);
-                                               gui_->recalculate_minimap();
-                                               gui_->invalidate_all();
-                                               gui_->draw();
-                                               gui_->update_display();
+       do {
+               //although this flag is used only in this method it has to be a 
class member
+               //since derived classes rely on it
+               player_type_changed_ = false;
+               end_turn_ = false;
+
+               if(current_team().is_human()) {
+                       LOG_NG << "is human...\n";
+                       try{
+                               before_human_turn(save);
+                               play_human_turn();
+                               after_human_turn();
+                       } catch(end_turn_exception& end_turn) {
+                               if (end_turn.redo == team_index) {
+                                       player_type_changed_ = true;
+                                       // if new controller is not human,
+                                       // reset gui to prev human one
+                                       if (!teams_[team_index-1].is_human()) {
+                                               int t = 
find_human_team_before(team_index);
+                                               if (t > 0) {
+                                                       gui_->set_team(t-1);
+                                                       
gui_->recalculate_minimap();
+                                                       gui_->invalidate_all();
+                                                       gui_->draw();
+                                                       gui_->update_display();
+                                               }
                                        }
                                }
                        }
-               }
-
-               if(game_config::debug)
-                       display::clear_debug_highlights();
-
-               LOG_NG << "human finished turn...\n";
-       } else if(current_team().is_ai()) {
-               play_ai_turn();
-       }
-
-       if (player_type_changed_) { goto redo_turn; }
+
+                       if(game_config::debug)
+                               display::clear_debug_highlights();
+
+                       LOG_NG << "human finished turn...\n";
+               } else if(current_team().is_ai()) {
+                       play_ai_turn();
+               }
+       } while (player_type_changed_);
+       //keep looping if the type of a team (human/ai/networked) has changed 
mid-turn
 }
 
 void playsingle_controller::before_human_turn(bool save)


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to