The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
tod_manager Class Reference

#include <tod_manager.hpp>

Classes

struct  area_time_of_day
 

Public Member Functions

 tod_manager (const config &scenario_cfg=config())
 
 ~tod_manager ()
 
tod_manageroperator= (const tod_manager &manager)
 
config to_config () const
 
void resolve_random (random_new::rng &r)
 handles random_start_time, should be called before the game starts. More...
 
int get_current_time (const map_location &loc=map_location::null_location()) const
 
void set_current_time (int time)
 
void set_current_time (int time, int area_index)
 
void set_current_time (int time, const std::string &area_id)
 
void set_area_id (int area_index, const std::string &id)
 
const time_of_dayget_time_of_day (int for_turn=0) const
 Returns global time of day for the passed turn. More...
 
const time_of_dayget_time_of_day (const map_location &loc, int for_turn=0) const
 Returns time of day for the passed turn at a location. More...
 
int get_current_area_time (int index) const
 
const time_of_day get_illuminated_time_of_day (const unit_map &units, const gamemap &map, const map_location &loc, int for_turn=0) const
 Returns time of day object for the passed turn at a location. More...
 
const time_of_dayget_previous_time_of_day () const
 
void replace_schedule (const config &time_cfg)
 Replace the time of day schedule. More...
 
void replace_schedule (const std::vector< time_of_day > &schedule)
 
void replace_local_schedule (const std::vector< time_of_day > &schedule, int area_index)
 
void replace_area_locations (int index, const std::set< map_location > &locs)
 
std::vector< std::stringget_area_ids () const
 
const std::set< map_location > & get_area_by_index (int index) const
 
const std::set< map_location > & get_area_by_id (const std::string &id) const
 
void add_time_area (const gamemap &map, const config &cfg)
 Adds a new local time area from config, making it follow its own time-of-day sequence. More...
 
void add_time_area (const std::string &id, const std::set< map_location > &locs, const config &time_cfg)
 Adds a new local time area from a set of locations, making those follow a different time-of-day sequence. More...
 
void remove_time_area (const std::string &id)
 Removes a time area from config, making it follow the scenario's normal time-of-day sequence. More...
 
void remove_time_area (int index)
 
bool has_time_area () const
 
const std::vector< time_of_day > & times (const map_location &loc=map_location::null_location()) const
 
const std::vector< time_of_day > & times (int index) const
 
int turn () const
 
int number_of_turns () const
 
void modify_turns (const std::string &mod)
 
void set_number_of_turns (int num)
 
void update_server_information () const
 
void modify_turns_by_wml (const std::string &mod)
 
void set_number_of_turns_by_wml (int num)
 
void set_turn (const int num, game_data *vars=nullptr, const bool increase_limit_if_needed=true)
 Dynamically change the current turn number. More...
 
void set_turn_by_wml (const int num, game_data *vars=nullptr, const bool increase_limit_if_needed=true)
 Dynamically change the current turn number. More...
 
bool next_turn (game_data *vars)
 Function to move to the next turn. More...
 
bool is_time_left ()
 Function to check the end of turns. More...
 
bool has_turn_event_fired ()
 
void turn_event_fired ()
 
bool has_tod_bonus_changed ()
 

Static Public Member Functions

static bool is_start_ToD (const std::string &)
 

Private Member Functions

const time_of_dayget_time_of_day_turn (const std::vector< time_of_day > &times, int nturn, const int current_time) const
 Returns time of day object in the turn "nturn". More...
 
int calculate_current_time (const int number_of_times, const int for_turn_number, const int current_time, const bool only_to_allowed_range=false) const
 Computes for the main time or a time area the index of its times where we're currently at. More...
 
void set_new_current_times (const int new_current_turn_number)
 For a change of the current turn number, sets the current times of the main time and all time areas. More...
 
void set_current_time (int time, area_time_of_day &area)
 

Private Attributes

int currentTime_
 
std::vector< time_of_daytimes_
 
std::vector< area_time_of_dayareas_
 
int turn_
 
int num_turns_
 
bool has_turn_event_fired_
 
bool has_tod_bonus_changed_
 
config::attribute_value random_tod_
 

Detailed Description

Definition at line 33 of file tod_manager.hpp.

Constructor & Destructor Documentation

tod_manager::tod_manager ( const config scenario_cfg = config())
explicit
tod_manager::~tod_manager ( )
inline

Definition at line 37 of file tod_manager.hpp.

Member Function Documentation

void tod_manager::add_time_area ( const gamemap map,
const config cfg 
)

Adds a new local time area from config, making it follow its own time-of-day sequence.

Parameters
cfgConfig object containing x,y range/list of locations and desired [time] information.

Definition at line 332 of file tod_manager.cpp.

References areas_, tod_manager::area_time_of_day::currentTime, has_tod_bonus_changed_, tod_manager::area_time_of_day::hexes, tod_manager::area_time_of_day::id, gamemap::parse_location_range(), time_of_day::parse_times(), tod_manager::area_time_of_day::times, tod_manager::area_time_of_day::xsrc, and tod_manager::area_time_of_day::ysrc.

Referenced by game_state::init(), and game_lua_kernel::intf_add_time_area().

void tod_manager::add_time_area ( const std::string id,
const std::set< map_location > &  locs,
const config time_cfg 
)

Adds a new local time area from a set of locations, making those follow a different time-of-day sequence.

Parameters
idIdentifier string to associate this time area with.
locsSet of locations to be affected.
time_cfgConfig object containing [time] information.

Definition at line 346 of file tod_manager.cpp.

References areas_, tod_manager::area_time_of_day::currentTime, has_tod_bonus_changed_, tod_manager::area_time_of_day::hexes, tod_manager::area_time_of_day::id, time_of_day::parse_times(), and tod_manager::area_time_of_day::times.

int tod_manager::calculate_current_time ( const int  number_of_times,
const int  for_turn_number,
const int  current_time,
const bool  only_to_allowed_range = false 
) const
private

Computes for the main time or a time area the index of its times where we're currently at.

number_of_times: size of that main time or time area's times vector for_turn_number: for which current turn current_time: the main or time area's current time

Definition at line 457 of file tod_manager.cpp.

References turn_.

Referenced by get_time_of_day_turn(), resolve_random(), set_new_current_times(), and tod_manager().

const std::set< map_location > & tod_manager::get_area_by_id ( const std::string id) const
Parameters
idThe id of the area to return.
Returns
The area with id id.

Definition at line 318 of file tod_manager.cpp.

References areas_.

Referenced by terrain_filterimpl::filter_area(), terrain_filter::get_locations(), and terrain_filter::match_internal().

const std::set< map_location > & tod_manager::get_area_by_index ( int  index) const
Returns
the nth area.

Definition at line 327 of file tod_manager.cpp.

References areas_.

Referenced by editor::context_manager::expand_areas_menu().

std::vector< std::string > tod_manager::get_area_ids ( ) const
int tod_manager::get_current_area_time ( int  index) const

Definition at line 144 of file tod_manager.cpp.

References areas_.

int tod_manager::get_current_time ( const map_location loc = map_location::null_location()) const

Definition at line 149 of file tod_manager.cpp.

References areas_, currentTime_, i, and map_location::null_location().

const time_of_day tod_manager::get_illuminated_time_of_day ( const unit_map units,
const gamemap map,
const map_location loc,
int  for_turn = 0 
) const
const time_of_day & tod_manager::get_previous_time_of_day ( ) const

Definition at line 139 of file tod_manager.cpp.

References currentTime_, get_time_of_day_turn(), times_, and turn_.

Referenced by game_display::new_turn().

const time_of_day& tod_manager::get_time_of_day ( int  for_turn = 0) const
inline
const time_of_day & tod_manager::get_time_of_day ( const map_location loc,
int  for_turn = 0 
) const

Returns time of day for the passed turn at a location.

tod areas matter, for_turn = 0 means current turn ignoring illumination

Definition at line 177 of file tod_manager.cpp.

References areas_, currentTime_, get_time_of_day_turn(), i, map_location::null_location(), times_, and turn_.

const time_of_day & tod_manager::get_time_of_day_turn ( const std::vector< time_of_day > &  times,
int  nturn,
const int  current_time 
) const
private

Returns time of day object in the turn "nturn".

Correct time is calculated from current time.

Definition at line 383 of file tod_manager.cpp.

References calculate_current_time().

Referenced by get_previous_time_of_day(), and get_time_of_day().

bool tod_manager::has_time_area ( ) const
inline

Definition at line 140 of file tod_manager.hpp.

References areas_.

Referenced by game_display::has_time_area().

bool tod_manager::has_tod_bonus_changed ( )
inline

Definition at line 181 of file tod_manager.hpp.

References has_tod_bonus_changed_.

bool tod_manager::has_turn_event_fired ( )
inline

Definition at line 177 of file tod_manager.hpp.

References has_turn_event_fired_.

bool tod_manager::is_start_ToD ( const std::string random_start_time)
static

Definition at line 259 of file tod_manager.cpp.

References utils::string_bool().

Referenced by ng::configure_engine::write_parameters().

bool tod_manager::is_time_left ( )

Function to check the end of turns.

Returns
True if time has not expired.

Definition at line 506 of file tod_manager.cpp.

References num_turns_, and turn_.

Referenced by next_turn().

void tod_manager::modify_turns ( const std::string mod)

Definition at line 389 of file tod_manager.cpp.

References utils::apply_modifier(), and num_turns_.

Referenced by modify_turns_by_wml().

void tod_manager::modify_turns_by_wml ( const std::string mod)

Definition at line 413 of file tod_manager.cpp.

References modify_turns(), and update_server_information().

Referenced by game_events::WML_HANDLER_FUNCTION().

bool tod_manager::next_turn ( game_data vars)

Function to move to the next turn.

Returns
True if time has not expired.

Definition at line 498 of file tod_manager.cpp.

References has_turn_event_fired_, is_time_left(), set_turn(), and turn_.

Referenced by play_controller::check_time_over().

int tod_manager::number_of_turns ( ) const
inline
tod_manager & tod_manager::operator= ( const tod_manager manager)

Definition at line 58 of file tod_manager.cpp.

References areas_, currentTime_, num_turns_, times_, and turn_.

void tod_manager::remove_time_area ( const std::string id)

Removes a time area from config, making it follow the scenario's normal time-of-day sequence.

Parameters
idIdentifier of time_area to remove. Supply an empty one to remove all local time areas.

Definition at line 358 of file tod_manager.cpp.

References areas_, has_tod_bonus_changed_, and i.

Referenced by game_lua_kernel::intf_remove_time_area().

void tod_manager::remove_time_area ( int  index)

Definition at line 376 of file tod_manager.cpp.

References areas_, and has_tod_bonus_changed_.

void tod_manager::replace_area_locations ( int  index,
const std::set< map_location > &  locs 
)

Definition at line 286 of file tod_manager.cpp.

References areas_, and has_tod_bonus_changed_.

void tod_manager::replace_local_schedule ( const std::vector< time_of_day > &  schedule,
int  area_index 
)
void tod_manager::replace_schedule ( const config time_cfg)

Replace the time of day schedule.

Definition at line 265 of file tod_manager.cpp.

References currentTime_, has_tod_bonus_changed_, time_of_day::parse_times(), and times_.

Referenced by game_lua_kernel::intf_replace_schedule().

void tod_manager::replace_schedule ( const std::vector< time_of_day > &  schedule)

Definition at line 276 of file tod_manager.cpp.

References currentTime_, has_tod_bonus_changed_, and times_.

void tod_manager::resolve_random ( random_new::rng r)

handles random_start_time, should be called before the game starts.

Definition at line 86 of file tod_manager.cpp.

References calculate_current_time(), currentTime_, random_new::rng::next_random(), output, random_tod_, utils::split(), config::attribute_value::str(), times_, config::attribute_value::to_bool(), and turn_.

Referenced by game_state::init().

void tod_manager::set_area_id ( int  area_index,
const std::string id 
)

Definition at line 304 of file tod_manager.cpp.

References areas_.

Referenced by editor::context_manager::rename_area_dialog().

void tod_manager::set_current_time ( int  time)
void tod_manager::set_current_time ( int  time,
int  area_index 
)

Definition at line 478 of file tod_manager.cpp.

References areas_, and set_current_time().

void tod_manager::set_current_time ( int  time,
const std::string area_id 
)

Definition at line 483 of file tod_manager.cpp.

References areas_, and set_current_time().

void tod_manager::set_current_time ( int  time,
area_time_of_day area 
)
private
void tod_manager::set_new_current_times ( const int  new_current_turn_number)
private

For a change of the current turn number, sets the current times of the main time and all time areas.

Definition at line 445 of file tod_manager.cpp.

References areas_, calculate_current_time(), currentTime_, set_current_time(), and times_.

Referenced by set_turn().

void tod_manager::set_number_of_turns ( int  num)

Definition at line 393 of file tod_manager.cpp.

References num_turns_.

Referenced by set_number_of_turns_by_wml(), set_turn(), and SYNCED_COMMAND_HANDLER_FUNCTION().

void tod_manager::set_number_of_turns_by_wml ( int  num)
void tod_manager::set_turn ( const int  num,
game_data vars = nullptr,
const bool  increase_limit_if_needed = true 
)

Dynamically change the current turn number.

Definition at line 424 of file tod_manager.cpp.

References game_data::get_variable(), has_tod_bonus_changed_, LOG_NG, num_turns_, set_new_current_times(), set_number_of_turns(), and turn_.

Referenced by next_turn(), set_turn_by_wml(), and SYNCED_COMMAND_HANDLER_FUNCTION().

void tod_manager::set_turn_by_wml ( const int  num,
game_data vars = nullptr,
const bool  increase_limit_if_needed = true 
)

Dynamically change the current turn number.

Definition at line 440 of file tod_manager.cpp.

References set_turn(), and update_server_information().

Referenced by game_events::WML_HANDLER_FUNCTION().

const std::vector< time_of_day > & tod_manager::times ( const map_location loc = map_location::null_location()) const
const std::vector<time_of_day>& tod_manager::times ( int  index) const
inline

Definition at line 144 of file tod_manager.hpp.

References areas_.

config tod_manager::to_config ( ) const
int tod_manager::turn ( ) const
inline
void tod_manager::turn_event_fired ( )
inline

Definition at line 179 of file tod_manager.hpp.

References has_turn_event_fired_.

Referenced by play_controller::do_init_side().

void tod_manager::update_server_information ( ) const

Member Data Documentation

std::vector<area_time_of_day> tod_manager::areas_
private
int tod_manager::currentTime_
private
bool tod_manager::has_tod_bonus_changed_
private
bool tod_manager::has_turn_event_fired_
private

Definition at line 240 of file tod_manager.hpp.

Referenced by has_turn_event_fired(), next_turn(), to_config(), and turn_event_fired().

int tod_manager::num_turns_
private
config::attribute_value tod_manager::random_tod_
private

Definition at line 243 of file tod_manager.hpp.

Referenced by resolve_random(), to_config(), and tod_manager().

std::vector<time_of_day> tod_manager::times_
private
int tod_manager::turn_
private

The documentation for this class was generated from the following files: