The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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:
Inheritance graph

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...
 
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
 
defensive_position const & best_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_aspect
get_advancements () const override
 
virtual double get_aggression () const override
 
virtual int get_attack_depth () 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 bool get_leader_ignores_keep () const override
 
virtual double get_leader_value () const override
 
virtual bool get_passive_leader () const override
 
virtual bool 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 const std::vector
< unit_ptr > & 
get_recall_list () const override
 
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_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_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) 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...
 
const std::string * get_appropriate_recall (const std::string &type, const data &leader_data) const
 A helper function for execute(). More...
 
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< 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 185 of file recruitment.hpp.

Member Enumeration Documentation

Enumerator
NORMAL 
SAVE_GOLD 
SPEND_ALL_GOLD 
LEADER_IN_DANGER 

Definition at line 278 of file recruitment.hpp.

Constructor & Destructor Documentation

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

Definition at line 106 of file recruitment.cpp.

References NORMAL, SAVE_GOLD, SPEND_ALL_GOLD, and state_.

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

Definition at line 188 of file recruitment.hpp.

Member Function Documentation

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 599 of file recruitment.cpp.

References average_local_cost_, resources::gameboard, pathfind::full_cost_map::get_average_cost_at(), gamemap::h(), important_hexes_, game_board::map(), and gamemap::w().

Referenced by update_important_hexes().

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 855 of file recruitment.cpp.

References a, b, gui2::cache, 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().

void ai::default_recruitment::recruitment::do_combat_analysis ( std::vector< data > *  leader_data)
private
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 1539 of file recruitment.cpp.

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

Referenced by execute().

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 1559 of file recruitment.cpp.

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

Referenced by execute().

double ai::default_recruitment::recruitment::evaluate ( )
virtual
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 190 of file recruitment.cpp.

References ai::readonly_context_proxy::current_team(), game_config::debug, do_combat_analysis(), do_randomness(), do_similarity_penalty(), ai::recall_result::E_NO_GOLD, ai::recruit_result::E_NO_GOLD, execute_recall(), execute_recruit(), resources::filter_con, 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(), handle_recruitment_more(), important_hexes_, important_terrain_, ai::default_recruitment::data::in_danger, lg::info(), LEADER_IN_DANGER, log_ai_recruitment, LOG_AI_RECRUITMENT, game_board::map(), NORMAL, map_location::null_location(), own_units_count_, ai::readonly_context_proxy::power_projection(), ai::default_recruitment::data::ratio_score, 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, resources::units, game_board::units(), update_average_lawful_bonus(), update_important_hexes(), update_own_units_count(), update_scouts_wanted(), update_state(), and lg::wml_error().

action_result_ptr ai::default_recruitment::recruitment::execute_recall ( const std::string &  id,
data leader_data 
)
private
action_result_ptr ai::default_recruitment::recruitment::execute_recruit ( const std::string &  type,
data leader_data 
)
private
const std::string * ai::default_recruitment::recruitment::get_appropriate_recall ( const std::string &  type,
const data leader_data 
) 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 469 of file recruitment.cpp.

References unit_type::cost(), ai::readonly_context_proxy::current_team(), resources::filter_con, unit_type_data::find(), ai::default_recruitment::data::leader, LOG_AI_RECRUITMENT, map_location::null_location(), game_config::recall_cost, actions::recall_unit(), and unit_types.

Referenced by execute().

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 651 of file recruitment.cpp.

References preferences::editor::TransitionUpdateMode::count, defense, movetype::defense_modifier(), unit_type_data::find(), important_terrain_, unit_type::movement_type(), gui2::terrain, and unit_types.

Referenced by compare_unit_types().

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 517 of file recruitment.cpp.

References 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().

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 555 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().

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 1026 of file recruitment.cpp.

References a, b, gui2::cache, and combat_cache_.

Referenced by compare_unit_types().

int ai::default_recruitment::recruitment::get_cheapest_unit_cost_for_leader ( const unit_map::const_iterator leader)
private
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 677 of file recruitment.cpp.

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

Referenced by update_important_hexes().

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 1412 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(), preferences::turns(), game_config::village_income, game_config::village_support, and team::villages().

Referenced by update_state().

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 1433 of file recruitment.cpp.

References own_units_in_combat_counter_.

Referenced by get_estimated_income().

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 1441 of file recruitment.cpp.

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

Referenced by get_estimated_income().

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 1166 of file recruitment.cpp.

References config::child_range(), preferences::editor::TransitionUpdateMode::count, own_units_count_, recruit_matches_job(), recruitment_instructions_, and update_own_units_count().

Referenced by evaluate(), and execute().

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 1207 of file recruitment.cpp.

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

Referenced by get_best_recruit_from_scores().

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

For Aspect "recruitment_more".

Definition at line 1637 of file recruitment.cpp.

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

Referenced by execute().

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 1255 of file recruitment.cpp.

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

Referenced by evaluate().

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 1659 of file recruitment.cpp.

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

Referenced by update_important_hexes().

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 1283 of file recruitment.cpp.

References gui2::event::find(), 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().

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 1310 of file recruitment.cpp.

References config::child_range(), preferences::editor::TransitionUpdateMode::count, 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().

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 1341 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().

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 1351 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().

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 1377 of file recruitment.cpp.

References recruit_matches_type().

Referenced by limit_ok(), and recruit_matches_job().

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

For Configuration / Aspect "recruitment-instructions".

Definition at line 1394 of file recruitment.cpp.

References config::clear(), and LOG_AI_RECRUITMENT.

Referenced by execute().

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 716 of file recruitment.cpp.

References map_labels::clear_all(), game_config::debug, important_hexes_, display::labels(), map_location::NORTH, resources::screen, and map_labels::set_label().

Referenced by execute().

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 1112 of file recruitment.cpp.

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

Referenced by compare_unit_types().

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

serialize

Reimplemented from ai::candidate_action.

Definition at line 131 of file recruitment.cpp.

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

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 731 of file recruitment.cpp.

References average_lawful_bonus_, round_double(), and resources::tod_manager.

Referenced by execute().

void ai::default_recruitment::recruitment::update_average_local_cost ( )
private
void ai::default_recruitment::recruitment::update_important_hexes ( )
private
void ai::default_recruitment::recruitment::update_own_units_count ( )
private
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 1702 of file recruitment.cpp.

References preferences::editor::TransitionUpdateMode::count, resources::gameboard, ai::readonly_context_proxy::get_villages_per_scout(), own_units_count_, recruit_matches_type(), round_double(), and scouts_wanted_.

Referenced by execute().

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

Member Data Documentation

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

Definition at line 281 of file recruitment.hpp.

Referenced by simulate_attack(), and update_average_lawful_bonus().

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

Definition at line 276 of file recruitment.hpp.

Referenced by evaluate(), and get_cheapest_unit_cost_for_leader().

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

Definition at line 277 of file recruitment.hpp.

Referenced by compare_unit_types(), and get_cached_combat_value().

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

Definition at line 273 of file recruitment.hpp.

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

count_map ai::default_recruitment::recruitment::own_units_count_
private
int ai::default_recruitment::recruitment::own_units_in_combat_counter_
private

Definition at line 274 of file recruitment.hpp.

Referenced by get_estimated_unit_gain(), and update_important_hexes().

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

Definition at line 280 of file recruitment.hpp.

Referenced by evaluate(), and execute().

config ai::default_recruitment::recruitment::recruitment_instructions_
private
int ai::default_recruitment::recruitment::recruitment_instructions_turn_
private

Definition at line 283 of file recruitment.hpp.

Referenced by evaluate().

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

Definition at line 286 of file recruitment.hpp.

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

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

Definition at line 279 of file recruitment.hpp.

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

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

Definition at line 285 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: