Rewrite some of my earlier changes to be less intrusive,

fixing some side-effect bugs.
This commit is contained in:
Alexander van Gessel 2008-12-25 01:32:44 +01:00
parent fa16daecf7
commit e493804a88
6 changed files with 26 additions and 18 deletions

View File

@ -389,13 +389,6 @@ void play_controller::init_gui(){
}
}
void play_controller::init_turn(){
std::stringstream turn_stream;
turn_stream << status_.turn();
game_events::fire("turn " + turn_stream.str());
game_events::fire("new turn");
}
void play_controller::init_side(const unsigned int team_index, bool /*is_replay*/){
log_scope("player turn");
team& current_team = teams_[team_index];
@ -509,6 +502,8 @@ void play_controller::finish_turn(){
update_locker lock_display(gui_->video(),recorder.is_skipping());
const std::string turn_num = event_stream.str();
gamestate_.set_variable("turn_number",turn_num);
game_events::fire("turn " + turn_num);
game_events::fire("new turn");
}
}

View File

@ -104,7 +104,6 @@ protected:
void fire_prestart(bool execute);
void fire_start(bool execute);
virtual void init_gui();
void init_turn();
virtual void init_side(const unsigned int team_index, bool is_replay = false);
void place_sides_in_preferred_locations(gamemap& map, const config::child_list& sides);
virtual void finish_side_turn();

View File

@ -47,6 +47,7 @@ playsingle_controller::playsingle_controller(const config& level,
player_type_changed_(false),
replaying_(false),
turn_over_(false),
skip_next_turn_(false),
victory_music_(),
defeat_music_()
{
@ -516,13 +517,13 @@ void playsingle_controller::play_turn(bool save)
for(player_number_ = first_player_; player_number_ <= teams_.size(); player_number_++) {
// If a side is empty skip over it.
if (current_team().is_empty()) continue;
try {
if (player_number_ == first_player_) {
init_turn();
if (skip_next_turn_) {
skip_next_turn_ = false;
throw end_turn_exception();
}
// If a side is empty skip over it.
if (current_team().is_empty()) continue;
init_side(player_number_ - 1);
} catch (end_turn_exception) {
if (current_team().is_network() == false) {
@ -572,7 +573,12 @@ void playsingle_controller::play_turn(bool save)
// Time has run out
check_time_over();
finish_turn();
try {
finish_turn();
} catch (end_turn_exception) {
// If [end_turn] is encountered, skip the first existing side's turn.
skip_next_turn_ = true;
}
}
void playsingle_controller::play_side(const unsigned int team_index, bool save)

View File

@ -84,6 +84,7 @@ protected:
bool player_type_changed_;
bool replaying_;
bool turn_over_;
bool skip_next_turn_;
private:
void report_victory(std::stringstream& report,
end_level_exception& end_level,

View File

@ -63,7 +63,8 @@ replay_controller::replay_controller(const config& level,
delay_(0),
is_playing_(false),
show_everything_(false),
show_team_(1)
show_team_(1),
skip_next_turn_(false)
{
init();
gamestate_start_ = gamestate_;
@ -325,8 +326,9 @@ void replay_controller::play_side(const unsigned int /*team_index*/, bool){
try{
try{
if (player_number_ == 1) {
play_controller::init_turn();
if (skip_next_turn_) {
skip_next_turn_ = false;
throw end_turn_exception();
}
play_controller::init_side(player_number_ - 1, true);
@ -355,7 +357,11 @@ void replay_controller::play_side(const unsigned int /*team_index*/, bool){
if (static_cast<size_t>(player_number_) > teams_.size()){
status_.next_turn();
finish_turn();
try {
finish_turn();
} catch (end_turn_exception) {
skip_next_turn_ = true;
}
player_number_ = 1;
current_turn_++;
}

View File

@ -70,6 +70,7 @@ private:
bool show_everything_;
unsigned int show_team_;
bool skip_next_turn_;
};