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