The Battle for Wesnoth  1.15.1+dev
unit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "units/id.hpp"
18 #include "units/ptr.hpp"
19 #include "units/types.hpp"
20 
21 #include <bitset>
22 #include <boost/dynamic_bitset_fwd.hpp>
23 #include <boost/ptr_container/ptr_vector.hpp>
24 #include <boost/variant.hpp>
25 
26 class display;
27 class team;
30 class vconfig;
31 struct color_t;
32 
33 namespace unit_detail
34 {
35  template<typename T>
36  const T& get_or_default(const std::unique_ptr<T>& v)
37  {
38  if(v) {
39  return *v;
40  } else {
41  static const T def;
42  return def;
43  }
44  }
45 }
46 
47 // Data typedef for unit_ability_list.
48 using unit_ability = std::pair<const config*, map_location>;
49 
51 {
52 public:
53  unit_ability_list(const map_location& loc = map_location()) : cfgs_() , loc_(loc) {}
54 
55  // Implemented in unit_abilities.cpp
56  std::pair<int, map_location> highest(const std::string& key, int def=0) const
57  {
58  return get_extremum(key, def, std::less<int>());
59  }
60  std::pair<int, map_location> lowest(const std::string& key, int def=0) const
61  {
62  return get_extremum(key, def, std::greater<int>());
63  }
64 
65  template<typename TComp>
66  std::pair<int, map_location> get_extremum(const std::string& key, int def, const TComp& comp) const;
67 
68  // The following make this class usable with standard library algorithms and such
70  typedef std::vector<unit_ability>::const_iterator const_iterator;
71 
72  iterator begin() { return cfgs_.begin(); }
73  const_iterator begin() const { return cfgs_.begin(); }
74  iterator end() { return cfgs_.end(); }
75  const_iterator end() const { return cfgs_.end(); }
76 
77  // Vector access
78  bool empty() const { return cfgs_.empty(); }
79  unit_ability& front() { return cfgs_.front(); }
80  const unit_ability& front() const { return cfgs_.front(); }
81  unit_ability& back() { return cfgs_.back(); }
82  const unit_ability& back() const { return cfgs_.back(); }
83 
84  iterator erase(const iterator& erase_it) { return cfgs_.erase(erase_it); }
85 
86  template<typename... T>
87  void emplace_back(T&&... args) { cfgs_.emplace_back(args...); }
88 
89  const map_location& loc() const { return loc_; }
90 private:
91  // Data
92  std::vector<unit_ability> cfgs_;
94 };
95 
96 /**
97  * This class represents a *single* unit of a specific type.
98  */
99 class unit
100 {
101 public:
102  /**
103  * Clear this unit status cache for all units. Currently only the hidden
104  * status of units is cached this way.
105  */
106  static void clear_status_caches();
107 
108  /** The path to the leader crown overlay. */
109  static const std::string& leader_crown();
110 private:
111  void init(const config& cfg, bool use_traits = false, const vconfig* vcfg = nullptr);
112 
113  void init(const unit_type& t, int side, bool real_unit, unit_race::GENDER gender = unit_race::NUM_GENDERS);
114 
115  // Copy constructor
116  unit(const unit& u);
117 
118  unit();
120  {
134  //note that UA_ATTACKS only tracks added/deleted attacks, not modified attacks.
140  UA_COUNT
141  };
143  {
144  changed_attributes_[int(attr)] = true;
145  }
146  bool get_attacks_changed() const;
148  {
149  return changed_attributes_[int(attr)];
150  }
151  void clear_changed_attributes();
152 public:
153  /** Initializes a unit from a config */
154  static unit_ptr create(const config& cfg, bool use_traits = false, const vconfig* vcfg = nullptr)
155  {
156  unit_ptr res(new unit());
157  res->init(cfg, use_traits, vcfg);
158  return res;
159  }
160 
161  /**
162  * Initializes a unit from a unit type.
163  *
164  * Only real_unit-s should have random traits, name and gender (to prevent OOS caused by RNG calls)
165  */
166  static unit_ptr create(const unit_type& t, int side, bool real_unit, unit_race::GENDER gender = unit_race::NUM_GENDERS)
167  {
168  unit_ptr res(new unit());
169  res->init(t, side, real_unit, gender);
170  return res;
171  }
172 
173  unit_ptr clone() const
174  {
175  return unit_ptr(new unit(*this));
176  }
177 
179  {
180  return unit_ptr(this);
181  }
182 
183  virtual ~unit();
184 
185  void swap(unit&);
186 
187  unit& operator=(const unit&) = delete;
188 
189  /**
190  * @defgroup unit_advance Advancement functions
191  * @{
192  */
193 
194  /** Advances this unit to another type */
195  void advance_to(const unit_type& t, bool use_traits = false);
196 
197  using advances_to_t = std::vector<std::string>;
198  /**
199  * Gets the possible types this unit can advance to on level-up.
200  *
201  * @returns A list of type IDs this unit may advance to.
202  */
203  const advances_to_t& advances_to() const
204  {
205  return advances_to_;
206  }
207 
208  /**
209  * Gets the names of the possible types this unit can advance to on level-up.
210  *
211  * @returns A list of the names of the types this unit may advance to.
212  */
213  const std::vector<std::string> advances_to_translated() const;
214 
215  /**
216  * Sets this unit's advancement options.
217  *
218  * @param advances_to A list of new type IDs this unit may advance to.
219  */
220  void set_advances_to(const std::vector<std::string>& advances_to);
221 
222  /**
223  * Checks whether this unit has any options to advance to.
224  *
225  * This considers both whether it has types to advance to OR whether any modifications
226  * specify non-type advancement options.
227  *
228  * Note this does not consider unit experience at all, it only checks option availability.
229  * See @ref advances if an experience check is necessary.
230  */
231  bool can_advance() const
232  {
233  return !advances_to_.empty() || !get_modification_advances().empty();
234  }
235 
236  /**
237  * Checks whether this unit is eligible for level-up.
238  *
239  * @retval true This unit has sufficient experience to level up and has advancement
240  * options available.
241  */
242  bool advances() const
243  {
244  return experience_ >= max_experience() && can_advance();
245  }
246 
247  /**
248  * Gets and image path and and associated description for each advancement option.
249  *
250  * Covers both type and modification-based advancements.
251  *
252  * @returns A data map, in image/description format. If the option is a unit type,
253  * advancement, the key is the type's image and the value the type ID.
254  *
255  * If the option is a modification, the key and value are set from config data
256  * (see @ref get_modification_advances).
257  */
258  std::map<std::string, std::string> advancement_icons() const;
259 
260  /**
261  * Gets any non-typed advanced options set by modifications.
262  *
263  * These are usually used to give a unit special advancement options that don't invole transforming to a
264  * new type.
265  *
266  * Note this is not the raw option data. Parsing is performed to ensure each option appears only once.
267  * Use @ref modification_advancements is the raw data is needed.
268  *
269  * @returns A config list of options data. Each option is unique.
270  */
271  std::vector<config> get_modification_advances() const;
272 
273  /**
274  * Gets the image and description data for modification advancements.
275  *
276  * @returns A list of pairs of the image paths(first) and descriptions (second) for
277  * each advancement option.
278  */
279  std::vector<std::pair<std::string, std::string>> amla_icons() const;
280 
281  using advancements_list= boost::ptr_vector<config>;
282  /** The raw, unparsed data for modification advancements. */
284  {
285  return advancements_;
286  }
287 
288  /** Sets the raw modification advancement option data */
289  void set_advancements(std::vector<config> advancements);
290 
291  /**
292  * @}
293  * @defgroup unit_access Basic data setters and getters
294  * @{
295  **/
296 
297 public:
298  /**
299  * The side this unit belongs to.
300  *
301  * Note that side numbers starts from 1, not 0, so be sure to subtract 1 if using as a container index.
302  */
303  int side() const
304  {
305  return side_;
306  }
307 
308  /** Sets the side this unit belongs to. */
309  void set_side(unsigned int new_side)
310  {
311  side_ = new_side;
312  }
313 
314  /** This unit's type, accounting for gender and variation. */
315  const unit_type& type() const
316  {
317  return *type_;
318  }
319 
320  /**
321  * The id of this unit's type.
322  *
323  * If you are dealing with creating units (e.g. recruitment), this is not what you want, as a
324  * variation can change this; use type().base_id() instead.
325  */
326  const std::string& type_id() const
327  {
328  return type_->id();
329  }
330 
331  /** Gets the translatable name of this unit's type. */
332  const t_string& type_name() const
333  {
334  return type_name_;
335  }
336 
337  /**
338  * Gets this unit's id.
339  *
340  * This is a unique string usually set by WML. It should *not* be used for internal tracking in
341  * the unit_map. Use @ref underlying_id for that.
342  */
343  const std::string& id() const
344  {
345  return id_;
346  }
347 
348  /** Sets this unit's string ID. */
349  void set_id(const std::string& id)
350  {
351  id_ = id;
352  }
353 
354  /** This unit's unique internal ID. This should *not* be used for user-facing operations. */
355  std::size_t underlying_id() const
356  {
357  return underlying_id_.value;
358  }
359 
360 private:
361  /** Sets the internal ID. */
362  void set_underlying_id(n_unit::id_manager& id_manager);
363 
364 public:
365  /** Gets this unit's translatable display name. */
366  const t_string& name() const
367  {
368  return name_;
369  }
370 
371  /**
372  * Sets this unit's translatable display name.
373  *
374  * This should only be used internally since it ignores the 'unrenamable' flag.
375  */
376  void set_name(const t_string& name)
377  {
378  name_ = name;
379  }
380 
381  /**
382  * Attempts to rename this unit's translatable display name, taking the 'unrenamable' flag into account.
383  *
384  * If a direct rename is desired, use @ref set_name.
385  * @todo should this also take a t_string?
386  */
387  void rename(const std::string& name)
388  {
389  if(!unrenamable_) {
390  name_ = name;
391  }
392  }
393 
394  /**
395  * Whether this unit can be renamed.
396  *
397  * This flag is considered by @ref rename, but not @ref set_name.
398  */
399  bool unrenamable() const
400  {
401  return unrenamable_;
402  }
403 
404  /**
405  * Sets the 'unrenamable' flag. Usually used for scenario-specific units which should not be renamed.
406  */
407  void set_unrenamable(bool unrenamable)
408  {
409  unrenamable_ = unrenamable;
410  }
411 
412  /** A detailed description of this unit. */
414  {
415  return description_;
416  }
417 
418  /** The gender of this unit. */
420  {
421  return gender_;
422  }
423 
424  /**
425  * The alignment of this unit.
426  *
427  * This affects the time of day during which this unit's attacks do the most damage.
428  */
429  unit_type::ALIGNMENT alignment() const
430  {
431  return alignment_;
432  }
433 
434  /** Sets the alignment of this unit. */
435  void set_alignment(unit_type::ALIGNMENT alignment)
436  {
437  set_attr_changed(UA_ALIGNMENT);
438  alignment_ = alignment;
439  }
440 
441  /**
442  * Gets this unit's race.
443  *
444  * @returns A pointer to a unit_race object - never nullptr, but it may point
445  * to the null race.
446  */
447  const unit_race* race() const
448  {
449  return race_;
450  }
451 
452  /** The current number of hitpoints this unit has. */
453  int hitpoints() const
454  {
455  return hit_points_;
456  }
457 
458  /** The max number of hitpoints this unit can have. */
459  int max_hitpoints() const
460  {
461  return max_hit_points_;
462  }
463 
464  void set_max_hitpoints(int value)
465  {
466  set_attr_changed(UA_MAX_HP);
467  max_hit_points_ = value;
468  }
469 
470  /** Sets the current hitpoint amount. */
471  void set_hitpoints(int hp)
472  {
473  hit_points_ = hp;
474  }
475 
476  /** The current number of experience points this unit has. */
477  int experience() const
478  {
479  return experience_;
480  }
481 
482  /** The max number of experience points this unit can have. */
483  int max_experience() const
484  {
485  return max_experience_;
486  }
487 
488  void set_max_experience(int value)
489  {
490  set_attr_changed(UA_MAX_XP);
491  max_experience_ = value;
492  }
493 
494  /** The number of experience points this unit needs to level up, or 0 if current XP > max XP. */
495  unsigned int experience_to_advance() const
496  {
497  return std::max(0, max_experience_ - experience_);
498  }
499 
500  /** The number of experience points over max this unit has, or 0 if current XP < max XP. */
501  unsigned int experience_overflow() const
502  {
503  return std::max(0, experience_ - max_experience_);
504  }
505 
506  /** Sets the current experience point amount. */
507  void set_experience(int xp)
508  {
509  experience_ = xp;
510  }
511 
512  /** The current level of this unit. */
513  int level() const
514  {
515  return level_;
516  }
517 
518  /** Sets the current level of this unit. */
519  void set_level(int level)
520  {
521  set_attr_changed(UA_LEVEL);
522  level_ = level;
523  }
524 
525  /** The ID of the variation of this unit's type. */
526  const std::string& variation() const
527  {
528  return variation_;
529  }
530 
531  /** The ID of the undead variation (ie, dwarf, swimmer) of this unit. */
532  void set_undead_variation(const std::string& value)
533  {
534  set_attr_changed(UA_UNDEAD_VARIATION);
535  undead_variation_ = value;
536  }
537  const std::string& undead_variation() const
538  {
539  return undead_variation_;
540  }
541 
542  /**
543  * An optional profile image to display in Help.
544  *
545  * @returns The specified image, this unit's type's sprite image if empty
546  * or 'unit_image' was set.
547  */
548  std::string small_profile() const;
549 
550  void set_small_profile(const std::string& value)
551  {
552  set_attr_changed(UA_SMALL_PROFILE);
553  small_profile_ = value;
554  }
555  /**
556  * An optional profile image displays when this unit is 'speaking' via [message].
557  *
558  * @returns The specified image, this unit's type's sprite image if empty
559  * or 'unit_image' was set.
560  */
561  std::string big_profile() const;
562 
563  void set_big_profile(const std::string& value)
564  {
565  set_attr_changed(UA_PROFILE);
566  profile_ = value;
567  adjust_profile(profile_);
568  }
569  /** Whether this unit can recruit other units - ie, are they a leader unit. */
570  bool can_recruit() const
571  {
572  return canrecruit_;
573  }
574 
575  /** Sets whether this unit can recruit other units. */
576  void set_can_recruit(bool canrecruit)
577  {
578  canrecruit_ = canrecruit;
579  }
580 
581  /** The type IDs of the other units this unit may recruit, if possible. */
582  const std::vector<std::string>& recruits() const
583  {
584  return recruit_list_;
585  }
586 
587  /** Sets the recruit list. */
588  void set_recruits(const std::vector<std::string>& recruits);
589 
590  /** How much gold is required to recruit this unit. */
591  int cost() const
592  {
593  return unit_value_;
594  }
595 
596  /** How much gold it costs to recall this unit. */
597  int recall_cost() const
598  {
599  return recall_cost_;
600  }
601 
602  /** Sets the cost of recalling this unit. */
604  {
605  recall_cost_ = recall_cost;
606  }
607 
608  /** Gets the filter constraints upon which units this unit may recall, if able. */
609  const config& recall_filter() const
610  {
611  return filter_recall_;
612  }
613 
614  /**
615  * Gets this unit's role.
616  *
617  * A role is a special string flag usually used to represent a unit's purpose in a scenario.
618  * It can be filtered on.
619  */
620  const std::string& get_role() const
621  {
622  return role_;
623  }
624 
625  /** Sets a unit's role */
626  void set_role(const std::string& role)
627  {
628  role_ = role;
629  }
630 
631  /**
632  * Gets this unit's usage. This is relevant to the AI.
633  *
634  * Usage refers to how the AI may consider utilizing this unit in combat.
635  * @todo document further
636  */
637  std::string usage() const
638  {
639  return unit_detail::get_or_default(usage_);
640  }
641 
642  /** Sets this unit's usage. */
643  void set_usage(const std::string& usage)
644  {
645  usage_.reset(new std::string(usage));
646  }
647 
648  /**
649  * Gets any user-defined variables this unit 'owns'.
650  *
651  * These are accessible via WML if the unit's data is serialized to a variable. They're strictly
652  * user-facing; internal engine calculations shouldn't use this.
653  */
655  {
656  return variables_;
657  }
658 
659  /** Const overload of @ref variables. */
660  const config& variables() const
661  {
662  return variables_;
663  }
664 
665  /**
666  * Gets whether this unit is currently hidden on the map.
667  *
668  * Hidden units are not drawn on the main map or the minimap. They are
669  * an implementation detail. For the [hides] ability, see invisible().
670  */
671  bool get_hidden() const
672  {
673  return hidden_;
674  }
675 
676  /** Sets whether the unit is hidden on the map. */
677  void set_hidden(bool state) const;
678 
679  /**
680  * The factor by which the HP bar should be scaled.
681  * @todo: document further
682  */
683  double hp_bar_scaling() const
684  {
685  return hp_bar_scaling_;
686  }
687 
688  /**
689  * The factor by which the XP bar should be scaled.
690  * @todo: document further
691  */
692  double xp_bar_scaling() const
693  {
694  return xp_bar_scaling_;
695  }
696 
697  /**
698  * Whether the unit has been instructed to hold its position.
699  * This excludes it from the unit cycling function.
700  * @return true if it is holding position
701  */
702  bool hold_position() const
703  {
704  return hold_position_;
705  }
706 
707  /**
708  * Toggle the unit's hold position status.
709  */
711  {
712  hold_position_ = !hold_position_;
713  if(hold_position_) {
714  end_turn_ = true;
715  }
716  }
717 
718  /**
719  * Set whether the user ended their turn
720  * @todo Verify meaning and explain better
721  */
722  void set_user_end_turn(bool value = true)
723  {
724  end_turn_ = value;
725  }
726 
727  /**
728  * Toggle whether the user ended their turn
729  * @todo Verify meaning and explain better
730  */
732  {
733  end_turn_ = !end_turn_;
734  if(!end_turn_) {
735  hold_position_ = false;
736  }
737  }
738 
739  /**
740  * Check whether the user ended their turn
741  * @todo Verify meaning and explain better
742  */
743  bool user_end_turn() const
744  {
745  return end_turn_;
746  }
747 
748  /**
749  * Refresh unit for the beginning of a turn
750  */
751  void new_turn();
752 
753  /**
754  * Refresh unit for the end of a turn
755  */
756  void end_turn();
757 
758  /**
759  * Refresh unit for the beginning of a new scenario
760  */
761  void new_scenario();
762 
763  /**
764  * Damage the unit.
765  * @returns true if the unit dies as a result
766  */
767  bool take_hit(int damage)
768  {
769  hit_points_ -= damage;
770  return hit_points_ <= 0;
771  }
772 
773  /**
774  * Heal the unit
775  * @amount The number of hitpoints to gain
776  */
777  void heal(int amount);
778 
779  /**
780  * Fully heal the unit, restoring it to max hitpoints
781  */
782  void heal_fully()
783  {
784  hit_points_ = max_hitpoints();
785  }
786 
787  /**
788  * Get the status effects currently affecting the unit.
789  * @return A set of status keys
790  */
791  const std::set<std::string> get_states() const;
792 
793  /**
794  * Check if the unit is affected by a status effect
795  * @param state The status effect to check
796  * @returns true if the unit is affected by the status effect
797  */
798  bool get_state(const std::string& state) const;
799 
800  /**
801  * Set whether the unit is affected by a status effect
802  * @param state The status effect to change
803  * @param value Whether the unit should be affected by the status
804  */
805  void set_state(const std::string& state, bool value);
806 
807  /**
808  * Built-in status effects known to the engine
809  */
810  enum state_t {
811  STATE_SLOWED = 0, ///< The unit is slowed - it moves slower and does less damage
812  STATE_POISONED, ///< The unit is poisoned - it loses health each turn
813  STATE_PETRIFIED, ///< The unit is petrified - it cannot move or be attacked
814  STATE_UNCOVERED, ///< The unit is uncovered - it was hiding but has been spotted
815  STATE_NOT_MOVED, ///< The unit has not moved @todo Explain better
816  STATE_UNHEALABLE, ///< The unit cannot be healed
817  STATE_GUARDIAN, ///< The unit is a guardian - it won't move unless a target is sighted
818  STATE_UNKNOWN = -1///< A status effect not known to the engine
819  };
820 
821  /**
822  * Set whether the unit is affected by a status effect
823  * @param state The status effect to change
824  * @param value Whether the unit should be affected by the status
825  */
826  void set_state(state_t state, bool value);
827 
828  /**
829  * Check if the unit is affected by a status effect
830  * @param state The status effect to check
831  * @returns true if the unit is affected by the status effect
832  */
833  bool get_state(state_t state) const;
834 
835  /**
836  * Convert a string status effect ID to a built-in status effect ID
837  * @returns the state_t representing the status, or STATE_UNKNOWN if it's not built-in
838  */
839  static state_t get_known_boolean_state_id(const std::string& state);
840 
841  /**
842  * Check if the unit has been poisoned
843  * @returns true if it's poisoned
844  */
845  bool poisoned() const
846  {
847  return get_state(STATE_POISONED);
848  }
849 
850  /**
851  * Check if the unit has been petrified
852  * @returns true if it's petrified
853  */
854  bool incapacitated() const
855  {
856  return get_state(STATE_PETRIFIED);
857  }
858 
859  /**
860  * Check if the unit has been slowed
861  * @returns true if it's slowed
862  */
863  bool slowed() const
864  {
865  return get_state(STATE_SLOWED);
866  }
867 
868  /**
869  * @}
870  * @defgroup unit_atk Attack and resistance functions
871  * @{
872  */
873 
874 public:
875  /** Gets an iterator over this unit's attacks. */
877  {
878  return make_attack_itors(attacks_);
879  }
880 
881  /** Const overload of @ref attacks. */
883  {
884  return make_attack_itors(attacks_);
885  }
886 
887  /**
888  * Adds a new attack to the unit.
889  * @param position An iterator pointing to the attack before which to insert the new one.
890  * @param args The arguments for constructing the attack
891  */
892  template<typename... Args>
893  attack_ptr add_attack(attack_itors::iterator position, Args&&... args)
894  {
895  set_attr_changed(UA_ATTACKS);
896  return *attacks_.emplace(position.base(), new attack_type(std::forward<Args>(args)...));
897  }
898 
899  /**
900  * Remove an attack from the unit
901  * @param atk A pointer to the attack to remove
902  * @return true if the attack was removed, false if it didn't exist on the unit
903  */
904  bool remove_attack(attack_ptr atk);
905 
906  /**
907  * Set the unit to have no attacks left for this turn.
908  */
909  void remove_attacks_ai();
910 
911  /**
912  * Calculates the damage this unit would take from a certain attack.
913  *
914  * @param attack The attack to consider.
915  * @param attacker Whether this unit should be considered the attacker.
916  * @param loc TODO: what does this do?
917  *
918  * @returns The expected damage.
919  */
920  int damage_from(const attack_type& attack, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr) const
921  {
922  return resistance_against(attack, attacker, loc, weapon);
923  }
924 
925  /** The maximum number of attacks this unit may perform per turn, usually 1. */
926  int max_attacks() const
927  {
928  return max_attacks_;
929  }
930 
931  void set_max_attacks(int value)
932  {
933  set_attr_changed(UA_MAX_AP);
934  max_attacks_ = value;
935  }
936 
937  /**
938  * Gets the remaining number of attacks this unit can perform this turn.
939  *
940  * If the 'incapacitated' status is set, this will always be 0.
941  */
942  int attacks_left() const
943  {
944  return (attacks_left_ == 0 || incapacitated()) ? 0 : attacks_left_;
945  }
946 
947  /**
948  * Gets the remaining number of attacks this unit can perform this turn.
949  *
950  * @param base_value If false, consider the `incapacitated` flag.
951  *
952  * @returns If @a base_value is true, the raw value is returned.
953  */
954  int attacks_left(bool base_value) const
955  {
956  return base_value ? attacks_left_ : attacks_left();
957  }
958 
959  /**
960  * Sets the number of attacks this unit has left this turn.
961  * @param left The number of attacks left
962  */
963  void set_attacks(int left)
964  {
965  attacks_left_ = std::max<int>(0, left);
966  }
967 
968  /**
969  * The unit's defense on a given terrain
970  * @param terrain The terrain to check
971  */
972  int defense_modifier(const t_translation::terrain_code& terrain) const;
973 
974  /**
975  * The unit's resistance against a given damage type
976  * @param damage_name The damage type
977  * @param attacker True if this unit is on the offensive (to resolve [resistance] abilities)
978  * @param loc The unit's location (to resolve [resistance] abilities)
979  */
980  int resistance_against(const std::string& damage_name, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr) const;
981 
982  /**
983  * The unit's resistance against a given attack
984  * @param atk The attack
985  * @param attacker True if this unit is on the offensive (to resolve [resistance] abilities)
986  * @param loc The unit's location (to resolve [resistance] abilities)
987  */
988  int resistance_against(const attack_type& atk, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr) const
989  {
990  return resistance_against(atk.type(), attacker, loc , weapon, atk.shared_from_this());
991  }
992 
993  /** Gets resistances without any abilities applied. */
995  {
996  return movement_type_.damage_table();
997  }
998 
999 private:
1000  bool resistance_filter_matches(const config& cfg, bool attacker, const std::string& damage_name, int res) const;
1001 
1002  /**
1003  * @}
1004  * @defgroup unit_trait Trait and upkeep functions
1005  * @{
1006  */
1007 public:
1008  /**
1009  * Applies mandatory traits (e.g. undead, mechanical) to a unit and then fills in the remaining traits
1010  * traits until no more are available (leaders have a restricted set of available traits) or the unit has
1011  * its maximum number of traits.
1012  *
1013  * This routine does not apply the effects of added traits to a unit; that must be done by the caller.
1014  *
1015  * Note that random numbers used in config files don't work in multiplayer, so leaders should be barred
1016  * from all random traits until that is fixed. Later the restrictions will be based on play balance.
1017  *
1018  * @param must_have_only Whether random or optional traits should be included or not. If false only
1019  * mandatory traits will be used.
1020  */
1021  void generate_traits(bool must_have_only = false);
1022 
1023  /**
1024  * Gets the names of the currently registered traits.
1025  *
1026  * @returns A list of translatable trait names.
1027  */
1028  const std::vector<t_string>& trait_names() const
1029  {
1030  return trait_names_;
1031  }
1032 
1033  /**
1034  * Gets the descriptions of the currently registered traits.
1035  *
1036  * @returns A list of translatable trait descriptions.
1037  */
1038  const std::vector<t_string>& trait_descriptions() const
1039  {
1040  return trait_descriptions_;
1041  }
1042 
1043  /**
1044  * Gets a list of the traits this unit currently has.
1045  *
1046  * @returns A list of trait IDs.
1047  */
1048  std::vector<std::string> get_traits_list() const;
1049 
1050  /**
1051  * Register a trait's name and its description for the UI's use.
1052  *
1053  * The resulting data can be fetched with @ref trait_names and @ref trait_descriptions.
1054  *
1055  * @param trait A config containing the trait's attributes.
1056  * @param description The translatable description of the trait.
1057  */
1058  void add_trait_description(const config& trait, const t_string& description);
1059 
1060  /**
1061  * Gets the amount of gold this unit costs a side per turn.
1062  *
1063  * This fetches an actual numeric gold value:
1064  * - If @rec can_recruit is true, no upkeep is paid (0 is returned).
1065  * - If a special upkeep flag is set, the associated gold amount is returned (see @ref upkeep_value_visitor).
1066  * - If a numeric value is already set, it is returned directly.
1067  *
1068  * @returns A gold value, evaluated based on the state of @ref upkeep_raw.
1069  */
1070  int upkeep() const;
1071 
1073  {
1074  static std::string type() { static std::string v = "full"; return v; }
1075  };
1076 
1078  {
1079  static std::string type() { static std::string v = "loyal"; return v; }
1080  };
1081 
1082  /** Visitor helper class to fetch the appropriate upkeep value. */
1083  class upkeep_value_visitor : public boost::static_visitor<int>
1084  {
1085  public:
1086  explicit upkeep_value_visitor(const unit& unit) : u_(unit) {}
1087 
1088  /** Full upkeep equals the unit's level. */
1089  int operator()(const upkeep_full&) const
1090  {
1091  return u_.level();
1092  }
1093 
1094  /** Loyal units cost no upkeep. */
1095  int operator()(const upkeep_loyal&) const
1096  {
1097  return 0;
1098  }
1099 
1100  int operator()(int v) const
1101  {
1102  return v;
1103  }
1104 
1105  private:
1106  const unit& u_;
1107  };
1108 
1109  /** Visitor helper struct to fetch the upkeep type flag if applicable, or the the value otherwise. */
1110  struct upkeep_type_visitor : public boost::static_visitor<std::string>
1111  {
1112  template<typename T>
1113  std::enable_if_t<!std::is_same<int, T>::value, std::string>
1114  operator()(T&) const
1115  {
1116  // Any special upkeep type should have an associated @ref type getter in its helper struct.
1117  return T::type();
1118  }
1119 
1120  std::string operator()(int v) const
1121  {
1122  return std::to_string(v);
1123  }
1124  };
1125 
1126  using upkeep_t = boost::variant<upkeep_full, upkeep_loyal, int>;
1127 
1128  /**
1129  * Gets the raw variant controlling the upkeep value.
1130  *
1131  * This should not usually be called directly. To get an actual numeric value of upkeep use @ref upkeep.
1132  */
1134  {
1135  return upkeep_;
1136  }
1137 
1138  /** Sets the upkeep value to a specific value value. Does not necessarily need to be numeric */
1140  {
1141  upkeep_ = v;
1142  }
1143 
1144  /** Gets whether this unit is loyal - ie, it costs no upkeep. */
1145  bool loyal() const;
1146 
1147  /** Gets whether this unit is fearless - ie, unaffected by time of day. */
1148  bool is_fearless() const
1149  {
1150  return is_fearless_;
1151  }
1152 
1153  /** Gets whether this unit is healthy - ie, always rest heals. */
1154  bool is_healthy() const
1155  {
1156  return is_healthy_;
1157  }
1158 
1159  /**
1160  * @}
1161  * @defgroup unit_mvmt Movement and location functions
1162  * @{
1163  */
1164 
1165 public:
1166  /** The maximum moves this unit has. */
1167  int total_movement() const
1168  {
1169  return max_movement_;
1170  }
1171 
1172  void set_total_movement(int value)
1173  {
1174  set_attr_changed(UA_MAX_MP);
1175  max_movement_ = value;
1176  }
1177 
1178  /**
1179  * Gets how far a unit can move, considering the `incapacitated` flag.
1180  *
1181  * @returns The remaining movement, or zero if incapacitated.
1182  */
1183  int movement_left() const
1184  {
1185  return (movement_ == 0 || incapacitated()) ? 0 : movement_;
1186  }
1187 
1188  /**
1189  * Gets how far a unit can move.
1190  *
1191  * @param base_value If false, consider the `incapacitated` flag.
1192  *
1193  * @returns If @a base_value is true, the raw value is returned.
1194  */
1195  int movement_left(bool base_value) const
1196  {
1197  return base_value ? movement_ : movement_left();
1198  }
1199 
1200  /**
1201  * Set this unit's remaining movement to @a moves.
1202  *
1203  * This does not affect maximum movement.
1204  *
1205  * @param moves The new number of moves
1206  * @param unit_action If to true, the "end turn" and "hold position" flags will be cleared
1207  * (as they should be if a unit acts, as opposed to the movement being set
1208  * by the engine for other reasons).
1209  */
1210  void set_movement(int moves, bool unit_action = false);
1211 
1212  /** Checks if this unit has moved. */
1213  bool has_moved() const
1214  {
1215  return movement_left() != total_movement();
1216  }
1217 
1218  /** Sets the unit to have no moves left for this turn. */
1219  void remove_movement_ai();
1220 
1221  /**
1222  * Checks whether this unit is 'resting'.
1223  *
1224  * Resting refers to whether this unit has not moved yet this turn. Note that this can be true even
1225  * if @ref movement_left is not equal to @ref total_movement.
1226  */
1227  bool resting() const
1228  {
1229  return resting_;
1230  }
1231 
1232  /** Sets this unit's resting status. */
1233  void set_resting(bool rest)
1234  {
1235  resting_ = rest;
1236  }
1237 
1238  /** Tests whether the unit has a zone-of-control, considering @ref incapacitated. */
1239  bool emits_zoc() const
1240  {
1241  return emit_zoc_ && !incapacitated();
1242  }
1243 
1244  /** Gets the raw zone-of-control flag, disregarding @ref incapacitated. */
1245  bool get_emit_zoc() const
1246  {
1247  return emit_zoc_;
1248  }
1249 
1250  /** Sets the raw zone-of-control flag. */
1251  void set_emit_zoc(bool val)
1252  {
1253  set_attr_changed(UA_ZOC);
1254  emit_zoc_ = val;
1255  }
1256 
1257  /** The current map location this unit is at. */
1259  {
1260  return loc_;
1261  }
1262 
1263  /**
1264  * Sets this unit's map location.
1265  *
1266  * Note this should only be called by unit_map or for temporary units.
1267  */
1268  void set_location(const map_location& loc)
1269  {
1270  loc_ = loc;
1271  }
1272 
1273  /** The current directin this unit is facing within its hex. */
1275  {
1276  return facing_;
1277  }
1278 
1279  /** The this unit's facing. */
1280  void set_facing(map_location::DIRECTION dir) const;
1281 
1282  /** Gets whether this unit has a multi-turn destination set. */
1283  bool has_goto() const
1284  {
1285  return get_goto().valid();
1286  }
1287 
1288  /** The map location to which this unit is moving over multiple turns, if any. */
1289  const map_location& get_goto() const
1290  {
1291  return goto_;
1292  }
1293 
1294  /** Sets this unit's long term destination. */
1295  void set_goto(const map_location& new_goto)
1296  {
1297  goto_ = new_goto;
1298  }
1299 
1300  /** Gets the unit's vision points. */
1301  int vision() const
1302  {
1303  return vision_ < 0 ? max_movement_ : vision_;
1304  }
1305 
1306  /** Gets the unit's jamming points. */
1307  int jamming() const
1308  {
1309  return jamming_;
1310  }
1311 
1312  /** Check whether the unit's move has been interrupted. */
1313  bool move_interrupted() const
1314  {
1315  return movement_left() > 0 && interrupted_move_.x >= 0 && interrupted_move_.y >= 0;
1316  }
1317 
1318  /** Get the target location of the unit's interrupted move. */
1320  {
1321  return interrupted_move_;
1322  }
1323 
1324  /** Set the target location of the unit's interrupted move. */
1325  void set_interrupted_move(const map_location& interrupted_move)
1326  {
1327  interrupted_move_ = interrupted_move;
1328  }
1329 
1330  /** Get the unit's movement type. */
1331  const movetype& movement_type() const
1332  {
1333  return movement_type_;
1334  }
1335 
1336  /**
1337  * Get the unit's movement cost on a particular terrain
1338  * @param terrain The terrain to check
1339  * @returns the number of movement points to enter that terrain
1340  */
1341  int movement_cost(const t_translation::terrain_code& terrain) const
1342  {
1343  return movement_type_.movement_cost(terrain, get_state(STATE_SLOWED));
1344  }
1345 
1346  /**
1347  * Get the unit's vision cost on a particular terrain
1348  * @param terrain The terrain to check
1349  * @returns the number of vision points to see into that terrain
1350  */
1351  int vision_cost(const t_translation::terrain_code& terrain) const
1352  {
1353  return movement_type_.vision_cost(terrain, get_state(STATE_SLOWED));
1354  }
1355 
1356  /**
1357  * Get the unit's jamming cost on a particular terrain
1358  * @param terrain The terrain to check
1359  * @returns the number of jamming points to jam that terrain
1360  */
1361  int jamming_cost(const t_translation::terrain_code& terrain) const
1362  {
1363  return movement_type_.jamming_cost(terrain, get_state(STATE_SLOWED));
1364  }
1365 
1366  /** Check if the unit is a flying unit. */
1367  bool is_flying() const
1368  {
1369  return movement_type_.is_flying();
1370  }
1371 
1372  /**
1373  * @}
1374  * @defgroup unit_mod Modification functions
1375  * @{
1376  */
1377 
1378 public:
1379  /** Get the raw modifications. */
1381  {
1382  return modifications_;
1383  }
1384 
1385  /** Set the raw modifications. */
1386  const config& get_modifications() const
1387  {
1388  return modifications_;
1389  }
1390 
1391  /**
1392  * Count modifications of a particular type.
1393  * @param type The type of modification to count.
1394  * Valid values are "advancement", "trait", "object"
1395  * @param id The ID of the modification to count
1396  * @return The total number of modifications of that type and ID.
1397  */
1398  std::size_t modification_count(const std::string& type, const std::string& id) const;
1399 
1400  /**
1401  * Add a new modification to the unit.
1402  * @param type The type of modification to add.
1403  * Valid values are "advancement", "trait", "object"
1404  * @param modification The details of the modification
1405  * @param no_add If true, apply the modification but don't save it for unit rebuild time.
1406  * Defaults to false.
1407  */
1408  void add_modification(const std::string& type, const config& modification, bool no_add = false);
1409 
1410  /**
1411  * Clears those modifications whose duration has expired.
1412  *
1413  * @param duration If empty, all temporary modifications (those not lasting forever) expire.
1414  * Otherwise, modifications whose duration equals @a duration expire.
1415  */
1416  void expire_modifications(const std::string& duration);
1417 
1418  static const std::set<std::string> builtin_effects;
1419 
1420  /**
1421  * Apply a builtin effect to the unit.
1422  * @param type The effect to apply. Must be one of the effects in @ref builtin_effects.
1423  * @param effect The details of the effect
1424  */
1425  void apply_builtin_effect(std::string type, const config& effect);
1426 
1427  /**
1428  * Construct a string describing a built-in effect.
1429  * @param type The effect to describe. Must be one of the effects in @ref builtin_effects.
1430  * @param effect The details of the effect
1431  */
1432  std::string describe_builtin_effect(std::string type, const config& effect);
1433 
1434  /** Re-apply all saved modifications. */
1435  void apply_modifications();
1436 
1437  /**
1438  * @}
1439  * @defgroup unit_img Image and animations functions
1440  * @{
1441  */
1442 
1443 public:
1444  /** @todo Document this */
1446  {
1447  return *anim_comp_;
1448  }
1449 
1450  /** The name of the file to game_display (used in menus). */
1451  std::string absolute_image() const;
1452 
1453  /** The default image to use for animation frames with no defined image. */
1454  std::string default_anim_image() const;
1455 
1456  /** Get the unit's halo image. */
1457  std::string image_halo() const
1458  {
1459  return unit_detail::get_or_default(halo_);
1460  }
1461 
1462  /** Set the unit's halo image. */
1463  void set_image_halo(const std::string& halo);
1464 
1465  /** Get the unit's ellipse image. */
1466  std::string image_ellipse() const
1467  {
1468  return unit_detail::get_or_default(ellipse_);
1469  }
1470 
1471  /** Set the unit's ellipse image. */
1472  void set_image_ellipse(const std::string& ellipse)
1473  {
1474  appearance_changed_ = true;
1475  ellipse_.reset(new std::string(ellipse));
1476  }
1477 
1478  /**
1479  * Get the source color palette to use when recoloring the unit's image.
1480  */
1481  const std::string& flag_rgb() const;
1482 
1483  /** Constructs a recolor (RC) IPF string for this unit's team color. */
1484  std::string TC_image_mods() const;
1485 
1486  /** Gets any IPF image mods applied by effects. */
1487  const std::string& effect_image_mods() const
1488  {
1489  return image_mods_;
1490  }
1491 
1492  /**
1493  * Gets an IPF string containing all IPF image mods.
1494  *
1495  * @returns An amalgamation of @ref effect_image_mods followed by @ref TC_image_mods.
1496  */
1497  std::string image_mods() const;
1498 
1499  /** Get the unit's overlay images. */
1500  const std::vector<std::string>& overlays() const
1501  {
1502  return overlays_;
1503  }
1504 
1505  /**
1506  * Color for this unit's *current* hitpoints.
1507  *
1508  * @returns A color between green and red representing how wounded this unit is.
1509  * The maximum_hitpoints are considered as base.
1510  */
1511  color_t hp_color() const;
1512 
1513  /**
1514  * Color for this unit's hitpoints.
1515  *
1516  * @param hitpoints The number of hitpoints the color represents.
1517  * @returns The color considering the current hitpoints as base.
1518  */
1519  color_t hp_color(int hitpoints) const;
1520 
1521  /**
1522  * Color for this unit's XP. See also @ref hp_color
1523  */
1524  color_t xp_color() const;
1525 
1526  /**
1527  * @}
1528  * @defgroup unit_abil Ability functions
1529  * @{
1530  */
1531 
1532 public:
1533  /**
1534  * Checks whether this unit currently possesses or is affected by a given ability.
1535  *
1536  * This means that the ability could be owned by this unit itself or by an adjacent unit, should
1537  * the ability affect an AoE in which this unit happens to be.
1538  *
1539  * @param tag_name The name of the ability to check for.
1540  * @param loc The location around which to check for affected units. This may or
1541  * may not be the location of this unit.
1542  */
1543  bool get_ability_bool(const std::string& tag_name, const map_location& loc) const;
1544 
1545  /**
1546  * Checks whether this unit currently possesses or is affected by a given ability.
1547  *
1548  * This means that the ability could be owned by this unit itself or by an adjacent unit, should
1549  * the ability affect an AoE in which this unit happens to be.
1550  *
1551  * This overload uses the location of this unit for calculations.
1552  *
1553  * @param tag_name The name of the ability to check for.
1554  */
1555  bool get_ability_bool(const std::string& tag_name) const
1556  {
1557  return get_ability_bool(tag_name, loc_);
1558  }
1559 
1560  /**
1561  * Gets the unit's active abilities of a particular type if it were on a specified location.
1562  * @param tag_name The type of ability to check for
1563  * @param loc The location to use for resolving abilities
1564  * @return A list of active abilities, paired with the location they are active on
1565  */
1566  unit_ability_list get_abilities(const std::string& tag_name, const map_location& loc, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr) const;
1567 
1568  /**
1569  * Gets the unit's active abilities of a particular type.
1570  * @param tag_name The type of ability to check for
1571  * @return A list of active abilities, paired with the location they are active on
1572  */
1573  unit_ability_list get_abilities(const std::string& tag_name, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr) const
1574  {
1575  return get_abilities(tag_name, loc_, weapon, opp_weapon);
1576  }
1577 
1578  /**
1579  * Gets the names and descriptions of this unit's abilities. Location-independent variant
1580  * with all abilities shown as active.
1581  *
1582  * @returns A list of quadruples consisting of (in order) id, base name,
1583  * male or female name as appropriate for the unit, and description.
1584  */
1585  std::vector<std::tuple<std::string, t_string, t_string, t_string>>
1586  ability_tooltips() const;
1587 
1588  /**
1589  * Gets the names and descriptions of this unit's abilities.
1590  *
1591  * @param active_list This vector will be the same length as the returned one and will
1592  * indicate whether or not the corresponding ability is active.
1593  *
1594  * @param loc The location on which to resolve the ability.
1595  *
1596  * @returns A list of quadruples consisting of (in order) id, base name,
1597  * male or female name as appropriate for the unit, and description.
1598  */
1599  std::vector<std::tuple<std::string, t_string, t_string, t_string>>
1600  ability_tooltips(boost::dynamic_bitset<>& active_list, const map_location& loc) const;
1601 
1602  /** Get a list of all abilities by ID. */
1603  std::vector<std::string> get_ability_list() const;
1604 
1605  /**
1606  * Check if the unit has an ability of a specific type.
1607  * @param ability The type of ability (tag name) to check for.
1608  * @returns true if the ability is present
1609  */
1610  bool has_ability_type(const std::string& ability) const;
1611 
1612  /**
1613  * Check if the unit has an ability of a specific ID.
1614  * @param ability The ID of ability to check for.
1615  * @returns true if the ability is present
1616  */
1617  bool has_ability_by_id(const std::string& ability) const;
1618 
1619  /**
1620  * Removes a unit's abilities with a specific ID.
1621  * @param ability The type of ability (tag name) to remove.
1622  */
1623  void remove_ability_by_id(const std::string& ability);
1624 
1625  bool abilities_filter_matches(const config& cfg, bool attacker, int res) const;
1626  bool ability_filter_fighter(const std::string& ability, const std::string& filter_attacker , const config& cfg, const map_location& loc, const unit& u2) const;
1627 
1628 private:
1629  /**
1630  * Check if an ability is active.
1631  * @param ability The type (tag name) of the ability
1632  * @param cfg an ability WML structure
1633  * @param loc The location on which to resolve the ability
1634  * @returns true if it is active
1635  */
1636  bool ability_active(const std::string& ability, const config& cfg, const map_location& loc) const;
1637 
1638  /**
1639  * Check if an ability affects adjacent units.
1640  * @param ability The type (tag name) of the ability
1641  * @param cfg an ability WML structure
1642  * @param loc The location on which to resolve the ability
1643  * @param from The "other unit" for filter matching
1644  */
1645  bool ability_affects_adjacent(const std::string& ability, const config& cfg, int dir, const map_location& loc, const unit& from) const;
1646 
1647  /**
1648  * Check if an ability affects the owning unit.
1649  * @param ability The type (tag name) of the ability
1650  * @param cfg an ability WML structure
1651  * @param loc The location on which to resolve the ability
1652  */
1653  bool ability_affects_self(const std::string& ability, const config& cfg, const map_location& loc) const;
1654 
1655  bool ability_affects_weapon(const config& cfg, const_attack_ptr weapon, bool is_opp) const;
1656 
1657 public:
1658  /** Get the unit formula manager. */
1660  {
1661  return *formula_man_;
1662  }
1663 
1664  /** Generates a random race-appropriate name if one has not already been provided. */
1665  void generate_name();
1666 
1667  // Only see_all = true use caching
1668  bool invisible(const map_location& loc, bool see_all = true) const;
1669 
1670  bool is_visible_to_team(const team& team, bool const see_all = true) const;
1671  /// Return true if the unit would be visible to team if its location were loc.
1672  bool is_visible_to_team(const map_location& loc, const team& team, bool const see_all = true) const;
1673 
1674  /**
1675  * Serializes the current unit metadata values.
1676  *
1677  * @param cfg The config to write to.
1678  * @param write_all set this to false to not write unchanged attributes.
1679  */
1680  void write(config& cfg, bool write_all = true) const;
1681 
1682  /**
1683  * Mark this unit as clone so it can be inserted to unit_map.
1684  *
1685  * @returns self (for convenience)
1686  */
1687  unit& mark_clone(bool is_temporary);
1688 
1689  /** @} */
1690 
1691  long ref_count() const
1692  {
1693  return ref_count_;
1694  }
1695 
1696  friend void intrusive_ptr_add_ref(const unit*);
1697  friend void intrusive_ptr_release(const unit*);
1698 
1699  void set_appearance_changed(bool value) { appearance_changed_ = value; }
1700  bool appearance_changed() const { return appearance_changed_; }
1701 
1702 protected:
1703  mutable long ref_count_; // used by intrusive_ptr
1704 
1705 private:
1707 
1708  std::vector<std::string> advances_to_;
1709 
1710  /** Never nullptr. Adjusted for gender and variation. */
1712 
1713  /** The displayed name of this unit type. */
1715 
1716  /** Never nullptr, but may point to the null race. */
1718 
1719  std::string id_;
1722 
1723  std::string undead_variation_;
1724  std::string variation_;
1725 
1730 
1731  int level_;
1732 
1735  std::vector<std::string> recruit_list_;
1736  unit_type::ALIGNMENT alignment_;
1737 
1738  std::string flag_rgb_;
1739  std::string image_mods_;
1740 
1742 
1743  int side_;
1744 
1746 
1747  std::unique_ptr<unit_formula_manager> formula_man_;
1748 
1751  int vision_;
1753 
1755 
1758  bool resting_;
1759 
1762 
1763  std::set<std::string> states_;
1764 
1765  static const std::size_t num_bool_states = 7;
1766 
1767  std::bitset<num_bool_states> known_boolean_states_;
1768  static std::map<std::string, state_t> known_boolean_state_names_;
1769 
1773 
1775 
1776  std::vector<std::string> overlays_;
1777 
1778  std::string role_;
1780 
1781 protected:
1782  // TODO: I think we actually consider this to be part of the gamestate, so it might be better if it's not mutable,
1783  // but it's not easy to separate this guy from the animation code right now.
1785 
1786 private:
1787  std::vector<t_string> trait_names_;
1788  std::vector<t_string> trait_descriptions_;
1789 
1792 
1793  bool is_fearless_, is_healthy_;
1794 
1796 
1797  // Animations:
1799 
1800  std::unique_ptr<unit_animation_component> anim_comp_;
1801 
1802  mutable bool hidden_;
1803  double hp_bar_scaling_, xp_bar_scaling_;
1804 
1807 
1809 
1811 
1812  std::unique_ptr<std::string> usage_;
1813  std::unique_ptr<std::string> halo_;
1814  std::unique_ptr<std::string> ellipse_;
1815 
1818 
1820 
1821  std::string profile_;
1822  std::string small_profile_;
1823 
1824  //Used to check whether the moving units during a move needs to be updated
1825  mutable bool appearance_changed_ = true;
1826  std::bitset<UA_COUNT> changed_attributes_;
1827 
1828  void parse_upkeep(const config::attribute_value& upkeep);
1829  void write_upkeep(config::attribute_value& upkeep) const;
1830 
1831  /**
1832  * Hold the visibility status cache for a unit, when not uncovered.
1833  * This is mutable since it is a cache.
1834  */
1835  mutable std::map<map_location, bool> invisibility_cache_;
1836 
1837  /**
1838  * Clears the cache.
1839  *
1840  * Since we don't change the state of the object we're marked const (also
1841  * required since the objects in the cache need to be marked const).
1842  */
1844  {
1845  invisibility_cache_.clear();
1846  }
1847 };
1848 
1849 /** Implement non-member swap function for std::swap (calls @ref unit::swap). */
1850 void swap(unit& lhs, unit& rhs);
1851 
1852 /**
1853  * Object which temporarily resets a unit's movement.
1854  *
1855  * @warning A unit whose movement is reset may not be deleted while held in a
1856  * @ref unit_movement_resetter object, so it's best to use thus only in a small scope.
1857  */
1859 {
1861  unit_movement_resetter& operator=(const unit_movement_resetter&) = delete;
1862 
1863  unit_movement_resetter(const unit& u, bool operate = true);
1865 
1866 private:
1868  int moves_;
1869 };
1870 
1871 /**
1872  * Gets a checksum for a unit.
1873  *
1874  * In MP games the descriptions are locally generated and might differ, so it
1875  * should be possible to discard them. Not sure whether replays suffer the
1876  * same problem.
1877  *
1878  * @param u this unit
1879  *
1880  * @returns the checksum for a unit
1881  */
1882 std::string get_checksum(const unit& u);
void set_experience(int xp)
Sets the current experience point amount.
Definition: unit.hpp:507
std::vector< attack_ptr > attack_list
bool move_interrupted() const
Check whether the unit&#39;s move has been interrupted.
Definition: unit.hpp:1313
int operator()(int v) const
Definition: unit.hpp:1100
int attacks_left() const
Gets the remaining number of attacks this unit can perform this turn.
Definition: unit.hpp:942
const unit_type * type_
Never nullptr.
Definition: unit.hpp:1711
attack_list attacks_
Definition: unit.hpp:1779
t_string type_name_
The displayed name of this unit type.
Definition: unit.hpp:1714
const map_location & loc() const
Definition: unit.hpp:89
bool empty() const
Definition: unit.hpp:78
void set_can_recruit(bool canrecruit)
Sets whether this unit can recruit other units.
Definition: unit.hpp:576
std::vector< std::string > recruit_list_
Definition: unit.hpp:1735
const unit_ability & back() const
Definition: unit.hpp:82
void set_big_profile(const std::string &value)
Definition: unit.hpp:563
config modifications_
Definition: unit.hpp:1805
int recall_cost_
Definition: unit.hpp:1733
utils::string_map modification_descriptions_
Definition: unit.hpp:1795
std::map< std::string, t_string > string_map
int jamming() const
Gets the unit&#39;s jamming points.
Definition: unit.hpp:1307
int vision() const
Gets the unit&#39;s vision points.
Definition: unit.hpp:1301
The unit is a guardian - it won&#39;t move unless a target is sighted.
Definition: unit.hpp:817
This class represents a single unit of a specific type.
Definition: unit.hpp:99
void intrusive_ptr_release(const unit *)
Definition: unit.cpp:229
boost::iterator_range< boost::indirect_iterator< attack_list::iterator > > attack_itors
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit&#39;s movement cost on a particular terrain.
Definition: unit.hpp:1341
The unit is uncovered - it was hiding but has been spotted.
Definition: unit.hpp:814
std::string image_mods_
Definition: unit.hpp:1739
void set_usage(const std::string &usage)
Sets this unit&#39;s usage.
Definition: unit.hpp:643
bool is_flying() const
Check if the unit is a flying unit.
Definition: unit.hpp:1367
const std::string & effect_image_mods() const
Gets any IPF image mods applied by effects.
Definition: unit.hpp:1487
std::vector< std::string > advances_to_
Definition: unit.hpp:1708
t_string name_
Definition: unit.hpp:1720
void emplace_back(T &&... args)
Definition: unit.hpp:87
iterator erase(const iterator &erase_it)
Definition: unit.hpp:84
Variant for storing WML attributes.
std::vector< t_string > trait_names_
Definition: unit.hpp:1787
int vision_
Definition: unit.hpp:1751
void set_appearance_changed(bool value)
Definition: unit.hpp:1699
unit_race::GENDER gender() const
The gender of this unit.
Definition: unit.hpp:419
void rename(const std::string &name)
Attempts to rename this unit&#39;s translatable display name, taking the &#39;unrenamable&#39; flag into account...
Definition: unit.hpp:387
const movetype & movement_type() const
Get the unit&#39;s movement type.
Definition: unit.hpp:1331
int hitpoints() const
The current number of hitpoints this unit has.
Definition: unit.hpp:453
config events_
Definition: unit.hpp:1771
std::string operator()(int v) const
Definition: unit.hpp:1120
unit_type::ALIGNMENT alignment_
Definition: unit.hpp:1736
const T & get_or_default(const std::unique_ptr< T > &v)
Definition: unit.hpp:36
map_location::DIRECTION facing_
Definition: unit.hpp:1784
std::string flag_rgb_
Definition: unit.hpp:1738
void set_user_end_turn(bool value=true)
Set whether the user ended their turn.
Definition: unit.hpp:722
config & variables()
Gets any user-defined variables this unit &#39;owns&#39;.
Definition: unit.hpp:654
void set_image_ellipse(const std::string &ellipse)
Set the unit&#39;s ellipse image.
Definition: unit.hpp:1472
void set_small_profile(const std::string &value)
Definition: unit.hpp:550
int jamming_
Definition: unit.hpp:1752
int unit_value_
Definition: unit.hpp:1790
bool generate_name_
Definition: unit.hpp:1817
bool hold_position_
Definition: unit.hpp:1756
const std::string & variation() const
The ID of the variation of this unit&#39;s type.
Definition: unit.hpp:526
const config & variables() const
Const overload of variables.
Definition: unit.hpp:660
unit_ptr clone() const
Definition: unit.hpp:173
The unit is poisoned - it loses health each turn.
Definition: unit.hpp:812
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
void set_location(const map_location &loc)
Sets this unit&#39;s map location.
Definition: unit.hpp:1268
map_location::DIRECTION facing() const
The current directin this unit is facing within its hex.
Definition: unit.hpp:1274
The unit is petrified - it cannot move or be attacked.
Definition: unit.hpp:813
config variables_
Definition: unit.hpp:1770
bool take_hit(int damage)
Damage the unit.
Definition: unit.hpp:767
const std::string & type() const
Definition: attack_type.hpp:42
int resistance_against(const attack_type &atk, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr) const
The unit&#39;s resistance against a given attack.
Definition: unit.hpp:988
const std::string & type_id() const
The id of this unit&#39;s type.
Definition: unit.hpp:326
bool resting() const
Checks whether this unit is &#39;resting&#39;.
Definition: unit.hpp:1227
attack_itors make_attack_itors(attack_list &atks)
The basic "size" of the unit - flying, small land, large land, etc.
Definition: movetype.hpp:41
std::string image_ellipse() const
Get the unit&#39;s ellipse image.
Definition: unit.hpp:1466
bool is_healthy_
Definition: unit.hpp:1793
bool get_emit_zoc() const
Gets the raw zone-of-control flag, disregarding incapacitated.
Definition: unit.hpp:1245
boost::ptr_vector< config > advancements_list
Definition: unit.hpp:281
unit_ability & front()
Definition: unit.hpp:79
void set_interrupted_move(const map_location &interrupted_move)
Set the target location of the unit&#39;s interrupted move.
Definition: unit.hpp:1325
utils::string_map get_base_resistances() const
Gets resistances without any abilities applied.
Definition: unit.hpp:994
bool get_hidden() const
Gets whether this unit is currently hidden on the map.
Definition: unit.hpp:671
int max_hit_points_
Definition: unit.hpp:1727
std::vector< unit_ability > cfgs_
Definition: unit.hpp:92
bool is_healthy() const
Gets whether this unit is healthy - ie, always rest heals.
Definition: unit.hpp:1154
attack_ptr add_attack(attack_itors::iterator position, Args &&... args)
Adds a new attack to the unit.
Definition: unit.hpp:893
unit_type::ALIGNMENT alignment() const
The alignment of this unit.
Definition: unit.hpp:429
static std::string type()
Definition: unit.hpp:1074
int cost() const
How much gold is required to recruit this unit.
Definition: unit.hpp:591
void set_total_movement(int value)
Definition: unit.hpp:1172
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
Definition: unit.hpp:154
double hp_bar_scaling() const
The factor by which the HP bar should be scaled.
Definition: unit.hpp:683
std::string small_profile_
Definition: unit.hpp:1822
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:1555
void set_id(const std::string &id)
Sets this unit&#39;s string ID.
Definition: unit.hpp:349
A single unit type that the player may recruit.
Definition: types.hpp:42
static std::map< std::string, state_t > known_boolean_state_names_
Definition: unit.hpp:1768
std::vector< unit_ability >::iterator iterator
Definition: unit.hpp:69
state_t
Built-in status effects known to the engine.
Definition: unit.hpp:810
map_location loc_
void set_name(const t_string &name)
Sets this unit&#39;s translatable display name.
Definition: unit.hpp:376
std::unique_ptr< unit_formula_manager > formula_man_
Definition: unit.hpp:1747
bool hold_position() const
Whether the unit has been instructed to hold its position.
Definition: unit.hpp:702
void intrusive_ptr_add_ref(const unit *)
Intrusive Pointer interface.
Definition: unit.cpp:214
void set_level(int level)
Sets the current level of this unit.
Definition: unit.hpp:519
const unit_type & type() const
This unit&#39;s type, accounting for gender and variation.
Definition: unit.hpp:315
int vision_cost(const t_translation::terrain_code &terrain) const
Get the unit&#39;s vision cost on a particular terrain.
Definition: unit.hpp:1351
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:495
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
bool poisoned() const
Check if the unit has been poisoned.
Definition: unit.hpp:845
std::string role_
Definition: unit.hpp:1778
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
Definition: parser.cpp:762
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
void set_max_attacks(int value)
Definition: unit.hpp:931
UNIT_ATTRIBUTE
Definition: unit.hpp:119
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:920
struct utils::detail::formula_initer init
const std::string & id() const
Gets this unit&#39;s id.
Definition: unit.hpp:343
void swap(unit &lhs, unit &rhs)
Implement non-member swap function for std::swap (calls unit::swap).
Definition: unit.cpp:2733
std::pair< const config *, map_location > unit_ability
Definition: unit.hpp:48
unit_ability_list(const map_location &loc=map_location())
Definition: unit.hpp:53
const unit_ability & front() const
Definition: unit.hpp:80
bool get_attr_changed(UNIT_ATTRIBUTE attr) const
Definition: unit.hpp:147
std::string profile_
Definition: unit.hpp:1821
int max_movement_
Definition: unit.hpp:1750
std::vector< unit_ability >::const_iterator const_iterator
Definition: unit.hpp:70
const config & recall_filter() const
Gets the filter constraints upon which units this unit may recall, if able.
Definition: unit.hpp:609
void set_max_experience(int value)
Definition: unit.hpp:488
void set_recall_cost(int recall_cost)
Sets the cost of recalling this unit.
Definition: unit.hpp:603
const_iterator end() const
Definition: unit.hpp:75
upkeep_t upkeep_raw() const
Gets the raw variant controlling the upkeep value.
Definition: unit.hpp:1133
const t_string & name() const
Gets this unit&#39;s translatable display name.
Definition: unit.hpp:366
static unit_ptr create(const unit_type &t, int side, bool real_unit, unit_race::GENDER gender=unit_race::NUM_GENDERS)
Initializes a unit from a unit type.
Definition: unit.hpp:166
unit_ptr shared_from_this()
Definition: unit.hpp:178
std::vector< std::string > advances_to_t
Definition: unit.hpp:197
int max_experience() const
The max number of experience points this unit can have.
Definition: unit.hpp:483
const map_location & get_goto() const
The map location to which this unit is moving over multiple turns, if any.
Definition: unit.hpp:1289
Object which temporarily resets a unit&#39;s movement.
Definition: unit.hpp:1858
int level() const
The current level of this unit.
Definition: unit.hpp:513
int max_experience_
Definition: unit.hpp:1729
void set_alignment(unit_type::ALIGNMENT alignment)
Sets the alignment of this unit.
Definition: unit.hpp:435
const std::vector< t_string > & trait_names() const
Gets the names of the currently registered traits.
Definition: unit.hpp:1028
const std::vector< std::string > & overlays() const
Get the unit&#39;s overlay images.
Definition: unit.hpp:1500
const t_string & type_name() const
Gets the translatable name of this unit&#39;s type.
Definition: unit.hpp:332
The unit has not moved.
Definition: unit.hpp:815
std::bitset< UA_COUNT > changed_attributes_
Definition: unit.hpp:1826
unit_race::GENDER gender_
Definition: unit.hpp:1745
const config & get_modifications() const
Set the raw modifications.
Definition: unit.hpp:1386
int attacks_left(bool base_value) const
Gets the remaining number of attacks this unit can perform this turn.
Definition: unit.hpp:954
int hit_points_
Definition: unit.hpp:1726
void set_hitpoints(int hp)
Sets the current hitpoint amount.
Definition: unit.hpp:471
static const ::config * terrain
The terrain used to create the cache.
Definition: minimap.cpp:130
std::unique_ptr< std::string > ellipse_
Definition: unit.hpp:1814
bool random_traits_
Definition: unit.hpp:1816
void set_attr_changed(UNIT_ATTRIBUTE attr)
Definition: unit.hpp:142
std::string get_checksum(const unit &u)
Gets a checksum for a unit.
Definition: unit.cpp:2635
std::string flag_rgb
config abilities_
Definition: unit.hpp:1806
std::vector< std::string > overlays_
Definition: unit.hpp:1776
Encapsulates the map of the game.
Definition: location.hpp:42
void set_unrenamable(bool unrenamable)
Sets the &#39;unrenamable&#39; flag.
Definition: unit.hpp:407
std::pair< int, map_location > lowest(const std::string &key, int def=0) const
Definition: unit.hpp:60
bool hidden_
Definition: unit.hpp:1802
bool user_end_turn() const
Check whether the user ended their turn.
Definition: unit.hpp:743
const advancements_list & modification_advancements() const
The raw, unparsed data for modification advancements.
Definition: unit.hpp:283
bool has_moved() const
Checks if this unit has moved.
Definition: unit.hpp:1213
movetype movement_type_
Definition: unit.hpp:1754
int jamming_cost(const t_translation::terrain_code &terrain) const
Get the unit&#39;s jamming cost on a particular terrain.
Definition: unit.hpp:1361
config filter_recall_
Definition: unit.hpp:1772
int max_attacks_
Definition: unit.hpp:1761
unit_animation_component & anim_comp() const
Definition: unit.hpp:1445
void set_undead_variation(const std::string &value)
The ID of the undead variation (ie, dwarf, swimmer) of this unit.
Definition: unit.hpp:532
void set_attacks(int left)
Sets the number of attacks this unit has left this turn.
Definition: unit.hpp:963
int max_hitpoints() const
The max number of hitpoints this unit can have.
Definition: unit.hpp:459
Visitor helper class to fetch the appropriate upkeep value.
Definition: unit.hpp:1083
const std::string & get_role() const
Gets this unit&#39;s role.
Definition: unit.hpp:620
map_location interrupted_move_
Definition: unit.hpp:1791
bool advances() const
Checks whether this unit is eligible for level-up.
Definition: unit.hpp:242
void set_emit_zoc(bool val)
Sets the raw zone-of-control flag.
Definition: unit.hpp:1251
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
Definition: unit.hpp:570
iterator begin()
Definition: unit.hpp:72
std::string usage() const
Gets this unit&#39;s usage.
Definition: unit.hpp:637
bool canrecruit_
Definition: unit.hpp:1734
attack_itors attacks()
Gets an iterator over this unit&#39;s attacks.
Definition: unit.hpp:876
int experience_
Definition: unit.hpp:1728
std::unique_ptr< std::string > usage_
Definition: unit.hpp:1812
int operator()(const upkeep_full &) const
Full upkeep equals the unit&#39;s level.
Definition: unit.hpp:1089
n_unit::unit_id underlying_id_
Definition: unit.hpp:1721
double xp_bar_scaling_
Definition: unit.hpp:1803
bool has_goto() const
Gets whether this unit has a multi-turn destination set.
Definition: unit.hpp:1283
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:44
t_string description_
Definition: unit.hpp:1810
const unit_race * race() const
Gets this unit&#39;s race.
Definition: unit.hpp:447
int attacks_left_
Definition: unit.hpp:1760
void heal_fully()
Fully heal the unit, restoring it to max hitpoints.
Definition: unit.hpp:782
boost::variant< upkeep_full, upkeep_loyal, int > upkeep_t
Definition: unit.hpp:1126
void set_max_hitpoints(int value)
Definition: unit.hpp:464
void set_goto(const map_location &new_goto)
Sets this unit&#39;s long term destination.
Definition: unit.hpp:1295
The unit cannot be healed.
Definition: unit.hpp:816
std::unique_ptr< std::string > halo_
Definition: unit.hpp:1813
std::enable_if_t<!std::is_same< int, T >::value, std::string > operator()(T &) const
Definition: unit.hpp:1114
std::shared_ptr< attack_type > attack_ptr
Definition: ptr.hpp:36
const_iterator begin() const
Definition: unit.hpp:73
advancements_list advancements_
Definition: unit.hpp:1808
const std::vector< std::string > & recruits() const
The type IDs of the other units this unit may recruit, if possible.
Definition: unit.hpp:582
double xp_bar_scaling() const
The factor by which the XP bar should be scaled.
Definition: unit.hpp:692
void set_role(const std::string &role)
Sets a unit&#39;s role.
Definition: unit.hpp:626
long ref_count_
Definition: unit.hpp:1703
std::unique_ptr< unit_animation_component > anim_comp_
Definition: unit.hpp:1800
const std::string & undead_variation() const
Definition: unit.hpp:537
static std::string type()
Definition: unit.hpp:1079
std::string image_halo() const
Get the unit&#39;s halo image.
Definition: unit.hpp:1457
unit_formula_manager & formula_manager() const
Get the unit formula manager.
Definition: unit.hpp:1659
const_attack_itors attacks() const
Const overload of attacks.
Definition: unit.hpp:882
Definition: display.hpp:44
boost::intrusive_ptr< unit > unit_ptr
Definition: ptr.hpp:29
int movement_
Definition: unit.hpp:1749
static const std::set< std::string > builtin_effects
Definition: unit.hpp:1418
bool is_fearless() const
Gets whether this unit is fearless - ie, unaffected by time of day.
Definition: unit.hpp:1148
void toggle_hold_position()
Toggle the unit&#39;s hold position status.
Definition: unit.hpp:710
double t
Definition: astarsearch.cpp:64
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:501
int experience() const
The current number of experience points this unit has.
Definition: unit.hpp:477
upkeep_t upkeep_
Definition: unit.hpp:1819
bool unrenamable_
Definition: unit.hpp:1741
int level_
Definition: unit.hpp:1731
lu_byte left
Definition: lparser.cpp:1026
const map_location & get_location() const
The current map location this unit is at.
Definition: unit.hpp:1258
std::bitset< num_bool_states > known_boolean_states_
Definition: unit.hpp:1767
int movement_left(bool base_value) const
Gets how far a unit can move.
Definition: unit.hpp:1195
void set_upkeep(upkeep_t v)
Sets the upkeep value to a specific value value.
Definition: unit.hpp:1139
bool appearance_changed() const
Definition: unit.hpp:1700
A variable-expanding proxy for the config class.
Definition: variable.hpp:42
void adjust_profile(std::string &profile)
Definition: types.cpp:1527
bool can_advance() const
Checks whether this unit has any options to advance to.
Definition: unit.hpp:231
const unit_race * race_
Never nullptr, but may point to the null race.
Definition: unit.hpp:1717
std::string variation_
Definition: unit.hpp:1724
t_string unit_description() const
A detailed description of this unit.
Definition: unit.hpp:413
void set_side(unsigned int new_side)
Sets the side this unit belongs to.
Definition: unit.hpp:309
bool emit_zoc_
Definition: unit.hpp:1774
bool incapacitated() const
Check if the unit has been petrified.
Definition: unit.hpp:854
std::map< map_location, bool > invisibility_cache_
Hold the visibility status cache for a unit, when not uncovered.
Definition: unit.hpp:1835
int operator()(const upkeep_loyal &) const
Loyal units cost no upkeep.
Definition: unit.hpp:1095
int total_movement() const
The maximum moves this unit has.
Definition: unit.hpp:1167
const map_location goto_
Definition: move.cpp:309
void set_resting(bool rest)
Sets this unit&#39;s resting status.
Definition: unit.hpp:1233
std::string id_
Definition: unit.hpp:1719
void clear_visibility_cache() const
Clears the cache.
Definition: unit.hpp:1843
bool emits_zoc() const
Tests whether the unit has a zone-of-control, considering incapacitated.
Definition: unit.hpp:1239
int side() const
The side this unit belongs to.
Definition: unit.hpp:303
std::vector< t_string > trait_descriptions_
Definition: unit.hpp:1788
map_location loc_
Definition: unit.hpp:93
bool resting_
Definition: unit.hpp:1758
long ref_count() const
Definition: unit.hpp:1691
boost::iterator_range< boost::indirect_iterator< attack_list::const_iterator > > const_attack_itors
config & get_modifications()
Get the raw modifications.
Definition: unit.hpp:1380
Visitor helper struct to fetch the upkeep type flag if applicable, or the the value otherwise...
Definition: unit.hpp:1110
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
bool slowed() const
Check if the unit has been slowed.
Definition: unit.hpp:863
map_location loc_
Definition: unit.hpp:1706
std::shared_ptr< const attack_type > const_attack_ptr
Definition: ptr.hpp:37
void toggle_user_end_turn()
Toggle whether the user ended their turn.
Definition: unit.hpp:731
upkeep_value_visitor(const unit &unit)
Definition: unit.hpp:1086
const advances_to_t & advances_to() const
Gets the possible types this unit can advance to on level-up.
Definition: unit.hpp:203
bool unrenamable() const
Whether this unit can be renamed.
Definition: unit.hpp:399
int recall_cost() const
How much gold it costs to recall this unit.
Definition: unit.hpp:597
int side_
Definition: unit.hpp:1743
std::string::const_iterator iterator
Definition: tokenizer.hpp:24
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
Definition: unit.hpp:1183
std::size_t underlying_id() const
This unit&#39;s unique internal ID.
Definition: unit.hpp:355
iterator end()
Definition: unit.hpp:74
int max_attacks() const
The maximum number of attacks this unit may perform per turn, usually 1.
Definition: unit.hpp:926
bool end_turn_
Definition: unit.hpp:1757
std::pair< int, map_location > highest(const std::string &key, int def=0) const
Definition: unit.hpp:56
unit_ability_list get_abilities(const std::string &tag_name, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
Gets the unit&#39;s active abilities of a particular type.
Definition: unit.hpp:1573
std::set< std::string > states_
Definition: unit.hpp:1763
std::string undead_variation_
Definition: unit.hpp:1723
const map_location & get_interrupted_move() const
Get the target location of the unit&#39;s interrupted move.
Definition: unit.hpp:1319
const std::vector< t_string > & trait_descriptions() const
Gets the descriptions of the currently registered traits.
Definition: unit.hpp:1038
unit_ability & back()
Definition: unit.hpp:81