Skip to content

Commit

Permalink
refactor play_controller::fire_start
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Mar 1, 2015
1 parent bf37365 commit 5ac4fba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
30 changes: 14 additions & 16 deletions src/play_controller.cpp
Expand Up @@ -301,24 +301,22 @@ void play_controller::fire_prestart()
gamestate_.gamedata_.get_variable("turn_number") = int(start_turn_);
}

void play_controller::fire_start(bool execute){
if(execute) {
gamestate_.gamedata_.set_phase(game_data::START);
pump().fire("start");
check_end_level();
// start event may modify start turn with WML, reflect any changes.
start_turn_ = turn();
gamestate_.gamedata_.get_variable("turn_number") = int(start_turn_);

// prestart and start events may modify the initial gold amount,
// reflect any changes.
BOOST_FOREACH(team& tm, gamestate_.board_.teams_)
{
tm.set_start_gold(tm.gold());
}
init_side_done_ = false;
void play_controller::fire_start()
{
gamestate_.gamedata_.set_phase(game_data::START);
pump().fire("start");
check_end_level();
// start event may modify start turn with WML, reflect any changes.
start_turn_ = turn();
gamestate_.gamedata_.get_variable("turn_number") = int(start_turn_);

// prestart and start events may modify the initial gold amount,
// reflect any changes.
BOOST_FOREACH(team& tm, gamestate_.board_.teams_)
{
tm.set_start_gold(tm.gold());
}
init_side_done_ = false;
gamestate_.gamedata_.set_phase(game_data::PLAY);
}

Expand Down
2 changes: 1 addition & 1 deletion src/play_controller.hpp
Expand Up @@ -215,7 +215,7 @@ class play_controller : public controller_base, public events::observer, public
///preload events cannot be synced
void fire_preload();
void fire_prestart();
void fire_start(bool execute);
void fire_start();
virtual void init_gui();
virtual void finish_side_turn();
void finish_turn(); //this should not throw an end turn or end level exception
Expand Down
6 changes: 3 additions & 3 deletions src/playsingle_controller.cpp
Expand Up @@ -242,7 +242,7 @@ boost::optional<LEVEL_RESULT> playsingle_controller::play_scenario_init(end_leve

events::raise_draw_event();
try {
fire_start(true);
fire_start();
} catch (end_level_exception & e) {
return e.result;
} catch (restart_turn_exception &) {
Expand All @@ -256,7 +256,7 @@ boost::optional<LEVEL_RESULT> playsingle_controller::play_scenario_init(end_leve
{
init_gui();
events::raise_draw_event();
fire_start(false);
gamestate_.gamedata_.set_phase(game_data::PLAY);
gui_->recalculate_minimap();
}
if( saved_game_.classification().random_mode != "" && (network::nconnections() != 0)) {
Expand Down Expand Up @@ -363,7 +363,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
{
LEVEL_RESULT end_level_result = *signal;

if(!this->gamestate_.gamedata_.phase() > game_data::PRESTART) {
if(this->gamestate_.gamedata_.phase() <= game_data::PRESTART) {
sdl::draw_solid_tinted_rectangle(
0, 0, gui_->video().getx(), gui_->video().gety(), 0, 0, 0, 1.0,
gui_->video().getSurface()
Expand Down
2 changes: 1 addition & 1 deletion src/replay_controller.cpp
Expand Up @@ -379,7 +379,7 @@ void replay_controller::reset_replay()

fire_prestart();
init_gui();
fire_start(true);
fire_start();
sync.do_final_checkup();
}
update_gui();
Expand Down

0 comments on commit 5ac4fba

Please sign in to comment.