The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ai::ai_default_rca::get_villages_phase Class Reference

#include <ca.hpp>

Inheritance diagram for ai::ai_default_rca::get_villages_phase:
Inheritance graph

Public Member Functions

 get_villages_phase (rca_context &context, const config &cfg)
 
virtual ~get_villages_phase ()
 
virtual double evaluate ()
 Evaluate the candidate action, resetting the internal state of the action. More...
 
virtual void execute ()
 Execute the candidate action. More...
 
- Public Member Functions inherited from ai::candidate_action
 candidate_action (rca_context &context, const config &cfg)
 
virtual ~candidate_action ()
 Destructor. More...
 
bool is_enabled () const
 Is this candidate action enabled ? More...
 
void enable ()
 Enable the candidate action. More...
 
void disable ()
 Disable the candidate action. More...
 
double get_score () const
 Get the usual score of the candidate action without re-evaluation. More...
 
double get_max_score () const
 Get the upper bound of the score of the candidate action without re-evaluation. More...
 
virtual std::string get_name () const
 Get the name of the candidate action (useful for debug purposes) More...
 
const std::stringget_type () const
 Get the type of the candidate action (useful for debug purposes) More...
 
virtual std::string get_id () const
 
virtual std::string get_engine () const
 
int get_recursion_count () const
 Get the value of the recursion counter. More...
 
virtual config to_config () const
 serialize More...
 
virtual void set_to_be_removed ()
 
virtual bool to_be_removed ()
 
- Public Member Functions inherited from ai::rca_context_proxy
 rca_context_proxy ()
 
virtual ~rca_context_proxy ()
 
void init_rca_context_proxy (rca_context &target)
 
rca_contextget_rca_context ()
 Unwrap. More...
 
- Public Member Functions inherited from ai::rca_context
 rca_context ()
 Constructor. More...
 
virtual ~rca_context ()
 Destructor. More...
 
bool is_offense ()
 
void set_offense ()
 
bool is_defense ()
 
void set_defense ()
 
void clear_strategy ()
 
bool has_strategy ()
 
- Public Member Functions inherited from ai::default_ai_context
 default_ai_context ()
 Constructor. More...
 
virtual ~default_ai_context ()
 Destructor. More...
 
- Public Member Functions inherited from ai::readwrite_context
 readwrite_context ()
 
virtual ~readwrite_context ()
 
- Public Member Functions inherited from ai::readonly_context
 readonly_context ()
 
virtual ~readonly_context ()
 
- Public Member Functions inherited from ai::side_context
virtual ~side_context ()
 empty destructor More...
 
 side_context ()
 empty constructor More...
 
- Public Member Functions inherited from ai::ai_context_proxy
 ai_context_proxy ()
 
void init_ai_context_proxy (ai_context &target)
 
virtual ~ai_context_proxy ()
 
ai_contextget_ai_context ()
 Unwrap. More...
 
- Public Member Functions inherited from ai::default_ai_context_proxy
int count_free_hexes_in_castle (const map_location &loc, std::set< map_location > &checked_hexes)
 
 default_ai_context_proxy ()
 
virtual ~default_ai_context_proxy ()
 
virtual const std::vector
< target > & 
additional_targets () const
 
virtual void add_target (const target &t) const
 
virtual void clear_additional_targets () const
 
virtual default_ai_contextget_default_ai_context ()
 
virtual std::vector< targetfind_targets (const move_map &enemy_dstsrc)
 
void init_default_ai_context_proxy (default_ai_context &target)
 
virtual int rate_terrain (const unit &u, const map_location &loc) const
 
virtual config to_default_ai_context_config () const
 
- Public Member Functions inherited from ai::readwrite_context_proxy
 readwrite_context_proxy ()
 
void init_readwrite_context_proxy (readwrite_context &target)
 
virtual readwrite_contextget_readwrite_context ()
 
virtual attack_result_ptr execute_attack_action (const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon)
 
virtual move_result_ptr execute_move_action (const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false)
 
virtual recall_result_ptr execute_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 execute_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 execute_stopunit_action (const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false)
 
virtual synced_command_result_ptr execute_synced_command_action (const std::string &lua_code, const map_location &location=map_location::null_location())
 
virtual teamcurrent_team_w ()
 
virtual void raise_gamestate_changed () const
 
virtual game_infoget_info_w ()
 
virtual config to_readwrite_context_config () const
 serialize this context to config More...
 
- Public Member Functions inherited from ai::readonly_context_proxy
 readonly_context_proxy ()
 
virtual ~readonly_context_proxy ()
 
void init_readonly_context_proxy (readonly_context &target)
 
virtual readonly_contextget_readonly_context ()
 
virtual void on_readonly_context_create ()
 
virtual const teamcurrent_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_infoget_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_mapget_aspects () const
 
virtual aspect_mapget_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_vectorget_attacks () const
 
virtual const variantget_attacks_as_variant () const
 
virtual const terrain_filterget_avoid () const
 
virtual double get_caution () const
 
virtual const move_mapget_dstsrc () const
 
virtual const move_mapget_enemy_dstsrc () const
 
virtual const moves_mapget_enemy_possible_moves () const
 
virtual const move_mapget_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_mapget_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_mapget_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_locationnearest_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_locationsuitable_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_tunit_stats_cache () const
 
- Public Member Functions inherited from ai::side_context_proxy
 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_contextget_side_context ()
 unwrap More...
 
virtual config to_side_context_config () const
 serialize this context to config More...
 
- Public Member Functions inherited from ai::component
 component ()
 
virtual ~component ()
 
virtual componentget_child (const path_element &child)
 
virtual std::vector< component * > get_children (const std::string &type)
 
virtual std::vector< std::stringget_children_types ()
 
virtual bool change_child (const path_element &child, const config &cfg)
 
virtual bool add_child (const path_element &child, const config &cfg)
 
virtual bool delete_child (const path_element &child)
 
property_handler_mapproperty_handlers ()
 

Private Types

typedef std::map< map_location,
std::vector< map_location > > 
treachmap
 
typedef std::vector< std::pair
< map_location, map_location > > 
tmoves
 

Private Member Functions

void dispatch (treachmap &reachmap, tmoves &moves)
 Dispatches all units to their best location. More...
 
bool dispatch_unit_simple (treachmap &reachmap, tmoves &moves)
 Dispatches all units who can reach one village. More...
 
bool dispatch_village_simple (treachmap &reachmap, tmoves &moves, size_t &village_count)
 
bool remove_village (treachmap &reachmap, tmoves &moves, const map_location &village)
 Removes a village for all units, returns true if anything is deleted. More...
 
treachmap::iterator remove_unit (treachmap &reachmap, tmoves &moves, treachmap::iterator unit)
 Removes a unit which can't reach any village anymore. More...
 
void dispatch_complex (treachmap &reachmap, tmoves &moves, const size_t village_count)
 Dispatches the units to a village after the simple dispatching failed. More...
 
void full_dispatch (treachmap &reachmap, tmoves &moves)
 Dispatches all units to a village, every unit can reach every village. More...
 
void dump_reachmap (treachmap &reachmap)
 Shows which villages every unit can reach (debug function). More...
 
void get_villages (const move_map &dstsrc, const move_map &enemy_dstsrc, unit_map::const_iterator &leader)
 
void find_villages (treachmap &reachmap, tmoves &moves, const std::multimap< map_location, map_location > &dstsrc, const std::multimap< map_location, map_location > &enemy_dstsrc)
 

Private Attributes

map_location keep_loc_
 Location of the keep the closest to our leader. More...
 
map_location leader_loc_
 Locaton of our leader. More...
 
map_location best_leader_loc_
 The best possible location for our leader if it can't reach a village. More...
 
bool debug_
 debug log level for AI enabled? More...
 
tmoves moves_
 

Additional Inherited Members

- Public Types inherited from ai::readonly_context
typedef std::map< std::pair
< map_location, const
unit_type * >, std::pair
< battle_context_unit_stats,
battle_context_unit_stats > > 
unit_stats_cache_t
 
- Static Public Attributes inherited from ai::candidate_action
static const double BAD_SCORE = 0
 
static const double HIGH_SCORE = 10000000
 

Detailed Description

Definition at line 114 of file ca.hpp.

Member Typedef Documentation

typedef std::vector<std::pair<map_location , map_location > > ai::ai_default_rca::get_villages_phase::tmoves
private

Definition at line 141 of file ca.hpp.

Definition at line 138 of file ca.hpp.

Constructor & Destructor Documentation

ai::ai_default_rca::get_villages_phase::get_villages_phase ( rca_context context,
const config cfg 
)

Definition at line 512 of file ca.cpp.

ai::ai_default_rca::get_villages_phase::~get_villages_phase ( )
virtual

Definition at line 522 of file ca.cpp.

Member Function Documentation

void ai::ai_default_rca::get_villages_phase::dispatch ( treachmap reachmap,
tmoves moves 
)
private

Dispatches all units to their best location.

Definition at line 768 of file ca.cpp.

References DBG_AI_TESTING_AI_DEFAULT, dispatch_complex(), dispatch_unit_simple(), dispatch_village_simple(), and dump_reachmap().

Referenced by dispatch_complex(), and get_villages().

void ai::ai_default_rca::get_villages_phase::dispatch_complex ( treachmap reachmap,
tmoves moves,
const size_t  village_count 
)
private

Dispatches the units to a village after the simple dispatching failed.

Definition at line 958 of file ca.cpp.

References DBG_AI_TESTING_AI_DEFAULT, debug_, dispatch(), gui2::event::find(), full_dispatch(), i, itor, leader_loc_, remove_unit(), remove_village(), and resources::units.

Referenced by dispatch().

bool ai::ai_default_rca::get_villages_phase::dispatch_unit_simple ( treachmap reachmap,
tmoves moves 
)
private

Dispatches all units who can reach one village.

Returns true if it modified reachmap isn't empty.

Definition at line 828 of file ca.cpp.

References DBG_AI_TESTING_AI_DEFAULT, itor, and remove_village().

Referenced by dispatch().

bool ai::ai_default_rca::get_villages_phase::dispatch_village_simple ( treachmap reachmap,
tmoves moves,
size_t &  village_count 
)
private

Definition at line 873 of file ca.cpp.

References DBG_AI_TESTING_AI_DEFAULT, itor, and remove_village().

Referenced by dispatch().

void ai::ai_default_rca::get_villages_phase::dump_reachmap ( treachmap reachmap)
private

Shows which villages every unit can reach (debug function).

Definition at line 1290 of file ca.cpp.

References debug_, and itor.

Referenced by dispatch(), and get_villages().

double ai::ai_default_rca::get_villages_phase::evaluate ( )
virtual

Evaluate the candidate action, resetting the internal state of the action.

Returns
the score
Return values
>0if the action is good
<=0if the action is not good

Implements ai::candidate_action.

Definition at line 526 of file ca.cpp.

References ai::candidate_action::BAD_SCORE, unit_map::find_leader(), ai::readonly_context_proxy::get_dstsrc(), ai::readonly_context_proxy::get_enemy_dstsrc(), ai::candidate_action::get_score(), ai::side_context_proxy::get_side(), get_villages(), moves_, and resources::units.

void ai::ai_default_rca::get_villages_phase::execute ( )
virtual
void ai::ai_default_rca::get_villages_phase::find_villages ( treachmap reachmap,
tmoves moves,
const std::multimap< map_location, map_location > &  dstsrc,
const std::multimap< map_location, map_location > &  enemy_dstsrc 
)
private
void ai::ai_default_rca::get_villages_phase::full_dispatch ( treachmap reachmap,
tmoves moves 
)
private

Dispatches all units to a village, every unit can reach every village.

Definition at line 1280 of file ca.cpp.

References DBG_AI_TESTING_AI_DEFAULT, i, and itor.

Referenced by dispatch_complex().

void ai::ai_default_rca::get_villages_phase::get_villages ( const move_map dstsrc,
const move_map enemy_dstsrc,
unit_map::const_iterator leader 
)
private
get_villages_phase::treachmap::iterator ai::ai_default_rca::get_villages_phase::remove_unit ( treachmap reachmap,
tmoves moves,
treachmap::iterator  unit 
)
private

Removes a unit which can't reach any village anymore.

Definition at line 942 of file ca.cpp.

References best_leader_loc_, DBG_AI_TESTING_AI_DEFAULT, leader_loc_, and map_location::null_location().

Referenced by dispatch_complex(), get_villages(), and remove_village().

bool ai::ai_default_rca::get_villages_phase::remove_village ( treachmap reachmap,
tmoves moves,
const map_location village 
)
private

Removes a village for all units, returns true if anything is deleted.

Definition at line 925 of file ca.cpp.

References itor, schema_validation::remove, and remove_unit().

Referenced by dispatch_complex(), dispatch_unit_simple(), and dispatch_village_simple().

Member Data Documentation

map_location ai::ai_default_rca::get_villages_phase::best_leader_loc_
private

The best possible location for our leader if it can't reach a village.

Definition at line 132 of file ca.hpp.

Referenced by find_villages(), get_villages(), and remove_unit().

bool ai::ai_default_rca::get_villages_phase::debug_
private

debug log level for AI enabled?

Definition at line 135 of file ca.hpp.

Referenced by dispatch_complex(), dump_reachmap(), and get_villages().

map_location ai::ai_default_rca::get_villages_phase::keep_loc_
private

Location of the keep the closest to our leader.

Definition at line 126 of file ca.hpp.

Referenced by find_villages(), and get_villages().

map_location ai::ai_default_rca::get_villages_phase::leader_loc_
private

Locaton of our leader.

Definition at line 129 of file ca.hpp.

Referenced by dispatch_complex(), find_villages(), get_villages(), and remove_unit().

tmoves ai::ai_default_rca::get_villages_phase::moves_
private

Definition at line 145 of file ca.hpp.

Referenced by evaluate(), execute(), and get_villages().


The documentation for this class was generated from the following files: