The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
attack_type Class Reference

#include <attack_type.hpp>

Public Member Functions

 attack_type (const config &cfg)
 
 ~attack_type ()
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
const t_stringname () const
 
const std::stringid () const
 
const std::stringtype () const
 
const std::stringicon () const
 
const std::stringrange () 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 config specials () const
 
void set_name (const t_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)
 
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 (std::vector< bool > *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 set_specials_context (const map_location &unit_loc, const map_location &other_loc, bool attacking, const attack_type *other_attack) const
 Sets the context under which specials will be checked for being active. More...
 
void set_specials_context (const map_location &loc, bool attacking=true) const
 Sets the context under which specials will be checked for being active. More...
 
void set_specials_context_for_listing () const
 
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
 

Private Types

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

Private Member Functions

bool special_active (const config &special, AFFECTS whom, 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_
 
bool is_attacker_
 
const attack_typeother_attack_
 
bool is_for_listing_
 
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_
 

Detailed Description

Definition at line 28 of file attack_type.hpp.

Member Enumeration Documentation

enum attack_type::AFFECTS
private
Enumerator
AFFECT_SELF 
AFFECT_OTHER 
AFFECT_EITHER 

Definition at line 100 of file attack_type.hpp.

Constructor & Destructor Documentation

attack_type::attack_type ( const config cfg)
explicit

Definition at line 40 of file attack_type.cpp.

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

attack_type::~attack_type ( )

Default implementation, but defined out-of-line for efficiency reasons.

Definition at line 72 of file attack_type.cpp.

Member Function Documentation

int attack_type::accuracy ( ) const
inline
std::string attack_type::accuracy_parry_description ( ) const

Definition at line 76 of file attack_type.cpp.

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

Referenced by attack_info().

bool attack_type::apply_modification ( const config cfg)
double attack_type::attack_weight ( ) const
inline
int attack_type::damage ( ) const
inline
double attack_type::defense_weight ( ) const
inline
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 332 of file attack_type.cpp.

References _(), _n(), accuracy(), damage(), lexical_cast(), matches_filter(), movement_used(), num_attacks(), parry(), utils::print_modifier(), set_accuracy(), set_damage(), set_parry(), and utils::signed_value().

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

References AFFECT_OTHER, AFFECT_SELF, i, other_attack_, special_active(), and specials_.

Referenced by battle_context_unit_stats::battle_context_unit_stats(), and matches_simple_filter().

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

References AFFECT_OTHER, AFFECT_SELF, config::child_range(), i, other_attack_, other_loc_, unit_ability_list::push_back(), self_loc_, special_active(), and specials_.

Referenced by battle_context_unit_stats::battle_context_unit_stats(), battle_prediction_pane::get_unit_strings(), modified_attacks(), and modified_damage().

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

Definition at line 38 of file attack_type.hpp.

References icon_.

Referenced by attack_type_callable::get_value(), and gui2::set_weapon_info().

const std::string& attack_type::id ( ) const
inline
bool attack_type::matches_filter ( const config filter) const

Returns whether or not *this matches the given filter.

Definition at line 158 of file attack_type.cpp.

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

Referenced by apply_modification(), describe_modification(), unit_animation::matches(), and game_events::matches_special_filter().

int attack_type::max_range ( ) const
inline

Definition at line 41 of file attack_type.hpp.

References max_range_.

Referenced by battle_context_unit_stats::battle_context_unit_stats().

int attack_type::min_range ( ) const
inline

Definition at line 40 of file attack_type.hpp.

References min_range_.

Referenced by battle_context_unit_stats::battle_context_unit_stats().

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

References 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 battle_context_unit_stats::battle_context_unit_stats().

int attack_type::modified_damage ( bool  is_backstab) const

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

Definition at line 743 of file abilities.cpp.

References damage(), unit_abilities::effect::get_composite_value(), and get_specials().

Referenced by attack_info(), and battle_context_unit_stats::battle_context_unit_stats().

int attack_type::movement_used ( ) const
inline
const t_string& attack_type::name ( ) const
inline
int attack_type::num_attacks ( ) const
inline
int attack_type::parry ( ) const
inline
const std::string& attack_type::range ( ) const
inline
void attack_type::set_accuracy ( int  value)
inline

Definition at line 58 of file attack_type.hpp.

References accuracy_.

Referenced by apply_modification(), and describe_modification().

void attack_type::set_attack_weight ( double  value)
inline

Definition at line 62 of file attack_type.hpp.

References attack_weight_.

Referenced by apply_modification().

void attack_type::set_damage ( int  value)
inline

Definition at line 60 of file attack_type.hpp.

References damage_.

Referenced by apply_modification(), and describe_modification().

void attack_type::set_defense_weight ( double  value)
inline

Definition at line 63 of file attack_type.hpp.

References defense_weight_.

Referenced by apply_modification().

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

Definition at line 54 of file attack_type.hpp.

References icon_.

Referenced by apply_modification().

void attack_type::set_movement_used ( int  value)
inline

Definition at line 91 of file attack_type.hpp.

References movement_used_.

void attack_type::set_name ( const t_string value)
inline

Definition at line 51 of file attack_type.hpp.

References description_.

Referenced by apply_modification().

void attack_type::set_num_attacks ( int  value)
inline

Definition at line 61 of file attack_type.hpp.

References num_attacks_.

void attack_type::set_parry ( int  value)
inline

Definition at line 59 of file attack_type.hpp.

References parry_.

Referenced by apply_modification(), and describe_modification().

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

Definition at line 55 of file attack_type.hpp.

References range_.

void attack_type::set_specials ( config  value)
inline

Definition at line 64 of file attack_type.hpp.

References specials_.

Referenced by apply_modification().

void attack_type::set_specials_context ( const map_location unit_loc,
const map_location other_loc,
bool  attacking,
const attack_type other_attack 
) const

Sets the context under which specials will be checked for being active.

This version is appropriate if both units in a combat are known.

Parameters
[in]unit_locThe location of the unit with this weapon.
[in]other_locThe location of the other unit in the combat.
[in]attackingWhether or not the unit with this weapon is the attacker.
[in]other_attackThe attack used by the other unit.

Definition at line 677 of file abilities.cpp.

References is_attacker_, is_for_listing_, other_attack_, other_loc_, and self_loc_.

Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), and battle_prediction_pane::get_unit_strings().

void attack_type::set_specials_context ( const map_location loc,
bool  attacking = true 
) const

Sets the context under which specials will be checked for being active.

This version is appropriate if there is no specific combat being considered.

Parameters
[in]locThe location of the unit with this weapon.
[in]attackingWhether or not the unit with this weapon is the attacker.

Definition at line 695 of file abilities.cpp.

References is_attacker_, is_for_listing_, map_location::null_location(), other_attack_, other_loc_, and self_loc_.

void attack_type::set_specials_context_for_listing ( ) const

Definition at line 704 of file abilities.cpp.

References is_for_listing_.

Referenced by attack_info().

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

Definition at line 53 of file attack_type.hpp.

References type_.

Referenced by apply_modification().

bool attack_type::special_active ( const config special,
AFFECTS  whom,
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]include_backstabfalse if backstab specials should not be active (usually true since backstab is usually accounted for elsewhere)

Definition at line 865 of file abilities.cpp.

References AFFECT_OTHER, AFFECT_SELF, config::child_range(), unit_map::end(), resources::filter_con, unit_map::find(), get_adjacent_tiles(), filter_context::get_disp_context(), map_location::get_relative_dir(), i, is_attacker_, is_for_listing_, terrain_filter::match(), unit_filter::matches(), map_location::NDIRECTIONS, other_attack_, other_loc_, map_location::parse_directions(), utils::parse_ranges(), self_loc_, display_context::teams(), and resources::units.

Referenced by get_special_bool(), get_specials(), special_tooltips(), and weapon_specials().

std::vector< std::pair< t_string, t_string > > attack_type::special_tooltips ( std::vector< bool > *  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 612 of file abilities.cpp.

References AFFECT_EITHER, config::all_children_range(), t_string::empty(), special_active(), and specials_.

Referenced by attack_info().

const config attack_type::specials ( ) const
inline

Definition at line 49 of file attack_type.hpp.

References specials_.

Referenced by attack_type_callable::get_value().

config attack_type::to_config ( ) const
inline

Definition at line 94 of file attack_type.hpp.

References c, and write().

const std::string& attack_type::type ( ) const
inline
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 649 of file abilities.cpp.

References AFFECT_EITHER, config::all_children_range(), name(), special_active(), and specials_.

Referenced by attack_type_callable::do_compare(), and gui2::set_weapon_info().

void attack_type::write ( config cfg) const

Member Data Documentation

int attack_type::accuracy_
private
double attack_type::attack_weight_
private

Definition at line 119 of file attack_type.hpp.

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

int attack_type::damage_
private

Definition at line 117 of file attack_type.hpp.

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

double attack_type::defense_weight_
private

Definition at line 120 of file attack_type.hpp.

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

t_string attack_type::description_
private

Definition at line 111 of file attack_type.hpp.

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

std::string attack_type::icon_
private

Definition at line 114 of file attack_type.hpp.

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

std::string attack_type::id_
private

Definition at line 112 of file attack_type.hpp.

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

bool attack_type::is_attacker_
mutableprivate

Definition at line 107 of file attack_type.hpp.

Referenced by set_specials_context(), and special_active().

bool attack_type::is_for_listing_
mutableprivate
int attack_type::max_range_
private

Definition at line 116 of file attack_type.hpp.

Referenced by max_range(), and write().

int attack_type::min_range_
private

Definition at line 116 of file attack_type.hpp.

Referenced by min_range(), and write().

int attack_type::movement_used_
private

Definition at line 123 of file attack_type.hpp.

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

int attack_type::num_attacks_
private

Definition at line 118 of file attack_type.hpp.

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

const attack_type* attack_type::other_attack_
mutableprivate
map_location attack_type::other_loc_
mutableprivate

Definition at line 106 of file attack_type.hpp.

Referenced by get_specials(), set_specials_context(), and special_active().

int attack_type::parry_
private
std::string attack_type::range_
private

Definition at line 115 of file attack_type.hpp.

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

map_location attack_type::self_loc_
mutableprivate

Definition at line 106 of file attack_type.hpp.

Referenced by get_specials(), set_specials_context(), and special_active().

config attack_type::specials_
private
std::string attack_type::type_
private

Definition at line 113 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: