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