The Battle for Wesnoth  1.15.1+dev
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
attack_type Class Reference

#include <attack_type.hpp>

Inheritance diagram for attack_type:
Inheritance graph

Classes

class  specials_context_t
 

Public Member Functions

 attack_type (const config &cfg)
 
const t_stringname () const
 
const std::string & id () const
 
const std::string & type () const
 
const std::string & icon () const
 
const std::string & range () const
 
int min_range () const
 
int max_range () const
 
std::string accuracy_parry_description () const
 
int accuracy () const
 
int parry () const
 
int damage () const
 
int num_attacks () const
 
double attack_weight () const
 
double defense_weight () const
 
const configspecials () const
 
void set_name (const t_string &value)
 
void set_id (const std::string &value)
 
void set_type (const std::string &value)
 
void set_icon (const std::string &value)
 
void set_range (const std::string &value)
 
void set_accuracy (int value)
 
void set_parry (int value)
 
void set_damage (int value)
 
void set_num_attacks (int value)
 
void set_attack_weight (double value)
 
void set_defense_weight (double value)
 
void set_specials (config value)
 
std::pair< int, bool > combat_ability (const std::string &ability, int abil_value=0, bool backstab_pos=false) const
 
bool bool_ability (const std::string &ability) const
 
bool get_special_bool (const std::string &special, bool simple_check=false) const
 Returns whether or not *this has a special with a tag or id equal to special. More...
 
unit_ability_list get_specials (const std::string &special) const
 Returns the currently active specials as an ability list, given the current context (see set_specials_context). More...
 
std::vector< std::pair< t_string, t_string > > special_tooltips (boost::dynamic_bitset<> *active_list=nullptr) const
 Returns a vector of names and descriptions for the specials of *this. More...
 
std::string weapon_specials (bool only_active=false, bool is_backstab=false) const
 Returns a comma-separated string of active names for the specials of *this. More...
 
void modified_attacks (bool is_backstab, unsigned &min_attacks, unsigned &max_attacks) const
 Calculates the number of attacks this weapon has, considering specials. More...
 
int modified_damage (bool is_backstab) const
 Returns the damage per attack of this weapon, considering specials. More...
 
bool matches_filter (const config &filter) const
 Returns whether or not *this matches the given filter. More...
 
bool apply_modification (const config &cfg)
 Modifies *this using the specifications in cfg, but only if *this matches cfg viewed as a filter. More...
 
bool describe_modification (const config &cfg, std::string *description)
 Trimmed down version of apply_modification(), with no modifications actually made. More...
 
int movement_used () const
 
void set_movement_used (int value)
 
void write (config &cfg) const
 
config to_config () const
 
specials_context_t specials_context (unit_const_ptr self, unit_const_ptr other, const map_location &unit_loc, const map_location &other_loc, bool attacking, const_attack_ptr other_attack) const
 
specials_context_t specials_context (unit_const_ptr self, const map_location &loc, bool attacking=true) const
 
specials_context_t specials_context (const unit_type &self_type, const map_location &loc, bool attacking=true) const
 
specials_context_t specials_context_for_listing (bool attacking=true) const
 
void set_changed (bool value)
 
bool get_changed () const
 

Private Types

enum  AFFECTS { AFFECT_SELF =1, AFFECT_OTHER =2, AFFECT_EITHER =3 }
 

Private Member Functions

bool special_active (const config &special, AFFECTS whom, const std::string &tag_name, bool include_backstab=true) const
 Returns whether or not the given special is active for the specified unit, based on the current context (see set_specials_context). More...
 

Private Attributes

map_location self_loc_
 
map_location other_loc_
 
unit_const_ptr self_
 
unit_const_ptr other_
 
bool is_attacker_
 
const_attack_ptr other_attack_
 
bool is_for_listing_ = false
 
t_string description_
 
std::string id_
 
std::string type_
 
std::string icon_
 
std::string range_
 
int min_range_
 
int max_range_
 
int damage_
 
int num_attacks_
 
double attack_weight_
 
double defense_weight_
 
int accuracy_
 
int movement_used_
 
int parry_
 
config specials_
 
bool changed_
 

Friends

class specials_context_t
 

Detailed Description

Definition at line 35 of file attack_type.hpp.

Member Enumeration Documentation

◆ AFFECTS

enum attack_type::AFFECTS
private
Enumerator
AFFECT_SELF 
AFFECT_OTHER 
AFFECT_EITHER 

Definition at line 103 of file attack_type.hpp.

Constructor & Destructor Documentation

◆ attack_type()

attack_type::attack_type ( const config cfg)
explicit

Definition at line 44 of file attack_type.cpp.

References description_, translation::egettext(), t_string::empty(), icon_, and id_.

Member Function Documentation

◆ accuracy()

int attack_type::accuracy ( ) const
inline

Definition at line 48 of file attack_type.hpp.

References accuracy_.

Referenced by attack_info(), impl_unit_attack_get(), and matches_simple_filter().

◆ accuracy_parry_description()

std::string attack_type::accuracy_parry_description ( ) const

Definition at line 77 of file attack_type.cpp.

References accuracy_, parry_, s, and utils::signed_percent().

Referenced by attack_info(), and max_range().

◆ apply_modification()

bool attack_type::apply_modification ( const config cfg)

◆ attack_weight()

double attack_type::attack_weight ( ) const
inline

Definition at line 52 of file attack_type.hpp.

References attack_weight_.

Referenced by battle_context::choose_attacker_weapon(), and impl_unit_attack_get().

◆ bool_ability()

bool attack_type::bool_ability ( const std::string &  ability) const

◆ combat_ability()

std::pair< int, bool > attack_type::combat_ability ( const std::string &  ability,
int  abil_value = 0,
bool  backstab_pos = false 
) const

◆ damage()

int attack_type::damage ( ) const
inline

Definition at line 50 of file attack_type.hpp.

References damage_.

Referenced by attack_info(), impl_unit_attack_get(), matches_simple_filter(), and modified_damage().

◆ defense_weight()

double attack_type::defense_weight ( ) const
inline

Definition at line 53 of file attack_type.hpp.

References defense_weight_.

Referenced by battle_context::choose_defender_weapon(), and impl_unit_attack_get().

◆ describe_modification()

bool attack_type::describe_modification ( const config cfg,
std::string *  description 
)

Trimmed down version of apply_modification(), with no modifications actually made.

This can be used to get a description of the modification(s) specified by cfg (if *this matches cfg as a filter).

If *description is provided, it will be set to a (translated) description of the modification(s) applied (currently only changes to the number of strikes, damage, accuracy, and parry are included in this description).

Returns
whether or not this matched the cfg as a filter.

Definition at line 355 of file attack_type.cpp.

References utils::format_conjunct_list(), matches_filter(), utils::print_modifier(), set_accuracy(), set_damage(), set_parry(), VGETTEXT, and VNGETTEXT.

Referenced by set_specials().

◆ get_changed()

bool attack_type::get_changed ( ) const
inline

Definition at line 158 of file attack_type.hpp.

References changed_.

◆ get_special_bool()

bool attack_type::get_special_bool ( const std::string &  special,
bool  simple_check = false 
) const

Returns whether or not *this has a special with a tag or id equal to special.

If simple_check is set to true, then the check is merely for being present. Otherwise (the default), the check is for a special active in the current context (see set_specials_context), including specials obtained from the opponent's attack.

Definition at line 639 of file abilities.cpp.

Referenced by matches_simple_filter(), and set_specials().

◆ get_specials()

unit_ability_list attack_type::get_specials ( const std::string &  special) const

Returns the currently active specials as an ability list, given the current context (see set_specials_context).

Definition at line 687 of file abilities.cpp.

References unit_ability_list::emplace_back(), and i.

Referenced by modified_attacks(), modified_damage(), and set_specials().

◆ icon()

const std::string& attack_type::icon ( ) const
inline

Definition at line 43 of file attack_type.hpp.

References icon_.

Referenced by attack_info(), impl_unit_attack_get(), and gui2::dialogs::unit_attack::pre_show().

◆ id()

const std::string& attack_type::id ( ) const
inline

Definition at line 41 of file attack_type.hpp.

References id_.

Referenced by impl_unit_attack_get(), and matches_simple_filter().

◆ matches_filter()

bool attack_type::matches_filter ( const config filter) const

Returns whether or not *this matches the given filter.

Definition at line 182 of file attack_type.cpp.

References config::all_children_range(), and matches_simple_filter().

Referenced by apply_modification(), describe_modification(), and set_specials().

◆ max_range()

int attack_type::max_range ( ) const
inline

Definition at line 46 of file attack_type.hpp.

References accuracy_parry_description(), and max_range_.

◆ min_range()

int attack_type::min_range ( ) const
inline

Definition at line 45 of file attack_type.hpp.

References min_range_.

◆ modified_attacks()

void attack_type::modified_attacks ( bool  is_backstab,
unsigned &  min_attacks,
unsigned &  max_attacks 
) const

Calculates the number of attacks this weapon has, considering specials.

This returns two numbers because of the swarm special. The actual number of attacks depends on the unit's health and should be: min_attacks + (max_attacks - min_attacks) * (current hp) / (max hp) c.f. swarm_blows()

Definition at line 875 of file abilities.cpp.

References combat_ability(), unit_ability_list::empty(), ERR_NG, unit_abilities::effect::get_composite_value(), get_specials(), unit_ability_list::highest(), and num_attacks().

Referenced by attack_info(), and set_specials().

◆ modified_damage()

int attack_type::modified_damage ( bool  is_backstab) const

Returns the damage per attack of this weapon, considering specials.

Definition at line 905 of file abilities.cpp.

References config::child(), combat_ability(), damage(), unit_abilities::effect::get_composite_value(), get_specials(), and map_location::valid().

Referenced by attack_info(), and set_specials().

◆ movement_used()

int attack_type::movement_used ( ) const
inline

Definition at line 93 of file attack_type.hpp.

References movement_used_.

Referenced by impl_unit_attack_get(), and matches_simple_filter().

◆ name()

const t_string& attack_type::name ( ) const
inline

Definition at line 40 of file attack_type.hpp.

References description_.

Referenced by attack_info(), impl_unit_attack_get(), and gui2::dialogs::unit_attack::pre_show().

◆ num_attacks()

int attack_type::num_attacks ( ) const
inline

Definition at line 51 of file attack_type.hpp.

References num_attacks_.

Referenced by attack_info(), impl_unit_attack_get(), matches_simple_filter(), and modified_attacks().

◆ parry()

int attack_type::parry ( ) const
inline

Definition at line 49 of file attack_type.hpp.

References parry_.

Referenced by attack_info(), impl_unit_attack_get(), and matches_simple_filter().

◆ range()

const std::string& attack_type::range ( ) const
inline

◆ set_accuracy()

void attack_type::set_accuracy ( int  value)
inline

Definition at line 61 of file attack_type.hpp.

References accuracy_, and set_changed().

Referenced by apply_modification(), describe_modification(), and impl_unit_attack_set().

◆ set_attack_weight()

void attack_type::set_attack_weight ( double  value)
inline

Definition at line 65 of file attack_type.hpp.

References attack_weight_, and set_changed().

Referenced by apply_modification(), and impl_unit_attack_set().

◆ set_changed()

void attack_type::set_changed ( bool  value)
inline

◆ set_damage()

void attack_type::set_damage ( int  value)
inline

Definition at line 63 of file attack_type.hpp.

References damage_, and set_changed().

Referenced by apply_modification(), describe_modification(), and impl_unit_attack_set().

◆ set_defense_weight()

void attack_type::set_defense_weight ( double  value)
inline

Definition at line 66 of file attack_type.hpp.

References defense_weight_, and set_changed().

Referenced by apply_modification(), and impl_unit_attack_set().

◆ set_icon()

void attack_type::set_icon ( const std::string &  value)
inline

Definition at line 59 of file attack_type.hpp.

References icon_, and set_changed().

Referenced by apply_modification(), and impl_unit_attack_set().

◆ set_id()

void attack_type::set_id ( const std::string &  value)
inline

Definition at line 57 of file attack_type.hpp.

References id_, and set_changed().

Referenced by impl_unit_attack_set().

◆ set_movement_used()

void attack_type::set_movement_used ( int  value)
inline

Definition at line 94 of file attack_type.hpp.

References movement_used_, and write().

Referenced by impl_unit_attack_set().

◆ set_name()

void attack_type::set_name ( const t_string value)
inline

Definition at line 56 of file attack_type.hpp.

References description_, and set_changed().

Referenced by apply_modification(), and impl_unit_attack_set().

◆ set_num_attacks()

void attack_type::set_num_attacks ( int  value)
inline

Definition at line 64 of file attack_type.hpp.

References num_attacks_, and set_changed().

Referenced by impl_unit_attack_set().

◆ set_parry()

void attack_type::set_parry ( int  value)
inline

Definition at line 62 of file attack_type.hpp.

References parry_, and set_changed().

Referenced by apply_modification(), describe_modification(), and impl_unit_attack_set().

◆ set_range()

void attack_type::set_range ( const std::string &  value)
inline

Definition at line 60 of file attack_type.hpp.

References range_, and set_changed().

Referenced by apply_modification(), and impl_unit_attack_set().

◆ set_specials()

void attack_type::set_specials ( config  value)
inline

◆ set_type()

void attack_type::set_type ( const std::string &  value)
inline

Definition at line 58 of file attack_type.hpp.

References set_changed(), and type_.

Referenced by apply_modification(), and impl_unit_attack_set().

◆ special_active()

bool attack_type::special_active ( const config special,
AFFECTS  whom,
const std::string &  tag_name,
bool  include_backstab = true 
) const
private

Returns whether or not the given special is active for the specified unit, based on the current context (see set_specials_context).

Parameters
[in]speciala weapon special WML structure
[in]whomspecifies which combatant we care about
[in]tag_nametag name of the special config
[in]include_backstabfalse if backstab specials should not be active (usually true since backstab is usually accounted for elsewhere)

Definition at line 1033 of file abilities.cpp.

References AFFECT_OTHER, AFFECT_SELF, config::child_range(), unit_map::end(), resources::filter_con, unit_map::find(), resources::gameboard, get_adjacent_tiles(), filter_context::get_disp_context(), map_location::get_relative_dir(), unit_map::iterator_base< iter_types >::get_shared_ptr(), display::get_singleton(), display_context::get_team(), display::get_units(), i, utf8::index(), is_attacker_, is_for_listing_, gamemap::is_village(), game_board::map(), map_location::NDIRECTIONS, other_, other_attack_, other_loc_, map_location::parse_directions(), utils::parse_ranges(), self_, self_loc_, unit::STATE_POISONED, and unit_map::iterator_base< iter_types >::valid().

◆ special_tooltips()

std::vector< std::pair< t_string, t_string > > attack_type::special_tooltips ( boost::dynamic_bitset<> *  active_list = nullptr) const

Returns a vector of names and descriptions for the specials of *this.

Each std::pair in the vector has first = name and second = description.

This uses either the active or inactive name/description for each special, based on the current context (see set_specials_context), provided active_list is not nullptr. Otherwise specials are assumed active. If the appropriate name is empty, the special is skipped.

Definition at line 719 of file abilities.cpp.

References t_string::empty(), and name().

Referenced by attack_info(), and set_specials().

◆ specials()

const config& attack_type::specials ( ) const
inline

Definition at line 54 of file attack_type.hpp.

References specials_.

Referenced by impl_unit_attack_get().

◆ specials_context() [1/3]

specials_context_t attack_type::specials_context ( unit_const_ptr  self,
unit_const_ptr  other,
const map_location unit_loc,
const map_location other_loc,
bool  attacking,
const_attack_ptr  other_attack 
) const
inline

◆ specials_context() [2/3]

specials_context_t attack_type::specials_context ( unit_const_ptr  self,
const map_location loc,
bool  attacking = true 
) const
inline

◆ specials_context() [3/3]

specials_context_t attack_type::specials_context ( const unit_type self_type,
const map_location loc,
bool  attacking = true 
) const
inline

◆ specials_context_for_listing()

specials_context_t attack_type::specials_context_for_listing ( bool  attacking = true) const
inline

Definition at line 151 of file attack_type.hpp.

References attack_type::specials_context_t::specials_context_t().

Referenced by attack_info().

◆ to_config()

config attack_type::to_config ( ) const
inline

Definition at line 97 of file attack_type.hpp.

References c, and write().

Referenced by impl_unit_attack_get().

◆ type()

const std::string& attack_type::type ( ) const
inline

◆ weapon_specials()

std::string attack_type::weapon_specials ( bool  only_active = false,
bool  is_backstab = false 
) const

Returns a comma-separated string of active names for the specials of *this.

Empty names are skipped.

This excludes inactive specials if only_active is true. Whether or not a special is active depends on the current context (see set_specials_context) and the is_backstab parameter.

Definition at line 755 of file abilities.cpp.

References font::inactive_details_color, name(), and font::span_color().

Referenced by gui2::dialogs::unit_attack::pre_show(), and set_specials().

◆ write()

void attack_type::write ( config cfg) const

Friends And Related Function Documentation

◆ specials_context_t

friend class specials_context_t
friend

Definition at line 109 of file attack_type.hpp.

Member Data Documentation

◆ accuracy_

int attack_type::accuracy_
private

◆ attack_weight_

double attack_type::attack_weight_
private

Definition at line 172 of file attack_type.hpp.

Referenced by apply_modification(), attack_weight(), set_attack_weight(), and write().

◆ changed_

bool attack_type::changed_
private

Definition at line 179 of file attack_type.hpp.

Referenced by get_changed(), and set_changed().

◆ damage_

int attack_type::damage_
private

Definition at line 170 of file attack_type.hpp.

Referenced by apply_modification(), damage(), set_damage(), and write().

◆ defense_weight_

double attack_type::defense_weight_
private

Definition at line 173 of file attack_type.hpp.

Referenced by apply_modification(), defense_weight(), set_defense_weight(), and write().

◆ description_

t_string attack_type::description_
private

Definition at line 164 of file attack_type.hpp.

Referenced by apply_modification(), attack_type(), name(), set_name(), and write().

◆ icon_

std::string attack_type::icon_
private

Definition at line 167 of file attack_type.hpp.

Referenced by apply_modification(), attack_type(), icon(), set_icon(), and write().

◆ id_

std::string attack_type::id_
private

Definition at line 165 of file attack_type.hpp.

Referenced by apply_modification(), attack_type(), id(), set_id(), and write().

◆ is_attacker_

bool attack_type::is_attacker_
mutableprivate

◆ is_for_listing_

bool attack_type::is_for_listing_ = false
mutableprivate

◆ max_range_

int attack_type::max_range_
private

Definition at line 169 of file attack_type.hpp.

Referenced by max_range(), and write().

◆ min_range_

int attack_type::min_range_
private

Definition at line 169 of file attack_type.hpp.

Referenced by min_range(), and write().

◆ movement_used_

int attack_type::movement_used_
private

Definition at line 176 of file attack_type.hpp.

Referenced by apply_modification(), movement_used(), set_movement_used(), and write().

◆ num_attacks_

int attack_type::num_attacks_
private

Definition at line 171 of file attack_type.hpp.

Referenced by apply_modification(), num_attacks(), set_num_attacks(), and write().

◆ other_

unit_const_ptr attack_type::other_
mutableprivate

◆ other_attack_

const_attack_ptr attack_type::other_attack_
mutableprivate

◆ other_loc_

map_location attack_type::other_loc_
mutableprivate

◆ parry_

int attack_type::parry_
private

◆ range_

std::string attack_type::range_
private

Definition at line 168 of file attack_type.hpp.

Referenced by apply_modification(), range(), set_range(), and write().

◆ self_

unit_const_ptr attack_type::self_
mutableprivate

◆ self_loc_

map_location attack_type::self_loc_
mutableprivate

◆ specials_

config attack_type::specials_
private

Definition at line 178 of file attack_type.hpp.

Referenced by apply_modification(), set_specials(), specials(), and write().

◆ type_

std::string attack_type::type_
private

Definition at line 166 of file attack_type.hpp.

Referenced by apply_modification(), set_type(), type(), and write().


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