From 50f89d522a8cbe0bd4ccb4ea7b220bdbb86b9651 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Thu, 29 May 2014 21:34:09 -0400 Subject: [PATCH] remove unnecessary arguments maybe_do_init_side and do_init_side both required a team_index argument, which was always player_number_ - 1, (checked this with assertions and playtesting), and which was available in the class which defined them --- src/play_controller.cpp | 35 ++++++++++++++++------------------- src/play_controller.hpp | 6 +++--- src/playsingle_controller.cpp | 5 +++-- src/playturn.cpp | 6 +++--- src/replay.cpp | 2 +- src/replay_controller.cpp | 2 +- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 0b7f326a867b..dea2ebeeac35 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -592,22 +592,22 @@ void play_controller::init_gui(){ } } -void play_controller::init_side(const unsigned int team_index, bool is_replay){ +void play_controller::init_side(bool is_replay){ log_scope("player turn"); bool only_visual = loading_game_ && init_side_done_; init_side_done_ = false; - mouse_handler_.set_side(team_index + 1); + mouse_handler_.set_side(player_number_); // If we are observers we move to watch next team if it is allowed if (is_observer() && !current_team().get_disallow_observers()) { - gui_->set_team(size_t(team_index)); + gui_->set_team(size_t(player_number_ - 1)); } - gui_->set_playing_team(size_t(team_index)); + gui_->set_playing_team(size_t(player_number_ - 1)); gamedata_.get_variable("side_number") = player_number_; gamedata_.last_selected = map_location::null_location; - maybe_do_init_side(team_index, is_replay, only_visual); + maybe_do_init_side(is_replay, only_visual); loading_game_ = false; } @@ -615,13 +615,12 @@ void play_controller::init_side(const unsigned int team_index, bool is_replay){ /** * Called by turn_info::process_network_data() or init_side() to call do_init_side() if necessary. */ -void play_controller::maybe_do_init_side(const unsigned int team_index, bool is_replay, bool only_visual) { +void play_controller::maybe_do_init_side(bool is_replay, bool only_visual) { /** * We do side init only if not done yet for a local side when we are not replaying. * For all other sides it is recorded in replay and replay handler has to handle * calling do_init_side() functions. **/ - assert(team_index == player_number_ - 1); if (is_replay || init_side_done_ || !current_team().is_local()) { return; } @@ -629,27 +628,25 @@ void play_controller::maybe_do_init_side(const unsigned int team_index, bool is_ if(!only_visual){ recorder.init_side(); set_scontext_synced sync; - do_init_side(team_index, is_replay); + do_init_side(is_replay); } else { - do_init_side(team_index, is_replay, true); + do_init_side(is_replay, true); } } /** * Called by replay handler or init_side() to do actual work for turn change. */ -void play_controller::do_init_side(const unsigned int team_index, bool is_replay, bool only_visual) { - assert(team_index == player_number_ - 1); +void play_controller::do_init_side(bool is_replay, bool only_visual) { log_scope("player turn"); //In case we might end up calling sync:network during the side turn events, //and we dont want do_init_side to be called when a player drops. init_side_done_ = true; - team& current_team = teams_[team_index]; const std::string turn_num = str_cast(turn()); - const std::string side_num = str_cast(team_index + 1); + const std::string side_num = str_cast(player_number_); // If this is right after loading a game we don't need to fire events and such. It was already done before saving. if (!only_visual) { @@ -666,7 +663,7 @@ void play_controller::do_init_side(const unsigned int team_index, bool is_replay game_events::fire("side " + side_num + " turn " + turn_num); } - if(current_team.is_human() && !is_replay) { + if(current_team().is_human() && !is_replay) { update_gui_to_player(player_number_ - 1); } // We want to work out if units for this player should get healed, @@ -680,15 +677,15 @@ void play_controller::do_init_side(const unsigned int team_index, bool is_replay } } - current_team.new_turn(); + current_team().new_turn(); // If the expense is less than the number of villages owned // times the village support capacity, // then we don't have to pay anything at all int expense = side_upkeep(player_number_) - - current_team.support(); + current_team().support(); if(expense > 0) { - current_team.spend_gold(expense); + current_team().spend_gold(expense); } calculate_healing(player_number_, !skip_replay_); @@ -709,14 +706,14 @@ void play_controller::do_init_side(const unsigned int team_index, bool is_replay const time_of_day &tod = tod_manager_.get_time_of_day(); - if (int(team_index) + 1 == first_player_) + if (player_number_ == first_player_) sound::play_sound(tod.sounds, sound::SOUND_SOURCES); if (!recorder.is_skipping()){ gui_->invalidate_all(); } - if (!recorder.is_skipping() && !skip_replay_ && current_team.get_scroll_to_leader()){ + if (!recorder.is_skipping() && !skip_replay_ && current_team().get_scroll_to_leader()){ gui_->scroll_to_leader(units_, player_number_,game_display::ONSCREEN,false); } loading_game_ = false; diff --git a/src/play_controller.hpp b/src/play_controller.hpp index 04b0725d21d7..d7c92c02dd70 100644 --- a/src/play_controller.hpp +++ b/src/play_controller.hpp @@ -110,8 +110,8 @@ class play_controller : public controller_base, public events::observer, public virtual void search(); virtual void toggle_accelerated_speed(); - void maybe_do_init_side(const unsigned int team_index, bool is_replay = false, bool only_visual = false); - void do_init_side(const unsigned int team_index, bool is_replay = false, bool only_visual = false); + void maybe_do_init_side(bool is_replay = false, bool only_visual = false); + void do_init_side(bool is_replay = false, bool only_visual = false); virtual void play_side(const unsigned int side_number, bool save) = 0; virtual void force_end_turn() = 0; @@ -194,7 +194,7 @@ class play_controller : public controller_base, public events::observer, public void fire_prestart(bool execute); void fire_start(bool execute); virtual void init_gui(); - virtual void init_side(const unsigned int team_index, bool is_replay = false); + void init_side(bool is_replay = false); void place_sides_in_preferred_locations(); virtual void finish_side_turn(); void finish_turn(); diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index ffc8bdd12902..011d3a1edce6 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -612,7 +612,7 @@ void playsingle_controller::play_turn(bool save) if (current_team().is_empty()) continue; try { save_blocker blocker; - init_side(player_number_ - 1); + init_side(); } catch (end_turn_exception) { if (current_team().is_network() == false) { turn_info turn_data(player_number_, replay_sender_,network_reader_); @@ -667,10 +667,11 @@ void playsingle_controller::play_idle_loop() void playsingle_controller::play_side(const unsigned int side_number, bool save) { + assert(static_cast(side_number) == player_number_); //check for team-specific items in the scenario gui_->parse_team_overlays(); - maybe_do_init_side(side_number, save); + maybe_do_init_side(save); //flag used when we fallback from ai and give temporarily control to human bool temporary_human = false; diff --git a/src/playturn.cpp b/src/playturn.cpp index c0e9e411daaa..aaa87b5ff0f1 100644 --- a/src/playturn.cpp +++ b/src/playturn.cpp @@ -218,7 +218,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg resources::screen->recalculate_minimap(); } - resources::controller->maybe_do_init_side(index); + resources::controller->maybe_do_init_side(); resources::whiteboard->on_change_controller(side,tm); @@ -312,7 +312,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg tm.set_current_player("ai" + side_drop); if (have_leader) leader->rename("ai" + side_drop); change_controller(side_drop, "ai"); - resources::controller->maybe_do_init_side(side_index); + resources::controller->maybe_do_init_side(); return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE; @@ -323,7 +323,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg if (have_leader) leader->rename("human" + side_drop); change_controller(side_drop, "human"); - resources::controller->maybe_do_init_side(side_index); + resources::controller->maybe_do_init_side(); return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE; case 2: diff --git a/src/replay.cpp b/src/replay.cpp index ff1c315d5123..bb1f752fa82b 100644 --- a/src/replay.cpp +++ b/src/replay.cpp @@ -825,7 +825,7 @@ REPLAY_RETURN do_replay_handle(int side_num) else { set_scontext_synced sync; - resources::controller->do_init_side(side_num - 1, true); + resources::controller->do_init_side(true); } } diff --git a/src/replay_controller.cpp b/src/replay_controller.cpp index 043a8cfcc5d9..53677812046a 100644 --- a/src/replay_controller.cpp +++ b/src/replay_controller.cpp @@ -447,7 +447,7 @@ void replay_controller::play_side(const unsigned int /*team_index*/, bool){ if (!current_team().is_empty()) { statistics::reset_turn_stats(current_team().save_id()); - play_controller::init_side(player_number_ - 1, true); + play_controller::init_side(true); DBG_REPLAY << "doing replay " << player_number_ << "\n"; // if have reached the end we don't want to execute finish_side_turn and finish_turn