move it_is_a_new_turn_ variable to tod_manager

it_is_a_new_turn_ is part of the gamestate so it should be part of the game_state object.
This commit is contained in:
gfgtdf 2015-09-06 23:26:29 +02:00
parent 4103ae29f5
commit 4afe65b4da
6 changed files with 13 additions and 10 deletions

View file

@ -138,7 +138,6 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
, player_number_(level["playing_team"].to_int() + 1)
, skip_replay_(skip_replay)
, linger_(false)
, it_is_a_new_turn_(level["it_is_a_new_turn"].to_bool(true))
, init_side_done_(level["init_side_done"].to_bool(false))
, init_side_done_now_(false)
, ticks_(ticks)
@ -380,11 +379,12 @@ void play_controller::do_init_side()
const std::string turn_num = str_cast(turn());
const std::string side_num = str_cast(player_number_);
if(it_is_a_new_turn_)
// We might have skipped some sides because they were empty so it is not enough to check for side_num==1
if(!gamestate().tod_manager_.has_turn_event_fired())
{
pump().fire("turn " + turn_num);
pump().fire("new turn");
it_is_a_new_turn_ = false;
gamestate().tod_manager_.turn_event_fired();
}
pump().fire("side turn");
@ -449,7 +449,6 @@ config play_controller::to_config() const
cfg.merge_attributes(level_);
cfg["init_side_done"] = init_side_done_;
cfg["it_is_a_new_turn"] = it_is_a_new_turn_;
gamestate_.write(cfg);

View file

@ -282,7 +282,6 @@ protected:
int player_number_;
bool skip_replay_;
bool linger_;
bool it_is_a_new_turn_;
bool init_side_done_;
/// whether we did init side in this session ( false = we did init side before we reloaded the game).
bool init_side_done_now_;

View file

@ -711,7 +711,6 @@ void playsingle_controller::handle_generic_event(const std::string& name){
void playsingle_controller::check_time_over(){
bool time_left = gamestate_.tod_manager_.next_turn(gamestate_.gamedata_);
it_is_a_new_turn_ = true;
if(!time_left) {
LOG_NG << "firing time over event...\n";
set_scontext_synced_base sync;

View file

@ -305,7 +305,6 @@ void replay_controller::reset_replay()
gui_->get_chat_manager().clear_chat_messages();
is_playing_ = false;
player_number_ = level_["playing_team"].to_int() + 1;
it_is_a_new_turn_ = level_["it_is_a_new_turn"].to_bool(true);
init_side_done_ = level_["init_side_done"].to_bool(false);
skip_replay_ = false;
gamestate_.tod_manager_= tod_manager_start_;
@ -537,7 +536,6 @@ void replay_controller::play_move_or_side(bool one_move) {
set_scontext_synced_base sync;
pump().fire("time over");
}
it_is_a_new_turn_ = true;
player_number_ = 1;
gui_->new_turn();
}

View file

@ -46,7 +46,8 @@ tod_manager::tod_manager(const config& scenario_cfg):
times_(),
areas_(),
turn_(scenario_cfg["turn_at"].to_int(1)),
num_turns_(scenario_cfg["turns"].to_int(-1))
num_turns_(scenario_cfg["turns"].to_int(-1)),
has_turn_event_fired_(!scenario_cfg["it_is_a_new_turn"].to_bool(true))
{
// ? : operator doesn't work in this case.
if (scenario_cfg["current_time"].to_int(-17403) == -17403)
@ -117,7 +118,7 @@ config tod_manager::to_config() const
cfg["turns"] = num_turns_;
cfg["current_time"] = currentTime_;
cfg["random_start_time"] = random_tod_;
cfg["it_is_a_new_turn"] = !has_turn_event_fired_;
std::vector<time_of_day>::const_iterator t;
for(t = times_.begin(); t != times_.end(); ++t) {
t->write(cfg.add_child("time"));
@ -457,6 +458,7 @@ int tod_manager::calculate_current_time(
bool tod_manager::next_turn(boost::optional<game_data&> vars)
{
set_turn(turn_ + 1, vars, false);
has_turn_event_fired_ = false;
return is_time_left();
}

View file

@ -180,6 +180,10 @@ class tod_manager : public savegame::savegame_config
* @returns True if time has not expired.
*/
bool is_time_left();
bool has_turn_event_fired()
{ return has_turn_event_fired_; }
void turn_event_fired()
{ has_turn_event_fired_ = true; }
private:
/**
@ -234,6 +238,8 @@ class tod_manager : public savegame::savegame_config
int turn_;
//turn limit
int num_turns_;
//Whether the "turn X" and the "new turn" events were already fired this turn.
bool has_turn_event_fired_;
//
config::attribute_value random_tod_;
};