The Battle for Wesnoth  1.19.7+dev
Classes | Enumerations | Enumerator | Functions | Variables | Friends
Ability functions

Classes

class  unit::recursion_guard
 Helper similar to std::unique_lock for detecting when calculations such as abilities have entered infinite recursion. More...
 

Enumerations

enum class  backwards_compatibility::unit_checksum_version { backwards_compatibility::current , backwards_compatibility::version_1_16_or_older }
 Optional parameter for get_checksum to use the algorithm of an older version of Wesnoth, thus preventing spurious OOS warnings while watching old replays. More...
 

Functions

static std::string unit::upkeep_full::type ()
 
static std::string unit::upkeep_loyal::type ()
 
 unit::upkeep_value_visitor::upkeep_value_visitor (const unit &unit)
 
int unit::upkeep_value_visitor::operator() (const upkeep_full &) const
 Full upkeep equals the unit's level. More...
 
int unit::upkeep_value_visitor::operator() (const upkeep_loyal &) const
 Loyal units cost no upkeep. More...
 
int unit::upkeep_value_visitor::operator() (int v) const
 
template<typename T >
std::enable_if_t<!std::is_same_v< int, T >, std::string > unit::upkeep_type_visitor::operator() (T &) const
 
std::string unit::upkeep_type_visitor::operator() (int v) const
 
template<typename N >
std::enable_if_t< std::is_arithmetic_v< N >, upkeep_tunit::upkeep_parser_visitor::operator() (N n) const
 
template<typename B >
std::enable_if_t< std::is_convertible_v< B, bool > &&!std::is_arithmetic_v< B >, upkeep_tunit::upkeep_parser_visitor::operator() (B b) const
 
upkeep_t unit::upkeep_parser_visitor::operator() (utils::monostate) const
 
upkeep_t unit::upkeep_parser_visitor::operator() (const std::string &s) const
 
bool unit::get_ability_bool (const std::string &tag_name, const map_location &loc) const
 Checks whether this unit currently possesses or is affected by a given ability. More...
 
bool unit::get_ability_bool (const std::string &tag_name) const
 Checks whether this unit currently possesses or is affected by a given ability. More...
 
unit_ability_list unit::get_abilities (const std::string &tag_name, const map_location &loc) const
 Gets the unit's active abilities of a particular type if it were on a specified location. More...
 
unit_ability_list unit::get_abilities (const std::string &tag_name) const
 Gets the unit's active abilities of a particular type. More...
 
unit_ability_list unit::get_abilities_weapons (const std::string &tag_name, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
 
unit_ability_list unit::get_abilities_weapons (const std::string &tag_name, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
 
const configunit::abilities () const
 
const std::set< std::string > & unit::checking_tags () const
 
std::vector< std::tuple< std::string, t_string, t_string, t_string > > unit::ability_tooltips () const
 Gets the names and descriptions of this unit's abilities. More...
 
std::vector< std::tuple< std::string, t_string, t_string, t_string > > unit::ability_tooltips (boost::dynamic_bitset<> &active_list, const map_location &loc) const
 Gets the names and descriptions of this unit's abilities. More...
 
std::vector< std::string > unit::get_ability_list () const
 Get a list of all abilities by ID. More...
 
bool unit::has_ability_type (const std::string &ability) const
 Check if the unit has an ability of a specific type. More...
 
bool unit::has_ability_by_id (const std::string &ability) const
 Check if the unit has an ability of a specific ID. More...
 
void unit::remove_ability_by_id (const std::string &ability)
 Removes a unit's abilities with a specific ID. More...
 
void unit::remove_ability_by_attribute (const config &filter)
 Removes a unit's abilities with a specific ID or other attribute. More...
 
 unit::recursion_guard::recursion_guard (const unit &u, const config &ability)
 Only expected to be called in update_variables_recursion(), which handles some of the checks. More...
 
 unit::recursion_guard::recursion_guard ()
 Construct an empty instance, only useful for extending the lifetime of a recursion_guard returned from unit.update_variables_recursion() by std::moving it to an instance declared in a larger scope. More...
 
 unit::recursion_guard::operator bool () const
 Returns true if a level of recursion was available at the time when update_variables_recursion() created this object. More...
 
 unit::recursion_guard::recursion_guard (recursion_guard &&other)
 
 unit::recursion_guard::recursion_guard (const recursion_guard &other)=delete
 
recursion_guardunit::recursion_guard::operator= (recursion_guard &&)
 
recursion_guardunit::recursion_guard::operator= (const recursion_guard &)=delete
 
 unit::recursion_guard::~recursion_guard ()
 
recursion_guard unit::update_variables_recursion (const config &ability) const
 
bool unit::ability_active (const std::string &ability, const config &cfg, const map_location &loc) const
 Check if an ability is active. More...
 
bool unit::ability_active_impl (const std::string &ability, const config &cfg, const map_location &loc) const
 Check if an ability is active. More...
 
bool unit::ability_affects_adjacent (const std::string &ability, const config &cfg, int dir, const map_location &loc, const unit &from) const
 Check if an ability affects adjacent units. More...
 
bool unit::ability_affects_self (const std::string &ability, const config &cfg, const map_location &loc) const
 Check if an ability affects the owning unit. More...
 
bool unit::ability_affects_weapon (const config &cfg, const const_attack_ptr &weapon, bool is_opp) const
 filters the weapons that condition the use of abilities for combat ([resistance],[leadership] or abilities used like specials (deprecated in two last cases) More...
 
unit_formula_managerunit::formula_manager () const
 Get the unit formula manager. More...
 
void unit::generate_name ()
 Generates a random race-appropriate name if one has not already been provided. More...
 
bool unit::invisible (const map_location &loc, bool see_all=true) const
 
bool unit::is_visible_to_team (const team &team, bool const see_all=true) const
 
bool unit::is_visible_to_team (const map_location &loc, const team &team, bool const see_all=true) const
 Return true if the unit would be visible to team if its location were loc. More...
 
void unit::write (config &cfg, bool write_all=true) const
 Serializes the current unit metadata values. More...
 
unitunit::mark_clone (bool is_temporary)
 Mark this unit as clone so it can be inserted to unit_map. More...
 
void unit::set_appearance_changed (bool value)
 
bool unit::appearance_changed () const
 
void unit::parse_upkeep (const config::attribute_value &upkeep)
 
void unit::write_upkeep (config::attribute_value &upkeep) const
 
void unit::clear_visibility_cache () const
 Clears the cache. More...
 
 unit_movement_resetter::unit_movement_resetter (const unit_movement_resetter &)=delete
 
unit_movement_resetterunit_movement_resetter::operator= (const unit_movement_resetter &)=delete
 
 unit_movement_resetter::unit_movement_resetter (const unit &u, bool operate=true)
 
 unit_movement_resetter::~unit_movement_resetter ()
 

Variables

const unitunit::upkeep_value_visitor::u_
 
std::shared_ptr< const unitunit::recursion_guard::parent
 
const std::set< std::string > unit::checking_tags_ {"disable", "attacks", "damage", "chance_to_hit", "berserk", "swarm", "drains", "heal_on_hit", "plague", "slow", "petrifies", "firststrike", "poison", "damage_type"}
 
map_location unit::loc_
 
std::vector< std::string > unit::advances_to_
 
const unit_typeunit::type_
 Never nullptr. More...
 
t_string unit::type_name_
 The displayed name of this unit type. More...
 
const unit_raceunit::race_
 Never nullptr, but may point to the null race. More...
 
std::string unit::id_
 
t_string unit::name_
 
n_unit::unit_id unit::underlying_id_
 
std::string unit::undead_variation_
 
std::string unit::variation_
 
int unit::hit_points_
 
int unit::max_hit_points_
 
int unit::experience_
 
int unit::max_experience_
 
int unit::level_
 
int unit::recall_cost_
 
bool unit::canrecruit_
 
std::vector< std::string > unit::recruit_list_
 
unit_alignments::type unit::alignment_
 
std::string unit::flag_rgb_
 
std::string unit::image_mods_
 
bool unit::unrenamable_
 
int unit::side_
 
unit_race::GENDER unit::gender_
 
std::unique_ptr< unit_formula_managerunit::formula_man_
 
int unit::movement_
 
int unit::max_movement_
 
int unit::vision_
 
int unit::jamming_
 
movetype unit::movement_type_
 
bool unit::hold_position_
 
bool unit::end_turn_
 
bool unit::resting_
 
int unit::attacks_left_
 
int unit::max_attacks_
 
std::set< std::string > unit::states_
 
static const std::size_t unit::num_bool_states = state_t::NUMBER_OF_STATES
 
std::bitset< num_bool_statesunit::known_boolean_states_
 
static std::map< std::string, state_tunit::known_boolean_state_names_
 
config unit::variables_
 
config unit::events_
 
config unit::filter_recall_
 
bool unit::emit_zoc_
 
std::vector< std::string > unit::overlays_
 
std::string unit::role_
 
attack_list unit::attacks_
 
std::vector< const config * > unit::open_queries_
 While processing a recursive match, all the filters that are currently being checked, oldest first. More...
 
map_location::direction unit::facing_
 
std::vector< t_stringunit::trait_names_
 
std::vector< t_stringunit::trait_descriptions_
 
std::vector< std::string > unit::trait_nonhidden_ids_
 
int unit::unit_value_
 
map_location unit::goto_
 
map_location unit::interrupted_move_
 
bool unit::is_fearless_
 
bool unit::is_healthy_
 
utils::string_map unit::modification_descriptions_
 
std::unique_ptr< unit_animation_componentunit::anim_comp_
 
bool unit::hidden_
 
double unit::hp_bar_scaling_
 
double unit::xp_bar_scaling_
 
config unit::modifications_
 
config unit::abilities_
 
std::vector< configunit::advancements_
 
t_string unit::description_
 
std::vector< t_stringunit::special_notes_
 
utils::optional< std::string > unit::usage_
 
utils::optional< std::string > unit::halo_
 
utils::optional< std::string > unit::ellipse_
 
bool unit::random_traits_
 
bool unit::generate_name_
 
upkeep_t unit::upkeep_
 
std::string unit::profile_
 
std::string unit::small_profile_
 
bool unit::appearance_changed_ = true
 
std::bitset< UA_COUNTunit::changed_attributes_
 
std::map< map_location, bool > unit::invisibility_cache_
 Hold the visibility status cache for a unit, when not uncovered. More...
 
unitunit_movement_resetter::u_
 
int unit_movement_resetter::moves_
 

Friends

class unit::recursion_guard::unit
 
class unit::unit_animation_component
 

already added

bool unit::get_self_ability_bool (const config &cfg, const std::string &ability, const map_location &loc) const
 Checks whether this unit currently possesses a given ability, and that that ability is active. More...
 
bool unit::get_self_ability_bool_weapon (const config &special, const std::string &tag_name, const map_location &loc, const const_attack_ptr &weapon=nullptr, const const_attack_ptr &opp_weapon=nullptr) const
 Checks whether this unit currently possesses a given ability of leadership type. More...
 
bool unit::get_adj_ability_bool (const config &cfg, const std::string &ability, int dir, const map_location &loc, const unit &from) const
 Checks whether this unit is affected by a given ability, and that that ability is active. More...
 
bool unit::get_adj_ability_bool_weapon (const config &special, const std::string &tag_name, int dir, const map_location &loc, const unit &from, const const_attack_ptr &weapon=nullptr, const const_attack_ptr &opp_weapon=nullptr) const
 Checks whether this unit is affected by a given ability of leadership type. More...
 
bool unit::ability_matches_filter (const config &cfg, const std::string &tag_name, const config &filter) const
 Verify what abilities attributes match with filter. More...
 

Detailed Description

Enumeration Type Documentation

◆ unit_checksum_version

Optional parameter for get_checksum to use the algorithm of an older version of Wesnoth, thus preventing spurious OOS warnings while watching old replays.

Enumerator
current 
version_1_16_or_older 

Included some of the flavortext from weapon specials.

Definition at line 2170 of file unit.hpp.

Function Documentation

◆ abilities()

const config& unit::abilities ( ) const
inline

◆ ability_active()

bool unit::ability_active ( const std::string &  ability,
const config cfg,
const map_location loc 
) const
private

Check if an ability is active.

Includes checks to prevent excessive recursion.

Parameters
abilityThe type (tag name) of the ability
cfgan ability WML structure
locThe location on which to resolve the ability
Returns
true if it is active

Definition at line 422 of file abilities.cpp.

References unit::ability_active_impl(), loc, and unit::update_variables_recursion().

Referenced by unit::ability_tooltips(), and unit::halo_or_icon_abilities().

◆ ability_active_impl()

bool unit::ability_active_impl ( const std::string &  ability,
const config cfg,
const map_location loc 
) const
private

Check if an ability is active.

The caller is responsible for preventing excessive recursion, so must hold a recursion_guard.

Parameters
abilityThe type (tag name) of the ability
cfgan ability WML structure
locThe location on which to resolve the ability
Returns
true if it is active

Definition at line 432 of file abilities.cpp.

References config::child_range(), unit_map::end(), resources::filter_con, unit_map::find(), get_adjacent_tiles(), filter_context::get_disp_context(), display_context::get_team(), i, map_location::indeterminate, utf8::index(), team::is_enemy(), loc, config::optional_child(), map_location::parse_directions(), utils::parse_ranges_unsigned(), unit::side(), and unit::side_.

Referenced by unit::ability_active(), and unit::get_adj_ability_bool().

◆ ability_affects_adjacent()

bool unit::ability_affects_adjacent ( const std::string &  ability,
const config cfg,
int  dir,
const map_location loc,
const unit from 
) const
private

Check if an ability affects adjacent units.

Parameters
abilityThe type (tag name) of the ability
cfgan ability WML structure
locThe location on which to resolve the ability
fromThe "other unit" for filter matching
dirThe direction the unit is facing

Definition at line 504 of file abilities.cpp.

References config::child_range(), utils::find(), i, unit::id(), loc, and map_location::parse_directions().

Referenced by unit::halo_or_icon_abilities().

◆ ability_affects_self()

bool unit::ability_affects_self ( const std::string &  ability,
const config cfg,
const map_location loc 
) const
private

Check if an ability affects the owning unit.

Parameters
abilityThe type (tag name) of the ability
cfgan ability WML structure
locThe location on which to resolve the ability

Definition at line 531 of file abilities.cpp.

References loc, unit_filter::matches(), config::optional_child(), and unit_filter::set_use_flat_tod().

Referenced by unit::halo_or_icon_abilities().

◆ ability_affects_weapon()

bool unit::ability_affects_weapon ( const config cfg,
const const_attack_ptr weapon,
bool  is_opp 
) const
private

filters the weapons that condition the use of abilities for combat ([resistance],[leadership] or abilities used like specials (deprecated in two last cases)

Definition at line 539 of file abilities.cpp.

References config::has_child(), and config::mandatory_child().

Referenced by unit::get_abilities_weapons().

◆ ability_matches_filter()

bool unit::ability_matches_filter ( const config cfg,
const std::string &  tag_name,
const config filter 
) const

Verify what abilities attributes match with filter.

Parameters
cfgthe config of ability to check.
tag_namethe tag name of ability to check.
filterthe filter used for checking.

Definition at line 2096 of file abilities.cpp.

Referenced by unit::remove_ability_by_attribute().

◆ ability_tooltips() [1/2]

std::vector< std::tuple< std::string, t_string, t_string, t_string > > unit::ability_tooltips ( ) const

Gets the names and descriptions of this unit's abilities.

Location-independent variant with all abilities shown as active.

Returns
A list of quadruples consisting of (in order) id, base name, male or female name as appropriate for the unit, and description.

Definition at line 321 of file abilities.cpp.

References _(), unit::abilities_, config::all_children_view(), and unit::gender_.

Referenced by gui2::unit_preview_pane::set_display_data(), and unit_abilities().

◆ ability_tooltips() [2/2]

std::vector< std::tuple< std::string, t_string, t_string, t_string > > unit::ability_tooltips ( boost::dynamic_bitset<> &  active_list,
const map_location loc 
) const

Gets the names and descriptions of this unit's abilities.

Parameters
active_listThis vector will be the same length as the returned one and will indicate whether or not the corresponding ability is active.
locThe location on which to resolve the ability.
Returns
A list of quadruples consisting of (in order) id, base name, male or female name as appropriate for the unit, and description.

Definition at line 333 of file abilities.cpp.

References unit::abilities_, unit::ability_active(), config::all_children_view(), unit::gender_, and loc.

◆ appearance_changed()

bool unit::appearance_changed ( ) const
inline

Definition at line 1989 of file unit.hpp.

References unit::appearance_changed_.

◆ checking_tags()

const std::set<std::string>& unit::checking_tags ( ) const
inline

◆ clear_visibility_cache()

void unit::clear_visibility_cache ( ) const
inlineprivate

Clears the cache.

Since we don't change the state of the object we're marked const (also required since the objects in the cache need to be marked const).

Definition at line 2139 of file unit.hpp.

References unit::invisibility_cache_.

◆ formula_manager()

unit_formula_manager& unit::formula_manager ( ) const
inline

Get the unit formula manager.

Definition at line 1957 of file unit.hpp.

References unit::formula_man_.

Referenced by wfl::set_unit_var_callable::execute_self(), and wfl::unit_callable::get_value().

◆ generate_name()

void unit::generate_name ( )

Generates a random race-appropriate name if one has not already been provided.

Definition at line 793 of file unit.cpp.

References t_string::empty(), unit::gender_, unit_race::generate_name(), unit::generate_name_, unit::name_, and unit::race_.

Referenced by unit::init().

◆ get_abilities() [1/2]

unit_ability_list unit::get_abilities ( const std::string &  tag_name) const
inline

Gets the unit's active abilities of a particular type.

Parameters
tag_nameThe type of ability to check for
Returns
A list of active abilities, paired with the location they are active on

Definition at line 1795 of file unit.hpp.

References unit::get_abilities(), and unit::loc_.

◆ get_abilities() [2/2]

unit_ability_list unit::get_abilities ( const std::string &  tag_name,
const map_location loc 
) const

Gets the unit's active abilities of a particular type if it were on a specified location.

Parameters
tag_nameThe type of ability to check for
locThe location to use for resolving abilities
Returns
A list of active abilities, paired with the location they are active on

Definition at line 218 of file abilities.cpp.

References unit::abilities_, config::child_range(), unit_ability_list::emplace_back(), unit_map::end(), unit_map::find(), unit::get_adj_ability_bool(), get_adjacent_tiles(), unit::get_self_ability_bool(), i, loc, and unit::loc_.

Referenced by unit::defense_modifier(), unit_filter_impl::unit_filter_compound::fill(), unit::get_abilities(), unit::get_abilities_weapons(), pathfind::get_teleport_locations(), and unit_display::reset_helpers().

◆ get_abilities_weapons() [1/2]

unit_ability_list unit::get_abilities_weapons ( const std::string &  tag_name,
const map_location loc,
const_attack_ptr  weapon = nullptr,
const_attack_ptr  opp_weapon = nullptr 
) const

◆ get_abilities_weapons() [2/2]

unit_ability_list unit::get_abilities_weapons ( const std::string &  tag_name,
const_attack_ptr  weapon = nullptr,
const_attack_ptr  opp_weapon = nullptr 
) const
inline

Definition at line 1802 of file unit.hpp.

References unit::get_abilities_weapons(), and unit::loc_.

◆ get_ability_bool() [1/2]

bool unit::get_ability_bool ( const std::string &  tag_name) const
inline

Checks whether this unit currently possesses or is affected by a given ability.

This means that the ability could be owned by this unit itself or by an adjacent unit, should the ability affect an AoE in which this unit happens to be.

This overload uses the location of this unit for calculations.

Parameters
tag_nameThe name of the ability to check for.

Definition at line 1740 of file unit.hpp.

References unit::get_ability_bool(), and unit::loc_.

◆ get_ability_bool() [2/2]

bool unit::get_ability_bool ( const std::string &  tag_name,
const map_location loc 
) const

Checks whether this unit currently possesses or is affected by a given ability.

This means that the ability could be owned by this unit itself or by an adjacent unit, should the ability affect an AoE in which this unit happens to be.

Parameters
tag_nameThe name of the ability to check for.
locThe location around which to check for affected units. This may or may not be the location of this unit.

Definition at line 183 of file abilities.cpp.

References unit::abilities_, config::child_range(), unit_map::end(), unit_map::find(), unit::get_adj_ability_bool(), get_adjacent_tiles(), unit::get_self_ability_bool(), i, and loc.

Referenced by pathfind::shortest_path_calculator::cost(), ai::ai_default_rca::get_healing_phase::evaluate(), pathfind::find_routes(), unit::get_ability_bool(), game_lua_kernel::intf_unit_ability(), unit::invisible(), pathfind::mark_route(), ai::ai_default_rca::aspect_attacks_base::rate_terrain(), and ai::default_ai_context_impl::rate_terrain().

◆ get_ability_list()

std::vector< std::string > unit::get_ability_list ( ) const

Get a list of all abilities by ID.

Definition at line 264 of file abilities.cpp.

References unit::abilities_, and config::all_children_view().

Referenced by wfl::unit_callable::get_value(), gui2::unit_preview_pane::set_display_data(), and UNIT_GETTER().

◆ get_adj_ability_bool()

bool unit::get_adj_ability_bool ( const config cfg,
const std::string &  ability,
int  dir,
const map_location loc,
const unit from 
) const

Checks whether this unit is affected by a given ability, and that that ability is active.

Returns
True if the ability tag_name is active.
Parameters
cfgthe const config to one of abilities ability checked.
abilityname of ability type checked.
loclocation of the unit checked.
fromunit adjacent to this is checked in case of [affect_adjacent] abilities.
dirdirection to research a unit adjacent to this.

Definition at line 1727 of file abilities.cpp.

References unit::ability_active_impl(), get_adjacent_tiles(), loc, unit::side(), and unit::update_variables_recursion().

Referenced by unit_filter_impl::unit_filter_compound::fill(), unit::get_abilities(), and unit::get_ability_bool().

◆ get_adj_ability_bool_weapon()

bool unit::get_adj_ability_bool_weapon ( const config special,
const std::string &  tag_name,
int  dir,
const map_location loc,
const unit from,
const const_attack_ptr weapon = nullptr,
const const_attack_ptr opp_weapon = nullptr 
) const

Checks whether this unit is affected by a given ability of leadership type.

Returns
True if the ability tag_name is active.
Parameters
specialthe const config to one of abilities tag_name checked.
tag_namename of ability type checked.
loclocation of the unit checked.
fromunit adjacent to this is checked in case of [affect_adjacent] abilities.
dirdirection to research a unit adjacent to this.
weaponthe attack used by unit checked in this function.
opp_weaponthe attack used by opponent to unit checked.

Definition at line 1743 of file abilities.cpp.

References loc.

◆ get_self_ability_bool()

bool unit::get_self_ability_bool ( const config cfg,
const std::string &  ability,
const map_location loc 
) const

Checks whether this unit currently possesses a given ability, and that that ability is active.

Returns
True if the ability tag_name is active.
Parameters
cfgthe const config to one of abilities tag_name checked.
abilityname of ability type checked.
loclocation of the unit checked.

Definition at line 1717 of file abilities.cpp.

References loc, and attack_type::update_variables_recursion().

Referenced by unit_filter_impl::unit_filter_compound::fill(), unit::get_abilities(), and unit::get_ability_bool().

◆ get_self_ability_bool_weapon()

bool unit::get_self_ability_bool_weapon ( const config special,
const std::string &  tag_name,
const map_location loc,
const const_attack_ptr weapon = nullptr,
const const_attack_ptr opp_weapon = nullptr 
) const

Checks whether this unit currently possesses a given ability of leadership type.

Returns
True if the ability tag_name is active.
Parameters
specialthe const config to one of abilities tag_name checked.
tag_namename of ability type checked.
loclocation of the unit checked.
weaponthe attack used by unit checked in this function.
opp_weaponthe attack used by opponent to unit checked.

Definition at line 1738 of file abilities.cpp.

References loc.

◆ has_ability_by_id()

bool unit::has_ability_by_id ( const std::string &  ability) const

Check if the unit has an ability of a specific ID.

Parameters
abilityThe ID of ability to check for.
Returns
true if the ability is present

Definition at line 1469 of file unit.cpp.

References unit::abilities_, and config::all_children_view().

Referenced by unit::apply_builtin_effect(), and unit_filter_impl::unit_filter_compound::fill().

◆ has_ability_type()

bool unit::has_ability_type ( const std::string &  ability) const

Check if the unit has an ability of a specific type.

Parameters
abilityThe type of ability (tag name) to check for.
Returns
true if the ability is present

Definition at line 558 of file abilities.cpp.

References unit::abilities_, and config::child_range().

Referenced by unit_filter_impl::unit_filter_compound::fill().

◆ invisible()

bool unit::invisible ( const map_location loc,
bool  see_all = true 
) const

◆ is_visible_to_team() [1/2]

bool unit::is_visible_to_team ( const map_location loc,
const team team,
bool const  see_all = true 
) const

Return true if the unit would be visible to team if its location were loc.

Definition at line 2629 of file unit.cpp.

References team::fogged(), display::get_singleton(), unit::invisible(), team::is_enemy(), n_unit::unit_id::is_fake(), loc, team::side(), unit::side(), and unit::underlying_id_.

◆ is_visible_to_team() [2/2]

bool unit::is_visible_to_team ( const team team,
bool const  see_all = true 
) const

◆ mark_clone()

unit & unit::mark_clone ( bool  is_temporary)

◆ operator bool()

unit::recursion_guard::operator bool ( ) const

Returns true if a level of recursion was available at the time when update_variables_recursion() created this object.

Definition at line 402 of file abilities.cpp.

◆ operator()() [1/9]

template<typename B >
std::enable_if_t<std::is_convertible_v<B, bool> && !std::is_arithmetic_v<B>, upkeep_t> unit::upkeep_parser_visitor::operator() ( b) const
inline

Definition at line 1252 of file unit.hpp.

References b.

◆ operator()() [2/9]

upkeep_t unit::upkeep_parser_visitor::operator() ( const std::string &  s) const
inline

Definition at line 1262 of file unit.hpp.

References s.

◆ operator()() [3/9]

int unit::upkeep_value_visitor::operator() ( const upkeep_full ) const
inline

Full upkeep equals the unit's level.

Definition at line 1194 of file unit.hpp.

References unit::level(), and unit::upkeep_value_visitor::u_.

◆ operator()() [4/9]

int unit::upkeep_value_visitor::operator() ( const upkeep_loyal ) const
inline

Loyal units cost no upkeep.

Definition at line 1200 of file unit.hpp.

◆ operator()() [5/9]

int unit::upkeep_value_visitor::operator() ( int  v) const
inline

Definition at line 1205 of file unit.hpp.

◆ operator()() [6/9]

std::string unit::upkeep_type_visitor::operator() ( int  v) const
inline

Definition at line 1228 of file unit.hpp.

◆ operator()() [7/9]

template<typename N >
std::enable_if_t<std::is_arithmetic_v<N>, upkeep_t> unit::upkeep_parser_visitor::operator() ( n) const
inline

Definition at line 1243 of file unit.hpp.

References n.

◆ operator()() [8/9]

template<typename T >
std::enable_if_t<!std::is_same_v<int, T>, std::string> unit::upkeep_type_visitor::operator() ( T &  ) const
inline

Definition at line 1222 of file unit.hpp.

◆ operator()() [9/9]

upkeep_t unit::upkeep_parser_visitor::operator() ( utils::monostate  ) const
inline

Definition at line 1257 of file unit.hpp.

◆ operator=() [1/3]

recursion_guard& unit::recursion_guard::operator= ( const recursion_guard )
delete

◆ operator=() [2/3]

unit_movement_resetter& unit_movement_resetter::operator= ( const unit_movement_resetter )
delete

◆ operator=() [3/3]

unit::recursion_guard & unit::recursion_guard::operator= ( unit::recursion_guard &&  other)

Definition at line 406 of file abilities.cpp.

References swap().

◆ parse_upkeep()

void unit::parse_upkeep ( const config::attribute_value upkeep)
private

Definition at line 2797 of file unit.cpp.

References e, unit::upkeep(), unit::upkeep_, and WRN_UT.

Referenced by unit::advance_to(), and unit::init().

◆ recursion_guard() [1/4]

unit::recursion_guard::recursion_guard ( )
explicitdefault

Construct an empty instance, only useful for extending the lifetime of a recursion_guard returned from unit.update_variables_recursion() by std::moving it to an instance declared in a larger scope.

◆ recursion_guard() [2/4]

unit::recursion_guard::recursion_guard ( const recursion_guard other)
delete

◆ recursion_guard() [3/4]

unit::recursion_guard::recursion_guard ( const unit u,
const config ability 
)
explicitprivate

Only expected to be called in update_variables_recursion(), which handles some of the checks.

Definition at line 391 of file abilities.cpp.

References unit::open_queries_.

◆ recursion_guard() [4/4]

unit::recursion_guard::recursion_guard ( unit::recursion_guard &&  other)

Definition at line 397 of file abilities.cpp.

References swap().

◆ remove_ability_by_attribute()

void unit::remove_ability_by_attribute ( const config filter)

Removes a unit's abilities with a specific ID or other attribute.

Parameters
filterthe config of ability to remove.

Definition at line 1493 of file unit.cpp.

References unit::abilities_, unit::ability_matches_filter(), config::erase(), i, config::ordered_begin(), config::ordered_end(), unit::set_attr_changed(), and unit::UA_ABILITIES.

Referenced by unit::apply_builtin_effect().

◆ remove_ability_by_id()

void unit::remove_ability_by_id ( const std::string &  ability)

Removes a unit's abilities with a specific ID.

Parameters
abilityThe type of ability (tag name) to remove.

Definition at line 1480 of file unit.cpp.

References unit::abilities_, config::erase(), i, config::ordered_begin(), config::ordered_end(), unit::set_attr_changed(), and unit::UA_ABILITIES.

Referenced by unit::apply_builtin_effect().

◆ set_appearance_changed()

void unit::set_appearance_changed ( bool  value)
inline

Definition at line 1988 of file unit.hpp.

References unit::appearance_changed_.

◆ type() [1/2]

static std::string unit::upkeep_full::type ( )
inlinestatic

Definition at line 1174 of file unit.hpp.

◆ type() [2/2]

static std::string unit::upkeep_loyal::type ( )
inlinestatic

Definition at line 1179 of file unit.hpp.

Referenced by unit::apply_builtin_effect().

◆ unit_movement_resetter() [1/2]

unit_movement_resetter::unit_movement_resetter ( const unit u,
bool  operate = true 
)

◆ unit_movement_resetter() [2/2]

unit_movement_resetter::unit_movement_resetter ( const unit_movement_resetter )
delete

◆ update_variables_recursion()

unit::recursion_guard unit::update_variables_recursion ( const config ability) const
private

Definition at line 381 of file abilities.cpp.

References utils::contains(), and unit::open_queries_.

Referenced by unit::ability_active(), and unit::get_adj_ability_bool().

◆ upkeep_value_visitor()

unit::upkeep_value_visitor::upkeep_value_visitor ( const unit unit)
inlineexplicit

Definition at line 1191 of file unit.hpp.

◆ write()

void unit::write ( config cfg,
bool  write_all = true 
) const

Serializes the current unit metadata values.

Parameters
cfgThe config to write to.
write_allset this to false to not write unchanged attributes.

Definition at line 1517 of file unit.cpp.

References unit::abilities_, config::add_child(), unit::advancements_, unit::advances_to_, unit::alignment_, config::append(), unit::attacks_, unit::attacks_left_, unit::can_recruit(), config::clear_children(), unit::description_, unit::ellipse_, unit::emit_zoc_, unit::events_, unit::experience_, unit::facing_, unit::filter_recall_, unit::flag_rgb_, unit::formula_man_, unit::gender_, gender_string(), unit::generate_name_, unit::get_attacks_changed(), unit::get_attr_changed(), unit::get_states(), string_enums::enum_base< Definition >::get_string(), unit::goto_, unit::halo_, unit::hidden_, unit::hit_points_, i, unit_type::icon(), unit_race::id(), unit::id_, unit_type::image(), unit::jamming_, utils::join(), unit::level_, unit::max_attacks_, unit::max_experience_, unit::max_hit_points_, unit::max_movement_, unit::modifications_, unit::movement_, unit::movement_type_, unit::name_, unit_type::parent_id(), unit::profile_, unit::race_, unit::random_traits_, unit::recall_cost_, unit::recruit_list_, unit::resting_, unit::role_, unit::side_, unit::small_profile_, unit::special_notes_, unit::type(), unit::type_id(), unit::type_name_, unit::UA_ABILITIES, unit::UA_ADVANCE_TO, unit::UA_ADVANCEMENTS, unit::UA_ALIGNMENT, unit::UA_ATTACKS, unit::UA_LEVEL, unit::UA_MAX_AP, unit::UA_MAX_HP, unit::UA_MAX_MP, unit::UA_MAX_XP, unit::UA_MOVEMENT_TYPE, unit::UA_NOTES, unit::UA_PROFILE, unit::UA_SMALL_PROFILE, unit::UA_ZOC, unit::undead_variation_, unit::underlying_id_, unit_type::unit_description(), unit::unit_value_, unit::unrenamable_, unit::usage_, n_unit::unit_id::value, unit::variables_, unit::variation_, unit::vision_, map_location::wml_x(), map_location::wml_y(), movetype::write(), map_location::write_direction(), and unit::write_upkeep().

Referenced by get_checksum(), and UNIT_GETTER().

◆ write_upkeep()

void unit::write_upkeep ( config::attribute_value upkeep) const
private

Definition at line 2811 of file unit.cpp.

References unit::upkeep(), and unit::upkeep_.

Referenced by unit::write().

◆ ~recursion_guard()

unit::recursion_guard::~recursion_guard ( )

Definition at line 414 of file abilities.cpp.

◆ ~unit_movement_resetter()

unit_movement_resetter::~unit_movement_resetter ( )

Variable Documentation

◆ abilities_

config unit::abilities_
private

◆ advancements_

std::vector<config> unit::advancements_
private

◆ advances_to_

std::vector<std::string> unit::advances_to_
private

◆ alignment_

unit_alignments::type unit::alignment_
private

◆ anim_comp_

std::unique_ptr<unit_animation_component> unit::anim_comp_
private

◆ appearance_changed_

bool unit::appearance_changed_ = true
mutableprivate

◆ attacks_

attack_list unit::attacks_
private

◆ attacks_left_

int unit::attacks_left_
private

◆ canrecruit_

bool unit::canrecruit_
private

Definition at line 2022 of file unit.hpp.

Referenced by unit::can_recruit(), unit::init(), and unit::set_can_recruit().

◆ changed_attributes_

std::bitset<UA_COUNT> unit::changed_attributes_
private

◆ checking_tags_

const std::set<std::string> unit::checking_tags_ {"disable", "attacks", "damage", "chance_to_hit", "berserk", "swarm", "drains", "heal_on_hit", "plague", "slow", "petrifies", "firststrike", "poison", "damage_type"}
private

Definition at line 1913 of file unit.hpp.

Referenced by unit::checking_tags().

◆ description_

t_string unit::description_
private

◆ ellipse_

utils::optional<std::string> unit::ellipse_
private

◆ emit_zoc_

bool unit::emit_zoc_
private

◆ end_turn_

bool unit::end_turn_
private

◆ events_

config unit::events_
private

Definition at line 2059 of file unit.hpp.

Referenced by unit::init(), and unit::write().

◆ experience_

int unit::experience_
private

◆ facing_

map_location::direction unit::facing_
mutableprotected

Definition at line 2078 of file unit.hpp.

Referenced by unit::facing(), unit::init(), unit::set_facing(), and unit::write().

◆ filter_recall_

config unit::filter_recall_
private

Definition at line 2060 of file unit.hpp.

Referenced by unit::init(), unit::recall_filter(), unit::set_recall_filter(), and unit::write().

◆ flag_rgb_

std::string unit::flag_rgb_
private

Definition at line 2026 of file unit.hpp.

Referenced by unit::advance_to(), unit::flag_rgb(), and unit::write().

◆ formula_man_

std::unique_ptr<unit_formula_manager> unit::formula_man_
private

Definition at line 2035 of file unit.hpp.

Referenced by unit::formula_manager(), unit::init(), and unit::write().

◆ gender_

unit_race::GENDER unit::gender_
private

◆ generate_name_

bool unit::generate_name_
private

Definition at line 2113 of file unit.hpp.

Referenced by unit::advance_to(), unit::generate_name(), unit::init(), and unit::write().

◆ goto_

map_location unit::goto_
private

◆ halo_

utils::optional<std::string> unit::halo_
private

Definition at line 2109 of file unit.hpp.

Referenced by unit::image_halo(), unit::set_image_halo(), and unit::write().

◆ hidden_

bool unit::hidden_
mutableprivate

Definition at line 2097 of file unit.hpp.

Referenced by unit::get_hidden(), unit::init(), unit::set_hidden(), and unit::write().

◆ hit_points_

int unit::hit_points_
private

◆ hold_position_

bool unit::hold_position_
private

◆ hp_bar_scaling_

double unit::hp_bar_scaling_
private

Definition at line 2098 of file unit.hpp.

Referenced by unit::advance_to(), unit::hp_bar_scaling(), and unit::init().

◆ id_

std::string unit::id_
private

◆ image_mods_

std::string unit::image_mods_
private

◆ interrupted_move_

map_location unit::interrupted_move_
private

◆ invisibility_cache_

std::map<map_location, bool> unit::invisibility_cache_
mutableprivate

Hold the visibility status cache for a unit, when not uncovered.

This is mutable since it is a cache.

Definition at line 2131 of file unit.hpp.

Referenced by unit::clear_visibility_cache(), and unit::invisible().

◆ is_fearless_

bool unit::is_fearless_
private

Definition at line 2088 of file unit.hpp.

Referenced by unit::advance_to(), unit::apply_builtin_effect(), and unit::is_fearless().

◆ is_healthy_

bool unit::is_healthy_
private

Definition at line 2088 of file unit.hpp.

Referenced by unit::advance_to(), unit::apply_builtin_effect(), and unit::is_healthy().

◆ jamming_

int unit::jamming_
private

◆ known_boolean_state_names_

std::map< std::string, unit::state_t > unit::known_boolean_state_names_
staticprivate
Initial value:
{
{"slowed", STATE_SLOWED},
{"poisoned", STATE_POISONED},
{"petrified", STATE_PETRIFIED},
{"uncovered", STATE_UNCOVERED},
{"not_moved", STATE_NOT_MOVED},
{"unhealable", STATE_UNHEALABLE},
{"guardian", STATE_GUARDIAN},
{"invulnerable", STATE_INVULNERABLE},
}
@ STATE_SLOWED
Definition: unit.hpp:860
@ STATE_NOT_MOVED
The unit is uncovered - it was hiding but has been spotted.
Definition: unit.hpp:864
@ STATE_GUARDIAN
The unit cannot be healed.
Definition: unit.hpp:866
@ STATE_INVULNERABLE
The unit is a guardian - it won't move unless a target is sighted.
Definition: unit.hpp:867
@ STATE_PETRIFIED
The unit is poisoned - it loses health each turn.
Definition: unit.hpp:862
@ STATE_UNHEALABLE
The unit has not moved.
Definition: unit.hpp:865
@ STATE_POISONED
The unit is slowed - it moves slower and does less damage.
Definition: unit.hpp:861
@ STATE_UNCOVERED
The unit is petrified - it cannot move or be attacked.
Definition: unit.hpp:863

Definition at line 2056 of file unit.hpp.

Referenced by unit::get_known_boolean_state_id(), unit::get_known_boolean_state_name(), and unit::get_states().

◆ known_boolean_states_

std::bitset<num_bool_states> unit::known_boolean_states_
private

Definition at line 2055 of file unit.hpp.

Referenced by unit::get_state(), and unit::set_state().

◆ level_

int unit::level_
private

◆ loc_

map_location unit::loc_
private

◆ max_attacks_

int unit::max_attacks_
private

◆ max_experience_

int unit::max_experience_
private

◆ max_hit_points_

int unit::max_hit_points_
private

◆ max_movement_

int unit::max_movement_
private

◆ modification_descriptions_

utils::string_map unit::modification_descriptions_
private

Definition at line 2090 of file unit.hpp.

Referenced by unit::advance_to().

◆ modifications_

config unit::modifications_
private

◆ movement_

int unit::movement_
private

◆ movement_type_

movetype unit::movement_type_
private

◆ moves_

int unit_movement_resetter::moves_
private

Definition at line 2161 of file unit.hpp.

Referenced by unit_movement_resetter::~unit_movement_resetter().

◆ name_

t_string unit::name_
private

◆ num_bool_states

const std::size_t unit::num_bool_states = state_t::NUMBER_OF_STATES
staticprivate

Definition at line 2053 of file unit.hpp.

◆ open_queries_

std::vector<const config*> unit::open_queries_
mutableprivate

While processing a recursive match, all the filters that are currently being checked, oldest first.

Each will have an instance of recursion_guard that is currently allocated permission to recurse, and which will pop the config off this stack when the recursion_guard is finalized.

Definition at line 2073 of file unit.hpp.

Referenced by unit::recursion_guard::recursion_guard(), and unit::update_variables_recursion().

◆ overlays_

std::vector<std::string> unit::overlays_
private

◆ parent

std::shared_ptr<const unit> unit::recursion_guard::parent
private

Definition at line 1908 of file unit.hpp.

◆ profile_

std::string unit::profile_
private

◆ race_

const unit_race* unit::race_
private

Never nullptr, but may point to the null race.

Definition at line 2005 of file unit.hpp.

Referenced by unit::advance_to(), unit::generate_name(), unit::init(), unit::race(), and unit::write().

◆ random_traits_

bool unit::random_traits_
private

Definition at line 2112 of file unit.hpp.

Referenced by unit::advance_to(), unit::generate_traits(), unit::init(), and unit::write().

◆ recall_cost_

int unit::recall_cost_
private

◆ recruit_list_

std::vector<std::string> unit::recruit_list_
private

Definition at line 2023 of file unit.hpp.

Referenced by unit::recruits(), unit::set_recruits(), and unit::write().

◆ resting_

bool unit::resting_
private

Definition at line 2046 of file unit.hpp.

Referenced by unit::end_turn(), unit::init(), unit::resting(), unit::set_resting(), and unit::write().

◆ role_

std::string unit::role_
private

Definition at line 2066 of file unit.hpp.

Referenced by unit::get_role(), unit::init(), unit::set_role(), and unit::write().

◆ side_

int unit::side_
private

◆ small_profile_

std::string unit::small_profile_
private

◆ special_notes_

std::vector<t_string> unit::special_notes_
private

◆ states_

std::set<std::string> unit::states_
private

Definition at line 2051 of file unit.hpp.

Referenced by unit::get_state(), unit::get_states(), and unit::set_state().

◆ trait_descriptions_

std::vector<t_string> unit::trait_descriptions_
private

◆ trait_names_

std::vector<t_string> unit::trait_names_
private

Definition at line 2081 of file unit.hpp.

Referenced by unit::add_trait_description(), unit::advance_to(), and unit::trait_names().

◆ trait_nonhidden_ids_

std::vector<std::string> unit::trait_nonhidden_ids_
private

◆ type_

const unit_type* unit::type_
private

Never nullptr.

Adjusted for gender and variation.

Definition at line 1999 of file unit.hpp.

Referenced by unit::advance_to(), unit::init(), unit::type(), and unit::type_id().

◆ type_name_

t_string unit::type_name_
private

The displayed name of this unit type.

Definition at line 2002 of file unit.hpp.

Referenced by unit::advance_to(), unit::type_name(), and unit::write().

◆ u_ [1/2]

const unit& unit::upkeep_value_visitor::u_
private

Definition at line 1211 of file unit.hpp.

Referenced by unit::upkeep_value_visitor::operator()().

◆ u_ [2/2]

unit& unit_movement_resetter::u_
private

◆ undead_variation_

std::string unit::undead_variation_
private

◆ underlying_id_

n_unit::unit_id unit::underlying_id_
private

◆ unit_value_

int unit::unit_value_
private

Definition at line 2085 of file unit.hpp.

Referenced by unit::advance_to(), unit::cost(), unit::init(), and unit::write().

◆ unrenamable_

bool unit::unrenamable_
private

◆ upkeep_

upkeep_t unit::upkeep_
private

◆ usage_

utils::optional<std::string> unit::usage_
private

Definition at line 2108 of file unit.hpp.

Referenced by unit::set_usage(), unit::usage(), and unit::write().

◆ variables_

config unit::variables_
private

Definition at line 2058 of file unit.hpp.

Referenced by unit::apply_modifications(), unit::init(), unit::variables(), and unit::write().

◆ variation_

std::string unit::variation_
private

◆ vision_

int unit::vision_
private

◆ xp_bar_scaling_

double unit::xp_bar_scaling_
private

Definition at line 2098 of file unit.hpp.

Referenced by unit::advance_to(), unit::init(), and unit::xp_bar_scaling().

Friends

◆ unit

friend class unit
friend

Definition at line 1883 of file unit.hpp.

◆ unit_animation_component

friend class unit_animation_component
friend

Definition at line 2093 of file unit.hpp.