Class that manages AIs for all sides and manages AI redeployment. More...
#include <manager.hpp>
Static Public Member Functions | |
static void | set_ai_info (const game_info &info) |
Sets AI information. More... | |
static void | clear_ai_info () |
Clears AI information. More... | |
static void | add_observer (events::observer *event_observer) |
Adds observer of game events. More... | |
static void | remove_observer (events::observer *event_observer) |
Removes an observer of game events. More... | |
static void | add_gamestate_observer (events::observer *event_observer) |
Adds observer of game events except ai_user_interact event and ai_sync_network event. More... | |
static void | remove_gamestate_observer (events::observer *event_observer) |
Removes an observer of game events except ai_user_interact event and ai_sync_network event. More... | |
static void | raise_user_interact () |
Notifies all observers of 'ai_user_interact' event. More... | |
static void | raise_sync_network () |
Notifies all observers of 'ai_sync_network' event. More... | |
static void | raise_gamestate_changed () |
Notifies all observers of 'ai_gamestate_changed' event. More... | |
static void | raise_tod_changed () |
Notifies all observers of 'ai_tod_changed' event. More... | |
static void | raise_recruit_list_changed () |
Notifies all observers of 'ai_recruit_list_changed' event. More... | |
static void | raise_turn_started () |
Notifies all observers of 'ai_turn_started' event. More... | |
static void | raise_map_changed () |
Notifies all observers of 'ai_map_changed' event. More... | |
static void | add_map_changed_observer (events::observer *event_observer) |
Adds an observer of 'ai_map_changed' event. More... | |
static void | add_recruit_list_changed_observer (events::observer *event_observer) |
Adds an observer of 'ai_recruit_list_changed' event. More... | |
static void | add_turn_started_observer (events::observer *event_observer) |
Adds an observer of 'ai_turn_started' event. More... | |
static void | add_tod_changed_observer (events::observer *event_observer) |
Adds an observer of 'ai_tod_changed' event. More... | |
static void | remove_map_changed_observer (events::observer *event_observer) |
Deletes an observer of 'ai_map_changed' event. More... | |
static void | remove_recruit_list_changed_observer (events::observer *event_observer) |
Deletes an observer of 'ai_recruit_list_changed' event. More... | |
static void | remove_turn_started_observer (events::observer *event_observer) |
Deletes an observer of 'ai_turn_started' event. More... | |
static void | remove_tod_changed_observer (events::observer *event_observer) |
Deletes an observer of 'ai_tod_changed' event. More... | |
static const std::string | evaluate_command (side_number side, const std::string &str) |
Evaluates a string command using command AI. More... | |
static bool | add_ai_for_side_from_file (side_number side, const std::string &file, bool replace=true) |
Adds active AI for specified side from file. More... | |
static bool | add_ai_for_side_from_config (side_number side, const config &cfg, bool replace=true) |
Adds active AI for specified side from cfg. More... | |
static bool | add_ai_for_side (side_number side, const std::string &ai_algorithm_type, bool replace=true) |
Adds active AI for specified side from parameters. More... | |
static void | remove_ai_for_side (side_number side) |
Removes top-level AI from side. More... | |
static void | remove_all_ais_for_side (side_number side) |
Removes all AIs from side. More... | |
static void | clear_ais () |
Clears all the AIs. More... | |
static game_info & | get_active_ai_info_for_side (side_number side) |
Gets AI info for active AI of the given side. More... | |
static std::string | get_active_ai_overview_for_side (side_number side) |
Gets AI Overview for active AI of the given side. More... | |
static std::string | get_active_ai_structure_for_side (side_number side) |
Gets AI Structure for active AI of the given side. More... | |
static std::string | get_active_ai_identifier_for_side (side_number side) |
Gets AI algorithm identifier for active AI of the given side. More... | |
static ai::holder & | get_active_ai_holder_for_side_dbg (side_number side) |
Gets the active AI holder for debug purposes. More... | |
static config | to_config (side_number side) |
Gets AI config for active AI of the given side. More... | |
static game_info & | get_ai_info () |
Gets global AI-game info. More... | |
static void | modify_active_ai_config_old_for_side (side_number side, const config::const_child_itors &ai_parameters) |
Modifies AI parameters for active AI of the given side. More... | |
static void | modify_active_ai_for_side (ai::side_number side, const config &cfg) |
Modifies AI parameters for active AI of the given side. More... | |
static void | play_turn (side_number side) |
Plays a turn for the specified side using its active AI. More... | |
Static Public Attributes | |
static const size_t | MAX_HISTORY_SIZE = 200 |
static const std::string | AI_TYPE_COMPOSITE_AI = "composite_ai" |
static const std::string | AI_TYPE_SAMPLE_AI = "sample_ai" |
static const std::string | AI_TYPE_IDLE_AI = "idle_ai" |
static const std::string | AI_TYPE_FORMULA_AI = "formula_ai" |
static const std::string | AI_TYPE_DFOOL_AI |
static const std::string | AI_TYPE_AI2 |
static const std::string | AI_TYPE_DEFAULT = "default" |
Private Types | |
typedef std::map< side_number, std::stack< holder > > | AI_map_of_stacks |
Private Member Functions | |
manager () | |
Static Private Member Functions | |
static const std::string | internal_evaluate_command (side_number side, const std::string &str) |
Evaluates an internal manager command. More... | |
static bool | should_intercept (const std::string &str) |
Determines if the command should be intercepted and evaluated as internal command. More... | |
static std::stack< holder > & | get_or_create_ai_stack_for_side (side_number side) |
Gets the AI stack for the specified side, create it if it doesn't exist. More... | |
static holder & | get_active_ai_holder_for_side (side_number side) |
Gets active holder for specified side. More... | |
static ai_composite & | get_active_ai_for_side (side_number side) |
Gets active AI for specified side. More... | |
Static Private Attributes | |
static AI_map_of_stacks | ai_map_ |
static std::deque < command_history_item > | history_ |
static long | history_item_counter_ = 1 |
static game_info * | ai_info_ |
static events::generic_event | map_changed_ |
static events::generic_event | recruit_list_changed_ |
static events::generic_event | user_interact_ |
static events::generic_event | sync_network_ |
static events::generic_event | tod_changed_ |
static events::generic_event | gamestate_changed_ |
static events::generic_event | turn_started_ |
static int | last_interact_ = 0 |
static int | num_interact_ = 0 |
Class that manages AIs for all sides and manages AI redeployment.
This class is responsible for managing the AI lifecycle It can be accessed like this: ai::manager::foo(...);
Definition at line 119 of file manager.hpp.
|
private |
Definition at line 467 of file manager.hpp.
|
private |
|
static |
Adds active AI for specified side from parameters.
side | side number (1-based, as in game_info). |
ai_algorithm_type | type of AI algorithm to create. |
replace | should new ai replace the current ai or 'be placed on top of it'. |
Definition at line 667 of file manager.cpp.
References get_or_create_ai_stack_for_side(), and remove_ai_for_side().
|
static |
Adds active AI for specified side from cfg.
side | side number (1-based, as in game_info). |
cfg | the config from which all ai parameters are to be read. |
replace | should new ai replace the current ai or 'be placed on top of it'. |
Definition at line 651 of file manager.cpp.
References get_or_create_ai_stack_for_side(), ai::configuration::parse_side_config(), and remove_ai_for_side().
Referenced by add_ai_for_side_from_file(), and team::team_info::read().
|
static |
Adds active AI for specified side from file.
side | side number (1-based, as in game_info). |
file | file name, follows the usual WML convention. |
replace | should new ai replace the current ai or 'be placed on top of it'. |
Definition at line 640 of file manager.cpp.
References add_ai_for_side_from_config(), ERR_AI_MANAGER, and ai::configuration::get_side_config_from_file().
Referenced by internal_evaluate_command(), game_lua_kernel::intf_modify_side(), and team::team_info::read().
|
static |
Adds observer of game events except ai_user_interact event and ai_sync_network event.
Definition at line 371 of file manager.cpp.
References events::generic_event::attach_handler(), gamestate_changed_, map_changed_, and turn_started_.
Referenced by ai::formula_ai::gamestate_change_observer::gamestate_change_observer(), ai::gamestate_observer::gamestate_observer(), ai::readonly_context_impl::readonly_context_impl(), ai::default_recruitment::recruitment::recruit_situation_change_observer::recruit_situation_change_observer(), and ai::aspect::redeploy().
|
static |
Adds an observer of 'ai_map_changed' event.
Definition at line 396 of file manager.cpp.
References events::generic_event::attach_handler(), and map_changed_.
Referenced by ai::keeps_cache::keeps_cache().
|
static |
Adds observer of game events.
Should be called in playsingle_controller 's constructor.
Definition at line 355 of file manager.cpp.
References events::generic_event::attach_handler(), gamestate_changed_, sync_network_, turn_started_, and user_interact_.
|
static |
Adds an observer of 'ai_recruit_list_changed' event.
Definition at line 402 of file manager.cpp.
References events::generic_event::attach_handler(), and recruit_list_changed_.
Referenced by ai::default_recruitment::recruitment::recruit_situation_change_observer::recruit_situation_change_observer().
|
static |
Adds an observer of 'ai_tod_changed' event.
Definition at line 385 of file manager.cpp.
References events::generic_event::attach_handler(), and tod_changed_.
Referenced by ai::aspect::redeploy().
|
static |
Adds an observer of 'ai_turn_started' event.
Definition at line 408 of file manager.cpp.
References events::generic_event::attach_handler(), and turn_started_.
Referenced by ai::keeps_cache::keeps_cache(), and ai::aspect::redeploy().
|
static |
Clears AI information.
Should be called in playsingle_controller 's destructor.
Definition at line 349 of file manager.cpp.
References ai_info_.
Referenced by set_ai_info().
|
static |
Clears all the AIs.
Definition at line 705 of file manager.cpp.
References ai_map_.
Referenced by playsingle_controller::~playsingle_controller().
|
static |
Evaluates a string command using command AI.
side | side number (1-based). |
str | string to evaluate. |
Definition at line 483 of file manager.cpp.
References ai::ai_composite::evaluate(), get_active_ai_for_side(), history_, history_item_counter_, internal_evaluate_command(), LOG_AI_MANAGER, MAX_HISTORY_SIZE, raise_gamestate_changed(), and should_intercept().
Referenced by events::menu_handler::do_ai_formula(), and internal_evaluate_command().
|
staticprivate |
Gets active AI for specified side.
side | side number (1-based, as in game_info). |
Definition at line 837 of file manager.cpp.
References get_active_ai_holder_for_side(), and ai::holder::get_ai_ref().
Referenced by evaluate_command(), and play_turn().
|
staticprivate |
Gets active holder for specified side.
Definition at line 819 of file manager.cpp.
References ai::configuration::get_default_ai_parameters(), and get_or_create_ai_stack_for_side().
Referenced by get_active_ai_for_side(), get_active_ai_holder_for_side_dbg(), get_active_ai_identifier_for_side(), get_active_ai_overview_for_side(), get_active_ai_structure_for_side(), modify_active_ai_config_old_for_side(), modify_active_ai_for_side(), and to_config().
|
static |
Gets the active AI holder for debug purposes.
Will only work in debug mode, otherwise returns a reference to an empty holder
side | side number(1-based) |
Definition at line 749 of file manager.cpp.
References game_config::debug, and get_active_ai_holder_for_side().
Referenced by intf_debug_ai().
|
static |
Gets AI algorithm identifier for active AI of the given side.
side | side number (1-based). |
Definition at line 744 of file manager.cpp.
References get_active_ai_holder_for_side(), and ai::holder::get_ai_identifier().
Referenced by play_controller::check_victory(), internal_evaluate_command(), and ai_testing::log_game_start().
|
static |
Gets AI info for active AI of the given side.
side | side number (1-based). |
Definition at line 765 of file manager.cpp.
References ai_info_.
Referenced by ai::action_result::get_info(), ai::readonly_context_impl::get_info(), and ai::readwrite_context_impl::get_info_w().
|
static |
Gets AI Overview for active AI of the given side.
side | side number (1-based) |
Definition at line 732 of file manager.cpp.
References get_active_ai_holder_for_side(), and ai::holder::get_ai_overview().
Referenced by gui2::team_mode_controller::handle_stuff_list_selection().
|
static |
Gets AI Structure for active AI of the given side.
side | side number (1-based) |
Definition at line 738 of file manager.cpp.
References get_active_ai_holder_for_side(), and ai::holder::get_ai_structure().
Referenced by gui2::team_mode_controller::handle_stuff_list_selection().
|
static |
Gets global AI-game info.
Definition at line 771 of file manager.cpp.
References ai_info_.
Referenced by ai::attack_analysis::attack_close(), and play_turn().
|
staticprivate |
Gets the AI stack for the specified side, create it if it doesn't exist.
Definition at line 807 of file manager.cpp.
References ai_map_.
Referenced by add_ai_for_side(), add_ai_for_side_from_config(), get_active_ai_holder_for_side(), remove_ai_for_side(), and remove_all_ais_for_side().
|
staticprivate |
Evaluates an internal manager command.
side | side number (1-based). |
str | string to evaluate. |
add_ai side file
replace_ai side file
remove_ai side
Definition at line 526 of file manager.cpp.
References add_ai_for_side_from_file(), evaluate_command(), get_active_ai_identifier_for_side(), history_, history_item_counter_, lexical_cast(), utils::parenthetical_split(), and remove_ai_for_side().
Referenced by evaluate_command().
|
static |
Modifies AI parameters for active AI of the given side.
This function is provided for backward-compatibility with [modify_side][ai]...[/ai][/modify_side] It can only add new facets to aspects
side | side_number (1-based, as in game_info). |
ai_parameters | AI parameters to be modified. |
Definition at line 714 of file manager.cpp.
References get_active_ai_holder_for_side(), and ai::holder::modify_side_ai_config().
Referenced by game_lua_kernel::intf_modify_side().
|
static |
Modifies AI parameters for active AI of the given side.
This function is a backend for [modify_ai] tag
side | side_number (1-based, as in game_info). |
cfg | - content of [modify_ai] tag |
Definition at line 722 of file manager.cpp.
References ai_info_, get_active_ai_holder_for_side(), and ai::holder::modify_ai().
Referenced by intf_modify_ai(), game_lua_kernel::intf_modify_ai_wml(), ai::ai_default_rca::candidate_action_evaluation_loop::remove_completed_cas(), and ai::ai_default_rca::move_leader_to_goals_phase::remove_goal().
|
static |
Plays a turn for the specified side using its active AI.
side | side number (1-based, as in game_info). |
Definition at line 781 of file manager.cpp.
References DBG_AI_MANAGER, game_events::t_pump::fire(), resources::game_events, get_active_ai_for_side(), get_ai_info(), last_interact_, ai::ai_composite::new_turn(), num_interact_, ai::ai_composite::play_turn(), game_events::manager::pump(), raise_tod_changed(), raise_turn_started(), ai::game_info::recent_attacks, and resources::tod_manager.
Referenced by playsingle_controller::play_ai_turn().
|
static |
Notifies all observers of 'ai_gamestate_changed' event.
Definition at line 454 of file manager.cpp.
References gamestate_changed_, and events::generic_event::notify_observers().
Referenced by ai::attack_result::do_execute(), ai::move_result::do_execute(), ai::recall_result::do_execute(), ai::recruit_result::do_execute(), ai::stopunit_result::do_execute(), ai::synced_command_result::do_execute(), evaluate_command(), ai::readwrite_context_impl::raise_gamestate_changed(), and ai::sim_gamestate_changed().
|
static |
Notifies all observers of 'ai_map_changed' event.
Definition at line 474 of file manager.cpp.
References map_changed_, and events::generic_event::notify_observers().
Referenced by game_events::WML_HANDLER_FUNCTION().
|
static |
Notifies all observers of 'ai_recruit_list_changed' event.
Definition at line 469 of file manager.cpp.
References events::generic_event::notify_observers(), and recruit_list_changed_.
Referenced by team::add_recruit(), and team::set_recruits().
|
static |
Notifies all observers of 'ai_sync_network' event.
Basically a request from the AI to sync the network.
Definition at line 449 of file manager.cpp.
References events::generic_event::notify_observers(), and sync_network_.
|
static |
Notifies all observers of 'ai_tod_changed' event.
Definition at line 459 of file manager.cpp.
References events::generic_event::notify_observers(), and tod_changed_.
Referenced by play_turn().
|
static |
Notifies all observers of 'ai_turn_started' event.
Definition at line 464 of file manager.cpp.
References events::generic_event::notify_observers(), and turn_started_.
Referenced by play_turn().
|
static |
Notifies all observers of 'ai_user_interact' event.
Function which should be called frequently to allow the user to interact with the interface. This function will make sure that interaction doesn't occur too often, so there is no problem with calling it very regularly.
Definition at line 431 of file manager.cpp.
References last_interact_, events::generic_event::notify_observers(), num_interact_, resources::simulation_, and user_interact_.
Referenced by ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), and ai::readonly_context_impl::raise_user_interact().
|
static |
Removes top-level AI from side.
side | side number (1-based, as in game_info). |
Definition at line 685 of file manager.cpp.
References get_or_create_ai_stack_for_side().
Referenced by add_ai_for_side(), add_ai_for_side_from_config(), and internal_evaluate_command().
|
static |
Removes all AIs from side.
side | side number (1-based, as in game_info). |
Definition at line 694 of file manager.cpp.
References get_or_create_ai_stack_for_side().
|
static |
Removes an observer of game events except ai_user_interact event and ai_sync_network event.
Definition at line 378 of file manager.cpp.
References events::generic_event::detach_handler(), gamestate_changed_, map_changed_, and turn_started_.
Referenced by ai::aspect::redeploy(), ai::aspect::~aspect(), ai::formula_ai::gamestate_change_observer::~gamestate_change_observer(), ai::gamestate_observer::~gamestate_observer(), ai::readonly_context_impl::~readonly_context_impl(), and ai::default_recruitment::recruitment::recruit_situation_change_observer::~recruit_situation_change_observer().
|
static |
Deletes an observer of 'ai_map_changed' event.
Definition at line 420 of file manager.cpp.
References events::generic_event::detach_handler(), and map_changed_.
Referenced by ai::keeps_cache::~keeps_cache().
|
static |
Removes an observer of game events.
Should be called in playsingle_controller 's destructor.
Definition at line 363 of file manager.cpp.
References events::generic_event::detach_handler(), gamestate_changed_, sync_network_, turn_started_, and user_interact_.
Referenced by playsingle_controller::~playsingle_controller().
|
static |
Deletes an observer of 'ai_recruit_list_changed' event.
Definition at line 414 of file manager.cpp.
References events::generic_event::detach_handler(), and recruit_list_changed_.
Referenced by ai::default_recruitment::recruitment::recruit_situation_change_observer::~recruit_situation_change_observer().
|
static |
Deletes an observer of 'ai_tod_changed' event.
Definition at line 390 of file manager.cpp.
References events::generic_event::detach_handler(), and tod_changed_.
Referenced by ai::aspect::redeploy(), and ai::aspect::~aspect().
|
static |
Deletes an observer of 'ai_turn_started' event.
Definition at line 426 of file manager.cpp.
References events::generic_event::detach_handler(), and turn_started_.
Referenced by ai::aspect::redeploy(), ai::aspect::~aspect(), and ai::keeps_cache::~keeps_cache().
Sets AI information.
info | ai_information to be set. |
Definition at line 339 of file manager.cpp.
References ai_info_, clear_ai_info(), and ai::registry::init().
|
staticprivate |
Determines if the command should be intercepted and evaluated as internal command.
str | command string to check. |
Definition at line 504 of file manager.cpp.
Referenced by evaluate_command().
|
static |
Gets AI config for active AI of the given side.
side | side number (1-based). |
Definition at line 759 of file manager.cpp.
References get_active_ai_holder_for_side(), and ai::holder::to_config().
Referenced by gui2::team_mode_controller::handle_stuff_list_selection(), and team::team_info::write().
|
staticprivate |
Definition at line 471 of file manager.hpp.
Referenced by clear_ai_info(), get_active_ai_info_for_side(), get_ai_info(), modify_active_ai_for_side(), and set_ai_info().
|
staticprivate |
Definition at line 468 of file manager.hpp.
Referenced by clear_ais(), and get_or_create_ai_stack_for_side().
|
static |
Definition at line 134 of file manager.hpp.
|
static |
Definition at line 129 of file manager.hpp.
|
static |
Definition at line 135 of file manager.hpp.
|
static |
Definition at line 133 of file manager.hpp.
|
static |
Definition at line 132 of file manager.hpp.
|
static |
Definition at line 131 of file manager.hpp.
|
static |
Definition at line 130 of file manager.hpp.
|
staticprivate |
Definition at line 478 of file manager.hpp.
Referenced by add_gamestate_observer(), add_observer(), raise_gamestate_changed(), remove_gamestate_observer(), and remove_observer().
|
staticprivate |
Definition at line 469 of file manager.hpp.
Referenced by evaluate_command(), and internal_evaluate_command().
|
staticprivate |
Definition at line 470 of file manager.hpp.
Referenced by evaluate_command(), and internal_evaluate_command().
|
staticprivate |
Definition at line 480 of file manager.hpp.
Referenced by play_turn(), and raise_user_interact().
|
staticprivate |
Definition at line 473 of file manager.hpp.
Referenced by add_gamestate_observer(), add_map_changed_observer(), raise_map_changed(), remove_gamestate_observer(), and remove_map_changed_observer().
|
static |
Definition at line 127 of file manager.hpp.
Referenced by evaluate_command().
|
staticprivate |
Definition at line 481 of file manager.hpp.
Referenced by play_turn(), and raise_user_interact().
|
staticprivate |
Definition at line 474 of file manager.hpp.
Referenced by add_recruit_list_changed_observer(), raise_recruit_list_changed(), and remove_recruit_list_changed_observer().
|
staticprivate |
Definition at line 476 of file manager.hpp.
Referenced by add_observer(), raise_sync_network(), and remove_observer().
|
staticprivate |
Definition at line 477 of file manager.hpp.
Referenced by add_tod_changed_observer(), raise_tod_changed(), and remove_tod_changed_observer().
|
staticprivate |
Definition at line 479 of file manager.hpp.
Referenced by add_gamestate_observer(), add_observer(), add_turn_started_observer(), raise_turn_started(), remove_gamestate_observer(), remove_observer(), and remove_turn_started_observer().
|
staticprivate |
Definition at line 475 of file manager.hpp.
Referenced by add_observer(), raise_user_interact(), and remove_observer().