#include <ai_interface.hpp>
Public Types | |
typedef gamemap::location | location |
A convenient typedef for the often used 'location' object. | |
typedef std::multimap < location, location > | move_map |
The standard way in which a map of possible moves is recorded. | |
Public Member Functions | |
ai_interface (info &arg) | |
The constructor. | |
virtual | ~ai_interface () |
virtual void | play_turn ()=0 |
Function that is called when the AI must play its turn. | |
team & | current_team () |
Return a reference to the 'team' object for the AI. | |
const team & | current_team () const |
void | diagnostic (const std::string &msg) |
Show a diagnostic message on the screen. | |
void | log_message (const std::string &msg) |
Display a debug message as a chat message. | |
events::generic_event & | user_interact () |
events::generic_event & | unit_recruited () |
events::generic_event & | unit_moved () |
events::generic_event & | enemy_attacked () |
Protected Member Functions | |
void | attack_enemy (const location u, const location target, int att_weapon, int def_weapon) |
This function should be called to attack an enemy. | |
location | move_unit (location from, location to, std::map< location, paths > &possible_moves) |
This function should be called to move a unit. | |
location | move_unit_partial (location from, location t, std::map< location, paths > &possible_moves) |
Identical to 'move_unit', except that the unit's movement isn't set to 0 after the move is complete. | |
void | calculate_possible_moves (std::map< location, paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const std::set< location > *remove_destinations=NULL) const |
Calculate the moves units may possibly make. | |
void | calculate_moves (const unit_map &units, std::map< location, paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const std::set< location > *remove_destinations=NULL, bool see_all=false) const |
A more fundamental version of calculate_possible_moves which allows the use of a speculative unit map. | |
bool | recruit (const std::string &unit_name, location loc=location()) |
Recruit a unit. | |
info & | get_info () |
functions to retrieve the 'info' object. | |
const info & | get_info () const |
void | raise_user_interact () |
Function which should be called frequently to allow the user to interact with the interface. | |
void | raise_unit_recruited () |
Notifies all interested observers of the event respectively. | |
void | raise_unit_moved () |
void | raise_enemy_attacked () |
virtual void | get_inputs (std::vector< game_logic::formula_input > *inputs) const |
virtual variant | get_value (const std::string &key) const |
Private Attributes | |
info | info_ |
int | last_interact_ |
events::generic_event | user_interact_ |
events::generic_event | unit_recruited_ |
events::generic_event | unit_moved_ |
events::generic_event | enemy_attacked_ |
Classes | |
struct | info |
info is structure which holds references to all the important objects that an AI might need access to, in order to make and implement its decisions. More... |
Definition at line 29 of file ai_interface.hpp.
A convenient typedef for the often used 'location' object.
Definition at line 33 of file ai_interface.hpp.
typedef std::multimap<location,location> ai_interface::move_map |
The standard way in which a map of possible moves is recorded.
Definition at line 36 of file ai_interface.hpp.
ai_interface::ai_interface | ( | info & | arg | ) | [inline] |
The constructor.
All derived classes should take an argument of type info& which they should pass to this constructor.
Definition at line 77 of file ai_interface.hpp.
virtual ai_interface::~ai_interface | ( | ) | [inline, virtual] |
Definition at line 80 of file ai_interface.hpp.
virtual void ai_interface::play_turn | ( | ) | [pure virtual] |
Function that is called when the AI must play its turn.
Derived classes should implement their AI algorithm in this function.
Implemented in idle_ai, sample_ai, ai, ai2, dfool::dfool_ai, python_ai, and formula_ai.
Referenced by formula_ai::execute_variant(), and formula_ai::make_move().
team& ai_interface::current_team | ( | ) | [inline] |
Return a reference to the 'team' object for the AI.
Definition at line 87 of file ai_interface.hpp.
References info_, ai_interface::info::team_num, and ai_interface::info::teams.
Referenced by ai::access_points(), ai::attack_analysis::analyze(), ai::analyze_potential_recruit_combat(), ai::analyze_potential_recruit_movements(), ai::analyze_targets(), ai::attack_depth(), ai::avoided_locations(), ai::choose_move(), ai::desperate_attack(), ai::do_attack_analysis(), sample_ai::do_attacks(), ai::do_combat(), ai::do_move(), sample_ai::do_moves(), ai::do_recruitment(), sample_ai::do_recruitment(), formula_ai::evaluate(), ai::find_targets(), ai::find_threats(), get_value(), sample_ai::get_villages(), ai::leader_can_reach_keep(), ai::move_leader_after_recruit(), ai::move_leader_to_goals(), ai::move_leader_to_keep(), ai::move_to_targets(), ai::move_unit(), move_unit_partial(), ai::multistep_move_possible(), formula_ai::play_turn(), dfool::dfool_ai::play_turn(), ai::attack_analysis::rating(), recruit(), ai::recruit_usage(), ai::retreat_units(), and dfool::dfool_ai::visible_units().
const team& ai_interface::current_team | ( | ) | const [inline] |
Definition at line 88 of file ai_interface.hpp.
References info_, ai_interface::info::team_num, and ai_interface::info::teams.
void ai_interface::diagnostic | ( | const std::string & | msg | ) |
Show a diagnostic message on the screen.
Definition at line 400 of file ai.cpp.
References game_config::debug, ai_interface::info::disp, info_, and display::set_diagnostic().
void ai_interface::log_message | ( | const std::string & | msg | ) |
Display a debug message as a chat message.
Definition at line 407 of file ai.cpp.
References game_display::add_chat_message(), game_config::debug, ai_interface::info::disp, info_, and game_display::MESSAGE_PUBLIC.
Referenced by ai::attack_analysis::rating().
events::generic_event& ai_interface::user_interact | ( | ) | [inline] |
events::generic_event& ai_interface::unit_recruited | ( | ) | [inline] |
events::generic_event& ai_interface::unit_moved | ( | ) | [inline] |
events::generic_event& ai_interface::enemy_attacked | ( | ) | [inline] |
void ai_interface::attack_enemy | ( | const location | u, | |
const location | target, | |||
int | weapon, | |||
int | def_weapon | |||
) | [protected] |
This function should be called to attack an enemy.
u | The location of the attacking unit. (Note this shouldn't be a reference since attack::attack() can invalidate the unit_map and references to the map are also invalid then.) | |
target | The location of the target unit. This unit must be in range of the attacking unit's weapon. (See note at param u.) | |
weapon | The number of the weapon (0-based) which should be used by the attacker. (It must be a valid weapon of the attacker.) | |
def_weapon | The number of the weapon (0-based) which should be used by the defender. (It must be a valid weapon of the defender.) |
Definition at line 1118 of file ai.cpp.
References replay::add_attack(), dialogs::advance_unit(), check_victory(), unit_map::count(), ai_interface::info::disp, unit_map::end(), lg::err, unit_map::find(), info_, LOG_STREAM, ai_interface::info::map, raise_enemy_attacked(), recorder, ai_interface::info::state, ai_interface::info::teams, and ai_interface::info::units.
Referenced by ai::attack_enemy(), and sample_ai::do_attacks().
gamemap::location ai_interface::move_unit | ( | location | from, | |
location | to, | |||
std::map< location, paths > & | possible_moves | |||
) | [protected] |
This function should be called to move a unit.
Once the unit has been moved, its movement allowance is set to 0. 'from': the location of the unit being moved. 'to': the location to be moved to. This must be a valid move for the unit. 'possible_moves': the map of possible moves, as obtained from 'calculate_possible_moves'.
Reimplemented in ai.
Definition at line 416 of file ai.cpp.
References unit_map::end(), unit_map::find(), info_, loc, move_unit_partial(), and ai_interface::info::units.
Referenced by sample_ai::do_attacks(), sample_ai::do_moves(), sample_ai::get_villages(), and ai::move_unit().
gamemap::location ai_interface::move_unit_partial | ( | location | from, | |
location | t, | |||
std::map< location, paths > & | possible_moves | |||
) | [protected] |
Identical to 'move_unit', except that the unit's movement isn't set to 0 after the move is complete.
Definition at line 433 of file ai.cpp.
References unit_map::add(), replay::add_movement(), current_team(), ai_interface::info::disp, game_display::display_unit_hex(), game_display::draw(), unit_map::end(), lg::err, unit_map::extract(), unit_map::find(), game_events::fire(), get_adjacent_tiles(), get_village(), info_, game_display::invalidate(), team::is_enemy(), gamemap::is_village(), LOG_AI, log_scope2, LOG_STREAM, ai_interface::info::map, unit_display::move_unit(), raise_unit_moved(), recorder, paths::routes, preferences::show_ai_moves(), ai_interface::info::team_num, ai_interface::info::teams, unit_display::unit_visible_on_path(), and ai_interface::info::units.
Referenced by move_unit(), and dfool::dfool_ai::moveto().
void ai_interface::calculate_possible_moves | ( | std::map< location, paths > & | possible_moves, | |
move_map & | srcdst, | |||
move_map & | dstsrc, | |||
bool | enemy, | |||
bool | assume_full_movement = false , |
|||
const std::set< location > * | remove_destinations = NULL | |||
) | const [protected] |
Calculate the moves units may possibly make.
'possible_moves': a map which will be filled with the paths each unit can take to get to every possible destination. You probably don't want to use this object at all, except to pass to 'move_unit'. 'srcdst': a map of units to all their possible destinations 'dstsrc': a map of destinations to all the units that can move to that destination 'enemy': if true, a map of possible moves for enemies will be calculated. If false, a map of possible moves for units on the AI's side will be calculated. The AI's own leader will not be included in this map. 'assume_full_movement': if true, the function will operate on the assumption that all units can move their full movement allotment. 'remove_destinations': a pointer to a set of possible destinations to omit.
Referenced by ai::analyze_targets(), ai::choose_move(), sample_ai::do_attacks(), ai::do_move(), sample_ai::do_moves(), sample_ai::get_villages(), ai::move_group(), ai::move_leader_after_recruit(), ai::move_unit(), formula_ai::prepare_move(), and ai::retreat_units().
void ai_interface::calculate_moves | ( | const unit_map & | units, | |
std::map< location, paths > & | possible_moves, | |||
move_map & | srcdst, | |||
move_map & | dstsrc, | |||
bool | enemy, | |||
bool | assume_full_movement = false , |
|||
const std::set< location > * | remove_destinations = NULL , |
|||
bool | see_all = false | |||
) | const [protected] |
A more fundamental version of calculate_possible_moves which allows the use of a speculative unit map.
Referenced by dfool::dfool_ai::moveto().
Recruit a unit.
It will recruit the unit with the given name, at the given location, or at an available location to recruit units if 'loc' is not a valid recruiting location.
false | if recruitment cannot be performed, because there are no available tiles, or not enough money. |
Definition at line 316 of file ai.cpp.
References replay::add_checksum_check(), replay::add_recruit(), calculate_team_data(), replay_undo::confirm_transaction(), current_team(), data, boost::foreach_detail_::end(), team_data::gold, team::gold(), info_, LOG_AI, ai_interface::info::map, team_data::net_income, raise_unit_recruited(), recorder, statistics::recruit_unit(), recruit_unit(), team::recruits(), preferences::show_ai_moves(), team::spend_gold(), ai_interface::info::state, ai_interface::info::team_num, ai_interface::info::teams, unit_type_data::types(), team_data::units, and ai_interface::info::units.
Referenced by formula_ai::do_recruitment(), sample_ai::do_recruitment(), formula_ai::execute_variant(), and ai::recruit_usage().
info& ai_interface::get_info | ( | ) | [inline, protected] |
functions to retrieve the 'info' object.
Used by derived classes to discover all necessary game information.
Definition at line 148 of file ai_interface.hpp.
References info_.
Referenced by dfool::dfool_ai::all_units(), ai::analyze_potential_recruit_movements(), sample_ai::do_attacks(), sample_ai::do_moves(), formula_ai::execute_variant(), ai::find_threats(), formula_ai::get_keeps(), python_ai::get_teams(), formula_ai::get_value(), get_value(), sample_ai::get_villages(), formula_ai::make_move(), ai::move_leader_to_goals(), formula_ai::play_turn(), dfool::dfool_ai::play_turn(), and dfool::dfool_ai::visible_units().
const info& ai_interface::get_info | ( | ) | const [inline, protected] |
void ai_interface::raise_user_interact | ( | ) | [protected] |
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 387 of file ai.cpp.
References last_interact_, events::generic_event::notify_observers(), and user_interact_.
Referenced by ai::choose_move(), ai::do_attack_analysis(), ai::do_move(), and ai::recruit_usage().
void ai_interface::raise_unit_recruited | ( | ) | [inline, protected] |
Notifies all interested observers of the event respectively.
Definition at line 158 of file ai_interface.hpp.
References events::generic_event::notify_observers(), and unit_recruited_.
Referenced by recruit().
void ai_interface::raise_unit_moved | ( | ) | [inline, protected] |
Definition at line 159 of file ai_interface.hpp.
References events::generic_event::notify_observers(), and unit_moved_.
Referenced by move_unit_partial().
void ai_interface::raise_enemy_attacked | ( | ) | [inline, protected] |
Definition at line 160 of file ai_interface.hpp.
References enemy_attacked_, and events::generic_event::notify_observers().
Referenced by attack_enemy().
void ai_interface::get_inputs | ( | std::vector< game_logic::formula_input > * | inputs | ) | const [protected, virtual] |
Reimplemented from game_logic::formula_callable.
Reimplemented in formula_ai.
Definition at line 2262 of file ai.cpp.
References game_logic::FORMULA_READ_ONLY.
Referenced by formula_ai::get_inputs().
variant ai_interface::get_value | ( | const std::string & | key | ) | const [protected, virtual] |
Implements game_logic::formula_callable.
Reimplemented in formula_ai.
Definition at line 2218 of file ai.cpp.
References unit_map::begin(), current_team(), unit_map::end(), get_info(), info_, ai_interface::info::map, ai_interface::info::state, ai_interface::info::team_num, gamestatus::teams, ai_interface::info::teams, ai_interface::info::units, team::villages(), gamemap::villages(), and villages_from_set().
Referenced by formula_ai::get_value().
info ai_interface::info_ [private] |
Definition at line 165 of file ai_interface.hpp.
Referenced by attack_enemy(), current_team(), diagnostic(), get_info(), get_value(), log_message(), move_unit(), move_unit_partial(), dfool::dfool_ai::play_turn(), and recruit().
int ai_interface::last_interact_ [private] |
Definition at line 167 of file ai_interface.hpp.
Referenced by raise_user_interact(), and user_interact().
Definition at line 168 of file ai_interface.hpp.
Referenced by raise_unit_recruited(), and unit_recruited().
Definition at line 169 of file ai_interface.hpp.
Referenced by raise_unit_moved(), and unit_moved().
Definition at line 170 of file ai_interface.hpp.
Referenced by enemy_attacked(), and raise_enemy_attacked().
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |