#include <recruitment.hpp>
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_filter > | get_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_context & | get_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_context & | get_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_context & | get_default_ai_context () |
virtual std::vector< target > | find_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_context & | get_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 team & | current_team_w () override |
virtual void | raise_gamestate_changed () const override |
virtual game_info & | get_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_context & | get_readonly_context () override |
virtual void | on_readonly_context_create () override |
virtual const team & | current_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_info & | get_info () const override |
virtual void | raise_user_interact () const override |
const defensive_position & | 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 bool | get_allow_ally_villages () const override |
virtual const aspect_map & | get_aspects () const override |
virtual aspect_map & | get_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_vector & | get_attacks () const override |
virtual const wfl::variant & | get_attacks_as_variant () const override |
virtual const terrain_filter & | get_avoid () const override |
virtual double | get_caution () const override |
virtual const move_map & | get_dstsrc () const override |
virtual const move_map & | get_enemy_dstsrc () const override |
virtual const moves_map & | get_enemy_possible_moves () const override |
virtual const move_map & | get_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_map & | get_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_map & | get_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_location & | nearest_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_location & | suitable_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_t & | unit_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_context & | get_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 component * | get_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_map & | property_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 |
data * | get_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... | |
config * | get_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_location > | important_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 |
Definition at line 167 of file recruitment.hpp.
|
private |
Enumerator | |
---|---|
NORMAL | |
SAVE_GOLD | |
SPEND_ALL_GOLD | |
LEADER_IN_DANGER |
Definition at line 261 of file recruitment.hpp.
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_.
|
inlinevirtual |
Definition at line 170 of file recruitment.hpp.
|
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_, loc, and game_board::map().
Referenced by update_important_hexes().
|
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().
|
private |
Combat Analysis.
Main function. Compares all enemy units with all of our possible recruits and fills the scores.
Definition at line 957 of file recruitment.cpp.
References compare_unit_types(), ai::readonly_context_proxy::current_team(), unit_type_data::find(), unit_map::find_leaders(), resources::gameboard, ai::readonly_context_proxy::get_recruitment_diversity(), unit_type::hitpoints(), unit::hitpoints(), unit::incapacitated(), unit_map::insert(), team::recruits(), team::side(), unit::side(), unit::type_id(), unit_types, and game_board::units().
Referenced by execute().
|
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().
|
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().
|
virtual |
Evaluate the candidate action, resetting the internal state of the action.
>0 | if the action is good |
<=0 | if the action is not good |
Implements ai::candidate_action.
Definition at line 154 of file recruitment.cpp.
References ai::candidate_action::BAD_SCORE, cheapest_unit_costs_, ai::readonly_context_proxy::current_team(), unit_map::find_leaders(), pathfind::find_vacant_castle(), resources::gameboard, get_cheapest_unit_cost_for_leader(), get_most_important_job(), ai::readonly_context_proxy::get_recruitment_instructions(), ai::candidate_action::get_score(), ai::side_context_proxy::get_side(), integrate_recruitment_pattern_in_recruitment_instructions(), ai::candidate_action::is_allowed_unit(), loc, LOG_AI_RECRUITMENT, map_location::null_location(), ai::default_recruitment::recruitment::recruit_situation_change_observer::recruit_list_changed(), recruit_situation_change_observer_, recruitment_instructions_, recruitment_instructions_turn_, ai::default_recruitment::recruitment::recruit_situation_change_observer::set_recruit_list_changed(), resources::tod_manager, tod_manager::turn(), and game_board::units().
|
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().
|
private |
A helper function for execute().
Definition at line 462 of file recruitment.cpp.
References ai::readonly_context_proxy::check_recall_action(), ai::action_result::execute(), ai::action_result::is_ok(), ai::default_recruitment::data::leader, map_location::null_location(), and ai::default_recruitment::data::recruit_count.
Referenced by execute().
|
private |
A helper function for execute().
Definition at line 476 of file recruitment.cpp.
References ai::readonly_context_proxy::check_recruit_action(), ai::action_result::execute(), ai::action_result::is_ok(), ai::default_recruitment::data::leader, LOG_AI_RECRUITMENT, map_location::null_location(), and ai::default_recruitment::data::recruit_count.
Referenced by execute().
|
private |
Definition at line 527 of file recruitment.cpp.
References ai::readonly_context_proxy::current_team(), ai::default_recruitment::data::leader, LOG_AI_RECRUITMENT, map_location::null_location(), actions::recall_unit(), and recall_unit_value().
Referenced by execute().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
private |
For Aspect "recruitment_save_gold".
Returns our_total_unit_costs / enemy_total_unit_costs.
Definition at line 1493 of file recruitment.cpp.
References unit::can_recruit(), unit::cost(), ai::readonly_context_proxy::current_team(), resources::gameboard, unit::hitpoints(), unit::incapacitated(), team::is_enemy(), unit::max_hitpoints(), team::side(), unit::side(), unit::total_movement(), and game_board::units().
Referenced by update_state().
|
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().
|
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().
|
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(), loc, and game_board::units().
Referenced by update_important_hexes().
|
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 utils::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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
private |
For Configuration / Aspect "recruitment-instructions".
Definition at line 1431 of file recruitment.cpp.
References config::clear(), and LOG_AI_RECRUITMENT.
Referenced by execute().
|
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, map_location::get_direction(), display::get_singleton(), important_hexes_, display::labels(), loc, map_location::north, and map_labels::set_label().
Referenced by execute().
|
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().
|
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().
|
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().
|
private |
For Map Analysis.
Creates a map where each hex is mapped to the average cost of the terrain for our units.
Definition at line 784 of file recruitment.cpp.
References average_local_cost_, movetype::terrain_costs::cost(), unit_type_data::find(), resources::gameboard, movetype::get_movement(), ai::side_context_proxy::get_side(), game_board::get_team(), gamemap_base::h(), loc, game_board::map(), unit_type::movement_type(), team::recruits(), unit_types, and gamemap_base::w().
Referenced by update_important_hexes().
|
private |
For Map Analysis.
Creates a std::set of hexes where a fight will occur with high probability.
Definition at line 814 of file recruitment.cpp.
References compare_cost_maps_and_update_important_hexes(), ai::readonly_context_proxy::current_team(), resources::gameboard, pathfind::full_cost_map::get_cost_at(), get_cost_map_of_side(), unit::get_location(), ai::side_context_proxy::get_side(), get_tiles_in_radius(), important_hexes_, important_terrain_, is_enemy_in_radius(), game_board::map(), gamemap_base::on_board(), own_units_in_combat_counter_, team::side(), unit::side(), game_board::units(), update_average_local_cost(), and gamemap::villages().
Referenced by execute().
|
private |
Definition at line 1721 of file recruitment.cpp.
References unit::can_recruit(), resources::gameboard, ai::side_context_proxy::get_side(), unit::incapacitated(), own_units_count_, unit::side(), unit::total_movement(), total_own_units_, unit::type_id(), and game_board::units().
Referenced by execute(), and get_most_important_job().
|
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().
|
private |
For Aspect "recruitment_save_gold".
Main method.
Definition at line 1540 of file recruitment.cpp.
References ai::readonly_context_proxy::current_team(), get_estimated_income(), ai::readonly_context_proxy::get_recruitment_save_gold(), get_unit_ratio(), LEADER_IN_DANGER, LOG_AI_RECRUITMENT, NORMAL, SAVE_GOLD, SPEND_ALL_GOLD, and state_.
Referenced by execute().
|
private |
Definition at line 264 of file recruitment.hpp.
Referenced by simulate_attack(), and update_average_lawful_bonus().
|
private |
Definition at line 258 of file recruitment.hpp.
Referenced by compare_cost_maps_and_update_important_hexes(), and update_average_local_cost().
|
private |
Definition at line 259 of file recruitment.hpp.
Referenced by evaluate(), and get_cheapest_unit_cost_for_leader().
|
private |
Definition at line 260 of file recruitment.hpp.
Referenced by compare_unit_types(), and get_cached_combat_value().
|
private |
Definition at line 255 of file recruitment.hpp.
Referenced by compare_cost_maps_and_update_important_hexes(), execute(), show_important_hexes(), and update_important_hexes().
|
private |
Definition at line 256 of file recruitment.hpp.
Referenced by execute(), get_average_defense(), and update_important_hexes().
|
private |
Definition at line 267 of file recruitment.hpp.
Referenced by execute(), get_best_recruit_from_scores(), get_most_important_job(), limit_ok(), update_own_units_count(), and update_scouts_wanted().
|
private |
Definition at line 257 of file recruitment.hpp.
Referenced by get_estimated_unit_gain(), and update_important_hexes().
|
private |
Definition at line 263 of file recruitment.hpp.
Referenced by evaluate(), and execute().
|
private |
Definition at line 265 of file recruitment.hpp.
Referenced by evaluate(), get_most_important_job(), and integrate_recruitment_pattern_in_recruitment_instructions().
|
private |
Definition at line 266 of file recruitment.hpp.
Referenced by evaluate().
|
private |
Definition at line 269 of file recruitment.hpp.
Referenced by execute(), get_best_recruit_from_scores(), and update_scouts_wanted().
|
private |
Definition at line 262 of file recruitment.hpp.
Referenced by execute(), recruitment(), to_config(), and update_state().
|
private |
Definition at line 268 of file recruitment.hpp.
Referenced by execute(), get_best_recruit_from_scores(), and update_own_units_count().