The Battle for Wesnoth  1.19.4+dev
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ai::readonly_context_impl Class Reference

#include <contexts.hpp>

Inheritance diagram for ai::readonly_context_impl:

Public Member Functions

 readonly_context_impl (side_context &context, const config &cfg)
 Constructor. More...
 
virtual ~readonly_context_impl ()
 Destructor. More...
 
virtual readonly_contextget_readonly_context () override
 
virtual void on_readonly_context_create () override
 
virtual void handle_generic_event (const std::string &event_name) override
 Handle generic event. More...
 
const teamcurrent_team () const override
 Return a reference to the 'team' object for the AI. More...
 
void diagnostic (const std::string &msg) override
 Show a diagnostic message on the screen. More...
 
void log_message (const std::string &msg) override
 Display a debug message as a chat message. More...
 
attack_result_ptr check_attack_action (const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
 Check if it is possible to attack enemy defender using our unit attacker from attackers current location,. More...
 
move_result_ptr check_move_action (const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) override
 Check if it is possible to move our unit from location 'from' to location 'to'. More...
 
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
 Check if it is possible to recall a unit for us on specified location. More...
 
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
 Check if it is possible to recruit a unit for us on specified location. More...
 
stopunit_result_ptr check_stopunit_action (const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) override
 Check if it is possible to remove unit movements and/or attack. More...
 
synced_command_result_ptr check_synced_command_action (const std::string &lua_code, const map_location &location=map_location::null_location()) override
 Check if it is possible to run Lua code. More...
 
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
 Calculate the moves units may possibly make. More...
 
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
 A more fundamental version of calculate_possible_moves which allows the use of a speculative unit map. More...
 
virtual const game_infoget_info () const override
 
void raise_user_interact () const override
 Function which should be called frequently to allow the user to interact with the interface. More...
 
virtual int get_recursion_count () const override
 Get the value of the recursion counter. More...
 
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 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 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 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 const move_mapget_srcdst () 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 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 void recalculate_move_maps () const override
 
virtual void recalculate_move_maps_enemy () const override
 
virtual void add_aspects (std::vector< aspect_ptr > &aspects) override
 
virtual void add_facet (const std::string &id, const config &cfg) const override
 
void on_create ()
 
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
 Weapon choice cache, to speed simulations. More...
 
- 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::side_context
virtual ~side_context ()
 empty destructor More...
 
 side_context ()
 empty constructor More...
 
- Public Member Functions inherited from ai::readonly_context
 readonly_context ()
 
virtual ~readonly_context ()
 
- Public Member Functions inherited from events::observer
virtual ~observer ()
 

Private Member Functions

template<typename T >
void add_known_aspect (const std::string &name, typesafe_aspect_ptr< T > &where)
 
bool applies_to_leader (const utils::variant< bool, std::vector< std::string >> &aspect_value, const std::string &id) const
 

Private Attributes

const config cfg_
 
std::vector< engine_ptrengines_
 AI Support Engines. More...
 
known_aspect_map known_aspects_
 
typesafe_aspect_ptr< unit_advancements_aspectadvancements_
 
typesafe_aspect_ptr< double > aggression_
 
typesafe_aspect_ptr< bool > allow_ally_villages_
 
aspect_map aspects_
 
typesafe_aspect_ptr< attacks_vectorattacks_
 
typesafe_aspect_ptr< terrain_filteravoid_
 
typesafe_aspect_ptr< double > caution_
 
std::map< map_location, defensive_positiondefensive_position_cache_
 
move_map dstsrc_
 
move_map enemy_dstsrc_
 
moves_map enemy_possible_moves_
 
move_map enemy_srcdst_
 
typesafe_aspect_ptr< std::string > grouping_
 
std::vector< goal_ptrgoals_
 
keeps_cache keeps_
 
typesafe_aspect_ptr< double > leader_aggression_
 
typesafe_aspect_ptr< configleader_goal_
 
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > leader_ignores_keep_
 
typesafe_aspect_ptr< double > leader_value_
 
bool move_maps_enemy_valid_
 
bool move_maps_valid_
 
bool dst_src_valid_lua_
 
bool dst_src_enemy_valid_lua_
 
bool src_dst_valid_lua_
 
bool src_dst_enemy_valid_lua_
 
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > passive_leader_
 
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > passive_leader_shares_keep_
 
moves_map possible_moves_
 
typesafe_aspect_ptr< double > recruitment_diversity_
 
typesafe_aspect_ptr< configrecruitment_instructions_
 
typesafe_aspect_ptr< std::vector< std::string > > recruitment_more_
 
typesafe_aspect_ptr< std::vector< std::string > > recruitment_pattern_
 
typesafe_aspect_ptr< int > recruitment_randomness_
 
typesafe_aspect_ptr< configrecruitment_save_gold_
 
recursion_counter recursion_counter_
 
typesafe_aspect_ptr< double > retreat_enemy_weight_
 
typesafe_aspect_ptr< double > retreat_factor_
 
typesafe_aspect_ptr< double > scout_village_targeting_
 
typesafe_aspect_ptr< bool > simple_targeting_
 
move_map srcdst_
 
typesafe_aspect_ptr< bool > support_villages_
 
unit_stats_cache_t unit_stats_cache_
 
typesafe_aspect_ptr< double > village_value_
 
typesafe_aspect_ptr< int > villages_per_scout_
 

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
 

Detailed Description

Definition at line 986 of file contexts.hpp.

Constructor & Destructor Documentation

◆ readonly_context_impl()

ai::readonly_context_impl::readonly_context_impl ( side_context context,
const config cfg 
)

◆ ~readonly_context_impl()

ai::readonly_context_impl::~readonly_context_impl ( )
virtual

Destructor.

Definition at line 285 of file contexts.cpp.

References ai::manager::get_singleton(), and ai::manager::remove_gamestate_observer().

Member Function Documentation

◆ add_aspects()

void ai::readonly_context_impl::add_aspects ( std::vector< aspect_ptr > &  aspects)
overridevirtual

Implements ai::readonly_context.

Definition at line 424 of file contexts.cpp.

References ERR_AI, i, and known_aspects_.

Referenced by on_readonly_context_create().

◆ add_facet()

void ai::readonly_context_impl::add_facet ( const std::string &  id,
const config cfg 
) const
overridevirtual

Implements ai::readonly_context.

Definition at line 437 of file contexts.cpp.

References ERR_AI, i, and known_aspects_.

◆ add_known_aspect()

template<typename T >
void ai::readonly_context_impl::add_known_aspect ( const std::string &  name,
typesafe_aspect_ptr< T > &  where 
)
private

Definition at line 156 of file contexts.cpp.

References aspects_, and known_aspects_.

Referenced by readonly_context_impl().

◆ applies_to_leader()

bool ai::readonly_context_impl::applies_to_leader ( const utils::variant< bool, std::vector< std::string >> &  aspect_value,
const std::string &  id 
) const
private

◆ best_defensive_position()

const defensive_position & ai::readonly_context_impl::best_defensive_position ( const map_location unit,
const move_map dstsrc,
const move_map srcdst,
const move_map enemy_dstsrc 
) const
overridevirtual

◆ calculate_moves()

void ai::readonly_context_impl::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
overridevirtual

A more fundamental version of calculate_possible_moves which allows the use of a speculative unit map.

NOTE: Support for a speculative map is broken (not used when pathfinding) and has not been used since (probably) r38610 (September 2009). (See the TODO in the implementation.)

TODO: This is where support for a speculative unit map is incomplete. There are several places (deep) within the paths constructor where resources::gameboard->units() is assumed to be the unit map. Rather than introduce a new parameter to numerous functions, a better solution may be for the creator of the speculative map (if one is used in the future) to cause resources::gameboard->units() to point to that map (and restore the "real" pointer when the speculating is completed). If that approach is adopted, calculate_moves() and calculate_possible_moves() become redundant, and one of them should probably be eliminated.

Implements ai::readonly_context.

Definition at line 330 of file contexts.cpp.

References unit_map::begin(), pathfind::paths::step::curr, current_team(), dst, unit_map::end(), enemy, resources::gameboard, ai::side_context_proxy::get_side(), src, and t.

Referenced by calculate_possible_moves().

◆ calculate_possible_moves()

void ai::readonly_context_impl::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
overridevirtual

Calculate the moves units may possibly make.

Parameters
possible_movesA map which will be filled with the paths each unit can take to get to every possible destination. You probably don't want to use this object at all, except to pass to 'move_unit'.
srcdstA map of units to all their possible destinations.
dstsrcA map of destinations to all the units that can move to that destination.
enemyif true, a map of possible moves for enemies will be calculated. If false, a map of possible moves for units on the AI's side will be calculated. The AI's own leader will not be included in this map.
assume_full_movementIf true, the function will operate on the assumption that all units can move their full movement allotment.
remove_destinationsa pointer to a terrain filter for possible destinations to omit.

Implements ai::readonly_context.

Definition at line 323 of file contexts.cpp.

References calculate_moves(), enemy, and resources::gameboard.

Referenced by recalculate_move_maps(), and recalculate_move_maps_enemy().

◆ check_attack_action()

attack_result_ptr ai::readonly_context_impl::check_attack_action ( const map_location attacker_loc,
const map_location defender_loc,
int  attacker_weapon 
)
overridevirtual

Check if it is possible to attack enemy defender using our unit attacker from attackers current location,.

Parameters
attacker_loclocation of attacker
defender_loclocation of defender
attacker_weaponweapon of attacker
Return values
possibleresults: ok, something wrong, attacker and/or defender are invalid, attacker and/or defender are invalid, or attacker doesn't have the specified weapon

Implements ai::readonly_context.

Definition at line 109 of file contexts.cpp.

References ai::actions::execute_attack_action(), unit_map::find(), resources::gameboard, get_aggression(), get_leader_aggression(), ai::side_context_proxy::get_side(), i, and game_board::units().

◆ check_move_action()

move_result_ptr ai::readonly_context_impl::check_move_action ( const map_location from,
const map_location to,
bool  remove_movement = true,
bool  unreach_is_ok = false 
)
overridevirtual

Check if it is possible to move our unit from location 'from' to location 'to'.

Parameters
fromlocation of our unit
towhere to move
remove_movementset unit movement to 0 in case of successful move
unreach_is_okwhether it's okay for a destination to be unreachable
Return values
possibleresults: ok, something wrong, move is interrupted, or move is impossible

Implements ai::readonly_context.

Definition at line 119 of file contexts.cpp.

References ai::actions::execute_move_action(), and ai::side_context_proxy::get_side().

◆ check_recall_action()

recall_result_ptr ai::readonly_context_impl::check_recall_action ( const std::string &  id,
const map_location where = map_location::null_location(),
const map_location from = map_location::null_location() 
)
overridevirtual

Check if it is possible to recall a unit for us on specified location.

Parameters
idthe id of the unit to be recruited.
wherelocation where the unit is to be recruited.
fromlocation of the recaller.
Return values
possibleresults: ok, something wrong, leader not on keep, no free space on keep, or not enough gold

Implements ai::readonly_context.

Definition at line 131 of file contexts.cpp.

References ai::actions::execute_recall_action(), and ai::side_context_proxy::get_side().

◆ check_recruit_action()

recruit_result_ptr ai::readonly_context_impl::check_recruit_action ( const std::string &  unit_name,
const map_location where = map_location::null_location(),
const map_location from = map_location::null_location() 
)
overridevirtual

Check if it is possible to recruit a unit for us on specified location.

Parameters
unit_namethe name of the unit to be recruited.
wherelocation where the unit is to be recruited.
fromlocation of the recruiter.
Return values
possibleresults: ok, something wrong, leader not on keep, no free space on keep, or not enough gold

Implements ai::readonly_context.

Definition at line 135 of file contexts.cpp.

References ai::actions::execute_recruit_action(), ai::side_context_proxy::get_side(), and unit_name().

◆ check_stopunit_action()

stopunit_result_ptr ai::readonly_context_impl::check_stopunit_action ( const map_location unit_location,
bool  remove_movement = true,
bool  remove_attacks = false 
)
overridevirtual

Check if it is possible to remove unit movements and/or attack.

Parameters
unit_locationthe location of our unit
remove_movementset remaining movements to 0
remove_attacksset remaining attacks to 0
Return values
possibleresults: ok, something wrong, or nothing to do

Implements ai::readonly_context.

Definition at line 143 of file contexts.cpp.

References ai::actions::execute_stopunit_action(), and ai::side_context_proxy::get_side().

◆ check_synced_command_action()

synced_command_result_ptr ai::readonly_context_impl::check_synced_command_action ( const std::string &  lua_code,
const map_location location = map_location::null_location() 
)
overridevirtual

Check if it is possible to run Lua code.

Parameters
lua_codethe code to be run
locationlocation to be passed to the code as x1/y1
Return values
possibleresults: ok, something wrong, or nothing to do

Implements ai::readonly_context.

Definition at line 151 of file contexts.cpp.

References ai::actions::execute_synced_command_action(), and ai::side_context_proxy::get_side().

◆ current_team()

const team & ai::readonly_context_impl::current_team ( ) const
overridevirtual

Return a reference to the 'team' object for the AI.

Implements ai::readonly_context.

Definition at line 310 of file contexts.cpp.

References resources::gameboard, ai::side_context_proxy::get_side(), and game_board::get_team().

Referenced by calculate_moves(), and leader_can_reach_keep().

◆ defensive_position_cache()

std::map< map_location, defensive_position > & ai::readonly_context_impl::defensive_position_cache ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 493 of file contexts.cpp.

References defensive_position_cache_.

◆ diagnostic()

void ai::readonly_context_impl::diagnostic ( const std::string &  msg)
overridevirtual

Show a diagnostic message on the screen.

Implements ai::readonly_context.

Definition at line 303 of file contexts.cpp.

References game_config::debug, display::get_singleton(), wfl::msg(), and display::set_diagnostic().

◆ get_advancements()

const unit_advancements_aspect & ai::readonly_context_impl::get_advancements ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 498 of file contexts.cpp.

References advancements_.

◆ get_aggression()

double ai::readonly_context_impl::get_aggression ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 508 of file contexts.cpp.

References aggression_.

Referenced by check_attack_action().

◆ get_allow_ally_villages()

bool ai::readonly_context_impl::get_allow_ally_villages ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 516 of file contexts.cpp.

References allow_ally_villages_.

◆ get_aspects() [1/2]

const aspect_map & ai::readonly_context_impl::get_aspects ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 524 of file contexts.cpp.

References aspects_.

◆ get_aspects() [2/2]

aspect_map & ai::readonly_context_impl::get_aspects ( )
overridevirtual

Implements ai::readonly_context.

Definition at line 529 of file contexts.cpp.

References aspects_.

◆ get_attacks()

const attacks_vector & ai::readonly_context_impl::get_attacks ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 534 of file contexts.cpp.

References attacks_.

◆ get_attacks_as_variant()

const wfl::variant & ai::readonly_context_impl::get_attacks_as_variant ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 543 of file contexts.cpp.

References attacks_.

◆ get_avoid()

const terrain_filter & ai::readonly_context_impl::get_avoid ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 552 of file contexts.cpp.

References config::add_child(), avoid_, and resources::filter_con.

Referenced by nearest_keep(), and recalculate_move_maps().

◆ get_caution()

double ai::readonly_context_impl::get_caution ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 563 of file contexts.cpp.

References caution_.

◆ get_dstsrc()

const move_map & ai::readonly_context_impl::get_dstsrc ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 571 of file contexts.cpp.

References dstsrc_, move_maps_valid_, and recalculate_move_maps().

◆ get_enemy_dstsrc()

const move_map & ai::readonly_context_impl::get_enemy_dstsrc ( ) const
overridevirtual

◆ get_enemy_possible_moves()

const moves_map & ai::readonly_context_impl::get_enemy_possible_moves ( ) const
overridevirtual

◆ get_enemy_srcdst()

const move_map & ai::readonly_context_impl::get_enemy_srcdst ( ) const
overridevirtual

◆ get_engine_by_cfg()

engine_ptr ai::readonly_context_impl::get_engine_by_cfg ( const config cfg)
overridevirtual

get engine by cfg, creating it if it is not created yet but known

Implements ai::readonly_context.

Definition at line 603 of file contexts.cpp.

References DBG_AI, engines_, ERR_AI, ai::engine_factory::get_list(), and ai::side_context_proxy::get_side().

◆ get_engines() [1/2]

const std::vector< engine_ptr > & ai::readonly_context_impl::get_engines ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 638 of file contexts.cpp.

References engines_.

◆ get_engines() [2/2]

std::vector< engine_ptr > & ai::readonly_context_impl::get_engines ( )
overridevirtual

Implements ai::readonly_context.

Definition at line 643 of file contexts.cpp.

References engines_.

◆ get_goals() [1/2]

const std::vector< goal_ptr > & ai::readonly_context_impl::get_goals ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 656 of file contexts.cpp.

References goals_.

Referenced by on_readonly_context_create().

◆ get_goals() [2/2]

std::vector< goal_ptr > & ai::readonly_context_impl::get_goals ( )
overridevirtual

Implements ai::readonly_context.

Definition at line 661 of file contexts.cpp.

References goals_.

◆ get_grouping()

std::string ai::readonly_context_impl::get_grouping ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 648 of file contexts.cpp.

References grouping_.

◆ get_info()

const game_info & ai::readonly_context_impl::get_info ( ) const
overridevirtual

◆ get_leader_aggression()

double ai::readonly_context_impl::get_leader_aggression ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 666 of file contexts.cpp.

References leader_aggression_.

Referenced by check_attack_action().

◆ get_leader_goal()

config ai::readonly_context_impl::get_leader_goal ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 674 of file contexts.cpp.

References leader_goal_.

◆ get_leader_ignores_keep()

utils::variant< bool, std::vector< std::string > > ai::readonly_context_impl::get_leader_ignores_keep ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 682 of file contexts.cpp.

References leader_ignores_keep_.

◆ get_leader_value()

double ai::readonly_context_impl::get_leader_value ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 690 of file contexts.cpp.

References leader_value_.

◆ get_passive_leader()

utils::variant< bool, std::vector< std::string > > ai::readonly_context_impl::get_passive_leader ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 698 of file contexts.cpp.

References passive_leader_.

◆ get_passive_leader_shares_keep()

utils::variant< bool, std::vector< std::string > > ai::readonly_context_impl::get_passive_leader_shares_keep ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 706 of file contexts.cpp.

References passive_leader_shares_keep_.

◆ get_possible_moves()

const moves_map & ai::readonly_context_impl::get_possible_moves ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 714 of file contexts.cpp.

References move_maps_valid_, possible_moves_, and recalculate_move_maps().

◆ get_readonly_context()

virtual readonly_context& ai::readonly_context_impl::get_readonly_context ( )
inlineoverridevirtual
   Unwrap - this class is not a proxy, so return *this

:w

Implements ai::readonly_context.

Definition at line 1003 of file contexts.hpp.

◆ get_recruitment_diversity()

double ai::readonly_context_impl::get_recruitment_diversity ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 722 of file contexts.cpp.

References recruitment_diversity_.

◆ get_recruitment_instructions()

const config ai::readonly_context_impl::get_recruitment_instructions ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 730 of file contexts.cpp.

References recruitment_instructions_.

◆ get_recruitment_more()

const std::vector< std::string > ai::readonly_context_impl::get_recruitment_more ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 738 of file contexts.cpp.

References recruitment_more_.

◆ get_recruitment_pattern()

const std::vector< std::string > ai::readonly_context_impl::get_recruitment_pattern ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 746 of file contexts.cpp.

References recruitment_pattern_.

◆ get_recruitment_randomness()

int ai::readonly_context_impl::get_recruitment_randomness ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 754 of file contexts.cpp.

References recruitment_randomness_.

◆ get_recruitment_save_gold()

const config ai::readonly_context_impl::get_recruitment_save_gold ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 762 of file contexts.cpp.

References recruitment_save_gold_.

◆ get_recursion_count()

int ai::readonly_context_impl::get_recursion_count ( ) const
overridevirtual

Get the value of the recursion counter.

Reimplemented from ai::side_context_proxy.

Definition at line 78 of file contexts.cpp.

References ai::recursion_counter::get_count(), and recursion_counter_.

◆ get_retreat_enemy_weight()

double ai::readonly_context_impl::get_retreat_enemy_weight ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 770 of file contexts.cpp.

References retreat_enemy_weight_.

◆ get_retreat_factor()

double ai::readonly_context_impl::get_retreat_factor ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 778 of file contexts.cpp.

References retreat_factor_.

◆ get_scout_village_targeting()

double ai::readonly_context_impl::get_scout_village_targeting ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 786 of file contexts.cpp.

References scout_village_targeting_.

◆ get_simple_targeting()

bool ai::readonly_context_impl::get_simple_targeting ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 794 of file contexts.cpp.

References simple_targeting_.

◆ get_srcdst()

const move_map & ai::readonly_context_impl::get_srcdst ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 802 of file contexts.cpp.

References move_maps_valid_, recalculate_move_maps(), and srcdst_.

◆ get_support_villages()

bool ai::readonly_context_impl::get_support_villages ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 810 of file contexts.cpp.

References support_villages_.

◆ get_village_value()

double ai::readonly_context_impl::get_village_value ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 818 of file contexts.cpp.

References village_value_.

◆ get_villages_per_scout()

int ai::readonly_context_impl::get_villages_per_scout ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 826 of file contexts.cpp.

References villages_per_scout_.

◆ handle_generic_event()

void ai::readonly_context_impl::handle_generic_event ( const std::string &  event_name)
overridevirtual

Handle generic event.

Implements events::observer.

Definition at line 290 of file contexts.cpp.

References invalidate_move_maps().

◆ invalidate_defensive_position_cache()

void ai::readonly_context_impl::invalidate_defensive_position_cache ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 854 of file contexts.cpp.

References defensive_position_cache_.

◆ invalidate_keeps_cache()

void ai::readonly_context_impl::invalidate_keeps_cache ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 859 of file contexts.cpp.

References ai::keeps_cache::clear(), and keeps_.

◆ invalidate_move_maps()

void ai::readonly_context_impl::invalidate_move_maps ( ) const
overridevirtual

◆ is_active()

bool ai::readonly_context_impl::is_active ( const std::string &  time_of_day,
const std::string &  turns 
) const
overridevirtual

◆ is_dst_src_enemy_valid_lua()

bool ai::readonly_context_impl::is_dst_src_enemy_valid_lua ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 839 of file contexts.cpp.

References dst_src_enemy_valid_lua_.

◆ is_dst_src_valid_lua()

bool ai::readonly_context_impl::is_dst_src_valid_lua ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 834 of file contexts.cpp.

References dst_src_valid_lua_.

◆ is_keep_ignoring_leader()

bool ai::readonly_context_impl::is_keep_ignoring_leader ( const std::string &  id) const
overridevirtual

Implements ai::readonly_context.

Definition at line 1244 of file contexts.cpp.

References applies_to_leader(), and leader_ignores_keep_.

◆ is_passive_keep_sharing_leader()

bool ai::readonly_context_impl::is_passive_keep_sharing_leader ( const std::string &  id) const
overridevirtual

Implements ai::readonly_context.

Definition at line 1254 of file contexts.cpp.

References applies_to_leader(), and passive_leader_shares_keep_.

Referenced by recalculate_move_maps().

◆ is_passive_leader()

bool ai::readonly_context_impl::is_passive_leader ( const std::string &  id) const
overridevirtual

Implements ai::readonly_context.

Definition at line 1249 of file contexts.cpp.

References applies_to_leader(), and passive_leader_.

Referenced by recalculate_move_maps().

◆ is_src_dst_enemy_valid_lua()

bool ai::readonly_context_impl::is_src_dst_enemy_valid_lua ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 849 of file contexts.cpp.

References src_dst_enemy_valid_lua_.

◆ is_src_dst_valid_lua()

bool ai::readonly_context_impl::is_src_dst_valid_lua ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 844 of file contexts.cpp.

References src_dst_valid_lua_.

◆ keeps()

const std::set< map_location > & ai::readonly_context_impl::keeps ( ) const
overridevirtual

Implements ai::readonly_context.

Definition at line 881 of file contexts.cpp.

References ai::keeps_cache::get(), and keeps_.

Referenced by nearest_keep(), and suitable_keep().

◆ leader_can_reach_keep()

bool ai::readonly_context_impl::leader_can_reach_keep ( ) const
overridevirtual

◆ log_message()

void ai::readonly_context_impl::log_message ( const std::string &  msg)
overridevirtual

◆ nearest_keep()

const map_location & ai::readonly_context_impl::nearest_keep ( const map_location loc) const
overridevirtual

◆ on_create()

void ai::readonly_context_impl::on_create ( )

◆ on_readonly_context_create()

void ai::readonly_context_impl::on_readonly_context_create ( )
overridevirtual

◆ power_projection()

double ai::readonly_context_impl::power_projection ( const map_location loc,
const move_map dstsrc 
) const
overridevirtual

Function which finds how much 'power' a side can attack a certain location with.

This is basically the maximum hp of damage that can be inflicted upon a unit on loc by full-health units, multiplied by the defense these units will have. (if 'use_terrain' is false, then it will be multiplied by 0.5)

Example: 'loc' can be reached by two units, one of whom has a 10-3 attack and has 48/48 hp, and can defend at 40% on the adjacent grassland. The other has a 8-2 attack, and has 30/40 hp, and can defend at 60% on the adjacent mountain. The rating will be 10*3*1.0*0.4 + 8*2*0.75*0.6 = 19.2

Implements ai::readonly_context.

Definition at line 984 of file contexts.cpp.

References unit::alignment(), unit::attacks(), unit::defense_modifier(), unit_map::end(), unit_map::find(), resources::gameboard, get_adjacent_tiles(), ai::side_context_proxy::get_side(), tod_manager::get_time_of_day(), unit::hitpoints(), i, utf8::index(), gamemap::is_village(), time_of_day::lawful_bonus, game_board::map(), unit::max_hitpoints(), gamemap_base::on_board(), unit::side(), resources::tod_manager, tod_manager::turn(), game_board::units(), map_location::valid(), and WRN_AI.

Referenced by best_defensive_position().

◆ raise_user_interact()

void ai::readonly_context_impl::raise_user_interact ( ) const
overridevirtual

Function which should be called frequently to allow the user to interact with the interface.

This function will make sure that interaction doesn't occur too often, so there is no problem with calling it very regularly.

Implements ai::readonly_context.

Definition at line 88 of file contexts.cpp.

References ai::manager::get_singleton(), and ai::manager::raise_user_interact().

◆ recalculate_move_maps()

void ai::readonly_context_impl::recalculate_move_maps ( ) const
overridevirtual

◆ recalculate_move_maps_enemy()

void ai::readonly_context_impl::recalculate_move_maps_enemy ( ) const
overridevirtual

◆ set_dst_src_enemy_valid_lua()

void ai::readonly_context_impl::set_dst_src_enemy_valid_lua ( )
overridevirtual

Implements ai::readonly_context.

Definition at line 1144 of file contexts.cpp.

References dst_src_enemy_valid_lua_.

◆ set_dst_src_valid_lua()

void ai::readonly_context_impl::set_dst_src_valid_lua ( )
overridevirtual

Implements ai::readonly_context.

Definition at line 1139 of file contexts.cpp.

References dst_src_valid_lua_.

◆ set_src_dst_enemy_valid_lua()

void ai::readonly_context_impl::set_src_dst_enemy_valid_lua ( )
overridevirtual

Implements ai::readonly_context.

Definition at line 1154 of file contexts.cpp.

References src_dst_enemy_valid_lua_.

◆ set_src_dst_valid_lua()

void ai::readonly_context_impl::set_src_dst_valid_lua ( )
overridevirtual

Implements ai::readonly_context.

Definition at line 1149 of file contexts.cpp.

References src_dst_valid_lua_.

◆ suitable_keep()

const map_location & ai::readonly_context_impl::suitable_keep ( const map_location leader_location,
const pathfind::paths leader_paths 
) const
overridevirtual

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

Implements ai::readonly_context.

Definition at line 1159 of file contexts.cpp.

References pathfind::paths::step::curr, pathfind::paths::destinations, resources::gameboard, keeps(), pathfind::paths::step::move_left, nearest_keep(), and map_location::null_location().

◆ to_readonly_context_config()

config ai::readonly_context_impl::to_readonly_context_config ( ) const
overridevirtual

serialize to config

Implements ai::readonly_context.

Definition at line 270 of file contexts.cpp.

References config::add_child(), aspects_, e, engines_, g, and goals_.

◆ unit_stats_cache()

readonly_context::unit_stats_cache_t & ai::readonly_context_impl::unit_stats_cache ( ) const
overridevirtual

Weapon choice cache, to speed simulations.

Implements ai::readonly_context.

Definition at line 1202 of file contexts.cpp.

References unit_stats_cache_.

Member Data Documentation

◆ advancements_

typesafe_aspect_ptr<unit_advancements_aspect> ai::readonly_context_impl::advancements_
private

Definition at line 1285 of file contexts.hpp.

Referenced by get_advancements(), and readonly_context_impl().

◆ aggression_

typesafe_aspect_ptr<double> ai::readonly_context_impl::aggression_
private

Definition at line 1286 of file contexts.hpp.

Referenced by get_aggression(), and readonly_context_impl().

◆ allow_ally_villages_

typesafe_aspect_ptr<bool> ai::readonly_context_impl::allow_ally_villages_
private

Definition at line 1287 of file contexts.hpp.

Referenced by get_allow_ally_villages(), and readonly_context_impl().

◆ aspects_

aspect_map ai::readonly_context_impl::aspects_
private

Definition at line 1288 of file contexts.hpp.

Referenced by add_known_aspect(), get_aspects(), and to_readonly_context_config().

◆ attacks_

typesafe_aspect_ptr<attacks_vector> ai::readonly_context_impl::attacks_
private

Definition at line 1289 of file contexts.hpp.

Referenced by get_attacks(), get_attacks_as_variant(), and readonly_context_impl().

◆ avoid_

typesafe_aspect_ptr<terrain_filter> ai::readonly_context_impl::avoid_
mutableprivate

Definition at line 1290 of file contexts.hpp.

Referenced by get_avoid(), and readonly_context_impl().

◆ caution_

typesafe_aspect_ptr<double> ai::readonly_context_impl::caution_
private

Definition at line 1291 of file contexts.hpp.

Referenced by get_caution(), and readonly_context_impl().

◆ cfg_

const config ai::readonly_context_impl::cfg_
private

Definition at line 1276 of file contexts.hpp.

Referenced by on_readonly_context_create().

◆ defensive_position_cache_

std::map<map_location,defensive_position> ai::readonly_context_impl::defensive_position_cache_
mutableprivate

◆ dst_src_enemy_valid_lua_

bool ai::readonly_context_impl::dst_src_enemy_valid_lua_
mutableprivate

◆ dst_src_valid_lua_

bool ai::readonly_context_impl::dst_src_valid_lua_
mutableprivate

◆ dstsrc_

move_map ai::readonly_context_impl::dstsrc_
mutableprivate

Definition at line 1293 of file contexts.hpp.

Referenced by get_dstsrc(), and recalculate_move_maps().

◆ enemy_dstsrc_

move_map ai::readonly_context_impl::enemy_dstsrc_
mutableprivate

Definition at line 1294 of file contexts.hpp.

Referenced by get_enemy_dstsrc(), and recalculate_move_maps_enemy().

◆ enemy_possible_moves_

moves_map ai::readonly_context_impl::enemy_possible_moves_
mutableprivate

Definition at line 1295 of file contexts.hpp.

Referenced by get_enemy_possible_moves(), and recalculate_move_maps_enemy().

◆ enemy_srcdst_

move_map ai::readonly_context_impl::enemy_srcdst_
mutableprivate

Definition at line 1296 of file contexts.hpp.

Referenced by get_enemy_srcdst(), and recalculate_move_maps_enemy().

◆ engines_

std::vector< engine_ptr > ai::readonly_context_impl::engines_
private

AI Support Engines.

Definition at line 1281 of file contexts.hpp.

Referenced by get_engine_by_cfg(), get_engines(), on_readonly_context_create(), and to_readonly_context_config().

◆ goals_

std::vector< goal_ptr > ai::readonly_context_impl::goals_
private

Definition at line 1298 of file contexts.hpp.

Referenced by get_goals(), and to_readonly_context_config().

◆ grouping_

typesafe_aspect_ptr<std::string> ai::readonly_context_impl::grouping_
private

Definition at line 1297 of file contexts.hpp.

Referenced by get_grouping(), and readonly_context_impl().

◆ keeps_

keeps_cache ai::readonly_context_impl::keeps_
mutableprivate

Definition at line 1299 of file contexts.hpp.

Referenced by invalidate_keeps_cache(), keeps(), and readonly_context_impl().

◆ known_aspects_

known_aspect_map ai::readonly_context_impl::known_aspects_
private

Definition at line 1283 of file contexts.hpp.

Referenced by add_aspects(), add_facet(), and add_known_aspect().

◆ leader_aggression_

typesafe_aspect_ptr<double> ai::readonly_context_impl::leader_aggression_
private

Definition at line 1300 of file contexts.hpp.

Referenced by get_leader_aggression(), and readonly_context_impl().

◆ leader_goal_

typesafe_aspect_ptr<config> ai::readonly_context_impl::leader_goal_
private

Definition at line 1301 of file contexts.hpp.

Referenced by get_leader_goal(), and readonly_context_impl().

◆ leader_ignores_keep_

typesafe_aspect_ptr<utils::variant<bool, std::vector<std::string> > > ai::readonly_context_impl::leader_ignores_keep_
private

◆ leader_value_

typesafe_aspect_ptr<double> ai::readonly_context_impl::leader_value_
private

Definition at line 1303 of file contexts.hpp.

Referenced by get_leader_value(), and readonly_context_impl().

◆ move_maps_enemy_valid_

bool ai::readonly_context_impl::move_maps_enemy_valid_
mutableprivate

◆ move_maps_valid_

bool ai::readonly_context_impl::move_maps_valid_
mutableprivate

◆ passive_leader_

typesafe_aspect_ptr<utils::variant<bool, std::vector<std::string> > > ai::readonly_context_impl::passive_leader_
private

Definition at line 1310 of file contexts.hpp.

Referenced by get_passive_leader(), is_passive_leader(), and readonly_context_impl().

◆ passive_leader_shares_keep_

typesafe_aspect_ptr<utils::variant<bool, std::vector<std::string> > > ai::readonly_context_impl::passive_leader_shares_keep_
private

◆ possible_moves_

moves_map ai::readonly_context_impl::possible_moves_
mutableprivate

Definition at line 1312 of file contexts.hpp.

Referenced by get_possible_moves(), and recalculate_move_maps().

◆ recruitment_diversity_

typesafe_aspect_ptr<double> ai::readonly_context_impl::recruitment_diversity_
private

Definition at line 1313 of file contexts.hpp.

Referenced by get_recruitment_diversity(), and readonly_context_impl().

◆ recruitment_instructions_

typesafe_aspect_ptr<config> ai::readonly_context_impl::recruitment_instructions_
private

Definition at line 1314 of file contexts.hpp.

Referenced by get_recruitment_instructions(), and readonly_context_impl().

◆ recruitment_more_

typesafe_aspect_ptr<std::vector<std::string> > ai::readonly_context_impl::recruitment_more_
private

Definition at line 1315 of file contexts.hpp.

Referenced by get_recruitment_more(), and readonly_context_impl().

◆ recruitment_pattern_

typesafe_aspect_ptr<std::vector<std::string> > ai::readonly_context_impl::recruitment_pattern_
private

Definition at line 1316 of file contexts.hpp.

Referenced by get_recruitment_pattern(), and readonly_context_impl().

◆ recruitment_randomness_

typesafe_aspect_ptr<int> ai::readonly_context_impl::recruitment_randomness_
private

Definition at line 1317 of file contexts.hpp.

Referenced by get_recruitment_randomness(), and readonly_context_impl().

◆ recruitment_save_gold_

typesafe_aspect_ptr<config> ai::readonly_context_impl::recruitment_save_gold_
private

Definition at line 1318 of file contexts.hpp.

Referenced by get_recruitment_save_gold(), and readonly_context_impl().

◆ recursion_counter_

recursion_counter ai::readonly_context_impl::recursion_counter_
private

Definition at line 1319 of file contexts.hpp.

Referenced by get_recursion_count().

◆ retreat_enemy_weight_

typesafe_aspect_ptr<double> ai::readonly_context_impl::retreat_enemy_weight_
private

Definition at line 1320 of file contexts.hpp.

Referenced by get_retreat_enemy_weight(), and readonly_context_impl().

◆ retreat_factor_

typesafe_aspect_ptr<double> ai::readonly_context_impl::retreat_factor_
private

Definition at line 1321 of file contexts.hpp.

Referenced by get_retreat_factor(), and readonly_context_impl().

◆ scout_village_targeting_

typesafe_aspect_ptr<double> ai::readonly_context_impl::scout_village_targeting_
private

Definition at line 1322 of file contexts.hpp.

Referenced by get_scout_village_targeting(), and readonly_context_impl().

◆ simple_targeting_

typesafe_aspect_ptr<bool> ai::readonly_context_impl::simple_targeting_
private

Definition at line 1323 of file contexts.hpp.

Referenced by get_simple_targeting(), and readonly_context_impl().

◆ src_dst_enemy_valid_lua_

bool ai::readonly_context_impl::src_dst_enemy_valid_lua_
mutableprivate

◆ src_dst_valid_lua_

bool ai::readonly_context_impl::src_dst_valid_lua_
mutableprivate

◆ srcdst_

move_map ai::readonly_context_impl::srcdst_
mutableprivate

Definition at line 1324 of file contexts.hpp.

Referenced by get_srcdst(), and recalculate_move_maps().

◆ support_villages_

typesafe_aspect_ptr<bool> ai::readonly_context_impl::support_villages_
private

Definition at line 1325 of file contexts.hpp.

Referenced by get_support_villages(), and readonly_context_impl().

◆ unit_stats_cache_

unit_stats_cache_t ai::readonly_context_impl::unit_stats_cache_
mutableprivate

Definition at line 1326 of file contexts.hpp.

Referenced by unit_stats_cache().

◆ village_value_

typesafe_aspect_ptr<double> ai::readonly_context_impl::village_value_
private

Definition at line 1327 of file contexts.hpp.

Referenced by get_village_value(), and readonly_context_impl().

◆ villages_per_scout_

typesafe_aspect_ptr<int> ai::readonly_context_impl::villages_per_scout_
private

Definition at line 1328 of file contexts.hpp.

Referenced by get_villages_per_scout(), and readonly_context_impl().


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