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