#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)=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_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... | |
const time_of_day & | 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. 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, 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_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_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_day > | times_ |
std::vector< area_time_of_day > | areas_ |
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_ |
Definition at line 32 of file tod_manager.hpp.
Definition at line 36 of file tod_manager.cpp.
References calculate_best_liminal_bonus(), currentTime_, fix_time_index(), config::has_attribute(), has_cfg_liminal_bonus_, liminal_bonus_, time_of_day::parse_times(), random_tod_, and times_.
|
inline |
Definition at line 36 of file tod_manager.hpp.
Adds a new local time area from config, making it follow its own time-of-day sequence.
map | The game's map. |
cfg | Config 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().
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 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.
|
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().
|
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().
|
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().
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 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().
const std::set< map_location > & tod_manager::get_area_by_index | ( | int | index | ) | const |
Definition at line 365 of file tod_manager.cpp.
References areas_, and utf8::index().
Referenced by editor::editor_controller::do_execute_command(), editor::context_manager::expand_areas_menu(), and game_lua_kernel::intf_get_time_of_day().
const std::string & tod_manager::get_area_id | ( | int | area_index | ) | const |
Definition at line 337 of file tod_manager.cpp.
References areas_.
std::vector< std::string > tod_manager::get_area_ids | ( | ) | const |
Definition at line 343 of file tod_manager.cpp.
References areas_.
Referenced by editor::editor_controller::can_execute_command(), editor::context_manager::expand_areas_menu(), and game_lua_kernel::intf_get_time_area().
std::pair< int, std::string > tod_manager::get_area_on_hex | ( | const map_location & | loc | ) | const |
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().
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_.
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().
int tod_manager::get_current_time | ( | const map_location & | loc = map_location::null_location() | ) | const |
Definition at line 165 of file tod_manager.cpp.
References areas_, currentTime_, i, and map_location::null_location().
Referenced by editor::editor_controller::custom_tods_dialog(), editor::editor_controller::get_action_state(), and tod_stats_at().
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 218 of file tod_manager.cpp.
References time_of_day::bonus_modified, bounded_add(), unit_abilities::EFFECT_WITHOUT_CLAMP_MIN_MAX, unit_ability_list::empty(), 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_base::on_board_with_border().
Referenced by combat_modifier(), wfl::gamestate::DEFINE_WFL_FUNCTION(), get_visible_time_of_day_at(), game_lua_kernel::intf_get_time_of_day(), and terrain_filter::match_internal().
|
inline |
Definition at line 193 of file tod_manager.hpp.
References liminal_bonus_.
Referenced by combat_modifier(), help::generate_time_of_day_topics(), time_of_day_at(), and unit_box_at().
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().
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_.
|
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_(), wfl::gamestate::DEFINE_WFL_FUNCTION(), ai::attack_result::do_execute(), get_illuminated_time_of_day(), game_display::get_time_of_day(), editor::editor_display::get_time_of_day(), get_visible_time_of_day_at(), 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(), and unit_box_at().
|
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().
|
inline |
Definition at line 150 of file tod_manager.hpp.
References areas_.
Referenced by game_display::has_time_area().
|
inline |
Definition at line 191 of file tod_manager.hpp.
References has_tod_bonus_changed_.
|
inline |
Definition at line 187 of file tod_manager.hpp.
References has_turn_event_fired_.
|
static |
Definition at line 284 of file tod_manager.cpp.
References utils::string_bool().
Referenced by ng::configure_engine::write_parameters().
bool tod_manager::is_time_left | ( | ) | const |
Function to check the end of turns.
Definition at line 578 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 445 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 471 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 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().
|
inline |
Definition at line 161 of file tod_manager.hpp.
References num_turns_.
Referenced by carryover_show_gold(), editor::context_manager::edit_scenario_dialog(), game_lua_kernel::intf_get_time_of_day(), and game_events::WML_HANDLER_FUNCTION().
|
default |
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 408 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 427 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 306 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, | ||
int | initial_time = 0 |
||
) |
Definition at line 313 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.
Referenced by game_lua_kernel::impl_schedule_set().
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().
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_.
|
inline |
Definition at line 199 of file tod_manager.hpp.
References calculate_best_liminal_bonus(), has_cfg_liminal_bonus_, liminal_bonus_, and times().
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().
void tod_manager::set_area_id | ( | int | area_index, |
const std::string & | id | ||
) |
Definition at line 331 of file tod_manager.cpp.
void tod_manager::set_current_time | ( | int | time | ) |
Definition at line 536 of file tod_manager.cpp.
References currentTime_, fix_time_index(), has_tod_bonus_changed_, and times_.
Referenced by set_current_time(), and set_new_current_times().
|
private |
Definition at line 561 of file tod_manager.cpp.
References tod_manager::area_time_of_day::currentTime, fix_time_index(), has_tod_bonus_changed_, and tod_manager::area_time_of_day::times.
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().
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().
|
inline |
Definition at line 195 of file tod_manager.hpp.
References has_cfg_liminal_bonus_, and liminal_bonus_.
|
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().
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().
void tod_manager::set_number_of_turns_by_wml | ( | int | num | ) |
Definition at line 477 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 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().
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().
const std::vector< time_of_day > & tod_manager::times | ( | const map_location & | loc = map_location::null_location() | ) | const |
Definition at line 179 of file tod_manager.cpp.
References areas_, i, map_location::null_location(), and times_.
Referenced by editor::editor_controller::custom_tods_dialog(), editor::context_manager::expand_local_time_menu(), editor::context_manager::expand_time_menu(), help::generate_time_of_day_topics(), editor::editor_controller::get_action_state(), get_area_time_of_day(), get_time_of_day_turn(), game_lua_kernel::impl_schedule_get(), game_lua_kernel::impl_schedule_len(), game_lua_kernel::impl_schedule_set(), reset_max_liminal_bonus(), and tod_stats_at().
|
inline |
Definition at line 154 of file tod_manager.hpp.
References areas_, and utf8::index().
config tod_manager::to_config | ( | std::string | textdomain = "" | ) | const |
Definition at line 95 of file tod_manager.cpp.
References config::add_child(), areas_, currentTime_, has_cfg_liminal_bonus_, has_turn_event_fired_, time_of_day::id, liminal_bonus_, num_turns_, random_tod_, times_, turn_, time_of_day::write(), and write_location_range().
Referenced by game_state::write().
|
inline |
Definition at line 160 of file tod_manager.hpp.
References turn_.
Referenced by events::mouse_handler::attack_enemy_(), carryover_show_gold(), 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(), play_controller::turn(), and game_events::WML_HANDLER_FUNCTION().
|
inline |
Definition at line 189 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 455 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 264 of file tod_manager.hpp.
Referenced by add_time_area(), get_area_by_id(), get_area_by_index(), get_area_id(), get_area_ids(), get_area_on_hex(), get_area_time_of_day(), get_current_area_time(), get_current_time(), get_time_of_day(), has_time_area(), 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 262 of file tod_manager.hpp.
Referenced by get_current_time(), get_previous_time_of_day(), get_time_of_day(), replace_schedule(), resolve_random(), set_current_time(), set_new_current_times(), to_config(), and tod_manager().
|
private |
Definition at line 276 of file tod_manager.hpp.
Referenced by reset_max_liminal_bonus(), set_max_liminal_bonus(), to_config(), and tod_manager().
|
private |
Definition at line 275 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 274 of file tod_manager.hpp.
Referenced by has_turn_event_fired(), next_turn(), to_config(), and turn_event_fired().
|
private |
Definition at line 267 of file tod_manager.hpp.
Referenced by get_max_liminal_bonus(), reset_max_liminal_bonus(), set_max_liminal_bonus(), to_config(), and tod_manager().
|
private |
Definition at line 272 of file tod_manager.hpp.
Referenced by is_time_left(), modify_turns(), number_of_turns(), set_number_of_turns(), set_turn(), to_config(), and update_server_information().
|
private |
Definition at line 278 of file tod_manager.hpp.
Referenced by resolve_random(), to_config(), and tod_manager().
|
private |
Definition at line 263 of file tod_manager.hpp.
Referenced by get_previous_time_of_day(), get_time_of_day(), replace_schedule(), resolve_random(), set_current_time(), set_new_current_times(), times(), to_config(), and tod_manager().
|
private |
Definition at line 270 of file tod_manager.hpp.
Referenced by calculate_time_index_at_turn(), get_area_time_of_day(), get_previous_time_of_day(), get_time_of_day(), is_time_left(), next_turn(), set_turn(), to_config(), turn(), and update_server_information().