The Battle for Wesnoth  1.19.17+dev
attack_type.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2025
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  std::string accuracy_parry_tooltip() const;
51  int accuracy() const { return accuracy_; }
52  int parry() const { return parry_; }
53  int damage() const { return damage_; }
54  int num_attacks() const { return num_attacks_; }
55  double attack_weight() const { return attack_weight_; }
56  double defense_weight() const { return defense_weight_; }
57  const config &specials() const { return specials_; }
58 
59  void set_name(const t_string& value) { description_ = value; set_changed(true); }
60  void set_id(const std::string& value) { id_ = value; set_changed(true); }
61  void set_type(const std::string& value) { type_ = value; set_changed(true); }
62  void set_icon(const std::string& value) { icon_ = value; set_changed(true); }
63  void set_range(const std::string& value) { range_ = value; set_changed(true); }
64  void set_min_range(int value) { min_range_ = value; set_changed(true); }
65  void set_max_range(int value) { max_range_ = value; set_changed(true); }
66  void set_attack_alignment(const std::string& value) { alignment_ = unit_alignments::get_enum(value); set_changed(true); }
67  void set_accuracy(int value) { accuracy_ = value; set_changed(true); }
68  void set_parry(int value) { parry_ = value; set_changed(true); }
69  void set_damage(int value) { damage_ = value; set_changed(true); }
70  void set_num_attacks(int value) { num_attacks_ = value; set_changed(true); }
71  void set_attack_weight(double value) { attack_weight_ = value; set_changed(true); }
72  void set_defense_weight(double value) { defense_weight_ = value; set_changed(true); }
73  void set_specials(config value) { specials_ = value; set_changed(true); }
74 
75 
76  // In unit_abilities.cpp:
77 
78  /**
79  * @return True iff the special @a special is active.
80  * @param special The special being checked.
81  * @param simple_check If true, check whether the unit has the special. Else, check whether the special is currently active.
82  */
83  bool has_special(const std::string& special, bool simple_check = false) const;
84  unit_ability_list get_specials(const std::string& special) const;
85  std::vector<std::pair<t_string, t_string>> special_tooltips(boost::dynamic_bitset<>* active_list = nullptr) const;
86  std::vector<std::pair<t_string, t_string>> abilities_special_tooltips(boost::dynamic_bitset<>* active_list) 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  /** @return A type()/replacement_type and a list of alternative_types that should be displayed in the selected unit's report. */
102  std::pair<std::string, std::set<std::string>> damage_types() const;
103  /** @return The type of attack used and the resistance value that does the most damage. */
104  std::pair<std::string, int> effective_damage_type() const;
105 
106  /** Returns the damage per attack of this weapon, considering specials. */
107  double modified_damage() const;
108  /** Return the defense value, considering specials.
109  * @param cth The chance_to_hit value modified or not by function.
110  * @param special_only Decide if get_specials() or get_specials_and_abilities()should be used.
111  */
112  int modified_chance_to_hit(int cth, bool special_only = false) const;
113 
114  /** Return the special weapon value, considering specials.
115  * @param abil_list The list of special checked.
116  * @param base_value The value modified or not by function.
117  */
118  int composite_value(const unit_ability_list& abil_list, int base_value) const;
119  /** Returns list for weapon like abilities for each ability type. */
120  unit_ability_list get_weapon_ability(const std::string& ability) const;
121  /**
122  * @param special the tag name to check for
123  * @return list which contains get_weapon_ability and get_specials list for each ability type, with overwritten items removed
124  */
125  unit_ability_list get_specials_and_abilities(const std::string& special) const;
126  /** used for abilities used like weapon and true specials
127  * @return True if the ability @a special is active.
128  * @param special The special being checked.
129  */
130  bool has_special_or_ability(const std::string& special) const;
131  /** check if special matche
132  * @return True if special matche with filter(if 'active' filter is true, check if special active).
133  * @param simple_check If true, check whether the unit has the special. Else, check whether the special is currently active.
134  * @param filter contain attributes to check(special_id, special_type etc...).
135  */
136  bool has_filter_special_or_ability(const config& filter, bool simple_check = false) const;
137  /**
138  * Returns true if this is a dummy attack_type, for example the placeholder that the unit_attack dialog
139  * uses when a defender has no weapon for a given range.
140  */
141  bool attack_empty() const {return (id().empty() && name().empty() && type().empty() && range().empty());}
142  /** remove special if matche condition
143  * @param filter if special check with filter, it will be removed.
144  */
146  /** check if special matche
147  * @return True if special matche with filter(if 'active' filter is true, check if special active).
148  * @param filter if special check with filter, return true.
149  */
151 
152  // In unit_types.cpp:
153 
154  bool matches_filter(const config& filter, const std::string& check_if_recursion = "") const;
155 
156  /** Applies effect modifications described by @a cfg. */
157  void apply_effect(const config& cfg);
158 
159  /**
160  * Generates a description of the effect specified by @a cfg, if applicable.
161  * This covers a subset of the effects which can be applied via @ref apply_effect.
162  */
163  static std::string describe_effect(const config& cfg);
164 
165  int movement_used() const { return movement_used_; }
166  void set_movement_used(int value) { movement_used_ = value; }
167  int attacks_used() const { return attacks_used_; }
168  void set_attacks_used(int value) { attacks_used_ = value; }
169 
170  void write(config& cfg) const;
171  inline config to_config() const { config c; write(c); return c; }
172 
174 
175  /**
176  * Helper similar to std::unique_lock for detecting when calculations such as has_special
177  * have entered infinite recursion.
178  *
179  * This assumes that there's only a single thread accessing the attack_type, it's a lightweight
180  * increment/decrement counter rather than a mutex.
181  */
183  friend class attack_type;
184  /**
185  * Only expected to be called in update_variables_recursion(), which handles some of the checks.
186  */
187  explicit recursion_guard(const attack_type& weapon, const config& special);
188  public:
189  /**
190  * Construct an empty instance, only useful for extending the lifetime of a
191  * recursion_guard returned from weapon.update_variables_recursion() by
192  * std::moving it to an instance declared in a larger scope.
193  */
194  explicit recursion_guard();
195 
196  /**
197  * Returns true if a level of recursion was available at the time when update_variables_recursion()
198  * created this object.
199  */
200  operator bool() const;
201 
202  recursion_guard(recursion_guard&& other) noexcept;
203  recursion_guard(const recursion_guard& other) = delete;
205  recursion_guard& operator=(const recursion_guard&) = delete;
206  ~recursion_guard();
207  private:
208  std::shared_ptr<const attack_type> parent;
209  };
210 
211  /**
212  * Tests which might otherwise cause infinite recursion should call this, check that the
213  * returned object evaluates to true, and then keep the object returned as long as the
214  * recursion might occur, similar to a reentrant mutex that's limited to a small number of
215  * reentrances.
216  *
217  * This only expects to be called in a single thread, but the whole of attack_type makes
218  * that assumption, for example its' mutable members are assumed to be set up by the current
219  * caller (or caller's caller, probably several layers up).
220  */
221  recursion_guard update_variables_recursion(const config& special) const;
222 
223 private:
224  // In unit_abilities.cpp:
225 
226  // Configured as a bit field, in case that is useful.
228  /**
229  * Filter a list of abilities or weapon specials
230  * @param cfg config of ability checked
231  * @param tag_name le type of ability who is checked
232  * @param filter config contain list of attribute who are researched in cfg
233  *
234  * @return true if all attribute with ability checked
235  */
236  bool special_matches_filter(const config & cfg, const std::string& tag_name, const config & filter) const;
237  /**
238  * Select best damage type based on frequency count for replacement_type.
239  *
240  * @param damage_type_list list of [damage_type] to check.
241  */
242  std::string select_replacement_type(const unit_ability_list& damage_type_list) const;
243  /**
244  * Select best damage type based on highest damage for alternative_type.
245  *
246  * @param damage_type_list list of [damage_type] to check.
247  * @param resistance_list list of "resistance" abilities to check for each type of damage checked.
248  */
249  std::pair<std::string, int> select_alternative_type(const unit_ability_list& damage_type_list, const unit_ability_list& resistance_list) const;
250  /**
251  * Filter a list of abilities or weapon specials, removing any entries that don't own
252  * the overwrite_specials attributes.
253  *
254  * @param overwriters list that may have overwrite_specials attributes.
255  * @param tag_name type of abilitie/special checked.
256  */
257  unit_ability_list overwrite_special_overwriter(unit_ability_list overwriters, const std::string& tag_name) const;
258  /**
259  * Check whether @a cfg would be overwritten by any element of @a overwriters.
260  *
261  * @return True if element checked is overwritable.
262  * @param overwriters list used for check if element is overwritable.
263  * @param cfg element checked.
264  * @param tag_name type of abilitie/special checked.
265  */
266  bool overwrite_special_checking(unit_ability_list& overwriters, const config& cfg, const std::string& tag_name) const;
267 
268  bool special_active(const config& special, AFFECTS whom, const std::string& tag_name,
269  bool in_abilities_tag = false) const;
270 
271  bool special_tooltip_active(const config& special, const std::string& tag_name) const;
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  const unit_const_ptr& self,
286  const const_attack_ptr& self_attack,
287  const 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  const unit_const_ptr& self,
298  const const_attack_ptr& self_attack,
299  const 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 const_attack_ptr& self_attack,
320  const const_attack_ptr& other_attack,
321  const config& special,
322  const 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 distant to @a u is checked.
337  * @param dist distance between unit distant and @a u.
338  * @param dir direction to research a unit distant to @a u.
339  * @param loc location of the unit checked.
340  * @param from_loc location of the unit distant to @a u.
341  * @param whom determine if unit affected or not by special ability.
342  * @param tag_name The special ability type who is being checked.
343  * @param leader_bool If true, [leadership] abilities are checked.
344  */
345  static bool check_adj_abilities_impl(
346  const const_attack_ptr& self_attack,
347  const const_attack_ptr& other_attack,
348  const config& special,
349  const unit_const_ptr& u,
350  const unit& from,
351  std::size_t dist,
352  int dir,
353  const map_location& loc,
354  const map_location& from_loc,
355  AFFECTS whom,
356  const std::string& tag_name,
357  bool leader_bool = false
358  );
359 
360  static bool special_active_impl(
361  const const_attack_ptr& self_attack,
362  const const_attack_ptr& other_attack,
363  const config& special,
364  AFFECTS whom,
365  const std::string& tag_name,
366  bool in_abilities_tag = false
367  );
368 
369  /** has_ability_impl : return an boolean value for checking of activities of abilities used like weapon
370  * @return True if @a special is active.
371  * @param self_attack the attack used by unit who fight.
372  * @param other_attack the attack used by opponent.
373  * @param self the unit who fight.
374  * @param self_loc location of @a self.
375  * @param whom determine if unit affected or not by special ability.
376  * @param special The special ability type who is being checked.
377  */
378  static bool has_ability_impl(
379  const const_attack_ptr& self_attack,
380  const unit_const_ptr& self,
381  const map_location& self_loc,
382  const const_attack_ptr& other_attack,
383  AFFECTS whom,
384  const std::string& special);
385 
386  /** special_distant_filtering_impl : return an boolean value if special matche with filter
387  * @return True if the @a special is active.
388  * @param self_attack the attack used by unit who fight.
389  * @param other_attack the attack used by opponent.
390  * @param self the unit who fight.
391  * @param self_loc location of @a self.
392  * @param whom determine if unit affected or not by special ability.
393  * @param filter if special check with filter, return true.
394  * @param sub_filter if true, check the attributes of [filter_special], else, check special(_id/type)(_active).
395  * @param leader_bool If true, [leadership] abilities are checked.
396  */
397  static bool special_distant_filtering_impl(
398  const const_attack_ptr& self_attack,
399  const unit_const_ptr& self,
400  const map_location& self_loc,
401  const const_attack_ptr& other_attack,
402  AFFECTS whom,
403  const config & filter,
404  bool sub_filter,
405  bool leader_bool=false);
406 
407  // Used via specials_context() to control which specials are
408  // considered active.
409  friend class specials_context_t;
413  mutable bool is_attacker_;
415  mutable bool is_for_listing_ = false;
416 public:
418  std::shared_ptr<const attack_type> parent;
419  friend class attack_type;
420  /** Initialize weapon specials context for listing */
421  explicit specials_context_t(const attack_type& weapon, bool attacking);
422  /** Initialize weapon specials context for a unit type */
423  specials_context_t(const attack_type& weapon, const unit_type& self_type, const map_location& loc, bool attacking = true);
424  /** Initialize weapon specials context for a single unit */
425  specials_context_t(const attack_type& weapon, const_attack_ptr other_weapon,
426  unit_const_ptr self, unit_const_ptr other,
427  const map_location& self_loc, const map_location& other_loc,
428  bool attacking);
429  /** Initialize weapon specials context for a pair of units */
430  specials_context_t(const attack_type& weapon, unit_const_ptr self, const map_location& loc, bool attacking);
432  bool was_moved = false;
433  public:
434  // Destructor at least needs to be public for all this to work.
437  };
438  // Set up a specials context.
439  // Usage: auto ctx = weapon.specials_context(...);
441  const map_location& unit_loc, const map_location& other_loc,
442  bool attacking, const_attack_ptr other_attack) const {
443  return specials_context_t(*this, other_attack, self, other, unit_loc, other_loc, attacking);
444  }
445  specials_context_t specials_context(unit_const_ptr self, const map_location& loc, bool attacking = true) const {
446  return specials_context_t(*this, self, loc, attacking);
447  }
448  specials_context_t specials_context(const unit_type& self_type, const map_location& loc, bool attacking = true) const {
449  return specials_context_t(*this, self_type, loc, attacking);
450  }
451  specials_context_t specials_context_for_listing(bool attacking = true) const {
452  return specials_context_t(*this, attacking);
453  }
454  void set_changed(bool value)
455  {
456  changed_ = value;
457  }
458  bool get_changed() const
459  {
460  return changed_;
461  }
462 private:
463 
465  std::string id_;
466  std::string type_;
467  std::string icon_;
468  std::string range_;
470  utils::optional<unit_alignments::type> alignment_;
471  int damage_;
475 
479  int parry_;
481  bool changed_;
482  /**
483  * While processing a recursive match, all the filters that are currently being checked, oldest first.
484  * Each will have an instance of recursion_guard that is currently allocated permission to recurse, and
485  * which will pop the config off this stack when the recursion_guard is finalized.
486  */
487  mutable std::vector<const config*> open_queries_;
488 };
489 
490 using attack_list = std::vector<attack_ptr>;
491 using attack_itors = boost::iterator_range<boost::indirect_iterator<attack_list::iterator>>;
492 using const_attack_itors = boost::iterator_range<boost::indirect_iterator<attack_list::const_iterator>>;
493 
495  return boost::make_iterator_range(boost::make_indirect_iterator(atks.begin()), boost::make_indirect_iterator(atks.end()));
496 }
497 
499  return boost::make_iterator_range(boost::make_indirect_iterator(atks.begin()), boost::make_indirect_iterator(atks.end()));
500 }
map_location loc
Definition: move.cpp:172
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(const recursion_guard &other)=delete
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...
recursion_guard & operator=(recursion_guard &&) noexcept
specials_context_t(const specials_context_t &)=delete
std::shared_ptr< const attack_type > parent
const config & specials() const
Definition: attack_type.hpp:57
std::string alignment_str() const
Returns alignment specified by alignment() for filtering when exist.
Definition: attack_type.hpp:95
bool special_active(const config &special, AFFECTS whom, const std::string &tag_name, bool in_abilities_tag=false) const
Definition: abilities.cpp:2167
void set_min_range(int value)
Definition: attack_type.hpp:64
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:56
void set_num_attacks(int value)
Definition: attack_type.hpp:70
specials_context_t specials_context(unit_const_ptr self, const map_location &loc, bool attacking=true) const
int min_range() const
Definition: attack_type.hpp:47
std::string weapon_specials_value(const std::set< std::string > &checking_tags) const
Definition: abilities.cpp:1040
int composite_value(const unit_ability_list &abil_list, int base_value) const
Return the special weapon value, considering specials.
Definition: abilities.cpp:1593
double attack_weight() const
Definition: attack_type.hpp:55
const_attack_ptr other_attack_
void add_formula_context(wfl::map_formula_callable &) const
Definition: abilities.cpp:668
const std::string & range() const
Definition: attack_type.hpp:46
bool special_tooltip_active(const config &special, const std::string &tag_name) const
Returns whether or not the given special is active for the specified unit, based on the current conte...
Definition: abilities.cpp:2323
void set_attacks_used(int value)
map_location self_loc_
int movement_used() const
std::vector< std::pair< t_string, t_string > > abilities_special_tooltips(boost::dynamic_bitset<> *active_list) const
Definition: abilities.cpp:914
specials_context_t specials_context_for_listing(bool attacking=true) const
bool has_special_or_ability_with_filter(const config &filter) const
check if special matche
Definition: abilities.cpp:2126
void set_accuracy(int value)
Definition: attack_type.hpp:67
bool get_changed() const
const std::string & type() const
Definition: attack_type.hpp:44
void set_movement_used(int value)
std::string select_replacement_type(const unit_ability_list &damage_type_list) const
Select best damage type based on frequency count for replacement_type.
Definition: abilities.cpp:1259
bool has_special_or_ability(const std::string &special) const
used for abilities used like weapon and true specials
Definition: abilities.cpp:1797
unit_ability_list get_weapon_ability(const std::string &ability) const
Returns list for weapon like abilities for each ability type.
Definition: abilities.cpp:1557
int parry() const
Definition: attack_type.hpp:52
std::string accuracy_parry_tooltip() const
std::string accuracy_parry_description() const
Definition: attack_type.cpp:85
double modified_damage() const
Returns the damage per attack of this weapon, considering specials.
Definition: abilities.cpp:1373
unit_ability_list get_specials_and_abilities(const std::string &special) const
Definition: abilities.cpp:1576
void apply_effect(const config &cfg)
Applies effect modifications described by cfg.
bool matches_filter(const config &filter, const std::string &check_if_recursion="") const
Returns whether or not *this matches the given filter.
static bool special_active_impl(const const_attack_ptr &self_attack, const const_attack_ptr &other_attack, const config &special, AFFECTS whom, const std::string &tag_name, bool in_abilities_tag=false)
Returns whether or not the given special is active for the specified unit, based on the current conte...
Definition: abilities.cpp:2183
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:1640
void set_specials(config value)
Definition: attack_type.hpp:73
unit_const_ptr self_
friend class specials_context_t
config specials_
void set_defense_weight(double value)
Definition: attack_type.hpp:72
int num_attacks() const
Definition: attack_type.hpp:54
static void weapon_specials_impl_adj(std::string &temp_string, const unit_const_ptr &self, const const_attack_ptr &self_attack, const 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:1100
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:1604
recursion_guard update_variables_recursion(const config &special) const
Tests which might otherwise cause infinite recursion should call this, check that the returned object...
std::pair< std::string, int > select_alternative_type(const unit_ability_list &damage_type_list, const unit_ability_list &resistance_list) const
Select best damage type based on highest damage for alternative_type.
Definition: abilities.cpp:1288
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:878
static void weapon_specials_impl_self(std::string &temp_string, const unit_const_ptr &self, const const_attack_ptr &self_attack, const 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:1080
bool has_filter_special_or_ability(const config &filter, bool simple_check=false) const
check if special matche
Definition: abilities.cpp:1881
std::pair< std::string, std::set< std::string > > damage_types() const
Return a type()/replacement_type and a list of alternative_types that should be displayed in the sele...
Definition: abilities.cpp:1352
std::string type_
std::string icon_
void set_parry(int value)
Definition: attack_type.hpp:68
void set_attack_weight(double value)
Definition: attack_type.hpp:71
void set_damage(int value)
Definition: attack_type.hpp:69
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
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:62
std::vector< const config * > open_queries_
While processing a recursive match, all the filters that are currently being checked,...
static bool check_adj_abilities_impl(const const_attack_ptr &self_attack, const const_attack_ptr &other_attack, const config &special, const unit_const_ptr &u, const unit &from, std::size_t dist, int dir, const map_location &loc, const map_location &from_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:1743
static bool check_self_abilities_impl(const const_attack_ptr &self_attack, const const_attack_ptr &other_attack, const config &special, const 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:1728
bool attack_empty() const
Returns true if this is a dummy attack_type, for example the placeholder that the unit_attack dialog ...
double defense_weight_
std::string id_
static bool special_distant_filtering_impl(const const_attack_ptr &self_attack, const unit_const_ptr &self, const map_location &self_loc, const const_attack_ptr &other_attack, AFFECTS whom, const config &filter, bool sub_filter, bool leader_bool=false)
special_distant_filtering_impl : return an boolean value if special matche with filter
Definition: abilities.cpp:1837
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:2121
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:60
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:65
utils::optional< unit_alignments::type > alignment_
attack_type(const config &cfg)
Definition: attack_type.cpp:50
int modified_chance_to_hit(int cth, bool special_only=false) const
Return the defense value, considering specials.
Definition: abilities.cpp:1379
void set_type(const std::string &value)
Definition: attack_type.hpp:61
void write(config &cfg) const
int accuracy() const
Definition: attack_type.hpp:51
unit_const_ptr other_
int max_range() const
Definition: attack_type.hpp:48
void set_range(const std::string &value)
Definition: attack_type.hpp:63
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:845
static bool has_ability_impl(const const_attack_ptr &self_attack, const unit_const_ptr &self, const map_location &self_loc, const const_attack_ptr &other_attack, AFFECTS whom, const std::string &special)
has_ability_impl : return an boolean value for checking of activities of abilities used like weapon
Definition: abilities.cpp:1758
static std::string describe_effect(const config &cfg)
Generates a description of the effect specified by cfg, if applicable.
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:53
void set_attack_alignment(const std::string &value)
Definition: attack_type.hpp:66
t_string description_
void set_name(const t_string &value)
Definition: attack_type.hpp:59
bool is_for_listing_
bool has_special(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.
Definition: abilities.cpp:816
std::pair< std::string, int > effective_damage_type() const
The type of attack used and the resistance value that does the most damage.
Definition: abilities.cpp:1321
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:157
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:132
Definitions for the interface to Wesnoth Markup Language (WML).
const config * cfg
constexpr auto filter
Definition: ranges.hpp:38
Definition: callable.hpp:26
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:46
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