The Battle for Wesnoth  1.15.6+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 (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_against (const std::string &damage_name, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr, 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 unit::get_base_resistances () const
 Gets resistances without any abilities applied. More...
 
bool unit::resistance_filter_matches (const config &cfg, bool attacker, 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 943 of file unit.hpp.

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 932 of file unit.hpp.

References 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 992 of file unit.hpp.

Referenced by wb::attack::apply_temp_modifier(), wfl::unit_callable::get_value(), wb::attack::remove_temp_modifier(), display_context::unit_can_move(), 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 1004 of file unit.hpp.

◆ 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.
locTODO: what does this do?
Returns
The expected damage.

Definition at line 970 of file unit.hpp.

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 unit::get_base_resistances ( ) const
inline

Gets resistances without any abilities applied.

Definition at line 1044 of file unit.hpp.

References mariadb::value::string.

Referenced by gui2::unit_preview_pane::set_displayed_unit(), 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 976 of file unit.hpp.

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

◆ remove_attack()

bool unit::remove_attack ( 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 2598 of file unit.cpp.

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

◆ resistance_against() [1/2]

int unit::resistance_against ( const std::string &  damage_name,
bool  attacker,
const map_location loc,
const_attack_ptr  weapon = nullptr,
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)

Definition at line 1660 of file unit.cpp.

References unit_ability_list::begin(), unit_ability_list::empty(), unit_ability_list::end(), unit_ability_list::erase(), unit::get_abilities_weapons(), unit_abilities::effect::get_composite_value(), unit_ability_list::highest(), i, unit::movement_type_, movetype::resistance_against(), and unit::resistance_filter_matches().

Referenced by wfl::gamestate::DEFINE_WFL_FUNCTION(), intf_unit_resistance(), gui2::unit_preview_pane::set_displayed_unit(), and unit_hp().

◆ resistance_against() [2/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)

Definition at line 1038 of file unit.hpp.

References attack_type::type().

◆ resistance_filter_matches()

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

◆ 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 1013 of file unit.hpp.

References left, mariadb::value::string, and gui2::terrain.

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

◆ set_max_attacks()

void unit::set_max_attacks ( int  value)
inline

Definition at line 981 of file unit.hpp.

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