#include <tod_manager.hpp>
Classes | |
struct | area_time_of_day |
Public Member Functions | |
tod_manager (const config &scenario_cfg=config()) | |
~tod_manager () | |
tod_manager & | operator= (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_day & | get_time_of_day (int for_turn=0) const |
Returns global time of day for the passed turn. More... | |
const time_of_day & | get_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_day & | get_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 () |
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_day & | get_time_of_day_turn (const std::vector< time_of_day > ×, 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_day > | times_ |
std::vector< area_time_of_day > | areas_ |
int | turn_ |
int | num_turns_ |
bool | has_turn_event_fired_ |
bool | has_tod_bonus_changed_ |
config::attribute_value | random_tod_ |
Definition at line 33 of file tod_manager.hpp.
Definition at line 38 of file tod_manager.cpp.
References calculate_current_time(), currentTime_, time_of_day::parse_times(), random_tod_, times_, and turn_.
|
inline |
Definition at line 37 of file tod_manager.hpp.
Adds a new local time area from config, making it follow its own time-of-day sequence.
cfg | Config 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.
id | Identifier string to associate this time area with. |
locs | Set of locations to be affected. |
time_cfg | Config 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.
|
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 |
id | The id of the area to return. |
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 |
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 |
Definition at line 309 of file tod_manager.cpp.
References areas_.
Referenced by editor::context_manager::expand_areas_menu(), game_lua_kernel::intf_set_time_of_day(), and editor::context_manager::rename_area_dialog().
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 |
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 195 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, itor, time_of_day::lawful_bonus, terrain_type::light_bonus(), unit_ability_list::lowest(), and gamemap::on_board_with_border().
Referenced by combat_modifier(), game_lua_kernel::intf_get_time_of_day(), terrain_filter::match_internal(), time_of_day_at(), and unit_box_at().
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().
|
inline |
Returns global time of day for the passed turn.
for_turn = 0 means current turn
Definition at line 56 of file tod_manager.hpp.
References currentTime_, get_time_of_day_turn(), times_, and turn_.
Referenced by events::mouse_handler::attack_enemy_(), ai::attack_result::do_execute(), get_illuminated_time_of_day(), game_display::get_time_of_day(), play_controller::init_side_end(), game_lua_kernel::intf_get_time_of_day(), ai::readonly_context_impl::is_active(), terrain_filter::match_internal(), game_display::new_turn(), ai::readonly_context_impl::power_projection(), time_of_day_at(), unit_box_at(), and game_events::WML_HANDLER_FUNCTION().
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_.
|
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().
|
inline |
Definition at line 140 of file tod_manager.hpp.
References areas_.
Referenced by game_display::has_time_area().
|
inline |
Definition at line 181 of file tod_manager.hpp.
References has_tod_bonus_changed_.
|
inline |
Definition at line 177 of file tod_manager.hpp.
References has_turn_event_fired_.
|
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.
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.
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().
|
inline |
Definition at line 151 of file tod_manager.hpp.
References num_turns_.
Referenced by editor::context_manager::edit_scenario_dialog(), game_lua_kernel::intf_get_time_of_day(), campaign_controller::show_carryover_message(), and game_events::WML_HANDLER_FUNCTION().
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.
id | Identifier 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().
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 | ||
) |
Definition at line 292 of file tod_manager.cpp.
References areas_, tod_manager::area_time_of_day::currentTime, has_tod_bonus_changed_, and tod_manager::area_time_of_day::times.
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().
Definition at line 471 of file tod_manager.cpp.
References currentTime_, has_tod_bonus_changed_, and times_.
Referenced by game_lua_kernel::intf_set_time_of_day(), set_current_time(), and set_new_current_times().
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().
|
private |
Definition at line 490 of file tod_manager.cpp.
References tod_manager::area_time_of_day::currentTime, has_tod_bonus_changed_, and tod_manager::area_time_of_day::times.
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().
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().
Definition at line 418 of file tod_manager.cpp.
References set_number_of_turns(), and update_server_information().
Referenced by game_events::WML_HANDLER_FUNCTION().
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 |
Definition at line 163 of file tod_manager.cpp.
References areas_, i, map_location::null_location(), and times_.
Referenced by editor::editor_controller::execute_command(), editor::context_manager::expand_local_time_menu(), editor::context_manager::expand_time_menu(), help::generate_time_of_day_topics(), and game_lua_kernel::intf_set_time_of_day().
|
inline |
Definition at line 144 of file tod_manager.hpp.
References areas_.
config tod_manager::to_config | ( | ) | const |
Definition at line 108 of file tod_manager.cpp.
References config::add_child(), areas_, currentTime_, has_turn_event_fired_, i, num_turns_, random_tod_, times_, turn_, and write_location_range().
Referenced by game_state::write().
|
inline |
Definition at line 150 of file tod_manager.hpp.
References turn_.
Referenced by events::mouse_handler::attack_enemy_(), ai::attack_result::do_execute(), ai::idle_stage::do_play_stage(), events::console_handler::do_turn(), ai::default_recruitment::recruitment::evaluate(), ai::default_recruitment::recruitment::execute(), game_lua_kernel::intf_get_time_of_day(), ai::readonly_context_impl::is_active(), ai_testing::log_game_end(), ai_testing::log_turn(), replay_controller::play_side_impl(), ai::readonly_context_impl::power_projection(), replay_controller::replay_next_turn(), campaign_controller::show_carryover_message(), play_controller::turn(), and game_events::WML_HANDLER_FUNCTION().
|
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 |
Definition at line 398 of file tod_manager.cpp.
References resources::controller, num_turns_, play_controller::send_to_wesnothd(), and turn_.
Referenced by modify_turns_by_wml(), set_number_of_turns_by_wml(), and set_turn_by_wml().
|
private |
Definition at line 233 of file tod_manager.hpp.
Referenced by add_time_area(), get_area_by_id(), get_area_by_index(), get_area_ids(), get_current_area_time(), get_current_time(), get_time_of_day(), has_time_area(), operator=(), remove_time_area(), replace_area_locations(), replace_local_schedule(), set_area_id(), set_current_time(), set_new_current_times(), times(), and to_config().
|
private |
Definition at line 231 of file tod_manager.hpp.
Referenced by get_current_time(), get_previous_time_of_day(), get_time_of_day(), operator=(), replace_schedule(), resolve_random(), set_current_time(), set_new_current_times(), to_config(), and tod_manager().
|
private |
Definition at line 241 of file tod_manager.hpp.
Referenced by add_time_area(), has_tod_bonus_changed(), remove_time_area(), replace_area_locations(), replace_local_schedule(), replace_schedule(), set_current_time(), and set_turn().
|
private |
Definition at line 240 of file tod_manager.hpp.
Referenced by has_turn_event_fired(), next_turn(), to_config(), and turn_event_fired().
|
private |
Definition at line 238 of file tod_manager.hpp.
Referenced by is_time_left(), modify_turns(), number_of_turns(), operator=(), set_number_of_turns(), set_turn(), to_config(), and update_server_information().
|
private |
Definition at line 243 of file tod_manager.hpp.
Referenced by resolve_random(), to_config(), and tod_manager().
|
private |
Definition at line 232 of file tod_manager.hpp.
Referenced by get_previous_time_of_day(), get_time_of_day(), operator=(), replace_schedule(), resolve_random(), set_current_time(), set_new_current_times(), times(), to_config(), and tod_manager().
|
private |
Definition at line 236 of file tod_manager.hpp.
Referenced by calculate_current_time(), get_previous_time_of_day(), get_time_of_day(), is_time_left(), next_turn(), operator=(), resolve_random(), set_turn(), to_config(), tod_manager(), turn(), and update_server_information().