The Battle for Wesnoth  1.15.1+dev
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 (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 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::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
 
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
 

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

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 31 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 35 of file tod_manager.hpp.

References map_location::null_location().

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

Definition at line 374 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().

◆ 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 388 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.

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

References generic_combat_modifier().

Referenced by tod_manager().

◆ calculate_current_time()

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

References turn_.

Referenced by get_time_of_day_turn(), resolve_random(), set_new_current_times(), 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 359 of file tod_manager.cpp.

References areas_.

◆ get_area_by_index()

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

Definition at line 369 of file tod_manager.cpp.

References areas_, and utf8::index().

Referenced by editor::editor_controller::do_execute_command(), and editor::context_manager::expand_areas_menu().

◆ get_area_ids()

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

◆ get_current_area_time()

int tod_manager::get_current_area_time ( int  index) const

Definition at line 180 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

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

tod areas matter, for_turn = 0 means current turn taking account of illumination caused by units

Definition at line 231 of file tod_manager.cpp.

References time_of_day::bonus_modified, bounded_add(), unit_map::end(), unit_map::find(), get_adjacent_tiles(), unit_abilities::effect::get_composite_value(), gamemap::get_terrain_info(), get_time_of_day(), unit_ability_list::highest(), i, time_of_day::lawful_bonus, terrain_type::light_bonus(), unit_ability_list::lowest(), and gamemap::on_board_with_border().

Referenced by combat_modifier(), and get_visible_time_of_day_at().

◆ get_max_liminal_bonus()

int tod_manager::get_max_liminal_bonus ( ) const
inline

Definition at line 181 of file tod_manager.hpp.

Referenced by combat_modifier(), time_of_day_at(), and unit_box_at().

◆ get_previous_time_of_day()

const time_of_day & tod_manager::get_previous_time_of_day ( ) const

Definition at line 175 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 ( int  for_turn = 0) const
inline

◆ get_time_of_day() [2/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 213 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_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 425 of file tod_manager.cpp.

References calculate_current_time().

Referenced by get_previous_time_of_day(), and get_time_of_day().

◆ has_time_area()

bool tod_manager::has_time_area ( ) const
inline

Definition at line 138 of file tod_manager.hpp.

References map_location::null_location().

Referenced by game_display::has_time_area().

◆ has_tod_bonus_changed()

bool tod_manager::has_tod_bonus_changed ( ) const
inline

Definition at line 179 of file tod_manager.hpp.

◆ has_turn_event_fired()

bool tod_manager::has_turn_event_fired ( ) const
inline

Definition at line 175 of file tod_manager.hpp.

◆ is_start_ToD()

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

Definition at line 294 of file tod_manager.cpp.

References utils::string_bool().

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

◆ 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 548 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 431 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 455 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 540 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)

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

References areas_, has_tod_bonus_changed_, and i.

◆ remove_time_area() [2/2]

void tod_manager::remove_time_area ( int  index)

Definition at line 418 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 327 of file tod_manager.cpp.

References areas_, and has_tod_bonus_changed_.

◆ replace_local_schedule()

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

◆ replace_schedule() [1/2]

void tod_manager::replace_schedule ( const config time_cfg)

Replace the time of day schedule.

Definition at line 300 of file tod_manager.cpp.

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

◆ replace_schedule() [2/2]

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

Definition at line 311 of file tod_manager.cpp.

References currentTime_, has_tod_bonus_changed_, and times_.

◆ resolve_random()

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

handles random_start_time, should be called before the game starts.

Definition at line 88 of file tod_manager.cpp.

References calculate_current_time(), currentTime_, randomness::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().

◆ set_area_id()

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

Definition at line 345 of file tod_manager.cpp.

References areas_.

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

◆ set_current_time() [1/4]

void tod_manager::set_current_time ( int  time)

Definition at line 513 of file tod_manager.cpp.

References currentTime_, has_tod_bonus_changed_, and times_.

Referenced by set_current_time(), and set_new_current_times().

◆ set_current_time() [2/4]

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

Definition at line 520 of file tod_manager.cpp.

References areas_, and set_current_time().

◆ set_current_time() [3/4]

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

Definition at line 525 of file tod_manager.cpp.

References areas_, and set_current_time().

◆ set_current_time() [4/4]

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

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

References areas_, calculate_current_time(), 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 435 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 466 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 482 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 142 of file tod_manager.hpp.

References utf8::index().

◆ to_config()

config tod_manager::to_config ( ) const

◆ turn()

int tod_manager::turn ( ) const
inline

◆ turn_event_fired()

void tod_manager::turn_event_fired ( )
inline

Definition at line 177 of file tod_manager.hpp.

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

Definition at line 249 of file tod_manager.hpp.

Referenced by operator=(), to_config(), and tod_manager().

◆ 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 247 of file tod_manager.hpp.

Referenced by next_turn(), operator=(), and to_config().

◆ liminal_bonus_

int tod_manager::liminal_bonus_
private

Definition at line 240 of file tod_manager.hpp.

Referenced by operator=(), to_config(), and tod_manager().

◆ num_turns_

int tod_manager::num_turns_
private

◆ random_tod_

config::attribute_value tod_manager::random_tod_
private

Definition at line 251 of file tod_manager.hpp.

Referenced by operator=(), 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: