The Battle for Wesnoth  1.19.7+dev
Functions
Attack and resistance functions

Functions

attack_itors unit::attacks ()
 Gets an iterator over this unit's attacks. More...
 
const_attack_itors unit::attacks () const
 Const overload of attacks. More...
 
template<typename... Args>
attack_ptr unit::add_attack (attack_itors::iterator position, Args &&... args)
 Adds a new attack to the unit. More...
 
bool unit::remove_attack (const attack_ptr &atk)
 Remove an attack from the unit. More...
 
void unit::remove_attacks_ai ()
 Set the unit to have no attacks left for this turn. More...
 
int unit::damage_from (const attack_type &attack, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr) const
 Calculates the damage this unit would take from a certain attack. More...
 
int unit::max_attacks () const
 The maximum number of attacks this unit may perform per turn, usually 1. More...
 
void unit::set_max_attacks (int value)
 
int unit::attacks_left () const
 Gets the remaining number of attacks this unit can perform this turn. More...
 
int unit::attacks_left (bool base_value) const
 Gets the remaining number of attacks this unit can perform this turn. More...
 
void unit::set_attacks (int left)
 Sets the number of attacks this unit has left this turn. More...
 
int unit::defense_modifier (const t_translation::terrain_code &terrain) const
 The unit's defense on a given terrain. More...
 
int unit::resistance_value (unit_ability_list resistance_list, const std::string &damage_name) const
 For the provided list of resistance abilities, determine the damage resistance based on which are active and any max_value that's present. More...
 
int unit::resistance_against (const std::string &damage_name, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr, const const_attack_ptr &opp_weapon=nullptr) const
 The unit's resistance against a given damage type. More...
 
int unit::resistance_against (const attack_type &atk, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr) const
 The unit's resistance against a given attack. More...
 
utils::string_map_res unit::get_base_resistances () const
 Gets resistances without any abilities applied. More...
 
bool unit::resistance_filter_matches (const config &cfg, const std::string &damage_name, int res) const
 

Detailed Description

Function Documentation

◆ add_attack()

template<typename... Args>
attack_ptr unit::add_attack ( attack_itors::iterator  position,
Args &&...  args 
)
inline

Adds a new attack to the unit.

Parameters
positionAn iterator pointing to the attack before which to insert the new one.
argsThe arguments for constructing the attack

Definition at line 950 of file unit.hpp.

References unit::attacks_, unit::set_attr_changed(), and unit::UA_ATTACKS.

Referenced by impl_unit_attacks_set().

◆ attacks() [1/2]

attack_itors unit::attacks ( )
inline

◆ attacks() [2/2]

const_attack_itors unit::attacks ( ) const
inline

Const overload of attacks.

Definition at line 939 of file unit.hpp.

References unit::attacks_, and make_attack_itors().

◆ attacks_left() [1/2]

int unit::attacks_left ( ) const
inline

Gets the remaining number of attacks this unit can perform this turn.

If the 'incapacitated' status is set, this will always be 0.

Definition at line 1000 of file unit.hpp.

References unit::attacks_left_, and unit::incapacitated().

Referenced by wb::attack::apply_temp_modifier(), unit::attacks_left(), ai::attack_analysis::execute_self(), wfl::unit_callable::get_value(), wb::attack::remove_temp_modifier(), display_context::unit_can_move(), UNIT_GETTER(), display_context::unit_orb_status(), and unit_weapons().

◆ attacks_left() [2/2]

int unit::attacks_left ( bool  base_value) const
inline

Gets the remaining number of attacks this unit can perform this turn.

Parameters
base_valueIf false, consider the incapacitated flag.
Returns
If base_value is true, the raw value is returned.

Definition at line 1012 of file unit.hpp.

References unit::attacks_left(), and unit::attacks_left_.

◆ damage_from()

int unit::damage_from ( const attack_type attack,
bool  attacker,
const map_location loc,
const_attack_ptr  weapon = nullptr 
) const
inline

Calculates the damage this unit would take from a certain attack.

Parameters
attackThe attack to consider.
attackerWhether this unit should be considered the attacker.
locThe unit's location (to resolve [resistance] abilities)
weaponThe weapon to check for any abilities or weapon specials
Returns
The expected damage.

Definition at line 978 of file unit.hpp.

References loc, and unit::resistance_against().

Referenced by battle_context_unit_stats::battle_context_unit_stats().

◆ defense_modifier()

int unit::defense_modifier ( const t_translation::terrain_code terrain) const

◆ get_base_resistances()

utils::string_map_res unit::get_base_resistances ( ) const
inline

Gets resistances without any abilities applied.

Definition at line 1064 of file unit.hpp.

References movetype::damage_table(), and unit::movement_type_.

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

◆ max_attacks()

int unit::max_attacks ( ) const
inline

The maximum number of attacks this unit may perform per turn, usually 1.

Definition at line 984 of file unit.hpp.

References unit::max_attacks_.

Referenced by wfl::unit_callable::get_value(), UNIT_GETTER(), display_context::unit_orb_status(), and unit_weapons().

◆ remove_attack()

bool unit::remove_attack ( const attack_ptr atk)

Remove an attack from the unit.

Parameters
atkA pointer to the attack to remove
Returns
true if the attack was removed, false if it didn't exist on the unit

Definition at line 2748 of file unit.cpp.

References unit::attacks_, utils::find(), unit::set_attr_changed(), and unit::UA_ATTACKS.

Referenced by impl_unit_attacks_set().

◆ remove_attacks_ai()

void unit::remove_attacks_ai ( )

Set the unit to have no attacks left for this turn.

Definition at line 2759 of file unit.cpp.

References unit::attacks_left_, unit::max_attacks_, and unit::set_attacks().

◆ resistance_against() [1/2]

int unit::resistance_against ( const attack_type atk,
bool  attacker,
const map_location loc,
const_attack_ptr  weapon = nullptr 
) const
inline

The unit's resistance against a given attack.

Parameters
atkThe attack
attackerTrue if this unit is on the offensive (to resolve [resistance] abilities)
locThe unit's location (to resolve [resistance] abilities)
weaponThe weapon to check for any abilities or weapon specials

Definition at line 1058 of file unit.hpp.

References loc, unit::resistance_against(), and attack_type::type().

◆ resistance_against() [2/2]

int unit::resistance_against ( const std::string &  damage_name,
bool  attacker,
const map_location loc,
const_attack_ptr  weapon = nullptr,
const const_attack_ptr opp_weapon = nullptr 
) const

The unit's resistance against a given damage type.

Parameters
damage_nameThe damage type
attackerTrue if this unit is on the offensive (to resolve [resistance] abilities)
locThe unit's location (to resolve [resistance] abilities)
weaponThe weapon to check for any abilities or weapon specials
opp_weaponThe opponent's weapon to check for any abilities or weapon specials

Definition at line 1781 of file unit.cpp.

References unit_ability_list::empty(), utils::erase_if(), unit::get_abilities_weapons(), i, loc, resistance_filter_matches_base(), and unit::resistance_value().

Referenced by unit::damage_from(), wfl::gamestate::DEFINE_WFL_FUNCTION(), intf_unit_resistance(), unit::resistance_against(), and unit_hp().

◆ resistance_filter_matches()

bool unit::resistance_filter_matches ( const config cfg,
const std::string &  damage_name,
int  res 
) const
private

Definition at line 1732 of file unit.cpp.

References unit_abilities::filter_base_matches(), utils::find(), and utils::split().

Referenced by unit::resistance_value().

◆ resistance_value()

int unit::resistance_value ( unit_ability_list  resistance_list,
const std::string &  damage_name 
) const

For the provided list of resistance abilities, determine the damage resistance based on which are active and any max_value that's present.

Parameters
resistance_listA list of resistance abilities that the unit has.
damage_nameThe name of the damage type, for example "blade".
Returns
The resistance value for a unit with the provided resistance abilities to the provided damage type.

Definition at line 1756 of file unit.cpp.

References unit_ability_list::empty(), utils::erase_if(), unit_abilities::effect::get_composite_value(), i, unit::movement_type_, movetype::resistance_against(), and unit::resistance_filter_matches().

Referenced by unit::resistance_against(), and select_alternative_type().

◆ set_attacks()

void unit::set_attacks ( int  left)
inline

Sets the number of attacks this unit has left this turn.

Parameters
leftThe number of attacks left

Definition at line 1021 of file unit.hpp.

References unit::attacks_left_.

Referenced by wb::attack::apply_temp_modifier(), unit::remove_attacks_ai(), wb::attack::remove_temp_modifier(), and UNIT_SETTER().

◆ set_max_attacks()

void unit::set_max_attacks ( int  value)
inline