Skip to content

Commit

Permalink
refactor do_init_side
Browse files Browse the repository at this point in the history
we move the visual part  in a new method and then call that method
instead having a only_visual parameter.
Also we move the set_scontext_scned from the caller to do_init_side
  • Loading branch information
gfgtdf committed Feb 25, 2015
1 parent 96296a8 commit f521f04
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
97 changes: 49 additions & 48 deletions src/play_controller.cpp
Expand Up @@ -374,7 +374,8 @@ possible_end_play_signal play_controller::init_side(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(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
Expand All @@ -386,20 +387,20 @@ void play_controller::maybe_do_init_side(bool is_replay, bool only_visual) {

if(!only_visual) {
recorder.init_side();
set_scontext_synced sync;
do_init_side(is_replay);
sync.do_final_checkup();
do_init_side();
}
else
{
do_init_side(is_replay, true);
do_init_side_visual();
}
}

/**
* Called by replay handler or init_side() to do actual work for turn change.
*/
void play_controller::do_init_side(bool is_replay, bool only_visual) {
void play_controller::do_init_side()
{
set_scontext_synced sync;
log_scope("player turn");
//In case we might end up calling sync:network during the side turn events,
//and we don't want do_init_side to be called when a player drops.
Expand All @@ -408,53 +409,54 @@ void play_controller::do_init_side(bool is_replay, bool only_visual) {
const std::string turn_num = str_cast(turn());
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) {
if(it_is_a_new_turn_)
{
pump().fire("turn " + turn_num);
pump().fire("new turn");
it_is_a_new_turn_ = false;
}

pump().fire("side turn");
pump().fire("side " + side_num + " turn");
pump().fire("side turn " + turn_num);
pump().fire("side " + side_num + " turn " + turn_num);

// We want to work out if units for this player should get healed,
// and the player should get income now.
// Healing/income happen if it's not the first turn of processing,
// or if we are loading a game.
if (turn() > 1) {
gamestate_.board_.new_turn(player_number_);
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 = gamestate_.board_.side_upkeep(player_number_) -
current_team().support();
if(expense > 0) {
current_team().spend_gold(expense);
}
if(it_is_a_new_turn_)
{
pump().fire("turn " + turn_num);
pump().fire("new turn");
it_is_a_new_turn_ = false;
}

calculate_healing(player_number_, !skip_replay_);
pump().fire("side turn");
pump().fire("side " + side_num + " turn");
pump().fire("side turn " + turn_num);
pump().fire("side " + side_num + " turn " + turn_num);

// We want to work out if units for this player should get healed,
// and the player should get income now.
// Healing/income happen if it's not the first turn of processing,
// or if we are loading a game.
if (turn() > 1) {
gamestate_.board_.new_turn(player_number_);
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 = gamestate_.board_.side_upkeep(player_number_) -
current_team().support();
if(expense > 0) {
current_team().spend_gold(expense);
}

// Prepare the undo stack.
undo_stack_->new_side_turn(player_number_);
calculate_healing(player_number_, !skip_replay_);
}

pump().fire("turn refresh");
pump().fire("side " + side_num + " turn refresh");
pump().fire("turn " + turn_num + " refresh");
pump().fire("side " + side_num + " turn " + turn_num + " refresh");
// Prepare the undo stack.
undo_stack_->new_side_turn(player_number_);

// Make sure vision is accurate.
actions::clear_shroud(player_number_, true);
check_victory();
}
pump().fire("turn refresh");
pump().fire("side " + side_num + " turn refresh");
pump().fire("turn " + turn_num + " refresh");
pump().fire("side " + side_num + " turn " + turn_num + " refresh");

// Make sure vision is accurate.
actions::clear_shroud(player_number_, true);
check_victory();
sync.do_final_checkup();
do_init_side_visual();
}
void play_controller::do_init_side_visual()
{
const time_of_day &tod = gamestate_.tod_manager_.get_time_of_day();

if (player_number_ == first_player_)
Expand All @@ -470,7 +472,6 @@ void play_controller::do_init_side(bool is_replay, bool only_visual) {
loading_game_ = false;
whiteboard_manager_->on_init_side();
}

//builds the snapshot config from its members and their configs respectively
config play_controller::to_config() const
{
Expand Down
3 changes: 2 additions & 1 deletion src/play_controller.hpp
Expand Up @@ -106,7 +106,8 @@ class play_controller : public controller_base, public events::observer, public
void save_map();

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);
void do_init_side();
void do_init_side_visual();

virtual void force_end_turn() = 0;
virtual void force_end_level(LEVEL_RESULT res) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/playsingle_controller.cpp
Expand Up @@ -588,7 +588,7 @@ possible_end_play_signal playsingle_controller::play_side()
//check for team-specific items in the scenario
gui_->parse_team_overlays();

HANDLE_END_PLAY_SIGNAL( maybe_do_init_side(false) );
HANDLE_END_PLAY_SIGNAL( maybe_do_init_side() );

//flag used when we fallback from ai and give temporarily control to human
bool temporary_human = false;
Expand Down
4 changes: 1 addition & 3 deletions src/replay.cpp
Expand Up @@ -826,9 +826,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
}
else
{
set_scontext_synced sync;
resources::controller->do_init_side(true);
sync.do_final_checkup();
resources::controller->do_init_side();
}
}

Expand Down

0 comments on commit f521f04

Please sign in to comment.