Skip to content

Commit

Permalink
remove unnecessary arguments
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cbeck88 committed May 31, 2014
1 parent f2504d8 commit 50f89d5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
35 changes: 16 additions & 19 deletions src/play_controller.cpp
Expand Up @@ -592,64 +592,61 @@ 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;
}

/**
* 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;
}

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) {
Expand All @@ -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,
Expand All @@ -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_);
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/play_controller.hpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/playsingle_controller.cpp
Expand Up @@ -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_);
Expand Down Expand Up @@ -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<int>(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;
Expand Down
6 changes: 3 additions & 3 deletions src/playturn.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/replay.cpp
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/replay_controller.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 50f89d5

Please sign in to comment.