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