The Battle for Wesnoth  1.15.0-dev
Functions
Ability functions

Functions

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_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) 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_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
 Gets the unit's active abilities of a particular type. More...
 
std::vector< std::tuple< std::string, t_string, t_string, t_string > > unit::ability_tooltips (boost::dynamic_bitset<> *active_list=nullptr) 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...
 
bool unit::abilities_filter_matches (const config &cfg, bool attacker, int res) const
 
bool unit::ability_filter_fighter (const std::string &ability, const std::string &filter_attacker, const config &cfg, const map_location &loc) 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_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_attack_ptr weapon, bool is_opp) const
 
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...
 

Detailed Description

Function Documentation

◆ abilities_filter_matches()

bool unit::abilities_filter_matches ( const config cfg,
bool  attacker,
int  res 
) const

Definition at line 1575 of file attack.cpp.

References unit_abilities::filter_base_matches().

◆ 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.

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 315 of file abilities.cpp.

References config::child(), config::child_range(), unit_map::end(), resources::filter_con, unit_map::find(), get_adjacent_tiles(), filter_context::get_disp_context(), display::get_singleton(), display_context::get_team(), display::get_units(), i, utf8::index(), unit_filter::matches(), map_location::NDIRECTIONS, map_location::parse_directions(), utils::parse_ranges(), and unit_filter::set_use_flat_tod().

◆ 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

Definition at line 387 of file abilities.cpp.

References config::child_range(), gui2::event::find(), i, and map_location::parse_directions().

◆ 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 411 of file abilities.cpp.

References config::child(), unit_filter::matches(), and unit_filter::set_use_flat_tod().

◆ ability_affects_weapon()

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

Definition at line 419 of file abilities.cpp.

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

◆ ability_filter_fighter()

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

◆ ability_tooltips()

std::vector< std::tuple< std::string, t_string, t_string, t_string > > unit::ability_tooltips ( boost::dynamic_bitset<> *  active_list = nullptr) const

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

Parameters
active_listIf nullptr, then all abilities are forced active. If not, this vector will be the same length as the returned one and will indicate whether or not the corresponding ability is active.
Returns
A list of triples consisting of (in order) id, base name, male or female name as appropriate for the unit, and description.

Definition at line 270 of file abilities.cpp.

References config_attribute_value::blank(), t_string::empty(), loc_, name(), and config_attribute_value::t_str().

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

◆ formula_manager()

unit_formula_manager& unit::formula_manager ( ) const
inline

Get the unit formula manager.

Definition at line 1646 of file unit.hpp.

References write().

Referenced by 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 816 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 map_location loc,
const_attack_ptr  weapon = nullptr,
const_attack_ptr  opp_weapon = nullptr 
) 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 183 of file abilities.cpp.

References unit_ability_list::emplace_back(), unit_map::end(), unit_map::find(), get_adjacent_tiles(), display::get_singleton(), display::get_units(), i, and loc_.

Referenced by unit::defense_modifier(), pathfind::get_teleport_locations(), unit_display::reset_helpers(), unit::resistance_against(), and under_leadership().

◆ get_abilities() [2/2]

unit_ability_list unit::get_abilities ( const std::string &  tag_name,
const_attack_ptr  weapon = nullptr,
const_attack_ptr  opp_weapon = nullptr 
) 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 1571 of file unit.hpp.

References loc_.

◆ get_ability_bool() [1/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 143 of file abilities.cpp.

References unit_map::end(), unit_map::find(), get_adjacent_tiles(), display::get_singleton(), display::get_units(), and i.

Referenced by pathfind::shortest_path_calculator::cost(), ai::ai_default_rca::get_healing_phase::evaluate(), pathfind::find_routes(), pathfind::get_teleport_locations(), 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_bool() [2/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 1553 of file unit.hpp.

References loc_.

◆ get_ability_list()

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

◆ 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 1381 of file unit.cpp.

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

Referenced by unit::apply_builtin_effect().

◆ 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 432 of file abilities.cpp.

References wfl::map_formula_callable::add(), config_attribute_value::apply_visitor(), d, e, unit_map::end(), wfl::formula_error::filename, unit_map::find(), display::get_singleton(), display::get_units(), i, wfl::formula_error::line, s, wfl::formula_error::type, and lg::wml_error().

◆ 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 team team,
bool const  see_all = true 
) const

◆ is_visible_to_team() [2/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 2430 of file unit.cpp.

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

◆ mark_clone()

unit & unit::mark_clone ( bool  is_temporary)

◆ 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 1392 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().

◆ 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 1415 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_type::base_id(), 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(), 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::overlays_, unit::profile_, unit::race_, unit::random_traits_, unit::recall_cost_, unit::recruit_list_, unit::resting_, unit::role_, unit::side_, unit::small_profile_, 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_PROFILE, unit::UA_SMALL_PROFILE, unit::UA_ZOC, unit::undead_variation_, unit::underlying_id_, unit::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 actions::find_recruit_location(), get_checksum(), and impl_unit_get().