#include <ai.hpp>
Classes | |
class | gamestate_change_observer |
Public Types | |
typedef game_logic::position_callable::move_map_backup | move_map_backup |
![]() | |
typedef std::map< std::pair < map_location, const unit_type * >, std::pair < battle_context_unit_stats, battle_context_unit_stats > > | unit_stats_cache_t |
Public Member Functions | |
formula_ai (readonly_context &context, const config &cfg) | |
virtual | ~formula_ai () |
virtual config | to_config () const |
std::string | evaluate (const std::string &formula_str) |
virtual void | add_formula_function (const std::string &name, game_logic::const_formula_ptr formula, game_logic::const_formula_ptr precondition, const std::vector< std::string > &args) |
void | swap_move_map (move_map_backup &backup) |
variant | get_keeps () const |
void | on_create () |
int | get_recursion_count () const |
Get the value of the recursion counter. More... | |
const variant & | get_keeps_cache () const |
bool | can_reach_unit (map_location unit_A, map_location unit_B) const |
void | handle_exception (game_logic::formula_error &e) const |
void | handle_exception (game_logic::formula_error &e, const std::string &failed_operation) const |
pathfind::teleport_map | get_allowed_teleports (unit_map::iterator &unit_it) const |
pathfind::plain_route | shortest_path_calculator (const map_location &src, const map_location &dst, unit_map::iterator &unit_it, pathfind::teleport_map &allowed_teleports) const |
game_logic::formula_ptr | create_optional_formula (const std::string &formula_string) |
Create a new formula from the string, using the symbol table which is stored in the AI. More... | |
game_logic::candidate_action_ptr | load_candidate_action_from_config (const config &cfg) |
void | evaluate_candidate_action (game_logic::candidate_action_ptr fai_ca) |
Evaluate the fai candidate action. More... | |
bool | execute_candidate_action (game_logic::candidate_action_ptr fai_ca) |
Execute the fai candidate action. More... | |
void | set_ai_context (ai_context *context) |
variant | make_action (game_logic::const_formula_ptr formula_, const game_logic::formula_callable &variables) |
![]() | |
readonly_context_proxy () | |
virtual | ~readonly_context_proxy () |
void | init_readonly_context_proxy (readonly_context &target) |
virtual readonly_context & | get_readonly_context () |
virtual void | on_readonly_context_create () |
virtual const team & | current_team () const |
virtual void | diagnostic (const std::string &msg) |
virtual void | log_message (const std::string &msg) |
virtual attack_result_ptr | check_attack_action (const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) |
virtual move_result_ptr | check_move_action (const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) |
virtual recall_result_ptr | check_recall_action (const std::string &id, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) |
virtual recruit_result_ptr | check_recruit_action (const std::string &unit_name, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) |
virtual stopunit_result_ptr | check_stopunit_action (const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) |
virtual synced_command_result_ptr | check_synced_command_action (const std::string &lua_code, const map_location &location=map_location::null_location()) |
virtual void | calculate_possible_moves (std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr) const |
virtual void | calculate_moves (const unit_map &units, std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr, bool see_all=false) const |
virtual const game_info & | get_info () const |
virtual void | raise_user_interact () const |
defensive_position const & | best_defensive_position (const map_location &unit, const move_map &dstsrc, const move_map &srcdst, const move_map &enemy_dstsrc) const |
virtual std::map< map_location, defensive_position > & | defensive_position_cache () const |
virtual const unit_advancements_aspect & | get_advancements () const |
virtual double | get_aggression () const |
virtual int | get_attack_depth () const |
virtual const aspect_map & | get_aspects () const |
virtual aspect_map & | get_aspects () |
virtual void | add_aspects (std::vector< aspect_ptr > &aspects) |
virtual void | add_facet (const std::string &id, const config &cfg) const |
virtual const attacks_vector & | get_attacks () const |
virtual const variant & | get_attacks_as_variant () const |
virtual const terrain_filter & | get_avoid () const |
virtual double | get_caution () const |
virtual const move_map & | get_dstsrc () const |
virtual const move_map & | get_enemy_dstsrc () const |
virtual const moves_map & | get_enemy_possible_moves () const |
virtual const move_map & | get_enemy_srcdst () const |
virtual engine_ptr | get_engine_by_cfg (const config &cfg) |
get engine by cfg, creating it if it is not created yet but known More... | |
virtual const std::vector < engine_ptr > & | get_engines () const |
virtual std::vector< engine_ptr > & | get_engines () |
virtual std::string | get_grouping () const |
virtual const std::vector < goal_ptr > & | get_goals () const |
virtual std::vector< goal_ptr > & | get_goals () |
virtual double | get_leader_aggression () const |
virtual config | get_leader_goal () const |
virtual bool | get_leader_ignores_keep () const |
virtual double | get_leader_value () const |
virtual bool | get_passive_leader () const |
virtual bool | get_passive_leader_shares_keep () const |
virtual const moves_map & | get_possible_moves () const |
virtual double | power_projection (const map_location &loc, const move_map &dstsrc) const |
Function which finds how much 'power' a side can attack a certain location with. More... | |
virtual const std::vector < unit_ptr > & | get_recall_list () const |
virtual double | get_recruitment_diversity () const |
virtual const config | get_recruitment_instructions () const |
virtual const std::vector < std::string > | get_recruitment_more () const |
virtual const std::vector < std::string > | get_recruitment_pattern () const |
virtual int | get_recruitment_randomness () const |
virtual const config | get_recruitment_save_gold () const |
virtual const move_map & | get_srcdst () const |
virtual double | get_scout_village_targeting () const |
virtual bool | get_simple_targeting () const |
virtual bool | get_support_villages () const |
virtual double | get_village_value () const |
virtual int | get_villages_per_scout () const |
virtual bool | is_active (const std::string &time_of_day, const std::string &turns) const |
virtual bool | is_dst_src_valid_lua () const |
virtual bool | is_dst_src_enemy_valid_lua () const |
virtual bool | is_src_dst_valid_lua () const |
virtual bool | is_src_dst_enemy_valid_lua () const |
virtual void | invalidate_defensive_position_cache () const |
virtual void | invalidate_move_maps () const |
virtual void | invalidate_keeps_cache () const |
virtual const std::set < map_location > & | keeps () const |
virtual bool | leader_can_reach_keep () const |
virtual const map_location & | nearest_keep (const map_location &loc) const |
virtual void | recalculate_move_maps () const |
virtual void | recalculate_move_maps_enemy () const |
virtual void | set_dst_src_valid_lua () |
virtual void | set_dst_src_enemy_valid_lua () |
virtual void | set_src_dst_valid_lua () |
virtual void | set_src_dst_enemy_valid_lua () |
virtual const map_location & | suitable_keep (const map_location &leader_location, const pathfind::paths &leader_paths) |
get most suitable keep for leader - nearest free that can be reached in 1 turn, if none - return nearest occupied that can be reached in 1 turn, if none - return nearest keep, if none - return null_location More... | |
virtual config | to_readonly_context_config () const |
serialize to config More... | |
virtual unit_stats_cache_t & | unit_stats_cache () const |
![]() | |
readonly_context () | |
virtual | ~readonly_context () |
![]() | |
virtual | ~side_context () |
empty destructor More... | |
side_context () | |
empty constructor More... | |
![]() | |
side_context_proxy () | |
virtual | ~side_context_proxy () |
void | init_side_context_proxy (side_context &target) |
virtual side_number | get_side () const |
Get the side number. More... | |
virtual void | set_side (side_number side) |
Set the side number. More... | |
virtual side_context & | get_side_context () |
unwrap More... | |
virtual config | to_side_context_config () const |
serialize this context to config More... | |
![]() | |
formula_callable (bool has_self=true) | |
variant | query_value (const std::string &key) const |
void | mutate_value (const std::string &key, const variant &value) |
std::vector< formula_input > | inputs () const |
bool | equals (const formula_callable *other) const |
bool | less (const formula_callable *other) const |
void | serialize (std::string &str) const |
bool | has_key (const std::string &key) const |
![]() | |
reference_counted_object () | |
reference_counted_object (const reference_counted_object &) | |
reference_counted_object & | operator= (const reference_counted_object &) |
virtual | ~reference_counted_object () |
void | add_ref () const |
void | dec_ref () const |
int | refcount () const |
Private Member Functions | |
void | display_message (const std::string &msg) const |
variant | execute_variant (const variant &var, ai_context &ai_, bool commandline=false) |
virtual variant | get_value (const std::string &key) const |
virtual void | get_inputs (std::vector< game_logic::formula_input > *inputs) const |
Friends | |
class | ai_default |
Additional Inherited Members | |
![]() | |
enum | TYPE { FORMULA_C, TERRAIN_C, LOCATION_C, UNIT_TYPE_C, UNIT_C, ATTACK_TYPE_C, MOVE_PARTIAL_C, MOVE_C, ATTACK_C, MOVE_MAP_C } |
![]() | |
virtual | ~formula_callable () |
virtual void | set_value (const std::string &key, const variant &value) |
virtual int | do_compare (const formula_callable *callable) const |
virtual void | serialize_to_string (std::string &) const |
![]() | |
void | turn_reference_counting_off () const |
![]() | |
TYPE | type_ |
|
explicit |
Definition at line 105 of file ai.cpp.
References reference_counted_object::add_ref(), ai::readonly_context_proxy::init_readonly_context_proxy(), and LOG_AI.
|
virtual |
Definition at line 562 of file ai.cpp.
References game_logic::function_symbol_table::add_function(), and function_table_.
Referenced by on_create().
bool ai::formula_ai::can_reach_unit | ( | map_location | unit_A, |
map_location | unit_B | ||
) | const |
Definition at line 920 of file ai.cpp.
References ai::readonly_context_proxy::get_srcdst(), i, tiles_adjacent(), and unit_moves().
Referenced by game_logic::attack_candidate_action::evaluate().
formula_ptr ai::formula_ai::create_optional_formula | ( | const std::string & | formula_string | ) |
Create a new formula from the string, using the symbol table which is stored in the AI.
formula_string | the string from which a formula should be created |
game_logic::formula_ptr() | if there were any problems |
Definition at line 148 of file ai.cpp.
References game_logic::formula::create_optional_formula(), e, function_table_, and handle_exception().
Referenced by ai::stage_unit_formulas::do_play_stage(), ai::stage_side_formulas::on_create(), and on_create().
|
private |
Definition at line 141 of file ai.cpp.
References display_chat_manager::add_chat_message(), game_display::get_chat_manager(), ai::side_context_proxy::get_side(), events::chat_handler::MESSAGE_PUBLIC, and resources::screen.
Referenced by handle_exception().
std::string ai::formula_ai::evaluate | ( | const std::string & | formula_str | ) |
Definition at line 165 of file ai.cpp.
References reference_counted_object::add_ref(), ai_ptr_, e, game_logic::formula::evaluate(), execute_variant(), function_table_, handle_exception(), variant::is_empty(), game_logic::formula_error::line, and variant::to_debug_string().
void ai::formula_ai::evaluate_candidate_action | ( | game_logic::candidate_action_ptr | fai_ca | ) |
Evaluate the fai candidate action.
Definition at line 974 of file ai.cpp.
References resources::units.
Referenced by ai::fai_candidate_action_wrapper::evaluate().
bool ai::formula_ai::execute_candidate_action | ( | game_logic::candidate_action_ptr | fai_ca | ) |
Execute the fai candidate action.
Definition at line 980 of file ai.cpp.
References reference_counted_object::add_ref(), variant::is_empty(), and make_action().
Referenced by ai::fai_candidate_action_wrapper::execute().
|
private |
Definition at line 272 of file ai.cpp.
References game_logic::map_formula_callable::add(), reference_counted_object::add_ref(), variant::as_string(), ai::readonly_context::check_recall_action(), ai::readonly_context::check_recruit_action(), ai::formula_ai::gamestate_change_observer::continue_check(), unit_map::count(), game_logic::move_callable::dst(), unit_map::end(), ERR_AI, error(), ai::readwrite_context::execute_attack_action(), ai::readwrite_context::execute_move_action(), unit_map::find(), game_logic::safe_call_callable::get_backup(), game_logic::safe_call_callable::get_main(), get_recursion_count(), ai::side_context_proxy::get_side(), infinite_loop_guardian_, variant::is_list(), variant::is_string(), LOG_AI, ai::recursion_counter::MAX_COUNTER_VALUE, variant::num_elements(), game_logic::safe_call_callable::set_backup_result(), ai::formula_ai::gamestate_change_observer::set_unit_var_check(), ai::formula_ai::gamestate_change_observer::set_var_check(), game_logic::move_callable::src(), variant::to_debug_string(), resources::units, and vars_.
Referenced by evaluate(), and make_action().
pathfind::teleport_map ai::formula_ai::get_allowed_teleports | ( | unit_map::iterator & | unit_it | ) | const |
Definition at line 266 of file ai.cpp.
References ai::readonly_context_proxy::current_team(), and pathfind::get_teleport_locations().
|
privatevirtual |
Reimplemented from game_logic::formula_callable.
Definition at line 863 of file ai.cpp.
References game_logic::FORMULA_READ_ONLY.
variant ai::formula_ai::get_keeps | ( | ) | const |
Definition at line 895 of file ai.cpp.
References resources::gameboard, get_adjacent_tiles(), h, variant::is_null(), and keeps_cache_.
Referenced by get_value().
|
inline |
Definition at line 117 of file ai.hpp.
References keeps_cache_.
|
virtual |
Get the value of the recursion counter.
Reimplemented from ai::readonly_context_proxy.
Definition at line 100 of file ai.cpp.
Referenced by execute_variant().
|
privatevirtual |
Implements game_logic::formula_callable.
Definition at line 584 of file ai.cpp.
References unit_map::begin(), unit_type_data::build_all(), ai::readonly_context_proxy::current_team(), variant::DECIMAL_VARIANT, recall_list_manager::end(), unit_map::end(), unit_type_data::find(), unit_map::find_leader(), unit_type::FULL, resources::gameboard, ai::readonly_context_proxy::get_aggression(), ai::readonly_context_proxy::get_attack_depth(), ai::readonly_context_proxy::get_attacks_as_variant(), ai::readonly_context_proxy::get_avoid(), ai::readonly_context_proxy::get_caution(), ai::readonly_context_proxy::get_dstsrc(), ai::readonly_context_proxy::get_enemy_dstsrc(), ai::readonly_context_proxy::get_enemy_srcdst(), ai::readonly_context_proxy::get_grouping(), get_keeps(), ai::readonly_context_proxy::get_leader_aggression(), ai::readonly_context_proxy::get_leader_ignores_keep(), ai::readonly_context_proxy::get_leader_value(), terrain_filter::get_locations(), ai::readonly_context_proxy::get_passive_leader(), ai::readonly_context_proxy::get_passive_leader_shares_keep(), ai::readonly_context_proxy::get_recruitment_pattern(), ai::readonly_context_proxy::get_scout_village_targeting(), ai::side_context_proxy::get_side(), ai::readonly_context_proxy::get_srcdst(), ai::readonly_context_proxy::get_support_villages(), ai::readonly_context_proxy::get_village_value(), ai::readonly_context_proxy::get_villages_per_scout(), i, team::is_enemy(), team::recall_list(), team::recruits(), resources::teams, resources::tod_manager, unit_types, resources::units, and vars_.
void ai::formula_ai::handle_exception | ( | game_logic::formula_error & | e | ) | const |
Definition at line 122 of file ai.cpp.
Referenced by create_optional_formula(), ai::stage_unit_formulas::do_play_stage(), ai::stage_side_formulas::do_play_stage(), evaluate(), game_logic::move_candidate_action::evaluate(), game_logic::attack_candidate_action::evaluate(), game_logic::base_candidate_action::execute_formula(), and on_create().
void ai::formula_ai::handle_exception | ( | game_logic::formula_error & | e, |
const std::string & | failed_operation | ||
) | const |
Definition at line 127 of file ai.cpp.
References display_message(), game_logic::formula_error::filename, game_logic::formula_error::formula, game_logic::formula_error::line, LOG_AI, and game_logic::formula_error::type.
variant ai::formula_ai::make_action | ( | game_logic::const_formula_ptr | formula_, |
const game_logic::formula_callable & | variables | ||
) |
Definition at line 194 of file ai.cpp.
References ai_ptr_, ERR_AI, execute_variant(), and LOG_AI.
Referenced by ai::stage_side_formulas::do_play_stage(), ai::stage_unit_formulas::do_play_stage(), and execute_candidate_action().
void ai::formula_ai::on_create | ( | ) |
Definition at line 937 of file ai.cpp.
References game_logic::map_formula_callable::add(), add_formula_function(), reference_counted_object::add_ref(), cfg_, config::child(), config::child_range(), create_optional_formula(), e, handle_exception(), i, game_logic::formula_callable::inputs(), variant::serialize_from_string(), utils::split(), and vars_.
void ai::formula_ai::set_ai_context | ( | ai_context * | context | ) |
pathfind::plain_route ai::formula_ai::shortest_path_calculator | ( | const map_location & | src, |
const map_location & | dst, | ||
unit_map::iterator & | unit_it, | ||
pathfind::teleport_map & | allowed_teleports | ||
) | const |
Definition at line 212 of file ai.cpp.
References pathfind::a_star_search(), ai::readonly_context_proxy::current_team(), unit_map::end(), unit_map::find(), resources::gameboard, get_adjacent_tiles(), map_location::get_relative_dir(), h, map_location::NDIRECTIONS, resources::teams, resources::units, units_, and map_location::valid().
void ai::formula_ai::swap_move_map | ( | move_map_backup & | backup | ) |
|
virtual |
Definition at line 1030 of file ai.cpp.
References config::add_child(), game_logic::map_formula_callable::begin(), cfg_, config::clear(), config::clear_children(), DBG_AI, game_logic::map_formula_callable::empty(), game_logic::map_formula_callable::end(), i, vars_, and WRN_AI.
|
private |
Definition at line 153 of file ai.hpp.
Referenced by evaluate(), make_action(), and set_ai_context().
|
private |
Definition at line 154 of file ai.hpp.
Referenced by on_create(), and to_config().
|
private |
Definition at line 165 of file ai.hpp.
Referenced by add_formula_function(), create_optional_formula(), and evaluate().
|
private |
Definition at line 163 of file ai.hpp.
Referenced by execute_variant().
|
mutableprivate |
Definition at line 161 of file ai.hpp.
Referenced by get_keeps(), and get_keeps_cache().
|
private |
|
private |
Definition at line 164 of file ai.hpp.
Referenced by execute_variant(), get_value(), on_create(), and to_config().