From fe00d72dd2d34addaed4071e20ba573dc8e7605c Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Fri, 13 Jun 2014 00:59:32 -0400 Subject: [PATCH] refactor tod_manager::set_turn, next_turn, accept game_data arg This improves encapsulation and almost allows to push resources out of the tod_manager --- src/game_events/action_wml.cpp | 2 +- src/menu_events.cpp | 2 +- src/playsingle_controller.cpp | 2 +- src/replay_controller.cpp | 2 +- src/tod_manager.cpp | 10 +++++----- src/tod_manager.hpp | 7 +++++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/game_events/action_wml.cpp b/src/game_events/action_wml.cpp index b51504a47fba..52080761f077 100644 --- a/src/game_events/action_wml.cpp +++ b/src/game_events/action_wml.cpp @@ -1345,7 +1345,7 @@ WML_HANDLER_FUNCTION(modify_turns, /*event_info*/, cfg) if(new_turn_number_u < 1 || (new_turn_number > tod_man.number_of_turns() && tod_man.number_of_turns() != -1)) { ERR_NG << "attempted to change current turn number to one out of range (" << new_turn_number << ")" << std::endl; } else if(new_turn_number_u != current_turn_number) { - tod_man.set_turn(new_turn_number_u); + tod_man.set_turn(new_turn_number_u, *resources::gamedata); resources::screen->new_turn(); } } diff --git a/src/menu_events.cpp b/src/menu_events.cpp index 008709000815..6999810eb8e5 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -3008,7 +3008,7 @@ void console_handler::do_turn() if (!data.empty()) { turn = lexical_cast_default(data, 1); } - resources::tod_manager->set_turn(turn); + resources::tod_manager->set_turn(turn, *resources::gamedata); menu_handler_.gui_->new_turn(); menu_handler_.gui_->redraw_everything(); diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index ea9fc0d343ac..11aa07ee81a0 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -1012,7 +1012,7 @@ void playsingle_controller::handle_generic_event(const std::string& name){ } possible_end_play_signal playsingle_controller::check_time_over(){ - bool b = tod_manager_.next_turn(); + bool b = tod_manager_.next_turn(*resources::gamedata); it_is_a_new_turn_ = true; if(!b) { diff --git a/src/replay_controller.cpp b/src/replay_controller.cpp index fab0e110aa97..764496801339 100644 --- a/src/replay_controller.cpp +++ b/src/replay_controller.cpp @@ -552,7 +552,7 @@ possible_end_play_signal replay_controller::play_side() { //during the orginal game player_number_ would also be gameboard_.teams().size(), player_number_ = gameboard_.teams().size(); finish_turn(); - tod_manager_.next_turn(); + tod_manager_.next_turn(*resources::gamedata); it_is_a_new_turn_ = true; player_number_ = 1; current_turn_++; diff --git a/src/tod_manager.cpp b/src/tod_manager.cpp index 5f37c2b33e9b..b112f20b8bff 100644 --- a/src/tod_manager.cpp +++ b/src/tod_manager.cpp @@ -378,7 +378,7 @@ void tod_manager::set_number_of_turns(int num) num_turns_ = std::max(num, -1); } -void tod_manager::set_turn(const int num, const bool increase_limit_if_needed) +void tod_manager::set_turn(const int num, boost::optional vars, const bool increase_limit_if_needed) { const int new_turn = std::max(num, 1); LOG_NG << "changing current turn number from " << turn_ << " to " << new_turn << '\n'; @@ -389,8 +389,8 @@ void tod_manager::set_turn(const int num, const bool increase_limit_if_needed) set_number_of_turns(new_turn); } turn_ = new_turn; - if (resources::gamedata) - resources::gamedata->get_variable("turn_number") = new_turn; + if (vars) + vars->get_variable("turn_number") = new_turn; } void tod_manager::set_new_current_times(const int new_current_turn_number) @@ -418,9 +418,9 @@ int tod_manager::calculate_current_time( return new_current_time; } -bool tod_manager::next_turn() +bool tod_manager::next_turn(boost::optional vars) { - set_turn(turn_ + 1, false); + set_turn(turn_ + 1, vars, false); return is_time_left(); } diff --git a/src/tod_manager.hpp b/src/tod_manager.hpp index a13505beeb1b..f2aa776d305e 100644 --- a/src/tod_manager.hpp +++ b/src/tod_manager.hpp @@ -19,8 +19,11 @@ #include "time_of_day.hpp" #include "savegame_config.hpp" +#include + class gamemap; class unit_map; +class game_data; namespace random_new { @@ -156,14 +159,14 @@ class tod_manager : public savegame::savegame_config void set_number_of_turns(int num); /** Dynamically change the current turn number. */ - void set_turn(const int num, const bool increase_limit_if_needed = true); + void set_turn(const int num, boost::optional vars = boost::none, const bool increase_limit_if_needed = true); /** * Function to move to the next turn. * * @returns True if time has not expired. */ - bool next_turn(); + bool next_turn(boost::optional vars); /** * Function to check the end of turns.