Skip to content

Commit

Permalink
push end play exceptions out of play_side()
Browse files Browse the repository at this point in the history
This changes both the playsingle and playmp implementations,
but not the replay_controller implementation which is separate.

( squashed: fixup an oversight in replay_controller::play_side )
  • Loading branch information
cbeck88 committed Jun 8, 2014
1 parent fed87a9 commit 051b204
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/playmp_controller.cpp
Expand Up @@ -92,7 +92,7 @@ void playmp_controller::stop_network(){
LOG_NG << "network processing stopped";
}

void playmp_controller::play_side()
possible_end_play_signal playmp_controller::play_side()
{
utils::string_map player;
player["name"] = current_team().current_player();
Expand All @@ -101,7 +101,7 @@ void playmp_controller::play_side()
gui_->send_notification(_("Turn changed"), turn_notification_msg);

// Proceed with the parent function.
playsingle_controller::play_side();
return playsingle_controller::play_side();
}

void playmp_controller::before_human_turn(){
Expand Down
2 changes: 1 addition & 1 deletion src/playmp_controller.hpp
Expand Up @@ -48,7 +48,7 @@ class playmp_controller : public playsingle_controller, public events::pump_moni
virtual void stop_network();
virtual bool can_execute_command(const hotkey::hotkey_command& command, int index=-1) const;

virtual void play_side();
virtual possible_end_play_signal play_side();
virtual void before_human_turn();
virtual void play_human_turn();
virtual void after_human_turn();
Expand Down
23 changes: 19 additions & 4 deletions src/playsingle_controller.cpp
Expand Up @@ -658,7 +658,7 @@ possible_end_play_signal playsingle_controller::play_turn()
LOG_NG << "result of replay: " << (replaying_?"true":"false") << "\n";
} else {
ai_testing::log_turn_start(player_number_);
HANDLE_END_PLAY_SIGNAL ( play_side() );
PROPOGATE_END_PLAY_SIGNAL ( play_side() );
}

finish_side_turn();
Expand Down Expand Up @@ -696,12 +696,12 @@ void playsingle_controller::play_idle_loop()
}
}

void playsingle_controller::play_side()
possible_end_play_signal playsingle_controller::play_side()
{
//check for team-specific items in the scenario
gui_->parse_team_overlays();

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

//flag used when we fallback from ai and give temporarily control to human
bool temporary_human = false;
Expand Down Expand Up @@ -738,6 +738,8 @@ void playsingle_controller::play_side()
update_gui_to_player(s-1);
}
}
} catch (end_level_exception & e) {
return possible_end_play_signal(e.to_struct());
}
// Ending the turn commits all moves.
undo_stack_->clear();
Expand All @@ -752,14 +754,24 @@ void playsingle_controller::play_side()
// Give control to a human for this turn.
player_type_changed_ = true;
temporary_human = true;
} catch (end_level_exception & e) { //Don't know at the moment if these two are possible but can't hurt to add
return possible_end_play_signal(e.to_struct());
} catch (end_turn_exception & e) {
return possible_end_play_signal(e.to_struct());
}
if(!player_type_changed_)
{
recorder.end_turn();
}

} else if(current_team().is_network()) {
play_network_turn();
try {
play_network_turn();
} catch (end_level_exception & e) { //Don't know at the moment if these two are possible but can't hurt to add
return possible_end_play_signal(e.to_struct());
} catch (end_turn_exception & e) {
return possible_end_play_signal(e.to_struct());
}
} else if(current_team().is_idle()) {
try{
end_turn_enable(false);
Expand All @@ -781,6 +793,8 @@ void playsingle_controller::play_side()
update_gui_to_player(s-1);
}
}
} catch (end_level_exception e) { //this shouldn't really be possible, but in case it is somehow this will prevent a crash.
return possible_end_play_signal(e.to_struct());
}
}

Expand All @@ -790,6 +804,7 @@ void playsingle_controller::play_side()
// Keep looping if the type of a team (human/ai/networked)
// has changed mid-turn
skip_next_turn_ = false;
return boost::none;
}

void playsingle_controller::before_human_turn()
Expand Down
2 changes: 1 addition & 1 deletion src/playsingle_controller.hpp
Expand Up @@ -92,7 +92,7 @@ class playsingle_controller : public play_controller

protected:
possible_end_play_signal play_turn();
virtual void play_side();
virtual possible_end_play_signal play_side();
virtual void before_human_turn();
void show_turn_dialog();
void execute_gotos();
Expand Down
2 changes: 1 addition & 1 deletion src/replay_controller.cpp
Expand Up @@ -104,7 +104,7 @@ possible_end_play_signal replay_controller::try_run_to_completion() {
return boost::none;
} else {
if (!is_playing_) {
HANDLE_END_PLAY_SIGNAL( play_replay() );
PROPOGATE_END_PLAY_SIGNAL( play_replay() );
}
}
}
Expand Down

0 comments on commit 051b204

Please sign in to comment.