The Battle for Wesnoth  1.19.17+dev
unit.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 "movetype.hpp"
20 #include "units/id.hpp"
21 #include "units/ptr.hpp"
22 #include "units/attack_type.hpp"
23 #include "units/race.hpp"
24 #include "utils/optional_fwd.hpp"
25 #include "utils/variant.hpp"
26 
27 #include <bitset>
28 #include "utils/optional_fwd.hpp"
29 
30 class team;
32 class vconfig;
33 struct color_t;
34 
35 /** Data typedef for active_ability_list. */
37 {
41  , p_ability_(p_ability)
42  {
43  }
44 
45  /**
46  * Used by the formula in the ability.
47  * The REAL location of the student (not the 'we are assuming the student is at this position' location)
48  * once active_ability_list can contain abilities from different 'students', as it contains abilities from
49  * a unit aswell from its opponents (abilities with apply_to= opponent)
50  */
52  /**
53  * The location of the teacher, that is the unit who owns the ability tags
54  * (different from student because of [affect_adjacent])
55  */
57 
58  const config& ability_cfg() const { return p_ability_->cfg(); }
59  const unit_ability_t& ability() const { return *p_ability_; }
60 private:
61  /** The contents of the ability tag, never nullptr. */
63 };
64 
66 {
67 public:
69 
70  // Implemented in unit_abilities.cpp
71  std::pair<int, map_location> highest(const std::string& key, int def=0) const
72  {
73  return get_extremum(key, def, std::less<int>());
74  }
75  std::pair<int, map_location> lowest(const std::string& key, int def=0) const
76  {
77  return get_extremum(key, def, std::greater<int>());
78  }
79 
80  template<typename TComp>
81  std::pair<int, map_location> get_extremum(const std::string& key, int def, const TComp& comp) const;
82 
83  // The following make this class usable with standard library algorithms and such
85  typedef std::vector<active_ability>::const_iterator const_iterator;
86 
87  iterator begin() { return cfgs_.begin(); }
88  const_iterator begin() const { return cfgs_.begin(); }
89  iterator end() { return cfgs_.end(); }
90  const_iterator end() const { return cfgs_.end(); }
91 
92  // Vector access
93  bool empty() const { return cfgs_.empty(); }
94  active_ability& front() { return cfgs_.front(); }
95  const active_ability& front() const { return cfgs_.front(); }
96  active_ability& back() { return cfgs_.back(); }
97  const active_ability& back() const { return cfgs_.back(); }
98  std::size_t size() { return cfgs_.size(); }
99 
100  iterator erase(const iterator& erase_it) { return cfgs_.erase(erase_it); }
101  iterator erase(const iterator& first, const iterator& last) { return cfgs_.erase(first, last); }
102 
103  template<typename... T>
104  void emplace_back(T&&... args) { cfgs_.emplace_back(args...); }
105 
106  const map_location& loc() const { return loc_; }
107 
108  /** Appends the abilities from @a other to @a this, ignores other.loc() */
109  void append(const active_ability_list& other)
110  {
111  std::copy(other.begin(), other.end(), std::back_inserter(cfgs_ ));
112  }
113 
114  /**
115  * Appends any abilities from @a other for which the given condition returns true to @a this, ignores other.loc().
116  *
117  * @param other where to copy the elements from
118  * @param predicate a single-argument function that takes a reference to an element and returns a bool
119  */
120  template<typename Predicate>
121  void append_if(const active_ability_list& other, const Predicate& predicate)
122  {
123  std::copy_if(other.begin(), other.end(), std::back_inserter(cfgs_ ), predicate);
124  }
125 
126 private:
127  // Data
128  std::vector<active_ability> cfgs_;
130 };
131 
132 /**
133  * This class represents a *single* unit of a specific type.
134  */
135 class unit : public std::enable_shared_from_this<unit>
136 {
137 public:
138  /**
139  * Clear this unit status cache for all units. Currently only the hidden
140  * status of units is cached this way.
141  */
142  static void clear_status_caches();
143 
144  /** The path to the leader crown overlay. */
145  static const std::string& leader_crown();
146 
147 private:
148  void init(const config& cfg, bool use_traits = false, const vconfig* vcfg = nullptr);
149 
150  void init(const unit_type& t, int side, bool real_unit, unit_race::GENDER gender = unit_race::NUM_GENDERS, const std::string& variation = "");
151 
152  // Copy constructor
153  unit(const unit& u);
154 
155  struct unit_ctor_t {};
156 
157 public:
158  //private default ctor, butusing constructor to allow calling make_shared<unit> in create().
159  unit(unit_ctor_t);
160  unit() = delete;
161 
162 private:
164  {
178  //note that UA_ATTACKS only tracks added/deleted attacks, not modified attacks.
185  UA_COUNT
186  };
187 
189  {
190  changed_attributes_[int(attr)] = true;
191  }
192 
193  bool get_attacks_changed() const;
194 
196  {
197  return changed_attributes_[int(attr)];
198  }
199 
201 
202 public:
203  /** Initializes a unit from a config */
204  static unit_ptr create(const config& cfg, bool use_traits = false, const vconfig* vcfg = nullptr)
205  {
206  unit_ptr res = std::make_shared<unit>(unit_ctor_t());
207  res->init(cfg, use_traits, vcfg);
208  return res;
209  }
210 
211  /**
212  * Initializes a unit from a unit type.
213  *
214  * Only real_unit-s should have random traits, name and gender (to prevent OOS caused by RNG calls)
215  */
216  static unit_ptr create(const unit_type& t, int side, bool real_unit, unit_race::GENDER gender = unit_race::NUM_GENDERS, const std::string& variation = "")
217  {
218  unit_ptr res = std::make_shared<unit>(unit_ctor_t());
219  res->init(t, side, real_unit, gender, variation);
220 
221  return res;
222  }
223 
224  unit_ptr clone() const
225  {
226  return std::shared_ptr<unit>(new unit(*this));
227  }
228 
229  virtual ~unit();
230 
231  unit& operator=(const unit&) = delete;
232 
233  /**
234  * @defgroup unit_advance Advancement functions
235  * @{
236  */
237 
238  /** Advances this unit to another type */
239  void advance_to(const unit_type& t, bool use_traits = false);
240 
241  using advances_to_t = std::vector<std::string>;
242  /**
243  * Gets the possible types this unit can advance to on level-up.
244  *
245  * @returns A list of type IDs this unit may advance to.
246  */
247  const advances_to_t& advances_to() const
248  {
249  return advances_to_;
250  }
251 
252  /**
253  * Gets the names of the possible types this unit can advance to on level-up.
254  *
255  * @returns A list of the names of the types this unit may advance to.
256  */
257  const std::vector<std::string> advances_to_translated() const;
258 
259  /**
260  * Sets this unit's advancement options.
261  *
262  * @param advances_to A list of new type IDs this unit may advance to.
263  */
264  void set_advances_to(const std::vector<std::string>& advances_to);
265 
266  /**
267  * Checks whether this unit has any options to advance to.
268  *
269  * This considers both whether it has types to advance to OR whether any modifications
270  * specify non-type advancement options.
271  *
272  * Note this does not consider unit experience at all, it only checks option availability.
273  * See @ref advances if an experience check is necessary.
274  */
275  bool can_advance() const
276  {
277  return !advances_to_.empty() || !get_modification_advances().empty();
278  }
279 
280  /**
281  * Checks whether this unit is eligible for level-up.
282  *
283  * @retval true This unit has sufficient experience to level up and has advancement
284  * options available.
285  */
286  bool advances() const
287  {
288  return experience_ >= max_experience() && can_advance();
289  }
290 
291  /**
292  * Gets and image path and and associated description for each advancement option.
293  *
294  * Covers both type and modification-based advancements.
295  *
296  * @returns A data map, in image/description format. If the option is a unit type,
297  * advancement, the key is the type's image and the value the type ID.
298  *
299  * If the option is a modification, the key and value are set from config data
300  * (see @ref get_modification_advances).
301  */
302  std::map<std::string, std::string> advancement_icons() const;
303 
304  /**
305  * Gets any non-typed advanced options set by modifications.
306  *
307  * These are usually used to give a unit special advancement options that don't invole transforming to a
308  * new type.
309  *
310  * Note this is not the raw option data. Parsing is performed to ensure each option appears only once.
311  * Use @ref modification_advancements is the raw data is needed.
312  *
313  * @returns A config list of options data. Each option is unique.
314  */
315  std::vector<config> get_modification_advances() const;
316 
317  /**
318  * Gets the image and description data for modification advancements.
319  *
320  * @returns A list of pairs of the image paths(first) and descriptions (second) for
321  * each advancement option.
322  */
323  std::vector<std::pair<std::string, std::string>> amla_icons() const;
324 
325  /** The raw, unparsed data for modification advancements. */
326  const std::vector<config>& modification_advancements() const
327  {
328  return advancements_;
329  }
330 
331  /** Sets the raw modification advancement option data */
332  void set_advancements(std::vector<config> advancements);
333 
334  /**
335  * @}
336  * @defgroup unit_access Basic data setters and getters
337  * @{
338  **/
339 
340 public:
341  /**
342  * The side this unit belongs to.
343  *
344  * Note that side numbers starts from 1, not 0, so be sure to subtract 1 if using as a container index.
345  */
346  int side() const
347  {
348  return side_;
349  }
350 
351  /** Sets the side this unit belongs to. */
352  void set_side(unsigned int new_side)
353  {
354  side_ = new_side;
355  }
356 
357  /** This unit's type, accounting for gender and variation. */
358  const unit_type& type() const
359  {
360  return *type_;
361  }
362 
363  /**
364  * The id of this unit's type.
365  *
366  * If you are dealing with creating units (e.g. recruitment), this is not what you want, as a
367  * variation can change this; use type().parent_id() instead.
368  */
369  const std::string& type_id() const;
370 
371  /** Gets the translatable name of this unit's type. */
372  const t_string& type_name() const
373  {
374  return type_name_;
375  }
376 
377  /**
378  * Gets this unit's id.
379  *
380  * This is a unique string usually set by WML. It should *not* be used for internal tracking in
381  * the unit_map. Use @ref underlying_id for that.
382  */
383  const std::string& id() const
384  {
385  return id_;
386  }
387 
388  /** Sets this unit's string ID. */
389  void set_id(const std::string& id)
390  {
391  id_ = id;
392  }
393 
394  /** This unit's unique internal ID. This should *not* be used for user-facing operations. */
395  std::size_t underlying_id() const
396  {
397  return underlying_id_.value;
398  }
399 
400 private:
401  /** Sets the internal ID. */
402  void set_underlying_id(n_unit::id_manager& id_manager);
403 
404 public:
405  /** Gets this unit's translatable display name. */
406  const t_string& name() const
407  {
408  return name_;
409  }
410 
411  /**
412  * Sets this unit's translatable display name.
413  *
414  * This should only be used internally since it ignores the 'unrenamable' flag.
415  */
416  void set_name(const t_string& name)
417  {
418  name_ = name;
419  }
420 
421  /**
422  * Attempts to rename this unit's translatable display name, taking the 'unrenamable' flag into account.
423  *
424  * If a direct rename is desired, use @ref set_name.
425  * @todo should this also take a t_string?
426  */
427  void rename(const std::string& name)
428  {
429  if(!unrenamable_) {
430  name_ = name;
431  }
432  }
433 
434  /**
435  * Whether this unit can be renamed.
436  *
437  * This flag is considered by @ref rename, but not @ref set_name.
438  */
439  bool unrenamable() const
440  {
441  return unrenamable_;
442  }
443 
444  /**
445  * Sets the 'unrenamable' flag. Usually used for scenario-specific units which should not be renamed.
446  */
448  {
450  }
451 
452  /**
453  * Whether this unit can be dismissed.
454  *
455  * This flag is used by the Unit Recall dialog.
456  */
457  bool dismissable() const
458  {
459  return dismissable_;
460  }
461 
462  /** A message of why this unit cannot be dismissed. */
464  {
465  return dismiss_message_;
466  }
467 
468  /** A detailed description of this unit. */
470  {
471  return description_;
472  }
473 
474  /** A detailed description of this unit. */
475  void set_unit_description(const t_string& new_desc)
476  {
477  description_ = new_desc;
478  }
479 
480  /** The unit's special notes. */
481  std::vector<t_string> unit_special_notes() const;
482 
483  /** The gender of this unit. */
485  {
486  return gender_;
487  }
488 
489  /**
490  * The alignment of this unit.
491  *
492  * This affects the time of day during which this unit's attacks do the most damage.
493  */
495  {
496  return alignment_;
497  }
498 
499  /** Sets the alignment of this unit. */
501  {
504  }
505 
506  /**
507  * Gets this unit's race.
508  *
509  * @returns A pointer to a unit_race object - never nullptr, but it may point
510  * to the null race.
511  */
512  const unit_race* race() const
513  {
514  return race_;
515  }
516 
517  /** The current number of hitpoints this unit has. */
518  int hitpoints() const
519  {
520  return hit_points_;
521  }
522 
523  /** The max number of hitpoints this unit can have. */
524  int max_hitpoints() const
525  {
526  return max_hit_points_;
527  }
528 
529  void set_max_hitpoints(int value)
530  {
532  max_hit_points_ = value;
533  }
534 
535  /** Sets the current hitpoint amount. */
536  void set_hitpoints(int hp)
537  {
538  hit_points_ = hp;
539  }
540 
541  /** The current number of experience points this unit has. */
542  int experience() const
543  {
544  return experience_;
545  }
546 
547  /** The max number of experience points this unit can have. */
548  int max_experience() const
549  {
550  return max_experience_;
551  }
552 
553  void set_max_experience(int value)
554  {
556  max_experience_ = value;
557  }
558 
559  /** The number of experience points this unit needs to level up, or 0 if current XP > max XP. */
560  unsigned int experience_to_advance() const
561  {
562  return std::max(0, max_experience_ - experience_);
563  }
564 
565  /** The number of experience points over max this unit has, or 0 if current XP < max XP. */
566  unsigned int experience_overflow() const
567  {
568  return std::max(0, experience_ - max_experience_);
569  }
570 
571  /** Sets the current experience point amount. */
572  void set_experience(int xp)
573  {
574  experience_ = xp;
575  }
576 
577  /** The current level of this unit. */
578  int level() const
579  {
580  return level_;
581  }
582 
583  /** Sets the current level of this unit. */
584  void set_level(int level)
585  {
587  level_ = level;
588  }
589 
590  /** The ID of the variation of this unit's type. */
591  const std::string& variation() const
592  {
593  return variation_;
594  }
595 
596  /** The ID of the undead variation (ie, dwarf, swimmer) of this unit. */
597  void set_undead_variation(const std::string& value)
598  {
600  undead_variation_ = value;
601  }
602  const std::string& undead_variation() const
603  {
604  return undead_variation_;
605  }
606 
607  /**
608  * An optional profile image to display in Help.
609  *
610  * @returns The specified image, this unit's type's sprite image if empty
611  * or 'unit_image' was set.
612  */
613  std::string small_profile() const;
614 
615  void set_small_profile(const std::string& value)
616  {
618  small_profile_ = value;
619  }
620  /**
621  * An optional profile image displays when this unit is 'speaking' via [message].
622  *
623  * @returns The specified image, this unit's type's sprite image if empty
624  * or 'unit_image' was set.
625  */
626  std::string big_profile() const;
627 
628  void set_big_profile(const std::string& value);
629 
630  /** Whether this unit can recruit other units - ie, are they a leader unit. */
631  bool can_recruit() const
632  {
633  return canrecruit_;
634  }
635 
636  /** Sets whether this unit can recruit other units. */
637  void set_can_recruit(bool canrecruit)
638  {
639  canrecruit_ = canrecruit;
640  }
641 
642  /** The type IDs of the other units this unit may recruit, if possible. */
643  const std::set<std::string>& recruits() const
644  {
645  return recruit_list_;
646  }
647 
648  /** Sets the recruit list. */
649  void set_recruits(const std::vector<std::string>& recruits);
650 
651  /** How much gold is required to recruit this unit. */
652  int cost() const
653  {
654  return unit_value_;
655  }
656 
657  /** How much gold it costs to recall this unit, or -1 if the side's default
658  * recall cost is used. */
659  int recall_cost() const
660  {
661  return recall_cost_;
662  }
663 
664  /** Sets the cost of recalling this unit. */
666  {
668  }
669 
670  /** Gets the filter constraints upon which units this unit may recall, if able. */
671  const config& recall_filter() const
672  {
673  return filter_recall_;
674  }
675 
676  /** Sets the filter constraints upon which units this unit may recall, if able. */
678  {
680  }
681 
682  /**
683  * Gets this unit's role.
684  *
685  * A role is a special string flag usually used to represent a unit's purpose in a scenario.
686  * It can be filtered on.
687  */
688  const std::string& get_role() const
689  {
690  return role_;
691  }
692 
693  /** Sets a unit's role */
694  void set_role(const std::string& role)
695  {
696  role_ = role;
697  }
698 
699  /**
700  * Gets this unit's usage. This is relevant to the AI.
701  *
702  * Usage refers to how the AI may consider utilizing this unit in combat.
703  * @todo document further
704  */
705  std::string usage() const
706  {
707  return usage_.value_or("");
708  }
709 
710  /** Sets this unit's usage. */
711  void set_usage(const std::string& usage)
712  {
713  usage_ = usage;
714  }
715 
716  /**
717  * Gets any user-defined variables this unit 'owns'.
718  *
719  * These are accessible via WML if the unit's data is serialized to a variable. They're strictly
720  * user-facing; internal engine calculations shouldn't use this.
721  */
723  {
724  return variables_;
725  }
726 
727  /** Const overload of @ref variables. */
728  const config& variables() const
729  {
730  return variables_;
731  }
732 
733  /**
734  * Gets whether this unit is currently hidden on the map.
735  *
736  * Hidden units are not drawn on the main map or the minimap. They are
737  * an implementation detail. For the [hides] ability, see invisible().
738  */
739  bool get_hidden() const
740  {
741  return hidden_;
742  }
743 
744  /** Sets whether the unit is hidden on the map. */
745  void set_hidden(bool state) const;
746 
747  /**
748  * The factor by which the HP bar should be scaled.
749  * Convenience wrapper around the unit_type value.
750  */
751  double hp_bar_scaling() const;
752  /**
753  * The factor by which the XP bar should be scaled.
754  * Convenience wrapper around the unit_type value.
755  */
756  double xp_bar_scaling() const;
757 
758  /**
759  * Whether the unit has been instructed to hold its position.
760  * This excludes it from the unit cycling function.
761  * @return true if it is holding position
762  */
763  bool hold_position() const
764  {
765  return hold_position_;
766  }
767 
768  /**
769  * Toggle the unit's hold position status.
770  */
772  {
774  if(hold_position_) {
775  end_turn_ = true;
776  }
777  }
778 
779  /**
780  * Set whether the user ended their turn
781  * @todo Verify meaning and explain better
782  */
783  void set_user_end_turn(bool value = true)
784  {
785  end_turn_ = value;
786  }
787 
788  /**
789  * Toggle whether the user ended their turn
790  * @todo Verify meaning and explain better
791  */
793  {
794  end_turn_ = !end_turn_;
795  if(!end_turn_) {
796  hold_position_ = false;
797  }
798  }
799 
800  /**
801  * Check whether the user ended their turn
802  * @todo Verify meaning and explain better
803  */
804  bool user_end_turn() const
805  {
806  return end_turn_;
807  }
808 
809  /**
810  * Refresh unit for the beginning of a turn
811  */
812  void new_turn();
813 
814  /**
815  * Refresh unit for the end of a turn
816  */
817  void end_turn();
818 
819  /**
820  * Refresh unit for the beginning of a new scenario
821  */
822  void new_scenario();
823 
824  /**
825  * Damage the unit.
826  * @returns true if the unit dies as a result
827  */
828  bool take_hit(int damage)
829  {
830  hit_points_ -= damage;
831  return hit_points_ <= 0;
832  }
833 
834  /**
835  * Heal the unit
836  * @param amount The number of hitpoints to gain
837  */
838  void heal(int amount);
839 
840  /**
841  * Fully heal the unit, restoring it to max hitpoints
842  */
843  void heal_fully()
844  {
846  }
847 
848  /**
849  * Get the status effects currently affecting the unit.
850  * @return A set of status keys
851  */
852  const std::set<std::string> get_states() const;
853 
854  /**
855  * Check if the unit is affected by a status effect
856  * @param state The status effect to check
857  * @returns true if the unit is affected by the status effect
858  */
859  bool get_state(const std::string& state) const;
860 
861  /**
862  * Set whether the unit is affected by a status effect
863  * @param state The status effect to change
864  * @param value Whether the unit should be affected by the status
865  */
866  void set_state(const std::string& state, bool value);
867 
868  /**
869  * Built-in status effects known to the engine
870  */
871  enum state_t {
872  STATE_SLOWED = 0, /** The unit is slowed - it moves slower and does less damage */
873  STATE_POISONED, /** The unit is poisoned - it loses health each turn */
874  STATE_PETRIFIED, /** The unit is petrified - it cannot move or be attacked */
875  STATE_UNCOVERED, /** The unit is uncovered - it was hiding but has been spotted */
876  STATE_NOT_MOVED, /** The unit has not moved @todo Explain better */
877  STATE_UNHEALABLE, /** The unit cannot be healed */
878  STATE_GUARDIAN, /** The unit is a guardian - it won't move unless a target is sighted */
879  STATE_INVULNERABLE, /** The unit is invulnerable - it cannot be hit by any attack */
880  NUMBER_OF_STATES, /** To set the size of known_boolean_states_ */
881  STATE_UNKNOWN = -1 /** A status effect not known to the engine */
882  };
883 
884  /**
885  * Set whether the unit is affected by a status effect
886  * @param state The status effect to change
887  * @param value Whether the unit should be affected by the status
888  */
889  void set_state(state_t state, bool value);
890 
891  /**
892  * Check if the unit is affected by a status effect
893  * @param state The status effect to check
894  * @returns true if the unit is affected by the status effect
895  */
896  bool get_state(state_t state) const;
897 
898  /**
899  * Convert a string status effect ID to a built-in status effect ID
900  * @returns the state_t representing the status, or STATE_UNKNOWN if it's not built-in
901  */
902  static state_t get_known_boolean_state_id(const std::string& state);
903 
904  /**
905  * Convert a built-in status effect ID to a string status effect ID
906  * @returns the string representing the status, or an empty string for STATE_UNKNOWN
907  */
908  static std::string get_known_boolean_state_name(state_t state);
909 
910  /**
911  * Check if the unit has been poisoned
912  * @returns true if it's poisoned
913  */
914  bool poisoned() const
915  {
916  return get_state(STATE_POISONED);
917  }
918 
919  /**
920  * Check if the unit has been petrified
921  * @returns true if it's petrified
922  */
923  bool incapacitated() const
924  {
925  return get_state(STATE_PETRIFIED);
926  }
927 
928  /**
929  * Check if the unit has been slowed
930  * @returns true if it's slowed
931  */
932  bool slowed() const
933  {
934  return get_state(STATE_SLOWED);
935  }
936 
937  /**
938  * @}
939  * @defgroup unit_atk Attack and resistance functions
940  * @{
941  */
942 
943 public:
944  /** Gets an iterator over this unit's attacks. */
946  {
947  return make_attack_itors(attacks_);
948  }
949 
950  /** Const overload of @ref attacks. */
952  {
953  return make_attack_itors(attacks_);
954  }
955 
956  /**
957  * Adds a new attack to the unit.
958  * @param position An iterator pointing to the attack before which to insert the new one.
959  * @param args The arguments for constructing the attack
960  */
961  template<typename... Args>
962  attack_ptr add_attack(attack_itors::iterator position, Args&&... args)
963  {
965  return *attacks_.emplace(position.base(), new attack_type(std::forward<Args>(args)...));
966  }
967 
968  /**
969  * Remove an attack from the unit
970  * @param atk A pointer to the attack to remove
971  * @return true if the attack was removed, false if it didn't exist on the unit
972  */
973  bool remove_attack(const attack_ptr& atk);
974 
975  /**
976  * Set the unit to have no attacks left for this turn.
977  */
978  void remove_attacks_ai();
979 
980  /**
981  * Calculates the damage this unit would take from a certain attack.
982  *
983  * @param attack The attack to consider.
984  * @param attacker Whether this unit should be considered the attacker.
985  * @param loc The unit's location (to resolve [resistance] abilities)
986  * @param weapon The weapon to check for any abilities or weapon specials
987  *
988  * @returns The expected damage.
989  */
990  int damage_from(const attack_type& attack, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr) const
991  {
992  return resistance_against(attack, attacker, loc, weapon);
993  }
994 
995  /** The maximum number of attacks this unit may perform per turn, usually 1. */
996  int max_attacks() const
997  {
998  return max_attacks_;
999  }
1000 
1001  void set_max_attacks(int value)
1002  {
1004  max_attacks_ = value;
1005  }
1006 
1007  /**
1008  * Gets the remaining number of attacks this unit can perform this turn.
1009  *
1010  * If the 'incapacitated' status is set, this will always be 0.
1011  */
1012  int attacks_left() const
1013  {
1014  return (attacks_left_ == 0 || incapacitated()) ? 0 : attacks_left_;
1015  }
1016 
1017  /**
1018  * Gets the remaining number of attacks this unit can perform this turn.
1019  *
1020  * @param base_value If false, consider the `incapacitated` flag.
1021  *
1022  * @returns If @a base_value is true, the raw value is returned.
1023  */
1024  int attacks_left(bool base_value) const
1025  {
1026  return base_value ? attacks_left_ : attacks_left();
1027  }
1028 
1029  /**
1030  * Sets the number of attacks this unit has left this turn.
1031  * @param left The number of attacks left
1032  */
1033  void set_attacks(int left)
1034  {
1035  attacks_left_ = std::max<int>(0, left);
1036  }
1037 
1038  /**
1039  * The unit's defense on a given terrain
1040  * @param terrain The terrain to check
1041  * @param loc location of unit
1042  */
1043  int defense_modifier(const t_translation::terrain_code& terrain, const map_location& loc) const;
1044 
1046  {
1047  return defense_modifier(terrain, loc_);
1048  }
1049 
1050  /**
1051  * For the provided list of resistance abilities, determine the damage resistance based on which are active and any max_value that's present.
1052  *
1053  * @param resistance_list A list of resistance abilities that the unit has.
1054  * @param damage_name The name of the damage type, for example "blade".
1055  * @return The resistance value for a unit with the provided resistance abilities to the provided damage type.
1056  */
1057  int resistance_value(active_ability_list resistance_list, const std::string& damage_name) const;
1058 
1059  /**
1060  * The unit's resistance against a given damage type
1061  * @param damage_name The damage type
1062  * @param attacker True if this unit is on the offensive (to resolve [resistance] abilities)
1063  * @param loc The unit's location (to resolve [resistance] abilities)
1064  * @param weapon The weapon to check for any abilities or weapon specials
1065  * @param opp_weapon The opponent's weapon to check for any abilities or weapon specials
1066  */
1067  int resistance_against(const std::string& damage_name, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr, const const_attack_ptr& opp_weapon = nullptr) const;
1068 
1069  /**
1070  * The unit's resistance against a given attack
1071  * @param atk The attack
1072  * @param attacker True if this unit is on the offensive (to resolve [resistance] abilities)
1073  * @param loc The unit's location (to resolve [resistance] abilities)
1074  * @param weapon The weapon to check for any abilities or weapon specials
1075  */
1076  int resistance_against(const attack_type& atk, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr) const
1077  {
1078  return resistance_against(atk.type(), attacker, loc , weapon, atk.shared_from_this());
1079  }
1080 
1081  /** Gets resistances without any abilities applied. */
1083  {
1084  return movement_type_.damage_table();
1085  }
1086 
1087 private:
1088  bool resistance_filter_matches(const config& cfg, const std::string& damage_name, int res) const;
1089 
1090  /**
1091  * @}
1092  * @defgroup unit_trait Trait and upkeep functions
1093  * @{
1094  */
1095 public:
1096  /**
1097  * Applies mandatory traits (e.g. undead, mechanical) to a unit and then fills in the remaining traits
1098  * traits until no more are available (leaders have a restricted set of available traits) or the unit has
1099  * its maximum number of traits.
1100  *
1101  * This routine does not apply the effects of added traits to a unit; that must be done by the caller.
1102  *
1103  * Note that random numbers used in config files don't work in multiplayer, so leaders should be barred
1104  * from all random traits until that is fixed. Later the restrictions will be based on play balance.
1105  *
1106  * @param must_have_only Whether random or optional traits should be included or not. If false only
1107  * mandatory traits will be used.
1108  */
1109  void generate_traits(bool must_have_only = false);
1110 
1111  /**
1112  * Gets the names of the currently registered traits.
1113  *
1114  * @returns A list of translatable trait names.
1115  */
1116  const std::vector<t_string>& trait_names() const
1117  {
1118  return trait_names_;
1119  }
1120 
1121  /**
1122  * Gets the descriptions of the currently registered traits.
1123  *
1124  * @returns A list of translatable trait descriptions.
1125  */
1126  const std::vector<t_string>& trait_descriptions() const
1127  {
1128  return trait_descriptions_;
1129  }
1130 
1131  /**
1132  * Gets the ids of the traits corresponding to those returned by trait_names() and
1133  * trait_descriptions(). Omits hidden traits, which are those with an empty name.
1134  *
1135  * @returns A list of trait IDs.
1136  */
1137  std::vector<std::string> trait_nonhidden_ids() const
1138  {
1139  return trait_nonhidden_ids_;
1140  }
1141 
1142  /** Gets a list of the modification this unit currently has.
1143  * @param mod_type type of modification.
1144  * @returns A list of modification IDs.
1145  */
1146  std::vector<std::string> get_modifications_list(const std::string& mod_type) const;
1147 
1148  /**
1149  * Gets a list of the traits this unit currently has, including hidden traits.
1150  *
1151  * @returns A list of trait IDs.
1152  */
1153  std::vector<std::string> get_traits_list() const
1154  {
1155  return get_modifications_list("trait");
1156  }
1157 
1158  std::vector<std::string> get_objects_list() const
1159  {
1160  return get_modifications_list("object");
1161  }
1162 
1163  std::vector<std::string> get_advancements_list() const
1164  {
1165  return get_modifications_list("advancement");
1166  }
1167 
1168  /**
1169  * Register a trait's name and its description for the UI's use.
1170  *
1171  * The resulting data can be fetched with @ref trait_names and @ref trait_descriptions.
1172  *
1173  * @param trait A config containing the trait's attributes.
1174  * @param description The translatable description of the trait.
1175  */
1176  void add_trait_description(const config& trait, const t_string& description);
1177 
1178  /**
1179  * Gets the amount of gold this unit costs a side per turn.
1180  *
1181  * This fetches an actual numeric gold value:
1182  * - If can_recruit is true, no upkeep is paid (0 is returned).
1183  * - If a special upkeep flag is set, the associated gold amount is returned (see @ref upkeep_value_visitor).
1184  * - If a numeric value is already set, it is returned directly.
1185  *
1186  * @returns A gold value, evaluated based on the state of @ref upkeep_raw.
1187  */
1188  int upkeep() const;
1189 
1191  {
1192  static std::string type() { static std::string v = "full"; return v; }
1193  };
1194 
1196  {
1197  static std::string type() { static std::string v = "loyal"; return v; }
1198  };
1199 
1200  using upkeep_t = utils::variant<upkeep_full, upkeep_loyal, int>;
1201 
1202  /** Visitor helper class to fetch the appropriate upkeep value. */
1204 #ifdef USING_BOOST_VARIANT
1205  : public boost::static_visitor<int>
1206 #endif
1207  {
1208  public:
1209  explicit upkeep_value_visitor(const unit& unit) : u_(unit) {}
1210 
1211  /** Full upkeep equals the unit's level. */
1212  int operator()(const upkeep_full&) const
1213  {
1214  return u_.level();
1215  }
1216 
1217  /** Loyal units cost no upkeep. */
1218  int operator()(const upkeep_loyal&) const
1219  {
1220  return 0;
1221  }
1222 
1223  int operator()(int v) const
1224  {
1225  return v;
1226  }
1227 
1228  private:
1229  const unit& u_;
1230  };
1231 
1232  /** Visitor helper struct to fetch the upkeep type flag if applicable, or the the value otherwise. */
1234 #ifdef USING_BOOST_VARIANT
1235  : public boost::static_visitor<std::string>
1236 #endif
1237  {
1238  template<typename T>
1239  std::enable_if_t<!std::is_same_v<int, T>, std::string>
1240  operator()(T&) const
1241  {
1242  // Any special upkeep type should have an associated @ref type getter in its helper struct.
1243  return T::type();
1244  }
1245 
1246  std::string operator()(int v) const
1247  {
1248  return std::to_string(v);
1249  }
1250  };
1251 
1252  /** Visitor helper class to parse the upkeep value from a config. */
1254 #ifdef USING_BOOST_VARIANT
1255  : public boost::static_visitor<upkeep_t>
1256 #endif
1257  {
1258  public:
1259  template<typename N>
1260  std::enable_if_t<std::is_arithmetic_v<N>, upkeep_t>
1261  operator()(N n) const
1262  {
1263  if(n == 0) return upkeep_loyal();
1264  if(n < 0) throw std::invalid_argument(std::to_string(n));
1265  return static_cast<int>(n);
1266  }
1267 
1268  template<typename B>
1269  std::enable_if_t<std::is_convertible_v<B, bool> && !std::is_arithmetic_v<B>, upkeep_t>
1270  operator()(B b) const
1271  {
1272  throw std::invalid_argument(b.str());
1273  }
1274 
1275  upkeep_t operator()(utils::monostate) const
1276  {
1277  return upkeep_full();
1278  }
1279 
1280  upkeep_t operator()(const std::string& s) const
1281  {
1282  if(s == "loyal" || s == "free")
1283  return upkeep_loyal();
1284  if(s == "full")
1285  return upkeep_full();
1286  throw std::invalid_argument(s);
1287  }
1288  };
1289 
1290  /**
1291  * Gets the raw variant controlling the upkeep value.
1292  *
1293  * This should not usually be called directly. To get an actual numeric value of upkeep use @ref upkeep.
1294  */
1296  {
1297  return upkeep_;
1298  }
1299 
1300  /** Sets the upkeep value to a specific value value. Does not necessarily need to be numeric */
1302  {
1303  upkeep_ = v;
1304  }
1305 
1306  /** Gets whether this unit is loyal - ie, it costs no upkeep. */
1307  bool loyal() const;
1308 
1309  void set_loyal(bool loyal);
1310 
1311  /** Gets whether this unit is fearless - ie, unaffected by time of day. */
1312  bool is_fearless() const
1313  {
1314  return is_fearless_;
1315  }
1316 
1317  /** Gets whether this unit is healthy - ie, always rest heals. */
1318  bool is_healthy() const
1319  {
1320  return is_healthy_;
1321  }
1322 
1323  /**
1324  * If this unit has abilities of @a tag_name type with [affect_adjacent] subtags, returns the radius of the one with the furthest reach.
1325  *
1326  * If the unit has no such abilities, returns zero.
1327  */
1328  std::size_t max_ability_radius_type(const std::string& tag_name) const
1329  {
1330  auto iter = max_ability_radius_type_.find(tag_name);
1331  return iter != max_ability_radius_type_.end() ? iter->second : 0;
1332  }
1333 
1334  /**
1335  * If this unit has abilities with [affect_adjacent] subtags, returns the radius of the one with the furthest reach.
1336  *
1337  * If the unit has no such abilities, returns zero.
1338  */
1339  std::size_t max_ability_radius() const
1340  {
1341  return max_ability_radius_;
1342  }
1343 
1344  /**
1345  * If this unit has abilities with [affect_adjacent] subtags and halo_image or overlay_image attributes, returns the radius of the one with the furthest reach.
1346  *
1347  * If the unit has no such abilities, returns zero.
1348  */
1349  std::size_t max_ability_radius_image() const
1350  {
1352  }
1353 
1354  /**
1355  * @}
1356  * @defgroup unit_mvmt Movement and location functions
1357  * @{
1358  */
1359 
1360 public:
1361  /** The maximum moves this unit has. */
1362  int total_movement() const
1363  {
1364  return max_movement_;
1365  }
1366 
1367  void set_total_movement(int value)
1368  {
1370  max_movement_ = value;
1371  }
1372 
1373  /**
1374  * Gets how far a unit can move, considering the `incapacitated` flag.
1375  *
1376  * @returns The remaining movement, or zero if incapacitated.
1377  */
1378  int movement_left() const
1379  {
1380  return (movement_ == 0 || incapacitated()) ? 0 : movement_;
1381  }
1382 
1383  /**
1384  * Gets how far a unit can move.
1385  *
1386  * @param base_value If false, consider the `incapacitated` flag.
1387  *
1388  * @returns If @a base_value is true, the raw value is returned.
1389  */
1390  int movement_left(bool base_value) const
1391  {
1392  return base_value ? movement_ : movement_left();
1393  }
1394 
1395  /**
1396  * Set this unit's remaining movement to @a moves.
1397  *
1398  * This does not affect maximum movement.
1399  *
1400  * @param moves The new number of moves
1401  * @param unit_action If to true, the "end turn" and "hold position" flags will be cleared
1402  * (as they should be if a unit acts, as opposed to the movement being set
1403  * by the engine for other reasons).
1404  */
1405  void set_movement(int moves, bool unit_action = false);
1406 
1407  /** Checks if this unit has moved. */
1408  bool has_moved() const
1409  {
1410  return movement_left() != total_movement();
1411  }
1412 
1413  /** Sets the unit to have no moves left for this turn. */
1414  void remove_movement_ai();
1415 
1416  /**
1417  * Checks whether this unit is 'resting'.
1418  *
1419  * Resting refers to whether this unit has not moved yet this turn. Note that this can be true even
1420  * if @ref movement_left is not equal to @ref total_movement.
1421  */
1422  bool resting() const
1423  {
1424  return resting_;
1425  }
1426 
1427  /** Sets this unit's resting status. */
1428  void set_resting(bool rest)
1429  {
1430  resting_ = rest;
1431  }
1432 
1433  /** Tests whether the unit has a zone-of-control, considering @ref incapacitated. */
1434  bool emits_zoc() const
1435  {
1436  return emit_zoc_ && !incapacitated();
1437  }
1438 
1439  /** Gets the raw zone-of-control flag, disregarding @ref incapacitated. */
1440  bool get_emit_zoc() const
1441  {
1442  return emit_zoc_;
1443  }
1444 
1445  /** Sets the raw zone-of-control flag. */
1446  void set_emit_zoc(bool val)
1447  {
1449  emit_zoc_ = val;
1450  }
1451 
1452  /** The current map location this unit is at. */
1454  {
1455  return loc_;
1456  }
1457 
1458  /**
1459  * Sets this unit's map location.
1460  *
1461  * Note this should only be called by unit_map or for temporary units.
1462  */
1464  {
1465  loc_ = loc;
1466  }
1467 
1468  /** The current direction this unit is facing within its hex. */
1470  {
1471  return facing_;
1472  }
1473 
1474  /** The this unit's facing. */
1475  void set_facing(map_location::direction dir) const;
1476 
1477  /** Gets whether this unit has a multi-turn destination set. */
1478  bool has_goto() const
1479  {
1480  return get_goto().valid();
1481  }
1482 
1483  /** The map location to which this unit is moving over multiple turns, if any. */
1484  const map_location& get_goto() const
1485  {
1486  return goto_;
1487  }
1488 
1489  /** Sets this unit's long term destination. */
1490  void set_goto(const map_location& new_goto)
1491  {
1492  goto_ = new_goto;
1493  }
1494 
1495  /** Gets the unit's vision points. */
1496  int vision() const
1497  {
1498  return vision_ < 0 ? max_movement_ : vision_;
1499  }
1500 
1501  /** Gets the unit's jamming points. */
1502  int jamming() const
1503  {
1504  return jamming_;
1505  }
1506 
1507  /** Check whether the unit's move has been interrupted. */
1508  bool move_interrupted() const
1509  {
1510  return movement_left() > 0 && interrupted_move_.x >= 0 && interrupted_move_.y >= 0;
1511  }
1512 
1513  /** Get the target location of the unit's interrupted move. */
1515  {
1516  return interrupted_move_;
1517  }
1518 
1519  /** Set the target location of the unit's interrupted move. */
1520  void set_interrupted_move(const map_location& interrupted_move)
1521  {
1522  interrupted_move_ = interrupted_move;
1523  }
1524 
1525  /** Get the unit's movement type. */
1526  const movetype& movement_type() const
1527  {
1528  return movement_type_;
1529  }
1530 
1531  /**
1532  * Get the unit's movement cost on a particular terrain
1533  * @param terrain The terrain to check
1534  * @returns the number of movement points to enter that terrain
1535  */
1536  int movement_cost(const t_translation::terrain_code& terrain) const
1537  {
1539  }
1540 
1541  /**
1542  * Get the unit's vision cost on a particular terrain
1543  * @param terrain The terrain to check
1544  * @returns the number of vision points to see into that terrain
1545  */
1546  int vision_cost(const t_translation::terrain_code& terrain) const
1547  {
1549  }
1550 
1551  /**
1552  * Get the unit's jamming cost on a particular terrain
1553  * @param terrain The terrain to check
1554  * @returns the number of jamming points to jam that terrain
1555  */
1556  int jamming_cost(const t_translation::terrain_code& terrain) const
1557  {
1559  }
1560 
1561  /** Check if the unit is a flying unit. */
1562  bool is_flying() const
1563  {
1564  return movement_type_.is_flying();
1565  }
1566 
1567  /**
1568  * @}
1569  * @defgroup unit_mod Modification functions
1570  * @{
1571  */
1572 
1573 public:
1574  /** Get the raw modifications. */
1576  {
1577  return modifications_;
1578  }
1579 
1580  /** Set the raw modifications. */
1581  const config& get_modifications() const
1582  {
1583  return modifications_;
1584  }
1585 
1586  /**
1587  * Count modifications of a particular type.
1588  * @param type The type of modification to count.
1589  * Valid values are "advancement", "trait", "object"
1590  * @param id The ID of the modification to count
1591  * @return The total number of modifications of that type and ID.
1592  */
1593  std::size_t modification_count(const std::string& type, const std::string& id) const;
1594 
1595  /**
1596  * Count modifications of a particular type.
1597  * @param type The type of modification to count.
1598  * Valid values are "advancement", "trait", "object"
1599  * @return The total number of modifications of that type.
1600  */
1601  std::size_t modification_count(const std::string& type) const;
1602 
1603  std::size_t traits_count() const
1604  {
1605  return modification_count("trait");
1606  }
1607 
1608  std::size_t objects_count() const
1609  {
1610  return modification_count("object");
1611  }
1612 
1613  std::size_t advancements_count() const
1614  {
1615  return modification_count("advancement");
1616  }
1617 
1618  /**
1619  * Add a new modification to the unit.
1620  * @param type The type of modification to add.
1621  * Valid values are "advancement", "trait", "object"
1622  * @param modification The details of the modification
1623  * @param no_add If true, apply the modification but don't save it for unit rebuild time.
1624  * Defaults to false.
1625  */
1626  void add_modification(const std::string& type, const config& modification, bool no_add = false);
1627 
1628  /**
1629  * Clears those modifications whose duration has expired.
1630  *
1631  * @param duration If empty, all temporary modifications (those not lasting forever) expire.
1632  * Otherwise, modifications whose duration equals @a duration expire.
1633  */
1634  void expire_modifications(const std::string& duration);
1635 
1636  static const std::set<std::string> builtin_effects;
1637 
1638  /**
1639  * Apply a builtin effect to the unit.
1640  * @param type The effect to apply. Must be one of the effects in @ref builtin_effects.
1641  * @param effect The details of the effect
1642  */
1643  void apply_builtin_effect(const std::string& type, const config& effect);
1644 
1645  /**
1646  * Construct a string describing a built-in effect.
1647  * @param type The effect to describe. Must be one of the effects in @ref builtin_effects.
1648  * @param effect The details of the effect
1649  */
1650  std::string describe_builtin_effect(const std::string& type, const config& effect);
1651 
1652  /** Re-apply all saved modifications. */
1653  void apply_modifications();
1654 
1655  /**
1656  * @}
1657  * @defgroup unit_img Image and animations functions
1658  * @{
1659  */
1660 
1661 public:
1662  /** @todo Document this */
1664  {
1665  return *anim_comp_;
1666  }
1667 
1668  /** The name of the file to game_display (used in menus). */
1669  std::string absolute_image() const;
1670 
1671  /** The default image to use for animation frames with no defined image. */
1672  std::string default_anim_image() const;
1673 
1674  /** Get the unit's halo image. */
1675  std::string image_halo() const
1676  {
1677  return halo_.value_or("");
1678  }
1679 
1680  std::vector<std::string> halo_or_icon_abilities(const std::string& image_type) const;
1681 
1682  /** Get the [halo] abilities halo image(s). */
1683  std::vector<std::string> halo_abilities() const
1684  {
1685  return halo_or_icon_abilities("halo");
1686  }
1687 
1688  /** Set the unit's halo image. */
1689  void set_image_halo(const std::string& halo);
1690 
1691  /** Get the unit's ellipse image. */
1692  std::string image_ellipse() const
1693  {
1694  return ellipse_.value_or("");
1695  }
1696 
1697  /** Set the unit's ellipse image. */
1698  void set_image_ellipse(const std::string& ellipse)
1699  {
1700  appearance_changed_ = true;
1701  ellipse_ = ellipse;
1702  }
1703 
1704  /**
1705  * Get the source color palette to use when recoloring the unit's image.
1706  */
1707  const std::string& flag_rgb() const;
1708 
1709  /** Constructs a recolor (RC) IPF string for this unit's team color. */
1710  std::string TC_image_mods() const;
1711 
1712  /** Gets any IPF image mods applied by effects. */
1713  const std::string& effect_image_mods() const
1714  {
1715  return image_mods_;
1716  }
1717 
1718  /**
1719  * Gets an IPF string containing all IPF image mods.
1720  *
1721  * @returns An amalgamation of @ref effect_image_mods followed by @ref TC_image_mods.
1722  */
1723  std::string image_mods() const;
1724 
1725  /** Get the unit's overlay images. */
1726  const std::vector<std::string>& overlays() const
1727  {
1728  return overlays_;
1729  }
1730 
1731  /** Get the [overlay] ability overlay images. */
1732  std::vector<std::string> overlays_abilities() const
1733  {
1734  return halo_or_icon_abilities("overlay");
1735  }
1736 
1737  /**
1738  * Color for this unit's *current* hitpoints.
1739  *
1740  * @returns A color between green and red representing how wounded this unit is.
1741  * The maximum_hitpoints are considered as base.
1742  */
1743  color_t hp_color() const;
1744  static color_t hp_color_max();
1745 
1746  /**
1747  * Color for this unit's hitpoints.
1748  *
1749  * @param hitpoints The number of hitpoints the color represents.
1750  * @returns The color considering the current hitpoints as base.
1751  */
1752  color_t hp_color(int hitpoints) const;
1753 
1754  /**
1755  * Color for this unit's XP. See also @ref hp_color
1756  */
1757  color_t xp_color() const;
1758  static color_t xp_color(int xp_to_advance, bool can_advance, bool has_amla);
1759 
1760  /**
1761  * @}
1762  * @defgroup unit_abil Ability functions
1763  * @{
1764  */
1765 
1766 public:
1767  /**
1768  * Checks whether this unit currently possesses or is affected by a given ability.
1769  *
1770  * This means that the ability could be owned by this unit itself or by an adjacent unit, should
1771  * the ability affect an AoE in which this unit happens to be.
1772  *
1773  * @param tag_name The name of the ability to check for.
1774  * @param loc The location around which to check for affected units. This may or
1775  * may not be the location of this unit.
1776  */
1777  bool get_ability_bool(const std::string& tag_name, const map_location& loc) const;
1778 
1779  /**
1780  * Checks whether this unit currently possesses or is affected by a given ability.
1781  *
1782  * This means that the ability could be owned by this unit itself or by an adjacent unit, should
1783  * the ability affect an AoE in which this unit happens to be.
1784  *
1785  * This overload uses the location of this unit for calculations.
1786  *
1787  * @param tag_name The name of the ability to check for.
1788  */
1789  bool get_ability_bool(const std::string& tag_name) const
1790  {
1791  return get_ability_bool(tag_name, loc_);
1792  }
1793 
1794  /** Checks whether this unit currently possesses a given ability, and that that ability is active.
1795  * @return True if the ability @a tag_name is active.
1796  * @param ab the ability checked
1797  * @param loc location of the unit checked.
1798  */
1799  bool get_self_ability_bool(const unit_ability_t& ab, const map_location& loc) const;
1800  /** Checks whether this unit currently possesses a given ability of leadership type
1801  * @return True if the ability @a tag_name is active.
1802  * @param ab the ability checked
1803  * @param loc location of the unit checked.
1804  * @param weapon the attack used by unit checked in this function.
1805  * @param opp_weapon the attack used by opponent to unit checked.
1806  */
1807  bool get_self_ability_bool_weapon(const unit_ability_t& ab, const map_location& loc, const const_attack_ptr& weapon = nullptr, const const_attack_ptr& opp_weapon = nullptr) const;
1808  /** Checks whether this unit is affected by a given ability, and that that ability is active.
1809  * @return True if the ability @a tag_name is active.
1810  * @param ab the ability checked
1811  * @param loc location of the unit checked.
1812  * @param from unit distant to @a this is checked in case of [affect_adjacent] abilities.
1813  * @param from_loc the 'other unit' location.
1814  * @param dist distance between unit distant and @a this.
1815  * @param dir direction to research a unit distant to @a this.
1816  */
1817  bool get_adj_ability_bool(const unit_ability_t& ab, std::size_t dist, int dir, const map_location& loc, const unit& from, const map_location& from_loc) const;
1818  /** Checks whether this unit is affected by a given ability of leadership type
1819  * @return True if the ability @a tag_name is active.
1820  * @param ab the ability checked
1821  * @param loc location of the unit checked.
1822  * @param from unit adjacent to @a this is checked in case of [affect_adjacent] abilities.
1823  * @param from_loc location of the @a from unit.
1824  * @param weapon the attack used by unit checked in this function.
1825  * @param opp_weapon the attack used by opponent to unit checked.
1826  * @param dist distance between unit distant and @a this.
1827  * @param dir direction to research a unit distant to @a this.
1828  */
1829  bool get_adj_ability_bool_weapon(const unit_ability_t& ab, std::size_t dist, int dir, const map_location& loc, const unit& from, const map_location& from_loc, const const_attack_ptr& weapon, const const_attack_ptr& opp_weapon) const;
1830 
1831  /**
1832  * Gets the unit's active abilities of a particular type if it were on a specified location.
1833  * @param tag_name The type of ability to check for
1834  * @param loc The location to use for resolving abilities
1835  * @return A list of active abilities, paired with the location they are active on
1836  */
1837  active_ability_list get_abilities(const std::string& tag_name, const map_location& loc) const;
1838 
1839  /**
1840  * Gets the unit's active abilities of a particular type.
1841  * @param tag_name The type of ability to check for
1842  * @return A list of active abilities, paired with the location they are active on
1843  */
1844  active_ability_list get_abilities(const std::string& tag_name) const
1845  {
1846  return get_abilities(tag_name, loc_);
1847  }
1848 
1849  active_ability_list get_abilities_weapons(const std::string& tag_name, const map_location& loc, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr) const;
1850 
1851  active_ability_list get_abilities_weapons(const std::string& tag_name, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr) const
1852  {
1853  return get_abilities_weapons(tag_name, loc_, weapon, opp_weapon);
1854  }
1855 
1857 
1859  }
1860 
1861  const ability_vector& abilities() const {
1862  return abilities_;
1863  }
1864 
1865  ability_vector abilities(const std::string& tag) const {
1867  }
1868 
1869  /**
1870  * Gets the names and descriptions of this unit's abilities. Location-independent variant
1871  * with all abilities shown as active.
1872  *
1873  * @returns A list of quadruples consisting of (in order) id, base name,
1874  * male or female name as appropriate for the unit, and description.
1875  */
1876  std::vector<std::tuple<std::string, t_string, t_string, t_string>>
1877  ability_tooltips() const;
1878 
1879  /**
1880  * Gets the names and descriptions of this unit's abilities.
1881  *
1882  * @param active_list This vector will be the same length as the returned one and will
1883  * indicate whether or not the corresponding ability is active.
1884  *
1885  * @param loc The location on which to resolve the ability.
1886  *
1887  * @returns A list of quadruples consisting of (in order) id, base name,
1888  * male or female name as appropriate for the unit, and description.
1889  */
1890  std::vector<std::tuple<std::string, t_string, t_string, t_string>>
1891  ability_tooltips(boost::dynamic_bitset<>& active_list, const map_location& loc) const;
1892 
1893  /** Get a list of all abilities by ID. */
1894  std::vector<std::string> get_ability_list() const;
1895 
1896  /**
1897  * Check if the unit has an ability of a specific type.
1898  * @param ability The type of ability (tag name) to check for.
1899  * @returns true if the ability is present
1900  */
1901  bool has_ability_type(const std::string& ability) const;
1902 
1903  /**
1904  * Check if the unit has an ability of a specific ID.
1905  * @param ability The ID of ability to check for.
1906  * @returns true if the ability is present
1907  */
1908  bool has_ability_by_id(const std::string& ability) const;
1909 
1910  /**
1911  * Removes a unit's abilities with a specific ID.
1912  * @param ability The type of ability (tag name) to remove.
1913  */
1914  void remove_ability_by_id(const std::string& ability);
1915 
1916  /**
1917  * Removes a unit's abilities with a specific ID or other attribute.
1918  * @param filter the config of ability to remove.
1919  */
1921 
1922  /**
1923  * Verify what abilities attributes match with filter.
1924  * @param ab the ability checked
1925  * @param filter the filter used for checking.
1926  */
1927  bool ability_matches_filter(const unit_ability_t& ab, const config & filter) const;
1928 
1929 
1930 private:
1931 
1932  /**
1933  * Helper similar to std::unique_lock for detecting when calculations such as abilities
1934  * have entered infinite recursion.
1935  *
1936  * This assumes that there's only a single thread accessing the unit, it's a lightweight
1937  * increment/decrement counter rather than a mutex.
1938  */
1940  friend class unit;
1941  /**
1942  * Only expected to be called in update_variables_recursion(), which handles some of the checks.
1943  */
1944  explicit recursion_guard(const unit& u, const config& ability);
1945  public:
1946  /**
1947  * Construct an empty instance, only useful for extending the lifetime of a
1948  * recursion_guard returned from unit.update_variables_recursion() by
1949  * std::moving it to an instance declared in a larger scope.
1950  */
1951  explicit recursion_guard();
1952 
1953  /**
1954  * Returns true if a level of recursion was available at the time when update_variables_recursion()
1955  * created this object.
1956  */
1957  operator bool() const;
1958 
1959  recursion_guard(recursion_guard&& other) noexcept;
1960  recursion_guard(const recursion_guard& other) = delete;
1962  recursion_guard& operator=(const recursion_guard&) = delete;
1963  ~recursion_guard();
1964  private:
1965  std::shared_ptr<const unit> parent;
1966  };
1967 
1968  recursion_guard update_variables_recursion(const config& ability) const;
1969 
1970  /**
1971  * Check if an ability is active. Includes checks to prevent excessive recursion.
1972  * @param ab the ability checked
1973  * @param loc The location on which to resolve the ability
1974  * @returns true if it is active
1975  */
1976  bool ability_active(const unit_ability_t& ab, const map_location& loc) const;
1977  /**
1978  * Check if an ability is active. The caller is responsible for preventing excessive recursion, so must hold a recursion_guard.
1979  * @param ab the ability checked
1980  * @param loc The location on which to resolve the ability
1981  * @returns true if it is active
1982  */
1983  bool ability_active_impl(const unit_ability_t& ab, const map_location& loc) const;
1984 
1985  /**
1986  * Check if an ability affects distant units.
1987  * @param ab the ability checked
1988  * @param loc The location on which to resolve the ability
1989  * @param from The "other unit" for filter matching
1990  * @param dist distance between unit distant and @a this.
1991  * @param dir direction to research a unit distant to @a this.
1992  */
1993  bool ability_affects_adjacent(const unit_ability_t& ab, std::size_t dist, int dir, const map_location& loc, const unit& from) const;
1994  /**
1995  * Check if an ability affects the owning unit.
1996  * @param ab the ability checked
1997  * @param loc The location on which to resolve the ability
1998  */
1999  bool ability_affects_self(const unit_ability_t& ab, const map_location& loc) const;
2000 
2001  /**
2002  * filters the weapons that condition the use of abilities for combat ([resistance],[leadership] or abilities used like specials
2003  * (deprecated in two last cases)
2004  */
2005  bool ability_affects_weapon(const unit_ability_t& ab, const const_attack_ptr& weapon, bool is_opp) const;
2006 
2007 public:
2008  /** Generates a random race-appropriate name if one has not already been provided. */
2009  void generate_name();
2010 
2011  // Only see_all = true use caching
2012  bool invisible(const map_location& loc, bool see_all = true) const;
2013 
2014  bool is_visible_to_team(const team& team, bool const see_all = true) const;
2015  /** Return true if the unit would be visible to team if its location were loc. */
2016  bool is_visible_to_team(const map_location& loc, const team& team, bool const see_all = true) const;
2017 
2018  /**
2019  * Serializes the current unit metadata values.
2020  *
2021  * @param cfg The config to write to.
2022  * @param write_all set this to false to not write unchanged attributes.
2023  */
2024  void write(config& cfg, bool write_all = true) const;
2025 
2026  /**
2027  * Mark this unit as clone so it can be inserted to unit_map.
2028  *
2029  * @returns self (for convenience)
2030  */
2031  unit& mark_clone(bool is_temporary);
2032 
2033 
2034  void set_appearance_changed(bool value) { appearance_changed_ = value; }
2035  bool appearance_changed() const { return appearance_changed_; }
2036 
2037 protected:
2038 
2039 private:
2041 
2042  std::vector<std::string> advances_to_;
2043 
2044  /** Never nullptr. Adjusted for gender and variation. */
2046 
2047  /** The displayed name of this unit type. */
2049 
2050  /** Never nullptr, but may point to the null race. */
2052 
2053  std::string id_;
2056 
2057  std::string undead_variation_;
2058  std::string variation_;
2059 
2064 
2065  int level_;
2066 
2069  std::set<std::string> recruit_list_;
2071 
2072  std::string flag_rgb_;
2073  std::string image_mods_;
2074 
2078 
2079  int side_;
2080 
2082 
2085  int vision_;
2087 
2089 
2092  bool resting_;
2093 
2096 
2097  std::set<std::string> states_;
2098 
2099  static const std::size_t num_bool_states = state_t::NUMBER_OF_STATES;
2100 
2101  std::bitset<num_bool_states> known_boolean_states_;
2102  static std::map<std::string, state_t> known_boolean_state_names_;
2103 
2107 
2109 
2110  std::vector<std::string> overlays_;
2111 
2112  std::string role_;
2114  /**
2115  * While processing a recursive match, all the filters that are currently being checked, oldest first.
2116  * Each will have an instance of recursion_guard that is currently allocated permission to recurse, and
2117  * which will pop the config off this stack when the recursion_guard is finalized.
2118  */
2119  mutable std::vector<const config*> open_queries_;
2120 
2121 protected:
2122  // TODO: I think we actually consider this to be part of the gamestate, so it might be better if it's not mutable,
2123  // but it's not easy to separate this guy from the animation code right now.
2125 
2126 private:
2127  std::vector<t_string> trait_names_;
2128  std::vector<t_string> trait_descriptions_;
2129  std::vector<std::string> trait_nonhidden_ids_;
2130 
2133 
2135 
2136  // Unit list/recall list favorite unit marking
2138 
2139 public:
2140  bool favorite() const { return is_favorite_; }
2141 
2143 
2144 private:
2145 
2147 
2148  // Animations:
2150 
2151  std::unique_ptr<unit_animation_component> anim_comp_;
2152 
2153  mutable bool hidden_;
2154 
2157 
2158  std::vector<config> advancements_;
2159 
2161  std::vector<t_string> special_notes_;
2162 
2163  utils::optional<std::string> usage_;
2164  utils::optional<std::string> halo_;
2165  utils::optional<std::string> ellipse_;
2166 
2169 
2171 
2172  std::string profile_;
2173  std::string small_profile_;
2174 
2175  //Used to check whether the moving units during a move needs to be updated
2176  mutable bool appearance_changed_ = true;
2177  std::bitset<UA_COUNT> changed_attributes_;
2178 
2181 
2182  /**
2183  * Hold the visibility status cache for a unit, when not uncovered.
2184  * This is mutable since it is a cache.
2185  */
2186  mutable std::map<map_location, bool> invisibility_cache_;
2187 
2188  /**
2189  * Clears the cache.
2190  *
2191  * Since we don't change the state of the object we're marked const (also
2192  * required since the objects in the cache need to be marked const).
2193  */
2195  {
2196  invisibility_cache_.clear();
2197  }
2198 
2199  /**
2200  * Used for easing checking if unit own a ability of specified type with [affect_adjacent] sub tag.
2201  *
2202  */
2203  std::map<std::string, std::size_t> max_ability_radius_type_;
2204  /**
2205  * Used for easing checking if unit own a ability with [affect_adjacent] sub tag.
2206  *
2207  */
2208  std::size_t max_ability_radius_;
2209  /**
2210  * used if ability own halo_image or overlay_image attributes in same time what [affect_adjacent].
2211  */
2213  void set_has_ability_distant();
2214 };
2215 
2216 /**
2217  * Object which temporarily resets a unit's movement.
2218  *
2219  * @warning A unit whose movement is reset may not be deleted while held in a
2220  * @ref unit_movement_resetter object, so it's best to use thus only in a small scope.
2221  */
2223 {
2226 
2227  unit_movement_resetter(const unit& u, bool operate = true);
2229 
2230 private:
2232  int moves_;
2233 };
2234 
2236 {
2237 /**
2238  * Optional parameter for get_checksum to use the algorithm of an older version of Wesnoth,
2239  * thus preventing spurious OOS warnings while watching old replays.
2240  */
2242  current,
2243  version_1_16_or_older /**< Included some of the flavortext from weapon specials. */
2244 };
2245 
2246 } // namespace backwards_compatibility
2247 
2248 /**
2249  * Gets a checksum for a unit.
2250  *
2251  * In MP games the descriptions are locally generated and might differ, so it
2252  * should be possible to discard them. Not sure whether replays suffer the
2253  * same problem.
2254  *
2255  * @param u this unit
2256  * @param version allows the checksum expected in older replays to be used
2257  *
2258  * @returns the checksum for a unit
2259  */
2260 std::string get_checksum(const unit& u,
map_location loc
Definition: move.cpp:172
double t
Definition: astarsearch.cpp:63
boost::iterator_range< boost::indirect_iterator< attack_list::iterator > > attack_itors
std::vector< ability_ptr > ability_vector
Definition: attack_type.hpp:37
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)
std::vector< active_ability >::iterator iterator
Definition: unit.hpp:84
void append_if(const active_ability_list &other, const Predicate &predicate)
Appends any abilities from other for which the given condition returns true to this,...
Definition: unit.hpp:121
active_ability & front()
Definition: unit.hpp:94
iterator erase(const iterator &first, const iterator &last)
Definition: unit.hpp:101
std::vector< active_ability >::const_iterator const_iterator
Definition: unit.hpp:85
std::pair< int, map_location > highest(const std::string &key, int def=0) const
Definition: unit.hpp:71
std::vector< active_ability > cfgs_
Definition: unit.hpp:128
iterator end()
Definition: unit.hpp:89
iterator erase(const iterator &erase_it)
Definition: unit.hpp:100
const map_location & loc() const
Definition: unit.hpp:106
const_iterator begin() const
Definition: unit.hpp:88
std::pair< int, map_location > get_extremum(const std::string &key, int def, const TComp &comp) const
Definition: abilities.cpp:744
void emplace_back(T &&... args)
Definition: unit.hpp:104
iterator begin()
Definition: unit.hpp:87
active_ability & back()
Definition: unit.hpp:96
const active_ability & front() const
Definition: unit.hpp:95
active_ability_list(const map_location &loc=map_location())
Definition: unit.hpp:68
map_location loc_
Definition: unit.hpp:129
void append(const active_ability_list &other)
Appends the abilities from other to this, ignores other.loc()
Definition: unit.hpp:109
const_iterator end() const
Definition: unit.hpp:90
std::pair< int, map_location > lowest(const std::string &key, int def=0) const
Definition: unit.hpp:75
bool empty() const
Definition: unit.hpp:93
const active_ability & back() const
Definition: unit.hpp:97
std::size_t size()
Definition: unit.hpp:98
const std::string & type() const
Definition: attack_type.hpp:90
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:157
The basic "size" of the unit - flying, small land, large land, etc.
Definition: movetype.hpp:44
int jamming_cost(const t_translation::terrain_code &terrain, bool slowed=false) const
Returns the cost to "jam" through the indicated terrain.
Definition: movetype.hpp:284
int vision_cost(const t_translation::terrain_code &terrain, bool slowed=false) const
Returns the cost to see through the indicated terrain.
Definition: movetype.hpp:281
int movement_cost(const t_translation::terrain_code &terrain, bool slowed=false) const
Returns the cost to move through the indicated terrain.
Definition: movetype.hpp:278
utils::string_map_res damage_table() const
Returns a map from damage types to resistances.
Definition: movetype.hpp:295
bool is_flying() const
Returns whether or not *this is flagged as a flying movement type.
Definition: movetype.hpp:273
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
Helper similar to std::unique_lock for detecting when calculations such as abilities have entered inf...
Definition: unit.hpp:1939
Visitor helper class to parse the upkeep value from a config.
Definition: unit.hpp:1257
Visitor helper class to fetch the appropriate upkeep value.
Definition: unit.hpp:1207
static config vector_to_cfg(const ability_vector &abilities)
Definition: attack_type.cpp:86
static ability_vector filter_tag(const ability_vector &vec, const std::string &tag)
Definition: attack_type.cpp:66
@ NUM_GENDERS
Definition: race.hpp:28
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:136
unit_ptr clone() const
Definition: unit.hpp:224
unit & operator=(const unit &)=delete
UNIT_ATTRIBUTE
Definition: unit.hpp:164
static void clear_status_caches()
Clear this unit status cache for all units.
Definition: unit.cpp:780
void set_attr_changed(UNIT_ATTRIBUTE attr)
Definition: unit.hpp:188
virtual ~unit()
Definition: unit.cpp:814
bool get_attr_changed(UNIT_ATTRIBUTE attr) const
Definition: unit.hpp:195
void clear_changed_attributes()
Definition: unit.cpp:2860
void init(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Definition: unit.cpp:442
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
Definition: unit.hpp:204
static const std::string & leader_crown()
The path to the leader crown overlay.
Definition: unit.cpp:1178
bool get_attacks_changed() const
Definition: unit.cpp:1544
unit()=delete
static unit_ptr create(const unit_type &t, int side, bool real_unit, unit_race::GENDER gender=unit_race::NUM_GENDERS, const std::string &variation="")
Initializes a unit from a unit type.
Definition: unit.hpp:216
A variable-expanding proxy for the config class.
Definition: variable.hpp:45
const config * cfg
int hit_points_
Definition: unit.hpp:2060
const ability_vector & abilities() const
Definition: unit.hpp:1861
int movement_
Definition: unit.hpp:2083
void generate_name()
Generates a random race-appropriate name if one has not already been provided.
Definition: unit.cpp:832
std::vector< t_string > trait_names_
Definition: unit.hpp:2127
int unit_value_
Definition: unit.hpp:2131
bool get_self_ability_bool_weapon(const unit_ability_t &ab, const map_location &loc, const const_attack_ptr &weapon=nullptr, const const_attack_ptr &opp_weapon=nullptr) const
Checks whether this unit currently possesses a given ability of leadership type.
Definition: abilities.cpp:1718
bool get_adj_ability_bool_weapon(const unit_ability_t &ab, std::size_t dist, int dir, const map_location &loc, const unit &from, const map_location &from_loc, const const_attack_ptr &weapon, const const_attack_ptr &opp_weapon) const
Checks whether this unit is affected by a given ability of leadership type.
Definition: abilities.cpp:1723
int attacks_left_
Definition: unit.hpp:2094
bool generate_name_
Definition: unit.hpp:2168
void clear_visibility_cache() const
Clears the cache.
Definition: unit.hpp:2194
bool ability_active_impl(const unit_ability_t &ab, const map_location &loc) const
Check if an ability is active.
Definition: abilities.cpp:535
bool ability_affects_self(const unit_ability_t &ab, const map_location &loc) const
Check if an ability affects the owning unit.
Definition: abilities.cpp:586
bool ability_active(const unit_ability_t &ab, const map_location &loc) const
Check if an ability is active.
Definition: abilities.cpp:450
ability_vector abilities(const std::string &tag) const
Definition: unit.hpp:1865
movetype movement_type_
Definition: unit.hpp:2088
config variables_
Definition: unit.hpp:2104
bool unrenamable_
Definition: unit.hpp:2075
active_ability_list get_abilities(const std::string &tag_name, const map_location &loc) const
Gets the unit's active abilities of a particular type if it were on a specified location.
Definition: abilities.cpp:242
int experience_
Definition: unit.hpp:2062
int vision_
Definition: unit.hpp:2085
void remove_ability_by_attribute(const config &filter)
Removes a unit's abilities with a specific ID or other attribute.
Definition: unit.cpp:1531
std::string undead_variation_
Definition: unit.hpp:2057
t_string type_name_
The displayed name of this unit type.
Definition: unit.hpp:2048
map_location interrupted_move_
Definition: unit.hpp:2132
ability_vector abilities_
Definition: unit.hpp:2156
unit_movement_resetter(const unit_movement_resetter &)=delete
bool random_traits_
Definition: unit.hpp:2167
void write(config &cfg, bool write_all=true) const
Serializes the current unit metadata values.
Definition: unit.cpp:1555
std::bitset< UA_COUNT > changed_attributes_
Definition: unit.hpp:2177
std::vector< const config * > open_queries_
While processing a recursive match, all the filters that are currently being checked,...
Definition: unit.hpp:2119
bool ability_matches_filter(const unit_ability_t &ab, const config &filter) const
Verify what abilities attributes match with filter.
Definition: abilities.cpp:2116
std::string small_profile_
Definition: unit.hpp:2173
void write_upkeep(config::attribute_value &upkeep) const
Definition: unit.cpp:2855
bool get_ability_bool(const std::string &tag_name, const map_location &loc) const
Checks whether this unit currently possesses or is affected by a given ability.
Definition: abilities.cpp:202
bool ability_affects_adjacent(const unit_ability_t &ab, std::size_t dist, int dir, const map_location &loc, const unit &from) const
Check if an ability affects distant units.
Definition: abilities.cpp:550
void set_favorite(bool favorite)
Definition: unit.hpp:2142
std::string id_
Definition: unit.hpp:2053
std::vector< t_string > special_notes_
Definition: unit.hpp:2161
void set_has_ability_distant()
Definition: unit.cpp:418
bool canrecruit_
Definition: unit.hpp:2068
std::string image_mods_
Definition: unit.hpp:2073
std::map< std::string, std::size_t > max_ability_radius_type_
Used for easing checking if unit own a ability of specified type with [affect_adjacent] sub tag.
Definition: unit.hpp:2203
std::string flag_rgb_
Definition: unit.hpp:2072
static std::map< std::string, state_t > known_boolean_state_names_
Definition: unit.hpp:2102
@ UA_IS_HEALTHY
Definition: unit.hpp:169
@ UA_SMALL_PROFILE
Definition: unit.hpp:182
@ UA_MAX_MP
Definition: unit.hpp:166
@ UA_ATTACKS
Definition: unit.hpp:179
@ UA_ZOC
Definition: unit.hpp:173
@ UA_MOVEMENT_TYPE
Definition: unit.hpp:172
@ UA_PROFILE
Definition: unit.hpp:181
@ UA_LEVEL
Definition: unit.hpp:171
@ UA_MAX_XP
Definition: unit.hpp:168
@ UA_IS_FEARLESS
Definition: unit.hpp:170
@ UA_ADVANCE_TO
Definition: unit.hpp:174
@ UA_MAX_AP
Definition: unit.hpp:167
@ UA_COUNT
Definition: unit.hpp:185
@ UA_ADVANCEMENTS
Definition: unit.hpp:175
@ UA_MAX_HP
Definition: unit.hpp:165
@ UA_ABILITIES
Definition: unit.hpp:183
@ UA_UNDEAD_VARIATION
Definition: unit.hpp:177
@ UA_UPKEEP
Definition: unit.hpp:184
@ UA_NOTES
Definition: unit.hpp:180
@ UA_ALIGNMENT
Definition: unit.hpp:176
void set_appearance_changed(bool value)
Definition: unit.hpp:2034
std::vector< std::tuple< std::string, t_string, t_string, t_string > > ability_tooltips() const
Gets the names and descriptions of this unit's abilities.
Definition: abilities.cpp:349
config events_
Definition: unit.hpp:2105
bool hidden_
Definition: unit.hpp:2153
bool is_healthy_
Definition: unit.hpp:2134
bool is_fearless_
Definition: unit.hpp:2134
active_ability_list get_abilities_weapons(const std::string &tag_name, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
Definition: abilities.cpp:284
utils::optional< std::string > ellipse_
Definition: unit.hpp:2165
const unit_type * type_
Never nullptr.
Definition: unit.hpp:2045
std::bitset< num_bool_states > known_boolean_states_
Definition: unit.hpp:2101
utils::optional< std::string > halo_
Definition: unit.hpp:2164
bool is_favorite_
Definition: unit.hpp:2137
map_location::direction facing_
Definition: unit.hpp:2124
int side_
Definition: unit.hpp:2079
std::shared_ptr< const unit > parent
Definition: unit.hpp:1965
const unit_race * race_
Never nullptr, but may point to the null race.
Definition: unit.hpp:2051
bool appearance_changed_
Definition: unit.hpp:2176
int operator()(const upkeep_loyal &) const
Loyal units cost no upkeep.
Definition: unit.hpp:1218
bool appearance_changed() const
Definition: unit.hpp:2035
unit_alignments::type alignment_
Definition: unit.hpp:2070
bool get_ability_bool(const std::string &tag_name) const
Checks whether this unit currently possesses or is affected by a given ability.
Definition: unit.hpp:1789
bool dismissable_
Definition: unit.hpp:2076
bool invisible(const map_location &loc, bool see_all=true) const
Definition: unit.cpp:2615
bool is_visible_to_team(const team &team, bool const see_all=true) const
Definition: unit.cpp:2658
active_ability_list get_abilities(const std::string &tag_name) const
Gets the unit's active abilities of a particular type.
Definition: unit.hpp:1844
std::enable_if_t<!std::is_same_v< int, T >, std::string > operator()(T &) const
Definition: unit.hpp:1240
n_unit::unit_id underlying_id_
Definition: unit.hpp:2055
std::string variation_
Definition: unit.hpp:2058
unit & mark_clone(bool is_temporary)
Mark this unit as clone so it can be inserted to unit_map.
Definition: unit.cpp:2716
bool has_ability_type(const std::string &ability) const
Check if the unit has an ability of a specific type.
Definition: abilities.cpp:613
std::enable_if_t< std::is_convertible_v< B, bool > &&!std::is_arithmetic_v< B >, upkeep_t > operator()(B b) const
Definition: unit.hpp:1270
static const std::size_t num_bool_states
Definition: unit.hpp:2099
config filter_recall_
Definition: unit.hpp:2106
int max_experience_
Definition: unit.hpp:2063
unit_race::GENDER gender_
Definition: unit.hpp:2081
int operator()(int v) const
Definition: unit.hpp:1223
t_string description_
Definition: unit.hpp:2160
std::set< std::string > recruit_list_
Definition: unit.hpp:2069
int level_
Definition: unit.hpp:2065
std::string role_
Definition: unit.hpp:2112
std::map< map_location, bool > invisibility_cache_
Hold the visibility status cache for a unit, when not uncovered.
Definition: unit.hpp:2186
recursion_guard()
Construct an empty instance, only useful for extending the lifetime of a recursion_guard returned fro...
upkeep_t operator()(const std::string &s) const
Definition: unit.hpp:1280
bool end_turn_
Definition: unit.hpp:2091
std::vector< std::string > advances_to_
Definition: unit.hpp:2042
std::unique_ptr< unit_animation_component > anim_comp_
Definition: unit.hpp:2151
std::enable_if_t< std::is_arithmetic_v< N >, upkeep_t > operator()(N n) const
Definition: unit.hpp:1261
recursion_guard & operator=(recursion_guard &&) noexcept
Definition: abilities.cpp:434
int recall_cost_
Definition: unit.hpp:2067
static std::string type()
Definition: unit.hpp:1197
attack_list attacks_
Definition: unit.hpp:2113
std::vector< std::string > get_ability_list() const
Get a list of all abilities by ID.
Definition: abilities.cpp:293
void remove_ability_by_id(const std::string &ability)
Removes a unit's abilities with a specific ID.
Definition: unit.cpp:1518
bool ability_affects_weapon(const unit_ability_t &ab, const const_attack_ptr &weapon, bool is_opp) const
filters the weapons that condition the use of abilities for combat ([resistance],[leadership] or abil...
Definition: abilities.cpp:594
utils::optional< std::string > usage_
Definition: unit.hpp:2163
map_location loc_
Definition: unit.hpp:2040
static std::string type()
Definition: unit.hpp:1192
std::vector< std::string > overlays_
Definition: unit.hpp:2110
config modifications_
Definition: unit.hpp:2155
recursion_guard update_variables_recursion(const config &ability) const
Definition: abilities.cpp:409
bool has_ability_by_id(const std::string &ability) const
Check if the unit has an ability of a specific ID.
Definition: unit.cpp:1507
bool hold_position_
Definition: unit.hpp:2090
config abilities_cfg() const
Definition: unit.hpp:1856
bool favorite() const
Definition: unit.hpp:2140
upkeep_value_visitor(const unit &unit)
Definition: unit.hpp:1209
std::string operator()(int v) const
Definition: unit.hpp:1246
bool get_self_ability_bool(const unit_ability_t &ab, const map_location &loc) const
Checks whether this unit currently possesses a given ability, and that that ability is active.
Definition: abilities.cpp:1698
void parse_upkeep(const config::attribute_value &upkeep)
Definition: unit.cpp:2841
recursion_guard(const recursion_guard &other)=delete
std::vector< config > advancements_
Definition: unit.hpp:2158
bool get_adj_ability_bool(const unit_ability_t &ab, std::size_t dist, int dir, const map_location &loc, const unit &from, const map_location &from_loc) const
Checks whether this unit is affected by a given ability, and that that ability is active.
Definition: abilities.cpp:1708
utils::string_map modification_descriptions_
Definition: unit.hpp:2146
upkeep_t operator()(utils::monostate) const
Definition: unit.hpp:1275
unit_checksum_version
Optional parameter for get_checksum to use the algorithm of an older version of Wesnoth,...
Definition: unit.hpp:2241
std::vector< std::string > trait_nonhidden_ids_
Definition: unit.hpp:2129
upkeep_t upkeep_
Definition: unit.hpp:2170
int operator()(const upkeep_full &) const
Full upkeep equals the unit's level.
Definition: unit.hpp:1212
std::set< std::string > states_
Definition: unit.hpp:2097
std::size_t max_ability_radius_image_
used if ability own halo_image or overlay_image attributes in same time what [affect_adjacent].
Definition: unit.hpp:2212
std::string profile_
Definition: unit.hpp:2172
t_string dismiss_message_
Definition: unit.hpp:2077
int jamming_
Definition: unit.hpp:2086
map_location goto_
Definition: unit.hpp:2132
t_string name_
Definition: unit.hpp:2054
int max_attacks_
Definition: unit.hpp:2095
int max_hit_points_
Definition: unit.hpp:2061
int max_movement_
Definition: unit.hpp:2084
bool resting_
Definition: unit.hpp:2092
std::size_t max_ability_radius_
Used for easing checking if unit own a ability with [affect_adjacent] sub tag.
Definition: unit.hpp:2208
std::vector< t_string > trait_descriptions_
Definition: unit.hpp:2128
active_ability_list get_abilities_weapons(const std::string &tag_name, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
Definition: unit.hpp:1851
bool emit_zoc_
Definition: unit.hpp:2108
unit_movement_resetter & operator=(const unit_movement_resetter &)=delete
@ version_1_16_or_older
Included some of the flavortext from weapon specials.
void set_big_profile(const std::string &value)
Definition: unit.cpp:1960
int max_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:524
void heal(int amount)
Heal the unit.
Definition: unit.cpp:1392
bool user_end_turn() const
Check whether the user ended their turn.
Definition: unit.hpp:804
void set_role(const std::string &role)
Sets a unit's role.
Definition: unit.hpp:694
unit_alignments::type alignment() const
The alignment of this unit.
Definition: unit.hpp:494
void toggle_user_end_turn()
Toggle whether the user ended their turn.
Definition: unit.hpp:792
bool incapacitated() const
Check if the unit has been petrified.
Definition: unit.hpp:923
void set_state(const std::string &state, bool value)
Set whether the unit is affected by a status effect.
Definition: unit.cpp:1484
int level() const
The current level of this unit.
Definition: unit.hpp:578
std::string usage() const
Gets this unit's usage.
Definition: unit.hpp:705
const std::string & get_role() const
Gets this unit's role.
Definition: unit.hpp:688
const t_string & type_name() const
Gets the translatable name of this unit's type.
Definition: unit.hpp:372
const std::set< std::string > & recruits() const
The type IDs of the other units this unit may recruit, if possible.
Definition: unit.hpp:643
void new_turn()
Refresh unit for the beginning of a turn.
Definition: unit.cpp:1353
void set_max_experience(int value)
Definition: unit.hpp:553
void set_max_hitpoints(int value)
Definition: unit.hpp:529
void set_hitpoints(int hp)
Sets the current hitpoint amount.
Definition: unit.hpp:536
bool unrenamable() const
Whether this unit can be renamed.
Definition: unit.hpp:439
const config & recall_filter() const
Gets the filter constraints upon which units this unit may recall, if able.
Definition: unit.hpp:671
int recall_cost() const
How much gold it costs to recall this unit, or -1 if the side's default recall cost is used.
Definition: unit.hpp:659
std::string big_profile() const
An optional profile image displays when this unit is 'speaking' via [message].
Definition: unit.cpp:1156
static state_t get_known_boolean_state_id(const std::string &state)
Convert a string status effect ID to a built-in status effect ID.
Definition: unit.cpp:1453
void set_level(int level)
Sets the current level of this unit.
Definition: unit.hpp:584
void rename(const std::string &name)
Attempts to rename this unit's translatable display name, taking the 'unrenamable' flag into account.
Definition: unit.hpp:427
void set_hidden(bool state) const
Sets whether the unit is hidden on the map.
Definition: unit.cpp:2812
void set_recall_filter(const config &filter)
Sets the filter constraints upon which units this unit may recall, if able.
Definition: unit.hpp:677
const std::string & variation() const
The ID of the variation of this unit's type.
Definition: unit.hpp:591
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:518
int cost() const
How much gold is required to recruit this unit.
Definition: unit.hpp:652
bool hold_position() const
Whether the unit has been instructed to hold its position.
Definition: unit.hpp:763
static std::string get_known_boolean_state_name(state_t state)
Convert a built-in status effect ID to a string status effect ID.
Definition: unit.cpp:1463
bool slowed() const
Check if the unit has been slowed.
Definition: unit.hpp:932
bool get_state(const std::string &state) const
Check if the unit is affected by a status effect.
Definition: unit.cpp:1425
unsigned int experience_overflow() const
The number of experience points over max this unit has, or 0 if current XP < max XP.
Definition: unit.hpp:566
std::string small_profile() const
An optional profile image to display in Help.
Definition: unit.cpp:1165
void heal_fully()
Fully heal the unit, restoring it to max hitpoints.
Definition: unit.hpp:843
void set_undead_variation(const std::string &value)
The ID of the undead variation (ie, dwarf, swimmer) of this unit.
Definition: unit.hpp:597
void toggle_hold_position()
Toggle the unit's hold position status.
Definition: unit.hpp:771
const std::string & type_id() const
The id of this unit's type.
Definition: unit.cpp:1955
void set_alignment(unit_alignments::type alignment)
Sets the alignment of this unit.
Definition: unit.hpp:500
bool get_hidden() const
Gets whether this unit is currently hidden on the map.
Definition: unit.hpp:739
void set_name(const t_string &name)
Sets this unit's translatable display name.
Definition: unit.hpp:416
void set_can_recruit(bool canrecruit)
Sets whether this unit can recruit other units.
Definition: unit.hpp:637
const std::set< std::string > get_states() const
Get the status effects currently affecting the unit.
Definition: unit.cpp:1408
void set_side(unsigned int new_side)
Sets the side this unit belongs to.
Definition: unit.hpp:352
void new_scenario()
Refresh unit for the beginning of a new scenario.
Definition: unit.cpp:1377
void end_turn()
Refresh unit for the end of a turn.
Definition: unit.cpp:1363
bool take_hit(int damage)
Damage the unit.
Definition: unit.hpp:828
const config & variables() const
Const overload of variables.
Definition: unit.hpp:728
const std::string & undead_variation() const
Definition: unit.hpp:602
const unit_race * race() const
Gets this unit's race.
Definition: unit.hpp:512
const unit_type & type() const
This unit's type, accounting for gender and variation.
Definition: unit.hpp:358
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:542
t_string block_dismiss_message() const
A message of why this unit cannot be dismissed.
Definition: unit.hpp:463
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
Definition: unit.hpp:631
void set_experience(int xp)
Sets the current experience point amount.
Definition: unit.hpp:572
void set_user_end_turn(bool value=true)
Set whether the user ended their turn.
Definition: unit.hpp:783
const std::string & id() const
Gets this unit's id.
Definition: unit.hpp:383
void set_underlying_id(n_unit::id_manager &id_manager)
Sets the internal ID.
Definition: unit.cpp:2699
int side() const
The side this unit belongs to.
Definition: unit.hpp:346
bool dismissable() const
Whether this unit can be dismissed.
Definition: unit.hpp:457
bool poisoned() const
Check if the unit has been poisoned.
Definition: unit.hpp:914
unsigned int experience_to_advance() const
The number of experience points this unit needs to level up, or 0 if current XP > max XP.
Definition: unit.hpp:560
state_t
Built-in status effects known to the engine.
Definition: unit.hpp:871
double xp_bar_scaling() const
The factor by which the XP bar should be scaled.
Definition: unit.cpp:2829
void set_unit_description(const t_string &new_desc)
A detailed description of this unit.
Definition: unit.hpp:475
void set_unrenamable(bool unrenamable)
Sets the 'unrenamable' flag.
Definition: unit.hpp:447
void set_recruits(const std::vector< std::string > &recruits)
Sets the recruit list.
Definition: unit.cpp:1265
std::vector< t_string > unit_special_notes() const
The unit's special notes.
Definition: unit.cpp:2868
void set_id(const std::string &id)
Sets this unit's string ID.
Definition: unit.hpp:389
config & variables()
Gets any user-defined variables this unit 'owns'.
Definition: unit.hpp:722
void set_recall_cost(int recall_cost)
Sets the cost of recalling this unit.
Definition: unit.hpp:665
std::size_t underlying_id() const
This unit's unique internal ID.
Definition: unit.hpp:395
double hp_bar_scaling() const
The factor by which the HP bar should be scaled.
Definition: unit.cpp:2825
void set_usage(const std::string &usage)
Sets this unit's usage.
Definition: unit.hpp:711
int max_experience() const
The max number of experience points this unit can have.
Definition: unit.hpp:548
void set_small_profile(const std::string &value)
Definition: unit.hpp:615
unit_race::GENDER gender() const
The gender of this unit.
Definition: unit.hpp:484
const t_string & name() const
Gets this unit's translatable display name.
Definition: unit.hpp:406
t_string unit_description() const
A detailed description of this unit.
Definition: unit.hpp:469
@ STATE_SLOWED
Definition: unit.hpp:872
@ STATE_UNKNOWN
To set the size of known_boolean_states_.
Definition: unit.hpp:881
@ STATE_NOT_MOVED
The unit is uncovered - it was hiding but has been spotted.
Definition: unit.hpp:876
@ STATE_GUARDIAN
The unit cannot be healed.
Definition: unit.hpp:878
@ STATE_INVULNERABLE
The unit is a guardian - it won't move unless a target is sighted.
Definition: unit.hpp:879
@ STATE_PETRIFIED
The unit is poisoned - it loses health each turn.
Definition: unit.hpp:874
@ NUMBER_OF_STATES
The unit is invulnerable - it cannot be hit by any attack.
Definition: unit.hpp:880
@ STATE_UNHEALABLE
The unit has not moved.
Definition: unit.hpp:877
@ STATE_POISONED
The unit is slowed - it moves slower and does less damage.
Definition: unit.hpp:873
@ STATE_UNCOVERED
The unit is petrified - it cannot move or be attacked.
Definition: unit.hpp:875
std::vector< std::string > advances_to_t
Definition: unit.hpp:241
std::vector< config > get_modification_advances() const
Gets any non-typed advanced options set by modifications.
Definition: unit.cpp:1884
std::vector< std::pair< std::string, std::string > > amla_icons() const
Gets the image and description data for modification advancements.
Definition: unit.cpp:1867
const advances_to_t & advances_to() const
Gets the possible types this unit can advance to on level-up.
Definition: unit.hpp:247
bool can_advance() const
Checks whether this unit has any options to advance to.
Definition: unit.hpp:275
bool advances() const
Checks whether this unit is eligible for level-up.
Definition: unit.hpp:286
void set_advancements(std::vector< config > advancements)
Sets the raw modification advancement option data.
Definition: unit.cpp:1949
void set_advances_to(const std::vector< std::string > &advances_to)
Sets this unit's advancement options.
Definition: unit.cpp:1287
const std::vector< config > & modification_advancements() const
The raw, unparsed data for modification advancements.
Definition: unit.hpp:326
std::map< std::string, std::string > advancement_icons() const
Gets and image path and and associated description for each advancement option.
Definition: unit.cpp:1827
const std::vector< std::string > advances_to_translated() const
Gets the names of the possible types this unit can advance to on level-up.
Definition: unit.cpp:1272
void advance_to(const unit_type &t, bool use_traits=false)
Advances this unit to another type.
Definition: unit.cpp:1009
void remove_attacks_ai()
Set the unit to have no attacks left for this turn.
Definition: unit.cpp:2794
attack_ptr add_attack(attack_itors::iterator position, Args &&... args)
Adds a new attack to the unit.
Definition: unit.hpp:962
bool remove_attack(const attack_ptr &atk)
Remove an attack from the unit.
Definition: unit.cpp:2783
int resistance_against(const attack_type &atk, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr) const
The unit's resistance against a given attack.
Definition: unit.hpp:1076
void set_max_attacks(int value)
Definition: unit.hpp:1001
int attacks_left(bool base_value) const
Gets the remaining number of attacks this unit can perform this turn.
Definition: unit.hpp:1024
int resistance_value(active_ability_list resistance_list, const std::string &damage_name) const
For the provided list of resistance abilities, determine the damage resistance based on which are act...
Definition: unit.cpp:1790
int damage_from(const attack_type &attack, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr) const
Calculates the damage this unit would take from a certain attack.
Definition: unit.hpp:990
int defense_modifier(const t_translation::terrain_code &terrain) const
Definition: unit.hpp:1045
bool resistance_filter_matches(const config &cfg, const std::string &damage_name, int res) const
Definition: unit.cpp:1768
attack_itors attacks()
Gets an iterator over this unit's attacks.
Definition: unit.hpp:945
int defense_modifier(const t_translation::terrain_code &terrain, const map_location &loc) const
The unit's defense on a given terrain.
Definition: unit.cpp:1756
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr, const const_attack_ptr &opp_weapon=nullptr) const
The unit's resistance against a given damage type.
Definition: unit.cpp:1815
utils::string_map_res get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:1082
int max_attacks() const
The maximum number of attacks this unit may perform per turn, usually 1.
Definition: unit.hpp:996
const_attack_itors attacks() const
Const overload of attacks.
Definition: unit.hpp:951
int attacks_left() const
Gets the remaining number of attacks this unit can perform this turn.
Definition: unit.hpp:1012
void set_attacks(int left)
Sets the number of attacks this unit has left this turn.
Definition: unit.hpp:1033
color_t xp_color() const
Color for this unit's XP.
Definition: unit.cpp:1253
unit_animation_component & anim_comp() const
Definition: unit.hpp:1663
const std::string & effect_image_mods() const
Gets any IPF image mods applied by effects.
Definition: unit.hpp:1713
std::vector< std::string > overlays_abilities() const
Get the [overlay] ability overlay images.
Definition: unit.hpp:1732
color_t hp_color() const
Color for this unit's current hitpoints.
Definition: unit.cpp:1209
std::vector< std::string > halo_abilities() const
Get the [halo] abilities halo image(s).
Definition: unit.hpp:1683
std::string TC_image_mods() const
Constructs a recolor (RC) IPF string for this unit's team color.
Definition: unit.cpp:2768
static color_t hp_color_max()
Definition: unit.cpp:1219
const std::string & flag_rgb() const
Get the source color palette to use when recoloring the unit's image.
Definition: unit.cpp:1183
std::string image_ellipse() const
Get the unit's ellipse image.
Definition: unit.hpp:1692
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
Definition: unit.cpp:2773
std::string default_anim_image() const
The default image to use for animation frames with no defined image.
Definition: unit.cpp:2597
std::string image_halo() const
Get the unit's halo image.
Definition: unit.hpp:1675
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
Definition: unit.hpp:1726
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2592
void set_image_ellipse(const std::string &ellipse)
Set the unit's ellipse image.
Definition: unit.hpp:1698
std::vector< std::string > halo_or_icon_abilities(const std::string &image_type) const
Definition: abilities.cpp:627
void set_image_halo(const std::string &halo)
Set the unit's halo image.
Definition: unit.cpp:2834
std::size_t advancements_count() const
Definition: unit.hpp:1613
std::size_t traits_count() const
Definition: unit.hpp:1603
void add_modification(const std::string &type, const config &modification, bool no_add=false)
Add a new modification to the unit.
Definition: unit.cpp:2473
static const std::set< std::string > builtin_effects
Definition: unit.hpp:1636
std::string describe_builtin_effect(const std::string &type, const config &effect)
Construct a string describing a built-in effect.
Definition: unit.cpp:1993
const config & get_modifications() const
Set the raw modifications.
Definition: unit.hpp:1581
config & get_modifications()
Get the raw modifications.
Definition: unit.hpp:1575
void apply_modifications()
Re-apply all saved modifications.
Definition: unit.cpp:2602
void expire_modifications(const std::string &duration)
Clears those modifications whose duration has expired.
Definition: unit.cpp:1320
std::size_t objects_count() const
Definition: unit.hpp:1608
void apply_builtin_effect(const std::string &type, const config &effect)
Apply a builtin effect to the unit.
Definition: unit.cpp:2058
std::size_t modification_count(const std::string &type, const std::string &id) const
Count modifications of a particular type.
Definition: unit.cpp:1967
bool emits_zoc() const
Tests whether the unit has a zone-of-control, considering incapacitated.
Definition: unit.hpp:1434
bool get_emit_zoc() const
Gets the raw zone-of-control flag, disregarding incapacitated.
Definition: unit.hpp:1440
int jamming() const
Gets the unit's jamming points.
Definition: unit.hpp:1502
bool has_goto() const
Gets whether this unit has a multi-turn destination set.
Definition: unit.hpp:1478
const map_location & get_location() const
The current map location this unit is at.
Definition: unit.hpp:1453
bool has_moved() const
Checks if this unit has moved.
Definition: unit.hpp:1408
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit's movement cost on a particular terrain.
Definition: unit.hpp:1536
const movetype & movement_type() const
Get the unit's movement type.
Definition: unit.hpp:1526
void set_movement(int moves, bool unit_action=false)
Set this unit's remaining movement to moves.
Definition: unit.cpp:1294
const map_location & get_interrupted_move() const
Get the target location of the unit's interrupted move.
Definition: unit.hpp:1514
int vision_cost(const t_translation::terrain_code &terrain) const
Get the unit's vision cost on a particular terrain.
Definition: unit.hpp:1546
void set_resting(bool rest)
Sets this unit's resting status.
Definition: unit.hpp:1428
void set_facing(map_location::direction dir) const
The this unit's facing.
Definition: unit.cpp:1721
void set_total_movement(int value)
Definition: unit.hpp:1367
void set_emit_zoc(bool val)
Sets the raw zone-of-control flag.
Definition: unit.hpp:1446
void set_goto(const map_location &new_goto)
Sets this unit's long term destination.
Definition: unit.hpp:1490
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1378
int movement_left(bool base_value) const
Gets how far a unit can move.
Definition: unit.hpp:1390
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1362
int jamming_cost(const t_translation::terrain_code &terrain) const
Get the unit's jamming cost on a particular terrain.
Definition: unit.hpp:1556
void set_location(const map_location &loc)
Sets this unit's map location.
Definition: unit.hpp:1463
void remove_movement_ai()
Sets the unit to have no moves left for this turn.
Definition: unit.cpp:2803
bool move_interrupted() const
Check whether the unit's move has been interrupted.
Definition: unit.hpp:1508
int vision() const
Gets the unit's vision points.
Definition: unit.hpp:1496
const map_location & get_goto() const
The map location to which this unit is moving over multiple turns, if any.
Definition: unit.hpp:1484
map_location::direction facing() const
The current direction this unit is facing within its hex.
Definition: unit.hpp:1469
bool resting() const
Checks whether this unit is 'resting'.
Definition: unit.hpp:1422
void set_interrupted_move(const map_location &interrupted_move)
Set the target location of the unit's interrupted move.
Definition: unit.hpp:1520
bool is_flying() const
Check if the unit is a flying unit.
Definition: unit.hpp:1562
std::vector< std::string > get_advancements_list() const
Definition: unit.hpp:1163
std::vector< std::string > get_objects_list() const
Definition: unit.hpp:1158
std::vector< std::string > get_modifications_list(const std::string &mod_type) const
Gets a list of the modification this unit currently has.
Definition: unit.cpp:974
int upkeep() const
Gets the amount of gold this unit costs a side per turn.
Definition: unit.cpp:1730
std::vector< std::string > trait_nonhidden_ids() const
Gets the ids of the traits corresponding to those returned by trait_names() and trait_descriptions().
Definition: unit.hpp:1137
std::size_t max_ability_radius_type(const std::string &tag_name) const
If this unit has abilities of tag_name type with [affect_adjacent] subtags, returns the radius of the...
Definition: unit.hpp:1328
void add_trait_description(const config &trait, const t_string &description)
Register a trait's name and its description for the UI's use.
Definition: unit.cpp:2576
bool is_healthy() const
Gets whether this unit is healthy - ie, always rest heals.
Definition: unit.hpp:1318
bool is_fearless() const
Gets whether this unit is fearless - ie, unaffected by time of day.
Definition: unit.hpp:1312
std::size_t max_ability_radius_image() const
If this unit has abilities with [affect_adjacent] subtags and halo_image or overlay_image attributes,...
Definition: unit.hpp:1349
utils::variant< upkeep_full, upkeep_loyal, int > upkeep_t
Definition: unit.hpp:1200
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:1126
std::vector< std::string > get_traits_list() const
Gets a list of the traits this unit currently has, including hidden traits.
Definition: unit.hpp:1153
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:1116
void generate_traits(bool must_have_only=false)
Applies mandatory traits (e.g.
Definition: unit.cpp:841
std::size_t max_ability_radius() const
If this unit has abilities with [affect_adjacent] subtags, returns the radius of the one with the fur...
Definition: unit.hpp:1339
upkeep_t upkeep_raw() const
Gets the raw variant controlling the upkeep value.
Definition: unit.hpp:1295
void set_loyal(bool loyal)
Definition: unit.cpp:1745
bool loyal() const
Gets whether this unit is loyal - ie, it costs no upkeep.
Definition: unit.cpp:1740
void set_upkeep(upkeep_t v)
Sets the upkeep value to a specific value value.
Definition: unit.hpp:1301
Definition: halo.cpp:41
std::string tag(std::string_view tag, Args &&... data)
Wraps the given data in the specified tag.
Definition: markup.hpp:45
constexpr auto filter
Definition: ranges.hpp:38
std::map< std::string, t_string, res_compare > string_map_res
std::map< std::string, t_string > string_map
std::string::const_iterator iterator
Definition: tokenizer.hpp:25
std::shared_ptr< const unit_ability_t > const_ability_ptr
Definition: ptr.hpp:39
std::shared_ptr< const attack_type > const_attack_ptr
Definition: ptr.hpp:34
std::shared_ptr< unit_ability_t > ability_ptr
Definition: ptr.hpp:38
std::shared_ptr< attack_type > attack_ptr
Definition: ptr.hpp:33
std::shared_ptr< unit > unit_ptr
Definition: ptr.hpp:26
Data typedef for active_ability_list.
Definition: unit.hpp:37
active_ability(const ability_ptr &p_ability, map_location student_loc, map_location teacher_loc)
Definition: unit.hpp:38
const config & ability_cfg() const
Definition: unit.hpp:58
map_location teacher_loc
The location of the teacher, that is the unit who owns the ability tags (different from student becau...
Definition: unit.hpp:56
const unit_ability_t & ability() const
Definition: unit.hpp:59
const_ability_ptr p_ability_
The contents of the ability tag, never nullptr.
Definition: unit.hpp:62
map_location student_loc
Used by the formula in the ability.
Definition: unit.hpp:51
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:61
Encapsulates the map of the game.
Definition: location.hpp:46
bool valid() const
Definition: location.hpp:111
direction
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:48
std::size_t value
Definition: id.hpp:25
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:49
Visitor helper struct to fetch the upkeep type flag if applicable, or the the value otherwise.
Definition: unit.hpp:1237
Object which temporarily resets a unit's movement.
Definition: unit.hpp:2223
static map_location::direction n
static map_location::direction s
std::string get_checksum(const unit &u, backwards_compatibility::unit_checksum_version version=backwards_compatibility::unit_checksum_version::current)
Gets a checksum for a unit.
Definition: unit.cpp:2874
MacOS doesn't support std::visit when targing MacOS < 10.14 (currently we target 10....
#define b