added turn members to tod_manager
This commit is contained in:
parent
063df523d5
commit
ad65cf8d44
3 changed files with 71 additions and 8 deletions
|
@ -53,7 +53,7 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
|
|||
mouse_handler_(NULL, teams_, units_, map_, status_, undo_stack_, redo_stack_),
|
||||
menu_handler_(NULL, units_, teams_, level, map_, game_config, status_, state_of_game, undo_stack_, redo_stack_),
|
||||
soundsources_manager_(),
|
||||
tod_manager_(level, &state_of_game),
|
||||
tod_manager_(level, num_turns, &state_of_game),
|
||||
gui_(),
|
||||
statistics_context_(level["name"]),
|
||||
level_(level),
|
||||
|
|
|
@ -17,24 +17,32 @@
|
|||
#include "gettext.hpp"
|
||||
#include "formula_string_utils.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
tod_manager::tod_manager(const config& time_cfg, game_state* state):
|
||||
currentTime_(0)
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
|
||||
tod_manager::tod_manager(const config& time_cfg, int num_turns, game_state* state):
|
||||
currentTime_(0),
|
||||
times_(),
|
||||
areas_(),
|
||||
turn_(1),
|
||||
num_turns_(num_turns)
|
||||
{
|
||||
std::string turn_at = time_cfg["turn_at"];
|
||||
if (state)
|
||||
{
|
||||
turn_at = utils::interpolate_variables_into_string(turn_at, *state);
|
||||
|
||||
}
|
||||
|
||||
int turn = 1;
|
||||
if(turn_at.empty() == false) {
|
||||
turn = atoi(turn_at.c_str());
|
||||
turn_ = atoi(turn_at.c_str());
|
||||
}
|
||||
|
||||
time_of_day::parse_times(time_cfg,times_);
|
||||
|
||||
set_start_ToD(const_cast<config&>(time_cfg), turn, NULL);
|
||||
set_start_ToD(const_cast<config&>(time_cfg), turn_, NULL);
|
||||
|
||||
foreach (const config &t, time_cfg.child_range("time_area")) {
|
||||
this->add_time_area(t);
|
||||
|
@ -222,3 +230,39 @@ void tod_manager::next_time_of_day()
|
|||
|
||||
currentTime_ = (currentTime_ + 1)%times_.size();
|
||||
}
|
||||
|
||||
|
||||
void tod_manager::modify_turns(const std::string& mod)
|
||||
{
|
||||
num_turns_ = std::max<int>(utils::apply_modifier(num_turns_,mod,0),-1);
|
||||
}
|
||||
void tod_manager::add_turns(int num)
|
||||
{
|
||||
num_turns_ = std::max<int>(num_turns_ + num,-1);
|
||||
}
|
||||
|
||||
void tod_manager::set_turn(unsigned int num)
|
||||
{
|
||||
VALIDATE(times_.size(), _("No time of day has been defined."));
|
||||
const unsigned int old_num = turn_;
|
||||
// Correct ToD
|
||||
int current_time = (num - 1) % times_.size();
|
||||
if (current_time < 0) {
|
||||
current_time += times_.size();
|
||||
}
|
||||
set_time_of_day(current_time);
|
||||
|
||||
if(static_cast<int>(num) > num_turns_ && num_turns_ != -1) {
|
||||
this->add_turns(num_turns_ - num);
|
||||
}
|
||||
turn_ = num;
|
||||
|
||||
LOG_NG << "changed current turn number from " << old_num << " to " << num << '\n';
|
||||
}
|
||||
|
||||
bool tod_manager::next_turn()
|
||||
{
|
||||
next_time_of_day();
|
||||
++turn_;
|
||||
return num_turns_ == -1 || turn_ <= size_t(num_turns_);
|
||||
}
|
|
@ -25,11 +25,11 @@
|
|||
|
||||
class game_state;
|
||||
|
||||
//time of day functionality
|
||||
//time of day and turn functionality
|
||||
class tod_manager : public savegame_config
|
||||
{
|
||||
public:
|
||||
tod_manager(const config& time_cfg, game_state* state=NULL);
|
||||
tod_manager(const config& time_cfg, int num_turns, game_state* state=NULL);
|
||||
~tod_manager() {}
|
||||
|
||||
config to_config();
|
||||
|
@ -86,6 +86,22 @@ class tod_manager : public savegame_config
|
|||
void next_time_of_day();
|
||||
const std::vector<time_of_day> times() const {return times_;}
|
||||
|
||||
//turn functions
|
||||
size_t turn() const {return turn_;}
|
||||
int number_of_turns() const {return num_turns_;}
|
||||
void modify_turns(const std::string& mod);
|
||||
void add_turns(int num);
|
||||
|
||||
/** Dynamically change the current turn number. */
|
||||
void set_turn(unsigned int num);
|
||||
|
||||
/**
|
||||
* Function to move to the next turn.
|
||||
*
|
||||
* @returns True if time has not expired.
|
||||
*/
|
||||
bool next_turn();
|
||||
|
||||
private:
|
||||
void set_start_ToD(config&, int current_turn, game_state*);
|
||||
|
||||
|
@ -114,5 +130,8 @@ class tod_manager : public savegame_config
|
|||
int currentTime_;
|
||||
std::vector<time_of_day> times_;
|
||||
std::vector<area_time_of_day> areas_;
|
||||
|
||||
size_t turn_;
|
||||
int num_turns_;
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue