Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Static Private Attributes

ai::manager Class Reference

Class that manages AIs for all sides and manages AI redeployment. More...

#include <manager.hpp>

Collaboration diagram for ai::manager:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static void set_ai_info (const game_info &info)
 Sets AI information.
static void clear_ai_info ()
 Clears AI information.
static void add_observer (events::observer *event_observer)
 Adds observer of game events.
static void remove_observer (events::observer *event_observer)
 Removes an observer of game events.
static void add_gamestate_observer (events::observer *event_observer)
 Adds observer of game events except ai_user_interact event and ai_sync_network event.
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.
static void raise_user_interact ()
 Notifies all observers of 'ai_user_interact' event.
static void raise_sync_network ()
 Notifies all observers of 'ai_sync_network' event.
static void raise_gamestate_changed ()
 Notifies all observers of 'ai_gamestate_changed' event.
static void raise_recruit_list_changed ()
 Notifies all observers of 'ai_recruit_list_changed' event.
static void raise_turn_started ()
 Notifies all observers of 'ai_turn_started' event.
static void raise_map_changed ()
 Notifies all observers of 'ai_map_changed' event.
static void add_map_changed_observer (events::observer *event_observer)
 Adds an observer of 'ai_map_changed' event.
static void add_recruit_list_changed_observer (events::observer *event_observer)
 Adds an observer of 'ai_recruit_list_changed' event.
static void add_turn_started_observer (events::observer *event_observer)
 Adds an observer of 'ai_turn_started' event.
static void remove_map_changed_observer (events::observer *event_observer)
 Deletes an observer of 'ai_map_changed' event.
static void remove_recruit_list_changed_observer (events::observer *event_observer)
 Deletes an observer of 'ai_recruit_list_changed' event.
static void remove_turn_started_observer (events::observer *event_observer)
 Deletes an observer of 'ai_turn_started' event.
static const std::string evaluate_command (side_number side, const std::string &str)
 Evaluates a string command using command AI.
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.
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.
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.
static ai_ptr create_transient_ai (const std::string &ai_algorithm_type, const config &cfg, ai_context *ai_context)
 Returns a smart pointer to a new AI.
static void remove_ai_for_side (side_number side)
 Removes top-level AI from side.
static void remove_all_ais_for_side (side_number side)
 Removes all AIs from side.
static void clear_ais ()
 Clears all the AIs.
static game_infoget_active_ai_info_for_side (side_number side)
 Gets AI info for active AI of the given side.
static std::string get_active_ai_overview_for_side (side_number side)
 Gets AI Overview for active AI of the given side.
static std::string get_active_ai_structure_for_side (side_number side)
 Gets AI Structure for active AI of the given side.
static std::string get_active_ai_identifier_for_side (side_number side)
 Gets AI algorithm identifier for active AI of the given side.
static config to_config (side_number side)
 Gets AI config for active AI of the given side.
static game_infoget_ai_info ()
 Gets global AI-game info.
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.
static void modify_active_ai_for_side (ai::side_number, const config &cfg)
 Modifies AI parameters for active AI of the given side.
static void play_turn (side_number side)
 Plays a turn for the specified side using its active AI.

Static Public Attributes

static const size_t MAX_HISTORY_SIZE = 200
static const std::string AI_TYPE_COMPOSITE_AI
static const std::string AI_TYPE_SAMPLE_AI
static const std::string AI_TYPE_IDLE_AI
static const std::string AI_TYPE_FORMULA_AI
static const std::string AI_TYPE_DFOOL_AI
static const std::string AI_TYPE_AI2
static const std::string AI_TYPE_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.
static bool should_intercept (const std::string &str)
 Determines if the command should be intercepted and evaluated as internal command.
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.
static holderget_active_ai_holder_for_side (side_number side)
 Gets active holder for specified side.
static interfaceget_active_ai_for_side (side_number side)
 Gets active AI for specified side.

Static Private Attributes

static AI_map_of_stacks ai_map_
static std::deque
< command_history_item
history_
static long history_item_counter_
static game_infoai_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 gamestate_changed_
static events::generic_event turn_started_
static int last_interact_
static int num_interact_

Detailed Description

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 116 of file manager.hpp.


Member Typedef Documentation

typedef std::map< side_number, std::stack< holder > > ai::manager::AI_map_of_stacks [private]

Definition at line 449 of file manager.hpp.


Constructor & Destructor Documentation

ai::manager::manager (  )  [private]

Member Function Documentation

static bool ai::manager::add_ai_for_side ( side_number  side,
const std::string &  ai_algorithm_type,
bool  replace = true 
) [static]

Adds active AI for specified side from parameters.

Note:
Running this command may invalidate references previously returned by manager. AI is not initialized at this point.
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'.
Returns:
true if successful.
static bool ai::manager::add_ai_for_side_from_config ( side_number  side,
const config cfg,
bool  replace = true 
) [static]

Adds active AI for specified side from cfg.

Note:
Running this command may invalidate references previously returned by manager. AI is not initialized at this point.
Parameters:
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'.
Returns:
true if successful.

Referenced by team::team_info::read().

Here is the caller graph for this function:

static bool ai::manager::add_ai_for_side_from_file ( side_number  side,
const std::string &  file,
bool  replace = true 
) [static]

Adds active AI for specified side from file.

Note:
Running this command may invalidate references previously returned by manager. AI is not initialized at this point.
Parameters:
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'.
Returns:
true if successful.

Referenced by team::team_info::read(), and WML_HANDLER_FUNCTION().

Here is the caller graph for this function:

static void ai::manager::add_gamestate_observer ( events::observer event_observer  )  [static]

Adds observer of game events except ai_user_interact event and ai_sync_network event.

Referenced by ai::formula_ai::gamestate_change_observer::gamestate_change_observer(), ai::gamestate_observer::gamestate_observer(), ai::readonly_context_impl::readonly_context_impl(), and ai::aspect::redeploy().

Here is the caller graph for this function:

static void ai::manager::add_map_changed_observer ( events::observer event_observer  )  [static]

Adds an observer of 'ai_map_changed' event.

Referenced by ai::keeps_cache::keeps_cache().

Here is the caller graph for this function:

static void ai::manager::add_observer ( events::observer event_observer  )  [static]

Adds observer of game events.

Should be called in playsingle_controller 's constructor.

Referenced by playsingle_controller::playsingle_controller().

Here is the caller graph for this function:

static void ai::manager::add_recruit_list_changed_observer ( events::observer event_observer  )  [static]

Adds an observer of 'ai_recruit_list_changed' event.

Referenced by ai::ai_default_recruitment_stage::recruit_situation_change_observer::recruit_situation_change_observer().

Here is the caller graph for this function:

static void ai::manager::add_turn_started_observer ( events::observer event_observer  )  [static]

Adds an observer of 'ai_turn_started' event.

Referenced by ai::keeps_cache::keeps_cache(), ai::ai_default_recruitment_stage::recruit_situation_change_observer::recruit_situation_change_observer(), and ai::aspect::redeploy().

Here is the caller graph for this function:

static void ai::manager::clear_ai_info (  )  [static]

Clears AI information.

Should be called in playsingle_controller 's destructor.

static void ai::manager::clear_ais (  )  [static]

Clears all the AIs.

Note:
Running this command may invalidate references previously returned by manager. For example, this is called from the destructor of playsingle_controller. It is necessary to do this if any of the info structures used by the AI goes out of scope.

Referenced by playsingle_controller::~playsingle_controller().

Here is the caller graph for this function:

static ai_ptr ai::manager::create_transient_ai ( const std::string &  ai_algorithm_type,
const config cfg,
ai_context ai_context 
) [static]

Returns a smart pointer to a new AI.

Parameters:
ai_algorithm_type type of AI algorithm to create
cfg a config of the ai
context context in which this ai is created
Returns:
the reference to the created AI

Referenced by ai::formula_ai::execute_variant(), and ai::testing_ai_default::fallback_to_other_ai::on_create().

Here is the caller graph for this function:

static const std::string ai::manager::evaluate_command ( side_number  side,
const std::string &  str 
) [static]

Evaluates a string command using command AI.

Note:
Running this command may invalidate references previously returned by manager. Will intercept those commands which start with '!' and '?', and will try to evaluate them as internal commands.
Parameters:
side side number (1-based).
str string to evaluate.
Returns:
string result of evaluation.

Referenced by events::menu_handler::do_ai_formula().

Here is the caller graph for this function:

static interface& ai::manager::get_active_ai_for_side ( side_number  side  )  [static, private]

Gets active AI for specified side.

Note:
Running this command may invalidate references previously returned by manager.
Parameters:
side side number (1-based, as in game_info).
Returns:
a reference to the active AI.
Note:
This reference may become invalid after specific manager operations.
static holder& ai::manager::get_active_ai_holder_for_side ( side_number  side  )  [static, private]

Gets active holder for specified side.

static std::string ai::manager::get_active_ai_identifier_for_side ( side_number  side  )  [static]

Gets AI algorithm identifier for active AI of the given side.

Parameters:
side side number (1-based).
Returns:
ai identifier for the active AI

Referenced by play_controller::check_victory(), and ai_testing::log_game_start().

Here is the caller graph for this function:

static game_info& ai::manager::get_active_ai_info_for_side ( side_number  side  )  [static]

Gets AI info for active AI of the given side.

Parameters:
side side number (1-based).
Returns:
a reference to active AI info.

Referenced by ai::readonly_context_impl::get_info(), ai::readwrite_context_impl::get_info_w(), and ai::action_result::get_my_team().

Here is the caller graph for this function:

static std::string ai::manager::get_active_ai_overview_for_side ( side_number  side  )  [static]

Gets AI Overview for active AI of the given side.

Parameters:
side side number (1-based)
Returns:
an ai overview

Referenced by gui2::team_mode_controller::handle_stuff_list_selection().

Here is the caller graph for this function:

static std::string ai::manager::get_active_ai_structure_for_side ( side_number  side  )  [static]

Gets AI Structure for active AI of the given side.

Parameters:
side side number (1-based)
Returns:
an ai structure

Referenced by gui2::team_mode_controller::handle_stuff_list_selection().

Here is the caller graph for this function:

static game_info& ai::manager::get_ai_info (  )  [static]

Gets global AI-game info.

Returns:
a reference to the AI-game info.

Referenced by ai::attack_analysis::attack_close().

Here is the caller graph for this function:

static std::stack< holder >& ai::manager::get_or_create_ai_stack_for_side ( side_number  side  )  [static, private]

Gets the AI stack for the specified side, create it if it doesn't exist.

static const std::string ai::manager::internal_evaluate_command ( side_number  side,
const std::string &  str 
) [static, private]

Evaluates an internal manager command.

Parameters:
side side number (1-based).
str string to evaluate.
Returns:
string result of evaluation.
Todo:
1.9 rewrite this function to use a fai or lua parser.
static void ai::manager::modify_active_ai_config_old_for_side ( side_number  side,
const config::const_child_itors ai_parameters 
) [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

Parameters:
side side_number (1-based, as in game_info).
ai_parameters AI parameters to be modified.

Referenced by WML_HANDLER_FUNCTION().

Here is the caller graph for this function:

static void ai::manager::modify_active_ai_for_side ( ai::side_number  ,
const config cfg 
) [static]

Modifies AI parameters for active AI of the given side.

This function is a backend for [modify_ai] tag

Parameters:
side side_number (1-based, as in game_info).
cfg - content of [modify_ai] tag

Referenced by intf_modify_ai(), ai::testing_ai_default::candidate_action_evaluation_loop::remove_completed_cas(), ai::testing_ai_default::move_leader_to_goals_phase::remove_goal(), and WML_HANDLER_FUNCTION().

Here is the caller graph for this function:

static void ai::manager::play_turn ( side_number  side  )  [static]

Plays a turn for the specified side using its active AI.

Parameters:
side side number (1-based, as in game_info).
static void ai::manager::raise_gamestate_changed (  )  [static]

Notifies all observers of 'ai_gamestate_changed' event.

static void ai::manager::raise_map_changed (  )  [static]

Notifies all observers of 'ai_map_changed' event.

Referenced by WML_HANDLER_FUNCTION().

Here is the caller graph for this function:

static void ai::manager::raise_recruit_list_changed (  )  [static]

Notifies all observers of 'ai_recruit_list_changed' event.

Referenced by team::add_recruit(), and team::set_recruits().

Here is the caller graph for this function:

static void ai::manager::raise_sync_network (  )  [static]

Notifies all observers of 'ai_sync_network' event.

Basically a request from the AI to sync the network.

Referenced by verify_and_get_global_variable().

Here is the caller graph for this function:

static void ai::manager::raise_turn_started (  )  [static]

Notifies all observers of 'ai_turn_started' event.

Referenced by playsingle_controller::before_human_turn().

Here is the caller graph for this function:

static void ai::manager::raise_user_interact (  )  [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.

Referenced by verify_and_get_global_variable().

Here is the caller graph for this function:

static void ai::manager::remove_ai_for_side ( side_number  side  )  [static]

Removes top-level AI from side.

Note:
Running this command may invalidate references previously returned by manager.
Parameters:
side side number (1-based, as in game_info).
static void ai::manager::remove_all_ais_for_side ( side_number  side  )  [static]

Removes all AIs from side.

Note:
Running this command may invalidate references previously returned by manager.
Parameters:
side side number (1-based, as in game_info).
static void ai::manager::remove_gamestate_observer ( events::observer event_observer  )  [static]

Removes an observer of game events except ai_user_interact event and ai_sync_network event.

Referenced by ai::aspect::redeploy(), ai::aspect::~aspect(), ai::formula_ai::gamestate_change_observer::~gamestate_change_observer(), ai::gamestate_observer::~gamestate_observer(), and ai::readonly_context_impl::~readonly_context_impl().

Here is the caller graph for this function:

static void ai::manager::remove_map_changed_observer ( events::observer event_observer  )  [static]

Deletes an observer of 'ai_map_changed' event.

Referenced by ai::keeps_cache::~keeps_cache().

Here is the caller graph for this function:

static void ai::manager::remove_observer ( events::observer event_observer  )  [static]

Removes an observer of game events.

Should be called in playsingle_controller 's destructor.

Referenced by playsingle_controller::~playsingle_controller().

Here is the caller graph for this function:

static void ai::manager::remove_recruit_list_changed_observer ( events::observer event_observer  )  [static]

Deletes an observer of 'ai_recruit_list_changed' event.

Referenced by ai::ai_default_recruitment_stage::recruit_situation_change_observer::~recruit_situation_change_observer().

Here is the caller graph for this function:

static void ai::manager::remove_turn_started_observer ( events::observer event_observer  )  [static]
static void ai::manager::set_ai_info ( const game_info info  )  [static]

Sets AI information.

Parameters:
info ai_information to be set.

Referenced by playsingle_controller::playsingle_controller().

Here is the caller graph for this function:

static bool ai::manager::should_intercept ( const std::string &  str  )  [static, private]

Determines if the command should be intercepted and evaluated as internal command.

Parameters:
str command string to check.
Returns:
true if the command should be intercepted and evaluated.
static config ai::manager::to_config ( side_number  side  )  [static]

Gets AI config for active AI of the given side.

Parameters:
side side number (1-based).
Returns:
a config object for the active AI

Referenced by gui2::team_mode_controller::handle_stuff_list_selection(), and team::team_info::write().

Here is the caller graph for this function:


Member Data Documentation

game_info* ai::manager::ai_info_ [static, private]

Definition at line 453 of file manager.hpp.

Definition at line 450 of file manager.hpp.

const std::string ai::manager::AI_TYPE_AI2 [static]

Definition at line 131 of file manager.hpp.

const std::string ai::manager::AI_TYPE_COMPOSITE_AI [static]

Definition at line 126 of file manager.hpp.

const std::string ai::manager::AI_TYPE_DEFAULT [static]

Definition at line 132 of file manager.hpp.

const std::string ai::manager::AI_TYPE_DFOOL_AI [static]

Definition at line 130 of file manager.hpp.

const std::string ai::manager::AI_TYPE_FORMULA_AI [static]

Definition at line 129 of file manager.hpp.

const std::string ai::manager::AI_TYPE_IDLE_AI [static]

Definition at line 128 of file manager.hpp.

const std::string ai::manager::AI_TYPE_SAMPLE_AI [static]

Definition at line 127 of file manager.hpp.

Definition at line 459 of file manager.hpp.

std::deque< command_history_item > ai::manager::history_ [static, private]

Definition at line 451 of file manager.hpp.

long ai::manager::history_item_counter_ [static, private]

Definition at line 452 of file manager.hpp.

int ai::manager::last_interact_ [static, private]

Definition at line 461 of file manager.hpp.

Definition at line 455 of file manager.hpp.

const size_t ai::manager::MAX_HISTORY_SIZE = 200 [static]

Definition at line 124 of file manager.hpp.

int ai::manager::num_interact_ [static, private]

Definition at line 462 of file manager.hpp.

Definition at line 456 of file manager.hpp.

Definition at line 458 of file manager.hpp.

Definition at line 460 of file manager.hpp.

Definition at line 457 of file manager.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:19:03 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs