#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_string & | name () 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 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_type * | other_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_ |
Definition at line 28 of file attack_type.hpp.
|
private |
Enumerator | |
---|---|
AFFECT_SELF | |
AFFECT_OTHER | |
AFFECT_EITHER |
Definition at line 100 of file attack_type.hpp.
|
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.
|
inline |
Definition at line 43 of file attack_type.hpp.
References accuracy_.
Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), describe_modification(), attack_type_callable::get_value(), and matches_simple_filter().
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 | ) |
Modifies *this using the specifications in cfg, but only if *this matches cfg viewed as a filter.
this
matched the cfg as a filter. Definition at line 195 of file attack_type.cpp.
References accuracy_, config::add_child(), config::all_children_range(), utils::apply_modifier(), attack_weight_, config::child(), config::clear(), damage_, defense_weight_, description_, t_string::empty(), gui2::event::find(), icon_, id_, lexical_cast(), matches_filter(), movement_used_, num_attacks_, parry_, set_accuracy(), set_attack_weight(), set_damage(), set_defense_weight(), set_icon(), set_name(), set_parry(), set_specials(), set_type(), specials_, utils::split(), and type_.
|
inline |
Definition at line 47 of file attack_type.hpp.
References attack_weight_.
Referenced by battle_context::choose_attacker_weapon(), and attack_type_callable::get_value().
|
inline |
Definition at line 45 of file attack_type.hpp.
References damage_.
Referenced by attack_info(), describe_modification(), attack_type_callable::do_compare(), battle_prediction_pane::get_unit_strings(), attack_type_callable::get_value(), matches_simple_filter(), and modified_damage().
|
inline |
Definition at line 48 of file attack_type.hpp.
References defense_weight_.
Referenced by battle_context::choose_defender_weapon(), and attack_type_callable::get_value().
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).
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().
|
inline |
Definition at line 38 of file attack_type.hpp.
References icon_.
Referenced by attack_type_callable::get_value(), and gui2::set_weapon_info().
|
inline |
Definition at line 36 of file attack_type.hpp.
References id_.
Referenced by attack_type_callable::do_compare(), attack_type_callable::get_value(), impl_unit_attacks_get(), luaW_pushsimweapon(), and matches_simple_filter().
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().
|
inline |
Definition at line 41 of file attack_type.hpp.
References max_range_.
Referenced by battle_context_unit_stats::battle_context_unit_stats().
|
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().
|
inline |
Definition at line 90 of file attack_type.hpp.
References movement_used_.
Referenced by describe_modification(), attack_type_callable::get_value(), and matches_simple_filter().
|
inline |
Definition at line 35 of file attack_type.hpp.
References description_.
Referenced by attack_info(), battle_prediction_pane::get_unit_strings(), attack_type_callable::get_value(), gui2::set_weapon_info(), unit_weapons(), and weapon_specials().
|
inline |
Definition at line 46 of file attack_type.hpp.
References num_attacks_.
Referenced by attack_info(), describe_modification(), attack_type_callable::do_compare(), attack_type_callable::get_value(), matches_simple_filter(), modified_attacks(), and gui2::set_weapon_info().
|
inline |
Definition at line 44 of file attack_type.hpp.
References parry_.
Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), describe_modification(), attack_type_callable::get_value(), and matches_simple_filter().
|
inline |
Definition at line 39 of file attack_type.hpp.
References range_.
Referenced by attack_info(), battle_context::choose_defender_weapon(), attack_type_callable::do_compare(), attack_type_callable::get_value(), matches_simple_filter(), and gui2::set_weapon_info().
Definition at line 58 of file attack_type.hpp.
References accuracy_.
Referenced by apply_modification(), and describe_modification().
|
inline |
Definition at line 62 of file attack_type.hpp.
References attack_weight_.
Referenced by apply_modification().
Definition at line 60 of file attack_type.hpp.
References damage_.
Referenced by apply_modification(), and describe_modification().
|
inline |
Definition at line 63 of file attack_type.hpp.
References defense_weight_.
Referenced by apply_modification().
|
inline |
Definition at line 54 of file attack_type.hpp.
References icon_.
Referenced by apply_modification().
Definition at line 91 of file attack_type.hpp.
References movement_used_.
Definition at line 51 of file attack_type.hpp.
References description_.
Referenced by apply_modification().
Definition at line 61 of file attack_type.hpp.
References num_attacks_.
Definition at line 59 of file attack_type.hpp.
References parry_.
Referenced by apply_modification(), and describe_modification().
|
inline |
Definition at line 55 of file attack_type.hpp.
References range_.
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.
[in] | unit_loc | The location of the unit with this weapon. |
[in] | other_loc | The location of the other unit in the combat. |
[in] | attacking | Whether or not the unit with this weapon is the attacker. |
[in] | other_attack | The 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.
[in] | loc | The location of the unit with this weapon. |
[in] | attacking | Whether 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().
|
inline |
Definition at line 53 of file attack_type.hpp.
References type_.
Referenced by apply_modification().
|
private |
Returns whether or not the given special is active for the specified unit, based on the current context (see set_specials_context).
[in] | special | a weapon special WML structure |
[in] | whom | specifies which combatant we care about |
[in] | include_backstab | false 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().
|
inline |
Definition at line 49 of file attack_type.hpp.
References specials_.
Referenced by attack_type_callable::get_value().
|
inline |
Definition at line 94 of file attack_type.hpp.
|
inline |
Definition at line 37 of file attack_type.hpp.
References type_.
Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), attack_type_callable::do_compare(), battle_prediction_pane::get_unit_strings(), attack_type_callable::get_value(), matches_simple_filter(), movetype::resistances::resistance_against(), and unit::resistance_against().
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().
Definition at line 427 of file attack_type.cpp.
References accuracy_, config::add_child(), attack_weight_, damage_, defense_weight_, description_, icon_, id_, max_range_, min_range_, movement_used_, num_attacks_, parry_, range_, specials_, and type_.
Referenced by to_config().
|
private |
Definition at line 122 of file attack_type.hpp.
Referenced by accuracy(), accuracy_parry_description(), apply_modification(), set_accuracy(), and write().
|
private |
Definition at line 119 of file attack_type.hpp.
Referenced by apply_modification(), attack_weight(), set_attack_weight(), and write().
|
private |
Definition at line 117 of file attack_type.hpp.
Referenced by apply_modification(), damage(), set_damage(), and write().
|
private |
Definition at line 120 of file attack_type.hpp.
Referenced by apply_modification(), defense_weight(), set_defense_weight(), and write().
|
private |
Definition at line 111 of file attack_type.hpp.
Referenced by apply_modification(), attack_type(), name(), set_name(), and write().
|
private |
Definition at line 114 of file attack_type.hpp.
Referenced by apply_modification(), attack_type(), icon(), set_icon(), and write().
|
private |
Definition at line 112 of file attack_type.hpp.
Referenced by apply_modification(), attack_type(), id(), and write().
|
mutableprivate |
Definition at line 107 of file attack_type.hpp.
Referenced by set_specials_context(), and special_active().
|
mutableprivate |
Definition at line 109 of file attack_type.hpp.
Referenced by set_specials_context(), set_specials_context_for_listing(), and special_active().
|
private |
Definition at line 116 of file attack_type.hpp.
Referenced by max_range(), and write().
|
private |
Definition at line 116 of file attack_type.hpp.
Referenced by min_range(), and write().
|
private |
Definition at line 123 of file attack_type.hpp.
Referenced by apply_modification(), movement_used(), set_movement_used(), and write().
|
private |
Definition at line 118 of file attack_type.hpp.
Referenced by apply_modification(), num_attacks(), set_num_attacks(), and write().
|
mutableprivate |
Definition at line 108 of file attack_type.hpp.
Referenced by get_special_bool(), get_specials(), set_specials_context(), and special_active().
|
mutableprivate |
Definition at line 106 of file attack_type.hpp.
Referenced by get_specials(), set_specials_context(), and special_active().
|
private |
Definition at line 124 of file attack_type.hpp.
Referenced by accuracy_parry_description(), apply_modification(), parry(), set_parry(), and write().
|
private |
Definition at line 115 of file attack_type.hpp.
Referenced by range(), set_range(), and write().
|
mutableprivate |
Definition at line 106 of file attack_type.hpp.
Referenced by get_specials(), set_specials_context(), and special_active().
|
private |
Definition at line 125 of file attack_type.hpp.
Referenced by apply_modification(), get_special_bool(), get_specials(), set_specials(), special_tooltips(), specials(), weapon_specials(), and write().
|
private |
Definition at line 113 of file attack_type.hpp.
Referenced by apply_modification(), set_type(), type(), and write().