The Battle for Wesnoth  1.19.5+dev
attack_type.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "map/location.hpp"
19 #include "tstring.hpp"
20 #include "config.hpp"
21 #include <string>
22 #include <vector>
23 
24 #include <boost/iterator/indirect_iterator.hpp>
25 #include <boost/dynamic_bitset_fwd.hpp>
26 
27 #include "units/ptr.hpp" // for attack_ptr
29 
30 class unit_ability_list;
31 class unit_type;
32 namespace wfl {
33  class map_formula_callable;
34 }
35 //the 'attack type' is the type of attack, how many times it strikes,
36 //and how much damage it does.
37 class attack_type : public std::enable_shared_from_this<attack_type>
38 {
39 public:
40 
41  explicit attack_type(const config& cfg);
42  const t_string& name() const { return description_; }
43  const std::string& id() const { return id_; }
44  const std::string& type() const { return type_; }
45  const std::string& icon() const { return icon_; }
46  const std::string& range() const { return range_; }
47  int min_range() const { return min_range_; }
48  int max_range() const { return max_range_; }
49  std::string accuracy_parry_description() const;
50  int accuracy() const { return accuracy_; }
51  int parry() const { return parry_; }
52  int damage() const { return damage_; }
53  int num_attacks() const { return num_attacks_; }
54  double attack_weight() const { return attack_weight_; }
55  double defense_weight() const { return defense_weight_; }
56  const config &specials() const { return specials_; }
57 
58  void set_name(const t_string& value) { description_ = value; set_changed(true); }
59  void set_id(const std::string& value) { id_ = value; set_changed(true); }
60  void set_type(const std::string& value) { type_ = value; set_changed(true); }
61  void set_icon(const std::string& value) { icon_ = value; set_changed(true); }
62  void set_range(const std::string& value) { range_ = value; set_changed(true); }
63  void set_min_range(int value) { min_range_ = value; set_changed(true); }
64  void set_max_range(int value) { max_range_ = value; set_changed(true); }
65  void set_attack_alignment(const std::string& value) { alignment_ = unit_alignments::get_enum(value); set_changed(true); }
66  void set_accuracy(int value) { accuracy_ = value; set_changed(true); }
67  void set_parry(int value) { parry_ = value; set_changed(true); }
68  void set_damage(int value) { damage_ = value; set_changed(true); }
69  void set_num_attacks(int value) { num_attacks_ = value; set_changed(true); }
70  void set_attack_weight(double value) { attack_weight_ = value; set_changed(true); }
71  void set_defense_weight(double value) { defense_weight_ = value; set_changed(true); }
72  void set_specials(config value) { specials_ = value; set_changed(true); }
73 
74 
75  // In unit_abilities.cpp:
76 
77  /**
78  * @return True iff the special @a special is active.
79  * @param special The special being checked.
80  * @param simple_check If true, check whether the unit has the special. Else, check whether the special is currently active.
81  * @param special_id If true, match @a special against the @c id of special tags.
82  * @param special_tags If true, match @a special against the tag name of special tags.
83  */
84  bool has_special(const std::string& special, bool simple_check=false, bool special_id=true, bool special_tags=true) const;
85  unit_ability_list get_specials(const std::string& special) const;
86  std::vector<std::pair<t_string, t_string>> special_tooltips(boost::dynamic_bitset<>* active_list = nullptr) const;
87  std::string weapon_specials() const;
88  std::string weapon_specials_value(const std::set<std::string> checking_tags) const;
89 
90  /** Returns alignment specified by alignment_ variable.
91  */
92  utils::optional<unit_alignments::type> alignment() const { return alignment_; }
93  /** Returns alignment specified by alignment() for filtering when exist.
94  */
95  std::string alignment_str() const { return alignment_ ? unit_alignments::get_string(*alignment_) : ""; }
96 
97  /** Calculates the number of attacks this weapon has, considering specials. */
98  void modified_attacks(unsigned & min_attacks,
99  unsigned & max_attacks) const;
100 
101  /**
102  * Select best damage type based on frequency count for replacement_type and based on highest damage for alternative_type.
103  *
104  * @param damage_type_list list of [damage_type] to check.
105  * @param key_name name of attribute checked 'alternative_type' or 'replacement_type'.
106  * @param resistance_list list of "resistance" abilities to check for each type of damage checked.
107  */
108  std::string select_damage_type(const unit_ability_list& damage_type_list, const std::string& key_name, unit_ability_list resistance_list) const;
109  /** return a modified damage type and/or add a secondary_type for hybrid use if special is active. */
110  std::pair<std::string, std::string> damage_type() const;
111  /** @return A list of alternative_type damage types. */
112  std::set<std::string> alternative_damage_types() const;
113 
114  /** Returns the damage per attack of this weapon, considering specials. */
115  int modified_damage() const;
116 
117  /** Return the special weapon value, considering specials.
118  * @param abil_list The list of special checked.
119  * @param base_value The value modified or not by function.
120  */
121  int composite_value(const unit_ability_list& abil_list, int base_value) const;
122  /** Returns list for weapon like abilities for each ability type. */
123  unit_ability_list get_weapon_ability(const std::string& ability) const;
124  /**
125  * @param special the tag name to check for
126  * @return list which contains get_weapon_ability and get_specials list for each ability type, with overwritten items removed
127  */
128  unit_ability_list get_specials_and_abilities(const std::string& special) const;
129  /** used for abilities used like weapon
130  * @return True if the ability @a special is active.
131  * @param special The special being checked.
132  * @param special_id If true, match @a special against the @c id of special tags.
133  * @param special_tags If true, match @a special against the tag name of special tags.
134  */
135  bool has_weapon_ability(const std::string& special, bool special_id=true, bool special_tags=true) const;
136  /** used for abilities used like weapon and true specials
137  * @return True if the ability @a special is active.
138  * @param special The special being checked.
139  * @param special_id If true, match @a special against the @c id of special tags.
140  * @param special_tags If true, match @a special against the tag name of special tags.
141  */
142  bool has_special_or_ability(const std::string& special, bool special_id=true, bool special_tags=true) const;
143  /**
144  * Returns true if this is a dummy attack_type, for example the placeholder that the unit_attack dialog
145  * uses when a defender has no weapon for a given range.
146  */
147  bool attack_empty() const {return (id().empty() && name().empty() && type().empty() && range().empty());}
148  /** remove special if matche condition
149  * @param filter if special check with filter, it will be removed.
150  */
151  void remove_special_by_filter(const config& filter);
152  /** check if special matche
153  * @return True if special matche with filter(if 'active' filter is true, check if special active).
154  * @param filter if special check with filter, return true.
155  */
156  bool has_special_with_filter(const config & filter) const;
157  bool has_ability_with_filter(const config & filter) const;
158  bool has_special_or_ability_with_filter(const config & filter) const;
159 
160  // In unit_types.cpp:
161 
162  bool matches_filter(const config& filter, const std::string& check_if_recursion = "") const;
163  bool apply_modification(const config& cfg);
164  bool describe_modification(const config& cfg,std::string* description);
165 
166  int movement_used() const { return movement_used_; }
167  void set_movement_used(int value) { movement_used_ = value; }
168  int attacks_used() const { return attacks_used_; }
169  void set_attacks_used(int value) { attacks_used_ = value; }
170 
171  void write(config& cfg) const;
172  inline config to_config() const { config c; write(c); return c; }
173 
175 
176  /**
177  * Helper similar to std::unique_lock for detecting when calculations such as has_special
178  * have entered infinite recursion.
179  *
180  * This assumes that there's only a single thread accessing the attack_type, it's a lightweight
181  * increment/decrement counter rather than a mutex.
182  */
184  friend class attack_type;
185  /**
186  * Only expected to be called in update_variables_recursion(), which handles some of the checks.
187  */
188  explicit recursion_guard(const attack_type& weapon, const config& special);
189  public:
190  /**
191  * Construct an empty instance, only useful for extending the lifetime of a
192  * recursion_guard returned from weapon.update_variables_recursion() by
193  * std::moving it to an instance declared in a larger scope.
194  */
195  explicit recursion_guard();
196 
197  /**
198  * Returns true if a level of recursion was available at the time when update_variables_recursion()
199  * created this object.
200  */
201  operator bool() const;
202 
204  recursion_guard(const recursion_guard& other) = delete;
208  private:
209  std::shared_ptr<const attack_type> parent;
210  };
211 
212  /**
213  * Tests which might otherwise cause infinite recursion should call this, check that the
214  * returned object evaluates to true, and then keep the object returned as long as the
215  * recursion might occur, similar to a reentrant mutex that's limited to a small number of
216  * reentrances.
217  *
218  * This only expects to be called in a single thread, but the whole of attack_type makes
219  * that assumption, for example its' mutable members are assumed to be set up by the current
220  * caller (or caller's caller, probably several layers up).
221  */
222  recursion_guard update_variables_recursion(const config& special) const;
223 
224 private:
225  // In unit_abilities.cpp:
226 
227  // Configured as a bit field, in case that is useful.
229  /**
230  * Filter a list of abilities or weapon specials
231  * @param cfg config of ability checked
232  * @param tag_name le type of ability who is checked
233  * @param filter config contain list of attribute who are researched in cfg
234  *
235  * @return true if all attribute with ability checked
236  */
237  bool special_matches_filter(const config & cfg, const std::string& tag_name, const config & filter) const;
238  /**
239  * Filter a list of abilities or weapon specials, removing any entries that don't own
240  * the overwrite_specials attributes.
241  *
242  * @param overwriters list that may have overwrite_specials attributes.
243  * @param tag_name type of abilitie/special checked.
244  */
245  unit_ability_list overwrite_special_overwriter(unit_ability_list overwriters, const std::string& tag_name) const;
246  /**
247  * Check whether @a cfg would be overwritten by any element of @a overwriters.
248  *
249  * @return True if element checked is overwritable.
250  * @param overwriters list used for check if element is overwritable.
251  * @param cfg element checked.
252  * @param tag_name type of abilitie/special checked.
253  */
254  bool overwrite_special_checking(unit_ability_list& overwriters, const config& cfg, const std::string& tag_name) const;
255  /** check_self_abilities : return an boolean value for checking of activities of abilities used like weapon
256  * @return True if the special @a special is active.
257  * @param cfg the config to one special ability checked.
258  * @param special The special ability type who is being checked.
259  */
260  bool check_self_abilities(const config& cfg, const std::string& special) const;
261  /** check_adj_abilities : return an boolean value for checking of activities of abilities used like weapon
262  * @return True if the special @a special is active.
263  * @param cfg the config to one special ability checked.
264  * @param special The special ability type who is being checked.
265  * @param dir direction to research a unit adjacent to self_.
266  * @param from unit adjacent to self_ is checked.
267  */
268  bool check_adj_abilities(const config& cfg, const std::string& special, int dir, const unit& from) const;
269  bool special_active(const config& special, AFFECTS whom, const std::string& tag_name,
270  const std::string& filter_self ="filter_self") const;
271 
272 /** weapon_specials_impl_self and weapon_specials_impl_adj : check if special name can be added.
273  * @param[in,out] temp_string the string modified and returned
274  * @param[in] self the unit checked.
275  * @param[in] self_attack the attack used by unit checked in this function.
276  * @param[in] other_attack the attack used by opponent to unit checked.
277  * @param[in] self_loc location of the unit checked.
278  * @param[in] whom determine if unit affected or not by special ability.
279  * @param[in,out] checking_name the reference for checking if a name is already added
280  * @param[in] checking_tags the reference for checking if special ability type can be used
281  * @param[in] leader_bool If true, [leadership] abilities are checked.
282  */
283  static void weapon_specials_impl_self(
284  std::string& temp_string,
285  unit_const_ptr self,
286  const_attack_ptr self_attack,
287  const_attack_ptr other_attack,
288  const map_location& self_loc,
289  AFFECTS whom,
290  std::set<std::string>& checking_name,
291  const std::set<std::string>& checking_tags={},
292  bool leader_bool=false
293  );
294 
295  static void weapon_specials_impl_adj(
296  std::string& temp_string,
297  unit_const_ptr self,
298  const_attack_ptr self_attack,
299  const_attack_ptr other_attack,
300  const map_location& self_loc,
301  AFFECTS whom,
302  std::set<std::string>& checking_name,
303  const std::set<std::string>& checking_tags={},
304  const std::string& affect_adjacents="",
305  bool leader_bool=false
306  );
307  /** check_self_abilities_impl : return an boolean value for checking of activities of abilities used like weapon
308  * @return True if the special @a tag_name is active.
309  * @param self_attack the attack used by unit checked in this function.
310  * @param other_attack the attack used by opponent to unit checked.
311  * @param special the config to one special ability checked.
312  * @param u the unit checked.
313  * @param loc location of the unit checked.
314  * @param whom determine if unit affected or not by special ability.
315  * @param tag_name The special ability type who is being checked.
316  * @param leader_bool If true, [leadership] abilities are checked.
317  */
318  static bool check_self_abilities_impl(
319  const_attack_ptr self_attack,
320  const_attack_ptr other_attack,
321  const config& special,
322  unit_const_ptr u,
323  const map_location& loc,
324  AFFECTS whom,
325  const std::string& tag_name,
326  bool leader_bool=false
327  );
328 
329 
330  /** check_adj_abilities_impl : return an boolean value for checking of activities of abilities used like weapon in unit adjacent to fighter
331  * @return True if the special @a tag_name is active.
332  * @param self_attack the attack used by unit who fight.
333  * @param other_attack the attack used by opponent.
334  * @param special the config to one special ability checked.
335  * @param u the unit who is or not affected by an abilities owned by @a from.
336  * @param from unit adjacent to @a u is checked.
337  * @param dir direction to research a unit adjacent to @a u.
338  * @param loc location of the unit checked.
339  * @param whom determine if unit affected or not by special ability.
340  * @param tag_name The special ability type who is being checked.
341  * @param leader_bool If true, [leadership] abilities are checked.
342  */
343  static bool check_adj_abilities_impl(
344  const_attack_ptr self_attack,
345  const_attack_ptr other_attack,
346  const config& special,
347  unit_const_ptr u,
348  const unit& from,
349  int dir,
350  const map_location& loc,
351  AFFECTS whom,
352  const std::string& tag_name,
353  bool leader_bool=false
354  );
355 
356  static bool special_active_impl(
357  const_attack_ptr self_attack,
358  const_attack_ptr other_attack,
359  const config& special,
360  AFFECTS whom,
361  const std::string& tag_name,
362  const std::string& filter_self ="filter_self"
363  );
364 
365  // Used via specials_context() to control which specials are
366  // considered active.
367  friend class specials_context_t;
371  mutable bool is_attacker_;
373  mutable bool is_for_listing_ = false;
374 public:
376  std::shared_ptr<const attack_type> parent;
377  friend class attack_type;
378  /** Initialize weapon specials context for listing */
379  explicit specials_context_t(const attack_type& weapon, bool attacking);
380  /** Initialize weapon specials context for a unit type */
381  specials_context_t(const attack_type& weapon, const unit_type& self_type, const map_location& loc, bool attacking = true);
382  /** Initialize weapon specials context for a single unit */
383  specials_context_t(const attack_type& weapon, const_attack_ptr other_weapon,
384  unit_const_ptr self, unit_const_ptr other,
385  const map_location& self_loc, const map_location& other_loc,
386  bool attacking);
387  /** Initialize weapon specials context for a pair of units */
388  specials_context_t(const attack_type& weapon, unit_const_ptr self, const map_location& loc, bool attacking);
390  bool was_moved = false;
391  public:
392  // Destructor at least needs to be public for all this to work.
395  };
396  // Set up a specials context.
397  // Usage: auto ctx = weapon.specials_context(...);
399  const map_location& unit_loc, const map_location& other_loc,
400  bool attacking, const_attack_ptr other_attack) const {
401  return specials_context_t(*this, other_attack, self, other, unit_loc, other_loc, attacking);
402  }
403  specials_context_t specials_context(unit_const_ptr self, const map_location& loc, bool attacking = true) const {
404  return specials_context_t(*this, self, loc, attacking);
405  }
406  specials_context_t specials_context(const unit_type& self_type, const map_location& loc, bool attacking = true) const {
407  return specials_context_t(*this, self_type, loc, attacking);
408  }
409  specials_context_t specials_context_for_listing(bool attacking = true) const {
410  return specials_context_t(*this, attacking);
411  }
412  void set_changed(bool value)
413  {
414  changed_ = value;
415  }
416  bool get_changed() const
417  {
418  return changed_;
419  }
420 private:
421 
423  std::string id_;
424  std::string type_;
425  std::string icon_;
426  std::string range_;
428  utils::optional<unit_alignments::type> alignment_;
429  int damage_;
433 
437  int parry_;
439  bool changed_;
440  /**
441  * While processing a recursive match, all the filters that are currently being checked, oldest first.
442  * Each will have an instance of recursion_guard that is currently allocated permission to recurse, and
443  * which will pop the config off this stack when the recursion_guard is finalized.
444  */
445  mutable std::vector<const config*> open_queries_;
446 };
447 
448 using attack_list = std::vector<attack_ptr>;
449 using attack_itors = boost::iterator_range<boost::indirect_iterator<attack_list::iterator>>;
450 using const_attack_itors = boost::iterator_range<boost::indirect_iterator<attack_list::const_iterator>>;
451 
453  return boost::make_iterator_range(boost::make_indirect_iterator(atks.begin()), boost::make_indirect_iterator(atks.end()));
454 }
455 
457  return boost::make_iterator_range(boost::make_indirect_iterator(atks.begin()), boost::make_indirect_iterator(atks.end()));
458 }
boost::iterator_range< boost::indirect_iterator< attack_list::iterator > > attack_itors
std::vector< attack_ptr > attack_list
boost::iterator_range< boost::indirect_iterator< attack_list::const_iterator > > const_attack_itors
attack_itors make_attack_itors(attack_list &atks)
Helper similar to std::unique_lock for detecting when calculations such as has_special have entered i...
recursion_guard & operator=(const recursion_guard &)=delete
recursion_guard(const recursion_guard &other)=delete
recursion_guard & operator=(recursion_guard &&)
std::shared_ptr< const attack_type > parent
recursion_guard()
Construct an empty instance, only useful for extending the lifetime of a recursion_guard returned fro...
specials_context_t(const specials_context_t &)=delete
specials_context_t(const attack_type &weapon, bool attacking)
Initialize weapon specials context for listing.
Definition: abilities.cpp:1206
std::shared_ptr< const attack_type > parent
const config & specials() const
Definition: attack_type.hpp:56
std::string alignment_str() const
Returns alignment specified by alignment() for filtering when exist.
Definition: attack_type.hpp:95
void set_min_range(int value)
Definition: attack_type.hpp:63
map_location other_loc_
std::string weapon_specials() const
Returns a comma-separated string of active names for the specials of *this.
Definition: abilities.cpp:995
double defense_weight() const
Definition: attack_type.hpp:55
void set_num_attacks(int value)
Definition: attack_type.hpp:69
specials_context_t specials_context(unit_const_ptr self, const map_location &loc, bool attacking=true) const
bool check_self_abilities(const config &cfg, const std::string &special) const
check_self_abilities : return an boolean value for checking of activities of abilities used like weap...
Definition: abilities.cpp:1746
bool has_special(const std::string &special, bool simple_check=false, bool special_id=true, bool special_tags=true) const
Returns whether or not *this has a special with a tag or id equal to special.
Definition: abilities.cpp:836
static bool special_active_impl(const_attack_ptr self_attack, const_attack_ptr other_attack, const config &special, AFFECTS whom, const std::string &tag_name, const std::string &filter_self="filter_self")
Returns whether or not the given special is active for the specified unit, based on the current conte...
Definition: abilities.cpp:2214
int min_range() const
Definition: attack_type.hpp:47
int composite_value(const unit_ability_list &abil_list, int base_value) const
Return the special weapon value, considering specials.
Definition: abilities.cpp:1586
double attack_weight() const
Definition: attack_type.hpp:54
const_attack_ptr other_attack_
void add_formula_context(wfl::map_formula_callable &) const
Definition: abilities.cpp:611
const std::string & range() const
Definition: attack_type.hpp:46
void set_attacks_used(int value)
map_location self_loc_
int movement_used() const
specials_context_t specials_context_for_listing(bool attacking=true) const
bool has_special_or_ability_with_filter(const config &filter) const
Definition: abilities.cpp:2190
void set_accuracy(int value)
Definition: attack_type.hpp:66
bool get_changed() const
const std::string & type() const
Definition: attack_type.hpp:44
void set_movement_used(int value)
unit_ability_list get_weapon_ability(const std::string &ability) const
Returns list for weapon like abilities for each ability type.
Definition: abilities.cpp:1550
bool has_ability_with_filter(const config &filter) const
Definition: abilities.cpp:2134
int parry() const
Definition: attack_type.hpp:51
std::string weapon_specials_value(const std::set< std::string > checking_tags) const
Definition: abilities.cpp:1043
std::string accuracy_parry_description() const
Definition: attack_type.cpp:85
unit_ability_list get_specials_and_abilities(const std::string &special) const
Definition: abilities.cpp:1569
bool apply_modification(const config &cfg)
Modifies *this using the specifications in cfg, but only if *this matches cfg viewed as a filter.
bool matches_filter(const config &filter, const std::string &check_if_recursion="") const
Returns whether or not *this matches the given filter.
bool overwrite_special_checking(unit_ability_list &overwriters, const config &cfg, const std::string &tag_name) const
Check whether cfg would be overwritten by any element of overwriters.
Definition: abilities.cpp:1633
void set_specials(config value)
Definition: attack_type.hpp:72
unit_const_ptr self_
bool check_adj_abilities(const config &cfg, const std::string &special, int dir, const unit &from) const
check_adj_abilities : return an boolean value for checking of activities of abilities used like weapo...
Definition: abilities.cpp:1766
friend class specials_context_t
config specials_
void set_defense_weight(double value)
Definition: attack_type.hpp:71
int num_attacks() const
Definition: attack_type.hpp:53
void set_changed(bool value)
unit_ability_list overwrite_special_overwriter(unit_ability_list overwriters, const std::string &tag_name) const
Filter a list of abilities or weapon specials, removing any entries that don't own the overwrite_spec...
Definition: abilities.cpp:1597
recursion_guard update_variables_recursion(const config &special) const
Tests which might otherwise cause infinite recursion should call this, check that the returned object...
static bool check_adj_abilities_impl(const_attack_ptr self_attack, const_attack_ptr other_attack, const config &special, unit_const_ptr u, const unit &from, int dir, const map_location &loc, AFFECTS whom, const std::string &tag_name, bool leader_bool=false)
check_adj_abilities_impl : return an boolean value for checking of activities of abilities used like ...
Definition: abilities.cpp:1771
static void weapon_specials_impl_adj(std::string &temp_string, unit_const_ptr self, const_attack_ptr self_attack, const_attack_ptr other_attack, const map_location &self_loc, AFFECTS whom, std::set< std::string > &checking_name, const std::set< std::string > &checking_tags={}, const std::string &affect_adjacents="", bool leader_bool=false)
Definition: abilities.cpp:1103
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.
Definition: abilities.cpp:941
std::string type_
std::string icon_
void set_parry(int value)
Definition: attack_type.hpp:67
void set_attack_weight(double value)
Definition: attack_type.hpp:70
void set_damage(int value)
Definition: attack_type.hpp:68
static void weapon_specials_impl_self(std::string &temp_string, unit_const_ptr self, const_attack_ptr self_attack, const_attack_ptr other_attack, const map_location &self_loc, AFFECTS whom, std::set< std::string > &checking_name, const std::set< std::string > &checking_tags={}, bool leader_bool=false)
weapon_specials_impl_self and weapon_specials_impl_adj : check if special name can be added.
Definition: abilities.cpp:1083
utils::optional< unit_alignments::type > alignment() const
Returns alignment specified by alignment_ variable.
Definition: attack_type.hpp:92
const t_string & name() const
Definition: attack_type.hpp:42
std::set< std::string > alternative_damage_types() const
Definition: abilities.cpp:1353
bool describe_modification(const config &cfg, std::string *description)
Trimmed down version of apply_modification(), with no modifications actually made.
int attacks_used() const
const std::string & id() const
Definition: attack_type.hpp:43
void set_icon(const std::string &value)
Definition: attack_type.hpp:61
std::vector< const config * > open_queries_
While processing a recursive match, all the filters that are currently being checked,...
bool attack_empty() const
Returns true if this is a dummy attack_type, for example the placeholder that the unit_attack dialog ...
static bool check_self_abilities_impl(const_attack_ptr self_attack, const_attack_ptr other_attack, const config &special, unit_const_ptr u, const map_location &loc, AFFECTS whom, const std::string &tag_name, bool leader_bool=false)
check_self_abilities_impl : return an boolean value for checking of activities of abilities used like...
Definition: abilities.cpp:1751
double defense_weight_
std::string id_
bool special_matches_filter(const config &cfg, const std::string &tag_name, const config &filter) const
Filter a list of abilities or weapon specials.
Definition: abilities.cpp:2099
int modified_damage() const
Returns the damage per attack of this weapon, considering specials.
Definition: abilities.cpp:1374
double attack_weight_
config to_config() const
void modified_attacks(unsigned &min_attacks, unsigned &max_attacks) const
Calculates the number of attacks this weapon has, considering specials.
Definition: abilities.cpp:1238
std::string range_
void set_id(const std::string &value)
Definition: attack_type.hpp:59
void remove_special_by_filter(const config &filter)
remove special if matche condition
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
void set_max_range(int value)
Definition: attack_type.hpp:64
utils::optional< unit_alignments::type > alignment_
attack_type(const config &cfg)
Definition: attack_type.cpp:50
void set_type(const std::string &value)
Definition: attack_type.hpp:60
void write(config &cfg) const
int accuracy() const
Definition: attack_type.hpp:50
unit_const_ptr other_
int max_range() const
Definition: attack_type.hpp:48
bool has_special_with_filter(const config &filter) const
check if special matche
Definition: abilities.cpp:2104
void set_range(const std::string &value)
Definition: attack_type.hpp:62
bool special_active(const config &special, AFFECTS whom, const std::string &tag_name, const std::string &filter_self="filter_self") const
Definition: abilities.cpp:2198
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...
Definition: abilities.cpp:908
std::string select_damage_type(const unit_ability_list &damage_type_list, const std::string &key_name, unit_ability_list resistance_list) const
Select best damage type based on frequency count for replacement_type and based on highest damage for...
Definition: abilities.cpp:1316
const std::string & icon() const
Definition: attack_type.hpp:45
specials_context_t specials_context(const unit_type &self_type, const map_location &loc, bool attacking=true) const
int damage() const
Definition: attack_type.hpp:52
void set_attack_alignment(const std::string &value)
Definition: attack_type.hpp:65
bool has_special_or_ability(const std::string &special, bool special_id=true, bool special_tags=true) const
used for abilities used like weapon and true specials
Definition: abilities.cpp:1892
t_string description_
bool has_weapon_ability(const std::string &special, bool special_id=true, bool special_tags=true) const
used for abilities used like weapon
Definition: abilities.cpp:1791
void set_name(const t_string &value)
Definition: attack_type.hpp:58
std::pair< std::string, std::string > damage_type() const
return a modified damage type and/or add a secondary_type for hybrid use if special is active.
Definition: abilities.cpp:1330
bool is_for_listing_
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
A single unit type that the player may recruit.
Definition: types.hpp:43
This class represents a single unit of a specific type.
Definition: unit.hpp:133
Definitions for the interface to Wesnoth Markup Language (WML).
Definition: contexts.hpp:43
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27
std::shared_ptr< const attack_type > const_attack_ptr
Definition: ptr.hpp:34
Encapsulates the map of the game.
Definition: location.hpp:45
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
Definition: enum_base.hpp:46
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
Definition: enum_base.hpp:57
mock_char c