The Battle for Wesnoth  1.19.5+dev
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ai::default_recruitment::recruitment Class Reference

#include <recruitment.hpp>

Inheritance diagram for ai::default_recruitment::recruitment:

Classes

class  recruit_situation_change_observer
 

Public Member Functions

 recruitment (rca_context &context, const config &cfg)
 
virtual ~recruitment ()
 
virtual double evaluate ()
 Evaluate the candidate action, resetting the internal state of the action. More...
 
virtual void execute ()
 Execute the candidate action. More...
 
config to_config () const
 serialize 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...
 
std::shared_ptr< unit_filterget_filter_own () const
 Get the unit filter for allowed units for this candidate action. More...
 
bool is_allowed_unit (const unit &u) const
 Flag indicating whether unit may be used by this candidate action. More...
 
virtual std::string get_name () const
 Get the name of the candidate action (useful for debug purposes) More...
 
const std::string & get_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 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 () override
 
virtual attack_result_ptr execute_attack_action (const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
 
virtual move_result_ptr execute_move_action (const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) override
 
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()) override
 
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()) override
 
virtual stopunit_result_ptr execute_stopunit_action (const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) override
 
virtual synced_command_result_ptr execute_synced_command_action (const std::string &lua_code, const map_location &location=map_location::null_location()) override
 
virtual teamcurrent_team_w () override
 
virtual void raise_gamestate_changed () const override
 
virtual game_infoget_info_w () override
 
virtual config to_readwrite_context_config () const override
 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 () override
 
virtual void on_readonly_context_create () override
 
virtual const teamcurrent_team () const override
 
virtual void diagnostic (const std::string &msg) override
 
virtual void log_message (const std::string &msg) override
 
virtual attack_result_ptr check_attack_action (const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
 
virtual move_result_ptr check_move_action (const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) override
 
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()) override
 
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()) override
 
virtual stopunit_result_ptr check_stopunit_action (const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) override
 
virtual synced_command_result_ptr check_synced_command_action (const std::string &lua_code, const map_location &location=map_location::null_location()) override
 
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 override
 
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 override
 
virtual const game_infoget_info () const override
 
virtual void raise_user_interact () const override
 
const defensive_positionbest_defensive_position (const map_location &unit, const move_map &dstsrc, const move_map &srcdst, const move_map &enemy_dstsrc) const override
 
virtual std::map< map_location, defensive_position > & defensive_position_cache () const override
 
virtual const unit_advancements_aspectget_advancements () const override
 
virtual double get_aggression () const override
 
virtual bool get_allow_ally_villages () const override
 
virtual const aspect_mapget_aspects () const override
 
virtual aspect_mapget_aspects () override
 
virtual void add_aspects (std::vector< aspect_ptr > &aspects) override
 
virtual void add_facet (const std::string &id, const config &cfg) const override
 
virtual const attacks_vectorget_attacks () const override
 
virtual const wfl::variantget_attacks_as_variant () const override
 
virtual const terrain_filterget_avoid () const override
 
virtual double get_caution () const override
 
virtual const move_mapget_dstsrc () const override
 
virtual const move_mapget_enemy_dstsrc () const override
 
virtual const moves_mapget_enemy_possible_moves () const override
 
virtual const move_mapget_enemy_srcdst () const override
 
virtual engine_ptr get_engine_by_cfg (const config &cfg) override
 get engine by cfg, creating it if it is not created yet but known More...
 
virtual const std::vector< engine_ptr > & get_engines () const override
 
virtual std::vector< engine_ptr > & get_engines () override
 
virtual std::string get_grouping () const override
 
virtual const std::vector< goal_ptr > & get_goals () const override
 
virtual std::vector< goal_ptr > & get_goals () override
 
virtual double get_leader_aggression () const override
 
virtual config get_leader_goal () const override
 
virtual utils::variant< bool, std::vector< std::string > > get_leader_ignores_keep () const override
 
virtual double get_leader_value () const override
 
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader () const override
 
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader_shares_keep () const override
 
virtual const moves_mapget_possible_moves () const override
 
virtual double power_projection (const map_location &loc, const move_map &dstsrc) const override
 Function which finds how much 'power' a side can attack a certain location with. More...
 
virtual double get_recruitment_diversity () const override
 
virtual const config get_recruitment_instructions () const override
 
virtual const std::vector< std::string > get_recruitment_more () const override
 
virtual const std::vector< std::string > get_recruitment_pattern () const override
 
virtual int get_recruitment_randomness () const override
 
virtual const config get_recruitment_save_gold () const override
 
virtual const move_mapget_srcdst () const override
 
virtual double get_retreat_enemy_weight () const override
 
virtual double get_retreat_factor () const override
 
virtual double get_scout_village_targeting () const override
 
virtual bool get_simple_targeting () const override
 
virtual bool get_support_villages () const override
 
virtual double get_village_value () const override
 
virtual int get_villages_per_scout () const override
 
virtual bool is_active (const std::string &time_of_day, const std::string &turns) const override
 
virtual bool is_keep_ignoring_leader (const std::string &id) const override
 
virtual bool is_passive_leader (const std::string &id) const override
 
virtual bool is_passive_keep_sharing_leader (const std::string &id) const override
 
virtual bool is_dst_src_valid_lua () const override
 
virtual bool is_dst_src_enemy_valid_lua () const override
 
virtual bool is_src_dst_valid_lua () const override
 
virtual bool is_src_dst_enemy_valid_lua () const override
 
virtual void invalidate_defensive_position_cache () const override
 
virtual void invalidate_move_maps () const override
 
virtual void invalidate_keeps_cache () const override
 
virtual const std::set< map_location > & keeps () const override
 
virtual bool leader_can_reach_keep () const override
 
virtual const map_locationnearest_keep (const map_location &loc) const override
 
virtual void recalculate_move_maps () const override
 
virtual void recalculate_move_maps_enemy () const override
 
virtual void set_dst_src_valid_lua () override
 
virtual void set_dst_src_enemy_valid_lua () override
 
virtual void set_src_dst_valid_lua () override
 
virtual void set_src_dst_enemy_valid_lua () override
 
virtual const map_locationsuitable_keep (const map_location &leader_location, const pathfind::paths &leader_paths) const override
 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 override
 serialize to config More...
 
virtual unit_stats_cache_tunit_stats_cache () const override
 
- 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 override
 Get the side number. More...
 
virtual void set_side (side_number side) override
 Set the side number. More...
 
virtual side_contextget_side_context () override
 unwrap More...
 
virtual config to_side_context_config () const override
 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::string > get_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

enum  states { NORMAL , SAVE_GOLD , SPEND_ALL_GOLD , LEADER_IN_DANGER }
 

Private Member Functions

action_result_ptr execute_recall (const std::string &id, data &leader_data)
 A helper function for execute(). More...
 
action_result_ptr execute_recruit (const std::string &type, data &leader_data)
 A helper function for execute(). More...
 
double recall_unit_value (const unit_const_ptr &recall_unit) const
 A helper function for execute(). More...
 
const std::string * get_appropriate_recall (const std::string &type, const data &leader_data) const
 
dataget_best_leader_from_ratio_scores (std::vector< data > &leader_data, const config *job) const
 A helper function for execute(). More...
 
const std::string get_best_recruit_from_scores (const data &leader_data, const config *job)
 A helper function for execute(). More...
 
void compare_cost_maps_and_update_important_hexes (const pathfind::full_cost_map &my_cost_map, const pathfind::full_cost_map &enemy_cost_map)
 For Map Analysis Computes from our cost map and the combined cost map of all enemies the important hexes. More...
 
double get_average_defense (const std::string &unit_type) const
 For Map Analysis. More...
 
const pathfind::full_cost_map get_cost_map_of_side (int side) const
 For Map Analysis. More...
 
void show_important_hexes () const
 For Map Analysis. More...
 
void update_average_lawful_bonus ()
 Calculates a average lawful bonus, so Combat Analysis will work better in caves and custom time of day cycles. More...
 
void update_average_local_cost ()
 For Map Analysis. More...
 
void update_important_hexes ()
 For Map Analysis. More...
 
double compare_unit_types (const std::string &a, const std::string &b)
 For Combat Analysis. More...
 
void do_combat_analysis (std::vector< data > *leader_data)
 Combat Analysis. More...
 
const double * get_cached_combat_value (const std::string &a, const std::string &b, double a_defense, double b_defense)
 For Combat Analysis. More...
 
void simulate_attack (const unit_type *const attacker, const unit_type *const defender, double attacker_defense, double defender_defense, double *damage_to_attacker, double *damage_to_defender) const
 For Combat Analysis. More...
 
configget_most_important_job ()
 For Configuration / Aspect "recruitment-instructions" We call a [recruit] tag a "job". More...
 
const std::string get_random_pattern_type_if_exists (const data &leader_data, const config *job) const
 For Configuration / Aspect "recruitment-instructions" If the flag pattern is set, this method returns a random element of the type-attribute. More...
 
void integrate_recruitment_pattern_in_recruitment_instructions ()
 For Configuration / Aspect "recruitment_pattern" Converts the (old) recruitment_pattern into a recruitment_instruction (job). More...
 
bool leader_matches_job (const data &leader_data, const config *job) const
 For Configuration / Aspect "recruitment-instructions" Checks if a given leader is specified in the "leader_id" attribute. More...
 
bool limit_ok (const std::string &recruit) const
 For Configuration / Aspect "recruitment-instructions" Checks if a recruit-type can be recruited according to the [limit]-tag. More...
 
bool recruit_matches_job (const std::string &recruit, const config *job) const
 For Configuration / Aspect "recruitment-instructions" Checks if a given recruit-type is specified in the "type" attribute. More...
 
bool recruit_matches_type (const std::string &recruit, const std::string &type) const
 For Configuration / Aspect "recruitment-instructions" Checks if a given recruit-type matches one atomic "type" attribute. More...
 
bool recruit_matches_types (const std::string &recruit, const std::vector< std::string > &types) const
 For Configuration / Aspect "recruitment-instructions" Checks if a given recruit-type matches one of the given types. More...
 
bool remove_job_if_no_blocker (config *job)
 For Configuration / Aspect "recruitment-instructions". More...
 
double get_estimated_income (int turns) const
 For Aspect "recruitment_save_gold". More...
 
double get_estimated_unit_gain () const
 For Aspect "recruitment_save_gold". More...
 
double get_estimated_village_gain () const
 For Aspect "recruitment_save_gold". More...
 
double get_unit_ratio () const
 For Aspect "recruitment_save_gold". More...
 
void update_state ()
 For Aspect "recruitment_save_gold". More...
 
void do_randomness (std::vector< data > *leader_data) const
 Will add a random value between 0 and "recruitment_randomness" to all recruits. More...
 
void do_similarity_penalty (std::vector< data > *leader_data) const
 Will give a penalty to similar units. More...
 
int get_cheapest_unit_cost_for_leader (const unit_map::const_iterator &leader)
 Called at the beginning and whenever the recruitment list changes. More...
 
void handle_recruitment_more (std::vector< data > *leader_data) const
 For Aspect "recruitment_more". More...
 
bool is_enemy_in_radius (const map_location &loc, int radius) const
 Helper function. More...
 
void update_own_units_count ()
 
void update_scouts_wanted ()
 This function will use the aspect villages_per_scout to decide how many scouts we want to recruit. More...
 

Private Attributes

std::set< map_locationimportant_hexes_
 
terrain_count_map important_terrain_
 
int own_units_in_combat_counter_
 
std::map< map_location, double > average_local_cost_
 
std::map< std::size_t, int > cheapest_unit_costs_
 
cache_table combat_cache_
 
states state_
 
recruit_situation_change_observer recruit_situation_change_observer_
 
int average_lawful_bonus_
 
config recruitment_instructions_
 
int recruitment_instructions_turn_
 
count_map own_units_count_
 
int total_own_units_
 
int scouts_wanted_
 

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 167 of file recruitment.hpp.

Member Enumeration Documentation

◆ states

Enumerator
NORMAL 
SAVE_GOLD 
SPEND_ALL_GOLD 
LEADER_IN_DANGER 

Definition at line 261 of file recruitment.hpp.

Constructor & Destructor Documentation

◆ recruitment()

ai::default_recruitment::recruitment::recruitment ( rca_context context,
const config cfg 
)

Definition at line 117 of file recruitment.cpp.

References NORMAL, SAVE_GOLD, SPEND_ALL_GOLD, and state_.

◆ ~recruitment()

virtual ai::default_recruitment::recruitment::~recruitment ( )
inlinevirtual

Definition at line 170 of file recruitment.hpp.

Member Function Documentation

◆ compare_cost_maps_and_update_important_hexes()

void ai::default_recruitment::recruitment::compare_cost_maps_and_update_important_hexes ( const pathfind::full_cost_map my_cost_map,
const pathfind::full_cost_map enemy_cost_map 
)
private

For Map Analysis Computes from our cost map and the combined cost map of all enemies the important hexes.

Definition at line 636 of file recruitment.cpp.

References average_local_cost_, gamemap_base::for_each_walkable_loc(), resources::gameboard, pathfind::full_cost_map::get_average_cost_at(), important_hexes_, and game_board::map().

Referenced by update_important_hexes().

◆ compare_unit_types()

double ai::default_recruitment::recruitment::compare_unit_types ( const std::string &  a,
const std::string &  b 
)
private

For Combat Analysis.

Calculates how good unit-type a is against unit type b. If the value is bigger then 0, a is better then b. If the value is 2.0 then unit-type a is twice as good as unit-type b. Since this function is called very often it uses a cache.

Definition at line 892 of file recruitment.cpp.

References b, combat_cache_, unit_type::cost(), ERR_AI_RECRUITMENT, unit_type_data::find(), get_average_defense(), get_cached_combat_value(), unit_type::hitpoints(), simulate_attack(), and unit_types.

Referenced by do_combat_analysis().

◆ do_combat_analysis()

void ai::default_recruitment::recruitment::do_combat_analysis ( std::vector< data > *  leader_data)
private

◆ do_randomness()

void ai::default_recruitment::recruitment::do_randomness ( std::vector< data > *  leader_data) const
private

Will add a random value between 0 and "recruitment_randomness" to all recruits.

Definition at line 1576 of file recruitment.cpp.

References randomness::generator, randomness::rng::get_random_double(), ai::readonly_context_proxy::get_recruitment_randomness(), and ai::default_recruitment::data::scores.

Referenced by execute().

◆ do_similarity_penalty()

void ai::default_recruitment::recruitment::do_similarity_penalty ( std::vector< data > *  leader_data) const
private

Will give a penalty to similar units.

Similar units are units in one advancement tree. Example (Archer can advance to Ranger): before after Elvish Fighter: 50 50 Elvish Archer: 50 25 Elvish Ranger: 50 25

Definition at line 1596 of file recruitment.cpp.

References unit_type::advancement_tree(), unit_type_data::find(), ai::default_recruitment::data::scores, and unit_types.

Referenced by execute().

◆ evaluate()

double ai::default_recruitment::recruitment::evaluate ( )
virtual

◆ execute()

void ai::default_recruitment::recruitment::execute ( )
virtual

Execute the candidate action.

Find important hexes and calculate other static things.

Fill scores.

Do recruitment according to [recruit]-tags and scores. Note that the scores don't indicate the preferred mix to recruit but rather the preferred mix of all units. So already existing units are considered.

Implements ai::candidate_action.

Definition at line 207 of file recruitment.cpp.

References ai::readonly_context_proxy::current_team(), data, game_config::debug, do_combat_analysis(), do_randomness(), do_similarity_penalty(), ai::recall_result::E_NO_GOLD, ai::recruit_result::E_NO_GOLD, ERR_WML, execute_recall(), execute_recruit(), unit_type_data::find(), unit_map::find_leaders(), pathfind::find_vacant_castle(), resources::gameboard, ai::default_recruitment::recruitment::recruit_situation_change_observer::gamestate_changed(), get_appropriate_recall(), get_best_leader_from_ratio_scores(), get_best_recruit_from_scores(), get_cheapest_unit_cost_for_leader(), ai::readonly_context_proxy::get_enemy_dstsrc(), get_most_important_job(), ai::readonly_context_proxy::get_recruitment_save_gold(), ai::side_context_proxy::get_side(), ai::action_result::get_status(), handle_recruitment_more(), important_hexes_, important_terrain_, ai::default_recruitment::data::in_danger, lg::info(), ai::candidate_action::is_allowed_unit(), ai::action_result::is_ok(), LEADER_IN_DANGER, log_ai_recruitment, LOG_AI_RECRUITMENT, lg::log_to_chat(), game_board::map(), NORMAL, map_location::null_location(), own_units_count_, ai::readonly_context_proxy::power_projection(), ai::default_recruitment::data::ratio_score, recall_unit_value(), ai::default_recruitment::recruitment::recruit_situation_change_observer::recruit_list_changed(), recruit_matches_type(), recruit_situation_change_observer_, ai::default_recruitment::data::recruits, remove_job_if_no_blocker(), ai::default_recruitment::recruitment::recruit_situation_change_observer::reset_gamestate_changed(), SAVE_GOLD, ai::default_recruitment::data::scores, scouts_wanted_, show_important_hexes(), team::side(), SPEND_ALL_GOLD, state_, ai::default_recruitment::data::to_string(), resources::tod_manager, total_own_units_, tod_manager::turn(), unit_types, game_board::units(), update_average_lawful_bonus(), update_important_hexes(), update_own_units_count(), update_scouts_wanted(), and update_state().

◆ execute_recall()

action_result_ptr ai::default_recruitment::recruitment::execute_recall ( const std::string &  id,
data leader_data 
)
private

◆ execute_recruit()

action_result_ptr ai::default_recruitment::recruitment::execute_recruit ( const std::string &  type,
data leader_data 
)
private

◆ get_appropriate_recall()

const std::string * ai::default_recruitment::recruitment::get_appropriate_recall ( const std::string &  type,
const data leader_data 
) const
private

◆ get_average_defense()

double ai::default_recruitment::recruitment::get_average_defense ( const std::string &  u_type) const
private

For Map Analysis.

Calculates for a given unit the average defense on the map. (According to important_hexes_ / important_terrain_)

Definition at line 688 of file recruitment.cpp.

References movetype::defense_modifier(), unit_type_data::find(), important_terrain_, unit_type::movement_type(), and unit_types.

Referenced by compare_unit_types().

◆ get_best_leader_from_ratio_scores()

data * ai::default_recruitment::recruitment::get_best_leader_from_ratio_scores ( std::vector< data > &  leader_data,
const config job 
) const
private

A helper function for execute().

Decides according to the leaders ratio scores which leader should recruit.

Definition at line 554 of file recruitment.cpp.

References data, randomness::rng::default_instance(), leader_matches_job(), ai::default_recruitment::data::ratio_score, ai::default_recruitment::data::recruit_count, and gui2::tip_of_the_day::shuffle().

Referenced by execute().

◆ get_best_recruit_from_scores()

const std::string ai::default_recruitment::recruitment::get_best_recruit_from_scores ( const data leader_data,
const config job 
)
private

A helper function for execute().

Counts own units and then decides what unit should be recruited so that the unit distribution approaches the given scores.

Definition at line 592 of file recruitment.cpp.

References ai::default_recruitment::data::get_normalized_scores(), get_random_pattern_type_if_exists(), i, limit_ok(), LOG_AI_RECRUITMENT, own_units_count_, recruit_matches_job(), recruit_matches_type(), scouts_wanted_, and total_own_units_.

Referenced by execute().

◆ get_cached_combat_value()

const double * ai::default_recruitment::recruitment::get_cached_combat_value ( const std::string &  a,
const std::string &  b,
double  a_defense,
double  b_defense 
)
private

For Combat Analysis.

Returns the cached combat value for two unit types or nullptr if there is none or terrain defenses are not within range.

Definition at line 1063 of file recruitment.cpp.

References b, and combat_cache_.

Referenced by compare_unit_types().

◆ get_cheapest_unit_cost_for_leader()

int ai::default_recruitment::recruitment::get_cheapest_unit_cost_for_leader ( const unit_map::const_iterator leader)
private

Called at the beginning and whenever the recruitment list changes.

Definition at line 1634 of file recruitment.cpp.

References cheapest_unit_costs_, ai::readonly_context_proxy::current_team(), unit_type_data::find(), lg::info(), LOG_AI_RECRUITMENT, game_config::recall_cost, team::recall_cost(), and unit_types.

Referenced by evaluate(), and execute().

◆ get_cost_map_of_side()

const pathfind::full_cost_map ai::default_recruitment::recruitment::get_cost_map_of_side ( int  side) const
private

For Map Analysis.

Creates cost maps for a side. Each hex is map to a) the summed movecost and b) how many units can reach this hex for all units of side.

Definition at line 714 of file recruitment.cpp.

References pathfind::full_cost_map::add_unit(), unit::can_recruit(), unit_type_data::find(), unit_map::find_leaders(), resources::gameboard, game_board::get_team(), unit::incapacitated(), team::recruits(), unit::side(), unit::total_movement(), unit_types, and game_board::units().

Referenced by update_important_hexes().

◆ get_estimated_income()

double ai::default_recruitment::recruitment::get_estimated_income ( int  turns) const
private

For Aspect "recruitment_save_gold".

Guess the income over the next turns. This doesn't need to be exact. In the end we are just interested if this value is positive or negative.

Definition at line 1449 of file recruitment.cpp.

References team::base_income(), resources::gameboard, get_estimated_unit_gain(), get_estimated_village_gain(), ai::side_context_proxy::get_side(), game_board::get_team(), i, display_context::side_upkeep(), game_config::village_income, game_config::village_support, and team::villages().

Referenced by update_state().

◆ get_estimated_unit_gain()

double ai::default_recruitment::recruitment::get_estimated_unit_gain ( ) const
private

For Aspect "recruitment_save_gold".

Guess how many units we will gain / loose over the next turns per turn.

Definition at line 1470 of file recruitment.cpp.

References own_units_in_combat_counter_.

Referenced by get_estimated_income().

◆ get_estimated_village_gain()

double ai::default_recruitment::recruitment::get_estimated_village_gain ( ) const
private

For Aspect "recruitment_save_gold".

Guess how many villages we will gain over the next turns per turn.

Definition at line 1478 of file recruitment.cpp.

References resources::gameboard, game_board::map(), utf8::size(), and gamemap::villages().

Referenced by get_estimated_income().

◆ get_most_important_job()

config * ai::default_recruitment::recruitment::get_most_important_job ( )
private

For Configuration / Aspect "recruitment-instructions" We call a [recruit] tag a "job".

Definition at line 1203 of file recruitment.cpp.

References config::child_range(), own_units_count_, recruit_matches_job(), recruitment_instructions_, and update_own_units_count().

Referenced by evaluate(), and execute().

◆ get_random_pattern_type_if_exists()

const std::string ai::default_recruitment::recruitment::get_random_pattern_type_if_exists ( const data leader_data,
const config job 
) const
private

For Configuration / Aspect "recruitment-instructions" If the flag pattern is set, this method returns a random element of the type-attribute.

Definition at line 1244 of file recruitment.cpp.

References randomness::generator, randomness::rng::get_random_int(), limit_ok(), LOG_AI_RECRUITMENT, recruit_matches_type(), ai::default_recruitment::data::recruits, and utils::split().

Referenced by get_best_recruit_from_scores().

◆ get_unit_ratio()

double ai::default_recruitment::recruitment::get_unit_ratio ( ) const
private

◆ handle_recruitment_more()

void ai::default_recruitment::recruitment::handle_recruitment_more ( std::vector< data > *  leader_data) const
private

For Aspect "recruitment_more".

Definition at line 1674 of file recruitment.cpp.

References ai::readonly_context_proxy::get_recruitment_more(), recruit_matches_type(), and ai::default_recruitment::data::scores.

Referenced by execute().

◆ integrate_recruitment_pattern_in_recruitment_instructions()

void ai::default_recruitment::recruitment::integrate_recruitment_pattern_in_recruitment_instructions ( )
private

For Configuration / Aspect "recruitment_pattern" Converts the (old) recruitment_pattern into a recruitment_instruction (job).

Definition at line 1292 of file recruitment.cpp.

References config::add_child(), ai::readonly_context_proxy::get_recruitment_pattern(), recruitment_instructions_, and s.

Referenced by evaluate().

◆ is_enemy_in_radius()

bool ai::default_recruitment::recruitment::is_enemy_in_radius ( const map_location loc,
int  radius 
) const
private

Helper function.

Returns true if there is a enemy within the radius.

Definition at line 1696 of file recruitment.cpp.

References ai::readonly_context_proxy::current_team(), unit_map::end(), unit_map::find(), resources::gameboard, get_tiles_in_radius(), and game_board::units().

Referenced by update_important_hexes().

◆ leader_matches_job()

bool ai::default_recruitment::recruitment::leader_matches_job ( const data leader_data,
const config job 
) const
private

For Configuration / Aspect "recruitment-instructions" Checks if a given leader is specified in the "leader_id" attribute.

Definition at line 1320 of file recruitment.cpp.

References ai::default_recruitment::data::leader, limit_ok(), recruit_matches_job(), ai::default_recruitment::data::recruits, and utils::split().

Referenced by get_best_leader_from_ratio_scores().

◆ limit_ok()

bool ai::default_recruitment::recruitment::limit_ok ( const std::string &  recruit) const
private

For Configuration / Aspect "recruitment-instructions" Checks if a recruit-type can be recruited according to the [limit]-tag.

Definition at line 1347 of file recruitment.cpp.

References ai::readonly_context_proxy::get_recruitment_instructions(), own_units_count_, recruit_matches_types(), and utils::split().

Referenced by get_best_recruit_from_scores(), get_random_pattern_type_if_exists(), and leader_matches_job().

◆ recall_unit_value()

double ai::default_recruitment::recruitment::recall_unit_value ( const unit_const_ptr recall_unit) const
private

A helper function for execute().

Checks if this unit type can be recalled. If yes, we calculate a estimated value in gold of the recall unit. If this value is less then the recall cost, we dismiss the unit. The unit with the highest value will be returned.

Definition at line 497 of file recruitment.cpp.

References unit_type::cost(), ai::readonly_context_proxy::current_team(), unit_type_data::find(), team::recall_cost(), actions::recall_unit(), and unit_types.

Referenced by execute(), and get_appropriate_recall().

◆ recruit_matches_job()

bool ai::default_recruitment::recruitment::recruit_matches_job ( const std::string &  recruit,
const config job 
) const
private

For Configuration / Aspect "recruitment-instructions" Checks if a given recruit-type is specified in the "type" attribute.

Definition at line 1378 of file recruitment.cpp.

References recruit_matches_types(), and utils::split().

Referenced by get_best_recruit_from_scores(), get_most_important_job(), and leader_matches_job().

◆ recruit_matches_type()

bool ai::default_recruitment::recruitment::recruit_matches_type ( const std::string &  recruit,
const std::string &  type 
) const
private

For Configuration / Aspect "recruitment-instructions" Checks if a given recruit-type matches one atomic "type" attribute.

Definition at line 1388 of file recruitment.cpp.

References unit_type_data::find(), unit_type::id(), unit_type::level(), s, unit_types, and unit_type::usage().

Referenced by execute(), get_best_recruit_from_scores(), get_random_pattern_type_if_exists(), handle_recruitment_more(), recruit_matches_types(), and update_scouts_wanted().

◆ recruit_matches_types()

bool ai::default_recruitment::recruitment::recruit_matches_types ( const std::string &  recruit,
const std::vector< std::string > &  types 
) const
private

For Configuration / Aspect "recruitment-instructions" Checks if a given recruit-type matches one of the given types.

Definition at line 1414 of file recruitment.cpp.

References recruit_matches_type().

Referenced by limit_ok(), and recruit_matches_job().

◆ remove_job_if_no_blocker()

bool ai::default_recruitment::recruitment::remove_job_if_no_blocker ( config job)
private

For Configuration / Aspect "recruitment-instructions".

Definition at line 1431 of file recruitment.cpp.

References config::clear(), and LOG_AI_RECRUITMENT.

Referenced by execute().

◆ show_important_hexes()

void ai::default_recruitment::recruitment::show_important_hexes ( ) const
private

For Map Analysis.

Shows the important hexes for debugging purposes on the map. Only if debug is activated.

Definition at line 753 of file recruitment.cpp.

References map_labels::clear_all(), game_config::debug, display::get_singleton(), important_hexes_, display::labels(), map_location::north, and map_labels::set_label().

Referenced by execute().

◆ simulate_attack()

void ai::default_recruitment::recruitment::simulate_attack ( const unit_type *const  attacker,
const unit_type *const  defender,
double  attacker_defense,
double  defender_defense,
double *  damage_to_attacker,
double *  damage_to_defender 
) const
private

For Combat Analysis.

Simulates a attack with a attacker and a defender. The function will use battle_context::better_combat() to decide which weapon to use.

Definition at line 1149 of file recruitment.cpp.

References unit_type::attacks(), average_lawful_bonus_, ERR_AI_RECRUITMENT, and unit_type::hitpoints().

Referenced by compare_unit_types().

◆ to_config()

config ai::default_recruitment::recruitment::to_config ( ) const
virtual

serialize

Reimplemented from ai::candidate_action.

Definition at line 142 of file recruitment.cpp.

References SAVE_GOLD, SPEND_ALL_GOLD, state_, and ai::candidate_action::to_config().

◆ update_average_lawful_bonus()

void ai::default_recruitment::recruitment::update_average_lawful_bonus ( )
private

Calculates a average lawful bonus, so Combat Analysis will work better in caves and custom time of day cycles.

Definition at line 768 of file recruitment.cpp.

References average_lawful_bonus_, and resources::tod_manager.

Referenced by execute().

◆ update_average_local_cost()

void ai::default_recruitment::recruitment::update_average_local_cost ( )
private

◆ update_important_hexes()

void ai::default_recruitment::recruitment::update_important_hexes ( )
private

◆ update_own_units_count()

void ai::default_recruitment::recruitment::update_own_units_count ( )
private

◆ update_scouts_wanted()

void ai::default_recruitment::recruitment::update_scouts_wanted ( )
private

This function will use the aspect villages_per_scout to decide how many scouts we want to recruit.

Definition at line 1739 of file recruitment.cpp.

References resources::gameboard, ai::readonly_context_proxy::get_villages_per_scout(), own_units_count_, recruit_matches_type(), and scouts_wanted_.

Referenced by execute().

◆ update_state()

void ai::default_recruitment::recruitment::update_state ( )
private

Member Data Documentation

◆ average_lawful_bonus_

int ai::default_recruitment::recruitment::average_lawful_bonus_
private

Definition at line 264 of file recruitment.hpp.

Referenced by simulate_attack(), and update_average_lawful_bonus().

◆ average_local_cost_

std::map<map_location, double> ai::default_recruitment::recruitment::average_local_cost_
private

◆ cheapest_unit_costs_

std::map<std::size_t, int> ai::default_recruitment::recruitment::cheapest_unit_costs_
private

Definition at line 259 of file recruitment.hpp.

Referenced by evaluate(), and get_cheapest_unit_cost_for_leader().

◆ combat_cache_

cache_table ai::default_recruitment::recruitment::combat_cache_
private

Definition at line 260 of file recruitment.hpp.

Referenced by compare_unit_types(), and get_cached_combat_value().

◆ important_hexes_

std::set<map_location> ai::default_recruitment::recruitment::important_hexes_
private

◆ important_terrain_

terrain_count_map ai::default_recruitment::recruitment::important_terrain_
private

Definition at line 256 of file recruitment.hpp.

Referenced by execute(), get_average_defense(), and update_important_hexes().

◆ own_units_count_

count_map ai::default_recruitment::recruitment::own_units_count_
private

◆ own_units_in_combat_counter_

int ai::default_recruitment::recruitment::own_units_in_combat_counter_
private

Definition at line 257 of file recruitment.hpp.

Referenced by get_estimated_unit_gain(), and update_important_hexes().

◆ recruit_situation_change_observer_

recruit_situation_change_observer ai::default_recruitment::recruitment::recruit_situation_change_observer_
private

Definition at line 263 of file recruitment.hpp.

Referenced by evaluate(), and execute().

◆ recruitment_instructions_

config ai::default_recruitment::recruitment::recruitment_instructions_
private

◆ recruitment_instructions_turn_

int ai::default_recruitment::recruitment::recruitment_instructions_turn_
private

Definition at line 266 of file recruitment.hpp.

Referenced by evaluate().

◆ scouts_wanted_

int ai::default_recruitment::recruitment::scouts_wanted_
private

Definition at line 269 of file recruitment.hpp.

Referenced by execute(), get_best_recruit_from_scores(), and update_scouts_wanted().

◆ state_

states ai::default_recruitment::recruitment::state_
private

Definition at line 262 of file recruitment.hpp.

Referenced by execute(), recruitment(), to_config(), and update_state().

◆ total_own_units_

int ai::default_recruitment::recruitment::total_own_units_
private

Definition at line 268 of file recruitment.hpp.

Referenced by execute(), get_best_recruit_from_scores(), and update_own_units_count().


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