remove unnecessary arguments

All of before_human_turn, play_side, play_turn had an argument
"bool save". The only use of this was by the playsingle controller
to determine whether or not to save an autosave -- it was controlled
in a single place by a single for loop in play_scenario.

Instead of polluting all of these functions, including play_controller,
and replay_controller, with arguments that they ignore, save was
replaced with a member variable of playsingle_controller. This is a
strict refactor in terms of behavior.
This commit is contained in:
Chris Beck 2014-05-30 00:45:05 -04:00
parent 19b381b560
commit 15e81134fb
7 changed files with 27 additions and 27 deletions

View File

@ -112,7 +112,7 @@ public:
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(bool save) = 0;
virtual void play_side() = 0;
virtual void force_end_turn() = 0;
virtual void force_end_level(LEVEL_RESULT res) = 0;

View File

@ -92,7 +92,7 @@ void playmp_controller::stop_network(){
LOG_NG << "network processing stopped";
}
void playmp_controller::play_side(bool save)
void playmp_controller::play_side()
{
utils::string_map player;
player["name"] = current_team().current_player();
@ -101,12 +101,12 @@ void playmp_controller::play_side(bool save)
gui_->send_notification(_("Turn changed"), turn_notification_msg);
// Proceed with the parent function.
playsingle_controller::play_side(save);
playsingle_controller::play_side();
}
void playmp_controller::before_human_turn(bool save){
void playmp_controller::before_human_turn(){
LOG_NG << "playmp::before_human_turn...\n";
playsingle_controller::before_human_turn(save);
playsingle_controller::before_human_turn();
turn_data_.send_data();
}

View File

@ -48,8 +48,8 @@ protected:
virtual void stop_network();
virtual bool can_execute_command(const hotkey::hotkey_command& command, int index=-1) const;
virtual void play_side(bool save);
virtual void before_human_turn(bool save);
virtual void play_side();
virtual void before_human_turn();
virtual void play_human_turn();
virtual void after_human_turn();
virtual void finish_side_turn();

View File

@ -448,13 +448,12 @@ LEVEL_RESULT playsingle_controller::play_scenario(
// Avoid autosaving after loading, but still
// allow the first turn to have an autosave.
bool save = !loading_game_;
do_autosaves_ = !loading_game_;
ai_testing::log_game_start();
for(; ; first_player_ = 1) {
play_turn(save);
save = true;
play_turn();
do_autosaves_ = true;
} //end for loop
} catch(const game::load_game_exception &) {
// Loading a new game is effectively a quit.
//
@ -598,7 +597,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
return QUIT;
}
void playsingle_controller::play_turn(bool save)
void playsingle_controller::play_turn()
{
resources::whiteboard->on_gamestate_change();
gui_->new_turn();
@ -633,7 +632,7 @@ void playsingle_controller::play_turn(bool save)
LOG_NG << "result of replay: " << (replaying_?"true":"false") << "\n";
} else {
ai_testing::log_turn_start(player_number_);
play_side(save);
play_side();
}
finish_side_turn();
@ -670,12 +669,12 @@ void playsingle_controller::play_idle_loop()
}
}
void playsingle_controller::play_side(bool save)
void playsingle_controller::play_side()
{
//check for team-specific items in the scenario
gui_->parse_team_overlays();
maybe_do_init_side(save);
maybe_do_init_side(do_autosaves_);
//flag used when we fallback from ai and give temporarily control to human
bool temporary_human = false;
@ -696,7 +695,7 @@ void playsingle_controller::play_side(bool save)
if (side_units(player_number_) != 0
|| (resources::units->size() == 0 && player_number_ == 1))
{
before_human_turn(save);
before_human_turn();
play_human_turn();
}
} catch(end_turn_exception& end_turn) {
@ -734,7 +733,7 @@ void playsingle_controller::play_side(bool save)
try{
end_turn_enable(false);
do_idle_notification();
before_human_turn(save);
before_human_turn();
play_idle_loop();
} catch(end_turn_exception& end_turn) {
@ -762,7 +761,7 @@ void playsingle_controller::play_side(bool save)
skip_next_turn_ = false;
}
void playsingle_controller::before_human_turn(bool save)
void playsingle_controller::before_human_turn()
{
log_scope("player turn");
browse_ = false;
@ -770,7 +769,7 @@ void playsingle_controller::before_human_turn(bool save)
ai::manager::raise_turn_started();
if(save && level_result_ == NONE) {
if(do_autosaves_ && level_result_ == NONE) {
savegame::autosave_savegame save(gamestate_, *gui_, to_config(), preferences::save_compression_format());
save.autosave(game_config::disable_autosave, preferences::autosavemax(), preferences::INFINITE_AUTO_SAVES);
}

View File

@ -74,9 +74,9 @@ public:
virtual void maybe_linger();
protected:
virtual void play_turn(bool save);
virtual void play_side(bool save);
virtual void before_human_turn(bool save);
virtual void play_turn();
virtual void play_side();
virtual void before_human_turn();
void show_turn_dialog();
void execute_gotos();
virtual void play_human_turn();
@ -105,6 +105,7 @@ protected:
bool replaying_;
bool turn_over_;
bool skip_next_turn_;
bool do_autosaves_;
LEVEL_RESULT level_result_;
void linger();
};

View File

@ -342,9 +342,9 @@ void replay_controller::replay_next_side(){
is_playing_ = true;
replay_ui_playback_should_start();
play_side(false);
play_side();
while (current_team().is_empty()) {
play_side( false);
play_side();
}
if (!skip_replay_ || !is_playing_) {
@ -439,13 +439,13 @@ void replay_controller::play_turn(){
while ( (!last_team) && (!recorder.at_end()) && is_playing_ ){
last_team = static_cast<size_t>(player_number_) == teams_.size();
play_side(false);
play_side();
play_slice();
}
}
//make only one side move
void replay_controller::play_side(bool){
void replay_controller::play_side(){
DBG_REPLAY << "Status turn number: " << turn() << "\n";
DBG_REPLAY << "Replay_Controller turn number: " << current_turn_ << "\n";

View File

@ -62,7 +62,7 @@ protected:
private:
void init();
virtual void play_turn();
virtual void play_side(bool save);
virtual void play_side();
void update_teams();
void update_gui();
void init_replay_display();