The Battle for Wesnoth  1.19.0-dev
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Static 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)=default
 
config to_config (std::string textdomain="") const
 
void resolve_random (randomness::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 std::string & get_area_id (int area_index) const
 
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...
 
const time_of_dayget_area_time_of_day (int area_i, int for_turn=0) const
 Returns time of day for the passed turn in the specified tod area. 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, int initial_time=0)
 
void replace_local_schedule (const std::vector< time_of_day > &schedule, int area_index, int initial_time=0)
 
void replace_area_locations (int index, const std::set< map_location > &locs)
 
std::vector< std::string > get_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
 
std::pair< int, std::string > get_area_on_hex (const map_location &loc) 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 () const
 Function to check the end of turns. More...
 
bool has_turn_event_fired () const
 
void turn_event_fired ()
 
bool has_tod_bonus_changed () const
 
int get_max_liminal_bonus () const
 
void set_max_liminal_bonus (int bonus)
 
void reset_max_liminal_bonus ()
 

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_time_index_at_turn (int number_of_times, int for_turn_number, int current_time) const
 Computes for the main time or a time area the index of its times where we're currently at. More...
 
int calculate_best_liminal_bonus (const std::vector< time_of_day > &schedule) const
 Computes the maximum absolute value of lawful_bonus in the schedule. 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)
 

Static Private Member Functions

static int fix_time_index (int number_of_times, int time)
 Computes for the main time or a time area the index of its times where we're currently at. More...
 

Private Attributes

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

Detailed Description

Definition at line 32 of file tod_manager.hpp.

Constructor & Destructor Documentation

◆ tod_manager()

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

◆ ~tod_manager()

tod_manager::~tod_manager ( )
inline

Definition at line 36 of file tod_manager.hpp.

Member Function Documentation

◆ add_time_area() [1/2]

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
mapThe game's map.
cfgConfig object containing x,y range/list of locations and desired [time] information.

Definition at line 383 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_base::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().

◆ add_time_area() [2/2]

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 397 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, id, tod_manager::area_time_of_day::id, time_of_day::parse_times(), and tod_manager::area_time_of_day::times.

◆ calculate_best_liminal_bonus()

int tod_manager::calculate_best_liminal_bonus ( const std::vector< time_of_day > &  schedule) const
private

Computes the maximum absolute value of lawful_bonus in the schedule.

Definition at line 583 of file tod_manager.cpp.

References generic_combat_modifier().

Referenced by reset_max_liminal_bonus(), and tod_manager().

◆ calculate_time_index_at_turn()

int tod_manager::calculate_time_index_at_turn ( int  number_of_times,
int  for_turn_number,
int  current_time 
) 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 527 of file tod_manager.cpp.

References modulo(), and turn_.

Referenced by get_time_of_day_turn(), and set_new_current_times().

◆ fix_time_index()

int tod_manager::fix_time_index ( int  number_of_times,
int  time 
)
staticprivate

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 518 of file tod_manager.cpp.

References modulo().

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

◆ get_area_by_id()

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 353 of file tod_manager.cpp.

References areas_.

Referenced by terrain_filter::get_locs_impl(), game_lua_kernel::intf_get_time_of_day(), and terrain_filter::match_internal().

◆ get_area_by_index()

const std::set< map_location > & tod_manager::get_area_by_index ( int  index) const

◆ get_area_id()

const std::string & tod_manager::get_area_id ( int  area_index) const

Definition at line 337 of file tod_manager.cpp.

References areas_.

Referenced by game_lua_kernel::impl_schedule_set().

◆ get_area_ids()

std::vector< std::string > tod_manager::get_area_ids ( ) const

◆ get_area_on_hex()

std::pair< int, std::string > tod_manager::get_area_on_hex ( const map_location loc) const
Returns
the area ID and index active on the given location.

Definition at line 370 of file tod_manager.cpp.

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

Referenced by game_lua_kernel::intf_get_time_area().

◆ get_area_time_of_day()

const time_of_day & tod_manager::get_area_time_of_day ( int  area_i,
int  for_turn = 0 
) const

Returns time of day for the passed turn in the specified tod area.

for_turn = 0 means current turn, ignoring illumination

Definition at line 209 of file tod_manager.cpp.

References areas_, get_time_of_day_turn(), times(), and turn_.

◆ get_current_area_time()

int tod_manager::get_current_area_time ( int  index) const

Definition at line 159 of file tod_manager.cpp.

References areas_, and utf8::index().

Referenced by editor::editor_controller::get_action_state().

◆ get_current_time()

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

◆ get_illuminated_time_of_day()

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

◆ get_max_liminal_bonus()

int tod_manager::get_max_liminal_bonus ( ) const
inline

◆ get_previous_time_of_day()

const time_of_day & tod_manager::get_previous_time_of_day ( ) const

Definition at line 154 of file tod_manager.cpp.

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

Referenced by game_display::new_turn().

◆ get_time_of_day() [1/2]

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 192 of file tod_manager.cpp.

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

◆ get_time_of_day() [2/2]

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

◆ get_time_of_day_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 434 of file tod_manager.cpp.

References calculate_time_index_at_turn(), dummytime(), and times().

Referenced by get_area_time_of_day(), get_previous_time_of_day(), and get_time_of_day().

◆ has_time_area()

bool tod_manager::has_time_area ( ) const
inline

Definition at line 150 of file tod_manager.hpp.

References areas_.

Referenced by game_display::has_time_area().

◆ has_tod_bonus_changed()

bool tod_manager::has_tod_bonus_changed ( ) const
inline

Definition at line 191 of file tod_manager.hpp.

References has_tod_bonus_changed_.

◆ has_turn_event_fired()

bool tod_manager::has_turn_event_fired ( ) const
inline

Definition at line 187 of file tod_manager.hpp.

References has_turn_event_fired_.

◆ is_start_ToD()

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

◆ is_time_left()

bool tod_manager::is_time_left ( ) const

Function to check the end of turns.

Returns
True if time has not expired.

Definition at line 578 of file tod_manager.cpp.

References num_turns_, and turn_.

Referenced by next_turn().

◆ modify_turns()

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

Definition at line 445 of file tod_manager.cpp.

References utils::apply_modifier(), and num_turns_.

Referenced by modify_turns_by_wml().

◆ modify_turns_by_wml()

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

Definition at line 471 of file tod_manager.cpp.

References modify_turns(), and update_server_information().

Referenced by game_events::WML_HANDLER_FUNCTION().

◆ next_turn()

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 571 of file tod_manager.cpp.

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

Referenced by play_controller::check_time_over().

◆ number_of_turns()

int tod_manager::number_of_turns ( ) const
inline

◆ operator=()

tod_manager& tod_manager::operator= ( const tod_manager manager)
default

◆ remove_time_area() [1/2]

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 408 of file tod_manager.cpp.

References areas_, has_tod_bonus_changed_, and i.

Referenced by game_lua_kernel::intf_remove_time_area().

◆ remove_time_area() [2/2]

void tod_manager::remove_time_area ( int  index)

Definition at line 427 of file tod_manager.cpp.

References areas_, and has_tod_bonus_changed_.

◆ replace_area_locations()

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

Definition at line 306 of file tod_manager.cpp.

References areas_, and has_tod_bonus_changed_.

Referenced by game_lua_kernel::impl_schedule_set().

◆ replace_local_schedule()

void tod_manager::replace_local_schedule ( const std::vector< time_of_day > &  schedule,
int  area_index,
int  initial_time = 0 
)

◆ replace_schedule() [1/2]

void tod_manager::replace_schedule ( const config time_cfg)

Replace the time of day schedule.

Definition at line 289 of file tod_manager.cpp.

References time_of_day::parse_times().

Referenced by game_lua_kernel::impl_schedule_set(), and game_lua_kernel::intf_replace_schedule().

◆ replace_schedule() [2/2]

void tod_manager::replace_schedule ( const std::vector< time_of_day > &  schedule,
int  initial_time = 0 
)

Definition at line 296 of file tod_manager.cpp.

References currentTime_, has_tod_bonus_changed_, and times_.

◆ reset_max_liminal_bonus()

void tod_manager::reset_max_liminal_bonus ( )
inline

◆ resolve_random()

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

handles random_start_time, should be called before the game starts.

Definition at line 66 of file tod_manager.cpp.

References currentTime_, fix_time_index(), randomness::rng::next_random(), output(), random_tod_, utils::split(), config_attribute_value::str(), times_, and config_attribute_value::to_bool().

Referenced by game_state::init().

◆ set_area_id()

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

Definition at line 331 of file tod_manager.cpp.

References areas_, and id.

◆ set_current_time() [1/4]

void tod_manager::set_current_time ( int  time)

◆ set_current_time() [2/4]

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

◆ set_current_time() [3/4]

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

Definition at line 552 of file tod_manager.cpp.

References areas_, and set_current_time().

◆ set_current_time() [4/4]

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

Definition at line 546 of file tod_manager.cpp.

References areas_, and set_current_time().

◆ set_max_liminal_bonus()

void tod_manager::set_max_liminal_bonus ( int  bonus)
inline

Definition at line 195 of file tod_manager.hpp.

References has_cfg_liminal_bonus_, and liminal_bonus_.

◆ set_new_current_times()

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 509 of file tod_manager.cpp.

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

Referenced by set_turn().

◆ set_number_of_turns()

void tod_manager::set_number_of_turns ( int  num)

Definition at line 450 of file tod_manager.cpp.

References num_turns_.

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

◆ set_number_of_turns_by_wml()

void tod_manager::set_number_of_turns_by_wml ( int  num)

◆ set_turn()

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 483 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().

◆ set_turn_by_wml()

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 503 of file tod_manager.cpp.

References set_turn(), and update_server_information().

Referenced by game_events::WML_HANDLER_FUNCTION().

◆ times() [1/2]

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

◆ times() [2/2]

const std::vector<time_of_day>& tod_manager::times ( int  index) const
inline

Definition at line 154 of file tod_manager.hpp.

References areas_, and utf8::index().

◆ to_config()

config tod_manager::to_config ( std::string  textdomain = "") const

◆ turn()

int tod_manager::turn ( ) const
inline

◆ turn_event_fired()

void tod_manager::turn_event_fired ( )
inline

Definition at line 189 of file tod_manager.hpp.

References has_turn_event_fired_.

Referenced by play_controller::do_init_side().

◆ update_server_information()

void tod_manager::update_server_information ( ) const

Member Data Documentation

◆ areas_

std::vector<area_time_of_day> tod_manager::areas_
private

◆ currentTime_

int tod_manager::currentTime_
private

◆ has_cfg_liminal_bonus_

bool tod_manager::has_cfg_liminal_bonus_
private

◆ has_tod_bonus_changed_

bool tod_manager::has_tod_bonus_changed_
private

◆ has_turn_event_fired_

bool tod_manager::has_turn_event_fired_
private

Definition at line 274 of file tod_manager.hpp.

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

◆ liminal_bonus_

int tod_manager::liminal_bonus_
private

◆ num_turns_

int tod_manager::num_turns_
private

◆ random_tod_

config::attribute_value tod_manager::random_tod_
private

Definition at line 278 of file tod_manager.hpp.

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

◆ times_

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

◆ turn_

int tod_manager::turn_
private

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