The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
unit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 /** @file */
16 
17 #ifndef UNIT_H_INCLUDED
18 #define UNIT_H_INCLUDED
19 
20 #include <boost/tuple/tuple.hpp>
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/ptr_container/ptr_vector.hpp>
23 #include <boost/variant.hpp>
24 
25 #include "units/types.hpp"
26 #include "units/ptr.hpp"
27 #include "units/id.hpp"
28 
29 class display;
30 class gamemap;
31 #if defined(_MSC_VER) && _MSC_VER <= 1600
32 /*
33  This is needed because msvc up to 2010 fails to correcty forward declare this struct as a return value this case.
34  And will create corrupt binaries without giving a warning / error.
35 */
36 #include <SDL_video.h>
37 #else
38 struct SDL_Color;
39 #endif
40 class team;
43 class vconfig;
44 
45 /// The things contained within a unit_ability_list.
46 typedef std::pair<const config *, map_location> unit_ability;
47 namespace unit_detail {
48  template<typename T> const T& get_or_default(const boost::scoped_ptr<T>& v)
49  {
50  if(v) {
51  return *v;
52  }
53  else {
54  static const T def;
55  return def;
56  }
57  }
58 }
60 {
61 public:
63  cfgs_()
64  {
65  }
66 
67  // Implemented in unit_abilities.cpp:
68  std::pair<int,map_location> highest(const std::string& key, int def=0) const;
69  std::pair<int,map_location> lowest(const std::string& key, int def=0) const;
70 
71  // The following make this class usable with standard library algorithms and such:
73  typedef std::vector<unit_ability>::const_iterator const_iterator;
74  iterator begin() { return cfgs_.begin(); }
75  const_iterator begin() const { return cfgs_.begin(); }
76  iterator end() { return cfgs_.end(); }
77  const_iterator end() const { return cfgs_.end(); }
78 
79  // Vector access:
80  bool empty() const { return cfgs_.empty(); }
81  unit_ability & front() { return cfgs_.front(); }
82  const unit_ability & front() const { return cfgs_.front(); }
83  unit_ability & back() { return cfgs_.back(); }
84  const unit_ability & back() const { return cfgs_.back(); }
85 
86  iterator erase(const iterator & erase_it) { return cfgs_.erase(erase_it); }
87  void push_back(const unit_ability & ability) { cfgs_.push_back(ability); }
88 
89 private:
90  // Data:
91  std::vector<unit_ability> cfgs_;
92 };
93 
94 
95 class unit
96 {
97 public:
98  /**
99  * Clear the unit status cache for all units. Currently only the hidden
100  * status of units is cached this way.
101  */
102  static void clear_status_caches();
103 
104  /** The path to the leader crown overlay. */
105  static const std::string& leader_crown();
106 
107  // Copy constructor
108  unit(const unit& u);
109 
110  /** Initializes a unit from a config */
111  explicit unit(
112  const config& cfg
113  , bool use_traits = false
114  , const vconfig* vcfg = nullptr
115  , n_unit::id_manager* id_manager = nullptr);
116 
117  /**
118  * Initializes a unit from a unit type
119  * only real_unit may have random traits, name and gender
120  * (to prevent OOS caused by RNG calls)
121  */
122  unit(const unit_type& t, int side, bool real_unit,
124  virtual ~unit();
125 
126  void swap (unit &);
127 
128  unit& operator=(unit);
129 
130 
131  /** Advances this unit to another type */
132  void advance_to(const unit_type &t, bool use_traits = false);
133  const std::vector<std::string>& advances_to() const { return advances_to_; }
134  const std::vector<std::string> advances_to_translated() const;
135  void set_advances_to(const std::vector<std::string>& advances_to);
136 
137  /**
138  * The id of the type of the unit.
139  * If you are dealing with creating units (e.g. recruitment), this is not what
140  * you want, as a variation can change this; use type().base_id() instead.
141  */
142  const std::string& type_id() const { return type_->id(); }
143  /** The type of the unit (accounting for gender and variation). */
144  const unit_type& type() const { return *type_; }
145 
146  /** id assigned by wml */
147  void set_id(const std::string& id) { id_ = id; }
148  const std::string& id() const { if (id_.empty()) return type_name(); else return id_; }
149  /** The unique internal ID of the unit */
150  size_t underlying_id() const { return underlying_id_.value; }
151 
152  /** The unit type name */
153  const t_string& type_name() const {return type_name_;}
155  const std::string& variation() const {return variation_; }
156 
157  /** The unit name for display */
158  const t_string &name() const { return name_; }
159  void set_name(const t_string &name) { name_ = name; }
160  void rename(const std::string& name) {if (!unrenamable_) name_= name;}
161 
162  /** The unit's profile */
163  std::string small_profile() const;
164  std::string big_profile() const;
165  /** Information about the unit -- a detailed description of it */
167 
168  int hitpoints() const { return hit_points_; }
169  int max_hitpoints() const { return max_hit_points_; }
170  void set_hitpoints(int hp) { hit_points_ = hp; }
171  int experience() const { return experience_; }
172  int max_experience() const { return max_experience_; }
173  void set_experience(int xp) { experience_ = xp; }
175  int level() const { return level_; }
176  void set_level(int level) { level_ = level; }
177  int recall_cost() const { return recall_cost_; }
178  void remove_movement_ai();
179  void remove_attacks_ai();
180 
181  /** Colors for the unit's *current* hitpoints.
182  * @returns a color between green and red representing
183  * how wounded the unit is.
184  * The maximum_hitpoints are considered as base.
185  */
186  SDL_Color hp_color() const;
187  /** Colors for the unit's hitpoints.
188  * @param hitpoints the amount of hitpoints the color represents.
189  * @returns the color considering the current hitpoints as base.
190  */
191  SDL_Color hp_color(int hitpoints) const;
192  /** Colors for the unit's XP. */
193  SDL_Color xp_color() const;
194 
195  double hp_bar_scaling() const { return hp_bar_scaling_; }
196  double xp_bar_scaling() const { return xp_bar_scaling_; }
197 
198  /** Set to true for some scenario-specific units which should not be renamed */
199  bool unrenamable() const { return unrenamable_; }
201  int side() const { return side_; }
202  const std::string& team_color() const { return flag_rgb_; }
203  unit_race::GENDER gender() const { return gender_; }
204  void set_side(unsigned int new_side) { side_ = new_side; }
205  fixed_t alpha() const { return alpha_; }
206 
207  bool can_recruit() const { return canrecruit_; }
208  void set_can_recruit(bool canrecruit) { canrecruit_ = canrecruit; }
209  const std::vector<std::string>& recruits() const
210  { return recruit_list_; }
211  void set_recruits(const std::vector<std::string>& recruits);
212  const config& recall_filter() const { return filter_recall_; }
213 
214  bool poisoned() const { return get_state(STATE_POISONED); }
215  bool incapacitated() const { return get_state(STATE_PETRIFIED); }
216  bool slowed() const { return get_state(STATE_SLOWED); }
217 
218  int total_movement() const { return max_movement_; }
219  /// Returns how far a unit can move this turn (zero if incapacitated).
220  int movement_left() const { return (movement_ == 0 || incapacitated()) ? 0 : movement_; }
221  /// Providing a true parameter to movement_left() causes it to ignore incapacitation.
222  int movement_left(bool base_value) const { return base_value ? movement_ : movement_left(); }
223  int vision() const { return vision_ < 0 ? max_movement_ : vision_; }
224  int jamming() const { return jamming_; }
226  bool hold_position() const { return hold_position_; }
227  void set_user_end_turn(bool value=true) { end_turn_ = value; }
229  bool user_end_turn() const { return end_turn_; }
230  int attacks_left() const { return (attacks_left_ == 0 || incapacitated()) ? 0 : attacks_left_; }
231  int max_attacks() const { return max_attacks_; }
232  void set_movement(int moves, bool unit_action=false);
233  void set_attacks(int left) { attacks_left_ = std::max<int>(0, left); }
234  void new_turn();
235  void end_turn();
236  void new_scenario();
237  /** Called on every draw */
238 
239  bool take_hit(int damage) { hit_points_ -= damage; return hit_points_ <= 0; }
240  void heal(int amount);
242  bool resting() const { return resting_; }
243  void set_resting(bool rest) { resting_ = rest; }
244 
245  const std::map<std::string,std::string> get_states() const;
246  bool get_state(const std::string& state) const;
247  void set_state(const std::string &state, bool value);
250  void set_state(state_t state, bool value);
251  bool get_state(state_t state) const;
252  static state_t get_known_boolean_state_id(const std::string &state);
253  static std::map<std::string, state_t> get_known_boolean_state_names();
254 
255  bool has_moved() const { return movement_left() != total_movement(); }
256  bool has_goto() const { return get_goto().valid(); }
257  bool emits_zoc() const { return emit_zoc_ && !incapacitated();}
258  bool matches_id(const std::string& unit_id) const;
259  /* cfg: standard unit filter */
260  const std::vector<std::string>& overlays() const { return overlays_; }
261 
262  void write(config& cfg) const;
263 
264  void set_role(const std::string& role) { role_ = role; }
265  const std::string &get_role() const { return role_; }
266 
267  void set_emit_zoc(bool val) { emit_zoc_ = val; }
268  bool get_emit_zoc() const { return emit_zoc_; }
269 
270 
271  const std::vector<attack_type>& attacks() const { return attacks_; }
272  std::vector<attack_type>& attacks() { return attacks_; }
273 
274  int damage_from(const attack_type& attack,bool attacker,const map_location& loc) const { return resistance_against(attack,attacker,loc); }
275 
277  void set_facing(map_location::DIRECTION dir) const;
279 
280  const std::vector<t_string>& trait_names() const { return trait_names_; }
281  const std::vector<t_string>& trait_descriptions() const { return trait_descriptions_; }
282  std::vector<std::string> get_traits_list() const;
283 
284  int cost () const { return unit_value_; }
285 
286  const map_location &get_location() const { return loc_; }
287  /** To be called by unit_map or for temporary units only. */
288  void set_location(const map_location &loc) { loc_ = loc; }
289 
290  const map_location& get_goto() const { return goto_; }
291  void set_goto(const map_location& new_goto) { goto_ = new_goto; }
292 
293  int upkeep() const;
294 
295  struct upkeep_full {};
296  struct upkeep_loyal {};
297  typedef boost::variant<upkeep_full, upkeep_loyal, int> t_upkeep;
298 
299  t_upkeep upkeep_raw() const { return upkeep_; }
300  void set_upkeep(t_upkeep v) { upkeep_ = v; }
301  bool loyal() const;
302 
303  void set_hidden(bool state) const;
304  bool get_hidden() const { return hidden_; }
305  bool is_flying() const { return movement_type_.is_flying(); }
306  bool is_fearless() const { return is_fearless_; }
307  bool is_healthy() const { return is_healthy_; }
309  { return movement_type_.movement_cost(terrain, get_state(STATE_SLOWED)); }
311  { return movement_type_.vision_cost(terrain, get_state(STATE_SLOWED)); }
313  { return movement_type_.jamming_cost(terrain, get_state(STATE_SLOWED)); }
315  int resistance_against(const std::string& damage_name,bool attacker,const map_location& loc) const;
316  int resistance_against(const attack_type& damage_type,bool attacker,const map_location& loc) const
317  { return resistance_against(damage_type.type(), attacker, loc); }
318 
319  //return resistances without any abilities applied
321  const movetype & movement_type() const { return movement_type_; }
322 
323  bool can_advance() const { return advances_to_.empty()==false || get_modification_advances().empty() == false; }
324  bool advances() const { return experience_ >= max_experience() && can_advance(); }
325 
326  std::map<std::string,std::string> advancement_icons() const;
327  std::vector<std::pair<std::string,std::string> > amla_icons() const;
328 
329  std::vector<config> get_modification_advances() const;
330 
331  typedef boost::ptr_vector<config> t_advancements;
332  void set_advancements(std::vector<config> advancements);
333  const t_advancements& modification_advancements() const
334  { return advancements_; }
335 
336  size_t modification_count(const std::string& type, const std::string& id) const;
337 
338  void add_modification(const std::string& type, const config& modification,
339  bool no_add=false);
340  void expire_modifications(const std::string & duration);
341 
342  static const std::set<std::string> builtin_effects;
343  void apply_builtin_effect(std::string type, const config& effect);
345 
346  bool move_interrupted() const { return movement_left() > 0 && interrupted_move_.x >= 0 && interrupted_move_.y >= 0; }
348  void set_interrupted_move(const map_location& interrupted_move) { interrupted_move_ = interrupted_move; }
349 
350  /** The name of the file to game_display (used in menus). */
351  std::string absolute_image() const;
352 
353  /** The default image to use for animation frames with no defined image. */
355 
357 
359 
361 
362  void set_image_halo(const std::string& halo);
363  void set_image_ellipse(const std::string& ellipse) { ellipse_.reset(new std::string(ellipse)); }
364  void set_usage(const std::string& usage) { usage_.reset(new std::string(usage)); }
365 
366  config &variables() { return variables_; }
367  const config &variables() const { return variables_; }
368  unit_type::ALIGNMENT alignment() const { return alignment_; }
369  void set_alignment(unit_type::ALIGNMENT alignment) { alignment_ = alignment; }
370  /// Never returns nullptr, but may point to the null race.
371  const unit_race* race() const { return race_; }
372 
373 
374  /**
375  * Returns true if the unit is currently under effect by an ability with this given TAG NAME.
376  * This means that the ability could be owned by the unit itself, or by an adjacent unit.
377  */
378  bool get_ability_bool(const std::string& tag_name, const map_location& loc) const;
379  /**
380  * Returns true if the unit is currently under effect by an ability with this given TAG NAME.
381  * This means that the ability could be owned by the unit itself, or by an adjacent unit.
382  */
383  bool get_ability_bool(const std::string &tag_name) const
384  { return get_ability_bool(tag_name, loc_); }
385  unit_ability_list get_abilities(const std::string &tag_name, const map_location& loc) const;
387  { return get_abilities(tag_name, loc_); }
388  /** Tuple of: neutral ability name, gendered ability name, description */
389  std::vector<boost::tuple<t_string,t_string,t_string> > ability_tooltips(std::vector<bool> *active_list=nullptr) const;
390  std::vector<std::string> get_ability_list() const;
391  bool has_ability_type(const std::string& ability) const;
392 
394 
395  void backup_state();
396  void apply_modifications();
397  void generate_traits(bool musthaveonly=false);
398  void generate_name();
399 
400  // Only see_all=true use caching
401  bool invisible(const map_location& loc, bool see_all=true) const;
402 
403  bool is_visible_to_team(team const& team, gamemap const & map , bool const see_all = true) const;
404 
405  /** Mark this unit as clone so it can be inserted to unit_map
406  * @returns self (for convenience)
407  **/
408  unit& clone(bool is_temporary=true);
409 
410  std::string TC_image_mods() const;
411  const std::string& effect_image_mods() const;
412  std::string image_mods() const;
413 
414  long ref_count() const { return ref_count_; }
415  friend void intrusive_ptr_add_ref(const unit *);
416  friend void intrusive_ptr_release(const unit *);
417 protected:
418  mutable long ref_count_; //used by intrusive_ptr
419 private:
420  /*
421  * cfg: an ability WML structure
422  */
423  bool ability_active(const std::string& ability,const config& cfg,const map_location& loc) const;
424  bool ability_affects_adjacent(const std::string& ability,const config& cfg,int dir,const map_location& loc,const unit& from) const;
425  bool ability_affects_self(const std::string& ability,const config& cfg,const map_location& loc) const;
426  bool resistance_filter_matches(const config& cfg,bool attacker,const std::string& damage_name, int res) const;
427 
428 public:
429  bool has_ability_by_id(const std::string& ability) const;
430  // ^ Needed for unit_filter
431 private:
432  void remove_ability_by_id(const std::string& ability);
433 
434  /** register a trait's name and its description for UI's use*/
435  void add_trait_description(const config& trait, const t_string& description);
436 
437  void set_underlying_id(n_unit::id_manager& id_manager);
438 
439 private:
441 
442  std::vector<std::string> advances_to_;
443  const unit_type * type_;/// Never nullptr. Adjusted for gender and variation.
444  t_string type_name_; /// The displayed name of the unit type.
445  const unit_race* race_; /// Never nullptr, but may point to the null race.
451 
456 
457  int level_;
458 
461  std::vector<std::string> recruit_list_;
462  unit_type::ALIGNMENT alignment_;
465 
467 
468  int side_;
469 
471 
473 
474  boost::scoped_ptr<unit_formula_manager> formula_man_;
475 
478  int vision_;
479  int jamming_;
482  bool end_turn_;
483  bool resting_;
486 
487  std::set<std::string> states_;
488  std::vector<bool> known_boolean_states_;
489  static std::map<std::string, state_t> known_boolean_state_names_;
493 
494  bool emit_zoc_;
495 
496  std::vector<std::string> overlays_;
497 
499  std::vector<attack_type> attacks_;
500 protected:
501  mutable map_location::DIRECTION facing_; //TODO: I think we actually consider this to be part of the gamestate, so it might be better if it's not mutable
502  //But it's not easy to separate this guy from the animation code right now.
503 private:
504  std::vector<t_string> trait_names_;
505  std::vector<t_string> trait_descriptions_;
506 
509 
511 
513  // Animations:
515 
516 private:
517  boost::scoped_ptr<unit_animation_component> anim_comp_;
518 
519  bool getsHit_;
520  mutable bool hidden_;
522 
525  t_advancements advancements_;
527  boost::scoped_ptr<std::string> usage_;
528  boost::scoped_ptr<std::string> halo_;
529  boost::scoped_ptr<std::string> ellipse_;
532  t_upkeep upkeep_;
535  //TODO add a to initializer list.
538  /**
539  * Hold the visibility status cache for a unit, when not uncovered.
540  * This is mutable since it is a cache.
541  */
542  mutable std::map<map_location, bool> invisibility_cache_;
543 
544  /**
545  * Clears the cache.
546  *
547  * Since we don't change the state of the object we're marked const (also
548  * required since the objects in the cache need to be marked const).
549  */
550  void clear_visibility_cache() const { invisibility_cache_.clear(); }
551 };
552 
553 /**
554  * Object which temporarily resets a unit's movement.
555  *
556  * @warning
557  * The unit whose movement is reset may not be deleted while a
558  * @ref unit_movement_resetter object 'holds'. So best use it only in a small
559  * scope.
560  */
562  : private boost::noncopyable
563 {
564  unit_movement_resetter(unit& u, bool operate=true);
566 
567 private:
569  int moves_;
570 };
571 
572 /**
573  * Gets a checksum for a unit.
574  *
575  * In MP games the descriptions are locally generated and might differ, so it
576  * should be possible to discard them. Not sure whether replays suffer the
577  * same problem.
578  *
579  * @param u the unit
580  *
581  * @returns the checksum for a unit
582  */
583 std::string get_checksum(const unit& u);
584 
585 #endif
std::string image_halo() const
Definition: unit.hpp:356
std::string image_mods() const
Definition: unit.cpp:2430
void set_resting(bool rest)
Definition: unit.hpp:243
const std::vector< t_string > & trait_descriptions() const
Definition: unit.hpp:281
bool has_moved() const
Definition: unit.hpp:255
void heal(int amount)
Definition: unit.cpp:1253
static const std::set< std::string > builtin_effects
Definition: unit.hpp:342
int total_movement() const
Definition: unit.hpp:218
void generate_traits(bool musthaveonly=false)
Apply mandatory traits (e.g.
Definition: unit.cpp:827
const unit_type * type_
Definition: unit.hpp:443
void set_unrenamable(bool unrenamable)
Definition: unit.hpp:200
const std::string & id() const
Definition: unit.hpp:148
t_string unit_description() const
Information about the unit – a detailed description of it.
Definition: unit.hpp:166
bool is_visible_to_team(team const &team, gamemap const &map, bool const see_all=true) const
Definition: unit.cpp:2333
t_string type_name_
Never nullptr. Adjusted for gender and variation.
Definition: unit.hpp:444
std::vector< bool > known_boolean_states_
Definition: unit.hpp:488
void apply_builtin_effect(std::string type, const config &effect)
Definition: unit.cpp:1800
const map_location & get_location() const
Definition: unit.hpp:286
bool has_goto() const
Definition: unit.hpp:256
std::vector< std::string > recruit_list_
Definition: unit.hpp:461
void set_usage(const std::string &usage)
Definition: unit.hpp:364
void set_hidden(bool state) const
Definition: unit.cpp:2460
std::string absolute_image() const
The name of the file to game_display (used in menus).
Definition: unit.cpp:2262
bool emits_zoc() const
Definition: unit.hpp:257
void set_user_end_turn(bool value=true)
Definition: unit.hpp:227
const std::string & team_color() const
Definition: unit.hpp:202
config modifications_
Definition: unit.hpp:523
void set_hitpoints(int hp)
Definition: unit.hpp:170
int recall_cost_
Definition: unit.hpp:459
utils::string_map modification_descriptions_
Definition: unit.hpp:512
bool ability_affects_adjacent(const std::string &ability, const config &cfg, int dir, const map_location &loc, const unit &from) const
Definition: abilities.cpp:383
void generate_name()
Definition: unit.cpp:804
unit_movement_resetter(unit &u, bool operate=true)
Definition: unit.cpp:2392
int max_hitpoints() const
Definition: unit.hpp:169
bool get_state(const std::string &state) const
Definition: unit.cpp:1289
void parse_upkeep(const config::attribute_value &upkeep)
Definition: unit.cpp:2475
Definition: unit.hpp:95
void set_id(const std::string &id)
id assigned by wml
Definition: unit.hpp:147
size_t underlying_id() const
The unique internal ID of the unit.
Definition: unit.hpp:150
std::string TC_image_mods() const
Definition: unit.cpp:2423
GLint level
Definition: glew.h:1220
const t_string & name() const
The unit name for display.
Definition: unit.hpp:158
void backup_state()
const t_string & type_name() const
The unit type name.
Definition: unit.hpp:153
int experience() const
Definition: unit.hpp:171
int vision_cost(const t_translation::t_terrain &terrain, bool slowed=false) const
Returns the cost to see through the indicated terrain.
Definition: movetype.hpp:202
bool user_end_turn() const
Definition: unit.hpp:229
std::string image_mods_
Definition: unit.hpp:464
int movement_cost(const t_translation::t_terrain &terrain) const
Definition: unit.hpp:308
double hp_bar_scaling() const
Definition: unit.hpp:195
std::vector< std::string > advances_to_
Definition: unit.hpp:442
t_string name_
Definition: unit.hpp:447
int jamming() const
Definition: unit.hpp:224
void new_scenario()
Definition: unit.cpp:1238
iterator erase(const iterator &erase_it)
Definition: unit.hpp:86
std::vector< config > get_modification_advances() const
Definition: unit.cpp:1630
fixed_t alpha_
Definition: unit.hpp:472
double xp_bar_scaling() const
Definition: unit.hpp:196
std::vector< t_string > trait_names_
Definition: unit.hpp:504
void remove_movement_ai()
Definition: unit.cpp:2451
int vision_
Definition: unit.hpp:478
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
std::vector< boost::tuple< t_string, t_string, t_string > > ability_tooltips(std::vector< bool > *active_list=nullptr) const
Tuple of: neutral ability name, gendered ability name, description.
Definition: abilities.cpp:261
int hitpoints() const
Definition: unit.hpp:168
Sint32 fixed_t
Definition: drawer.hpp:40
bool matches_id(const std::string &unit_id) const
Definition: unit.cpp:2417
int upkeep() const
Definition: unit.cpp:1498
config events_
Definition: unit.hpp:491
void clear_visibility_cache() const
Clears the cache.
Definition: unit.hpp:550
void set_recall_cost(int recall_cost)
Definition: unit.hpp:174
void set_image_halo(const std::string &halo)
Definition: unit.cpp:2467
unit & operator=(unit)
Assignment operator.
Definition: unit.cpp:797
unit_type::ALIGNMENT alignment_
Definition: unit.hpp:462
bool is_fearless_
Definition: unit.hpp:510
map_location::DIRECTION facing_
Definition: unit.hpp:501
std::string flag_rgb_
Definition: unit.hpp:463
const map_location & get_interrupted_move() const
Definition: unit.hpp:347
int jamming_
Definition: unit.hpp:479
std::string usage() const
Definition: unit.hpp:360
int unit_value_
Definition: unit.hpp:507
bool is_healthy() const
Definition: unit.hpp:307
const std::vector< std::string > advances_to_translated() const
Definition: unit.cpp:1121
void toggle_user_end_turn()
Definition: unit.hpp:228
void set_image_ellipse(const std::string &ellipse)
Definition: unit.hpp:363
bool generate_name_
Definition: unit.hpp:531
bool hold_position_
Definition: unit.hpp:481
bool poisoned() const
Definition: unit.hpp:214
bool resistance_filter_matches(const config &cfg, bool attacker, const std::string &damage_name, int res) const
Definition: unit.cpp:1535
GLuint const GLfloat * val
Definition: glew.h:2614
void advance_to(const unit_type &t, bool use_traits=false)
Advances this unit to another type.
Definition: unit.cpp:904
config variables_
Definition: unit.hpp:490
std::pair< int, map_location > highest(const std::string &key, int def=0) const
Definition: abilities.cpp:426
void set_alignment(unit_type::ALIGNMENT alignment)
Definition: unit.hpp:369
int side() const
Definition: unit.hpp:201
void write(config &cfg) const
Definition: unit.cpp:1379
SDL_Color xp_color() const
Colors for the unit's XP.
Definition: unit.cpp:1075
void write_upkeep(config::attribute_value &upkeep) const
Definition: unit.cpp:2496
bool move_interrupted() const
Definition: unit.hpp:346
void set_state(const std::string &state, bool value)
Definition: unit.cpp:1337
int max_attacks() const
Definition: unit.hpp:231
GLsizeiptr const GLvoid GLenum usage
Definition: glew.h:1649
The basic "size" of the unit - flying, small land, large land, etc.
Definition: movetype.hpp:28
bool is_healthy_
Definition: unit.hpp:510
bool get_ability_bool(const std::string &tag_name, const map_location &loc) const
Returns true if the unit is currently under effect by an ability with this given TAG NAME...
Definition: abilities.cpp:129
boost::ptr_vector< config > t_advancements
Definition: unit.hpp:331
void expire_modifications(const std::string &duration)
Clears those modifications whose duration has expired.
Definition: unit.cpp:1180
unit_ability & front()
Definition: unit.hpp:81
GLdouble GLdouble t
Definition: glew.h:1366
int max_hit_points_
Definition: unit.hpp:453
std::string small_profile() const
The unit's profile.
Definition: unit.cpp:1020
std::vector< unit_ability > cfgs_
Definition: unit.hpp:91
int movement_cost(const t_translation::t_terrain &terrain, bool slowed=false) const
Returns the cost to move through the indicated terrain.
Definition: movetype.hpp:199
bool get_hidden() const
Definition: unit.hpp:304
friend void intrusive_ptr_release(const unit *)
Definition: unit.cpp:180
Variant for storing WML attributes.
Definition: config.hpp:223
int defense_modifier(const t_translation::t_terrain &terrain) const
Definition: unit.cpp:1520
std::string small_profile_
Definition: unit.hpp:534
static std::map< std::string, state_t > known_boolean_state_names_
Definition: unit.hpp:489
map_location goto_
Definition: unit.hpp:508
unit(const unit &u)
Definition: unit.cpp:246
std::string describe_builtin_effect(std::string type, const config &effect)
Definition: unit.cpp:1720
std::vector< unit_ability >::iterator iterator
Definition: unit.hpp:72
const map_location & get_goto() const
Definition: unit.hpp:290
const std::vector< std::string > & recruits() const
Definition: unit.hpp:209
t_advancements advancements_
Definition: unit.hpp:525
void apply_modifications()
Definition: unit.cpp:2271
const unit_type & type() const
The type of the unit (accounting for gender and variation).
Definition: unit.hpp:144
int resistance_against(const attack_type &damage_type, bool attacker, const map_location &loc) const
Definition: unit.hpp:316
std::map< std::string, std::string > advancement_icons() const
Definition: unit.cpp:1580
void set_role(const std::string &role)
Definition: unit.hpp:264
const std::string & type_id() const
The id of the type of the unit.
Definition: unit.hpp:142
static void clear_status_caches()
Clear the unit status cache for all units.
Definition: unit.cpp:610
std::string role_
Definition: unit.hpp:498
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
t_upkeep upkeep_
Definition: unit.hpp:532
static const std::string & leader_crown()
The path to the leader crown overlay.
Definition: unit.cpp:234
bool incapacitated() const
Definition: unit.hpp:215
void set_facing(map_location::DIRECTION dir) const
Definition: unit.cpp:1491
boost::variant< upkeep_full, upkeep_loyal, int > t_upkeep
Definition: unit.hpp:297
std::map< std::string, t_string > string_map
void swap(unit &)
Swap, for copy and swap idiom.
Definition: unit.cpp:728
const config & variables() const
Definition: unit.hpp:367
const std::vector< std::string > & overlays() const
Definition: unit.hpp:260
const std::string & undead_variation() const
Definition: unit.hpp:154
unit_type::ALIGNMENT alignment() const
Definition: unit.hpp:368
bool valid() const
Definition: location.hpp:69
const_iterator begin() const
Definition: unit.hpp:75
void set_emit_zoc(bool val)
Definition: unit.hpp:267
std::string profile_
Definition: unit.hpp:533
int max_movement_
Definition: unit.hpp:477
bool advances() const
Definition: unit.hpp:324
std::vector< unit_ability >::const_iterator const_iterator
Definition: unit.hpp:73
const GLdouble * v
Definition: glew.h:1359
GLsizei const GLfloat * value
Definition: glew.h:1817
void set_can_recruit(bool canrecruit)
Definition: unit.hpp:208
void heal_all()
Definition: unit.hpp:241
int vision_cost(const t_translation::t_terrain &terrain) const
Definition: unit.hpp:310
void set_recruits(const std::vector< std::string > &recruits)
Definition: unit.cpp:1112
void rename(const std::string &name)
Definition: unit.hpp:160
size_t value
Definition: id.hpp:30
void add_trait_description(const config &trait, const t_string &description)
register a trait's name and its description for UI's use
Definition: unit.cpp:2249
Encapsulates the map of the game.
Definition: map.hpp:37
state_t
Definition: unit.hpp:248
bool can_recruit() const
Definition: unit.hpp:207
bool ability_affects_self(const std::string &ability, const config &cfg, const map_location &loc) const
Definition: abilities.cpp:411
const t_advancements & modification_advancements() const
Definition: unit.hpp:333
unit_race::GENDER gender() const
Definition: unit.hpp:203
std::string image_ellipse() const
Definition: unit.hpp:358
Object which temporarily resets a unit's movement.
Definition: unit.hpp:561
int max_experience_
Definition: unit.hpp:455
fixed_t alpha() const
Definition: unit.hpp:205
unit_animation_component & anim_comp() const
Definition: unit.hpp:276
int damage_from(const attack_type &attack, bool attacker, const map_location &loc) const
Definition: unit.hpp:274
unit_race::GENDER gender_
Definition: unit.hpp:470
boost::scoped_ptr< unit_animation_component > anim_comp_
Definition: unit.hpp:517
bool has_ability_type(const std::string &ability) const
Definition: abilities.cpp:419
bool is_flying() const
Returns whether or not *this is flagged as a flying movement type.
Definition: movetype.hpp:194
int hit_points_
Definition: unit.hpp:452
int movement_left() const
Returns how far a unit can move this turn (zero if incapacitated).
Definition: unit.hpp:220
static const ::config * terrain
The terrain used to create the cache.
Definition: minimap.cpp:135
boost::scoped_ptr< std::string > halo_
Definition: unit.hpp:528
const T & get_or_default(const boost::scoped_ptr< T > &v)
Definition: unit.hpp:48
bool random_traits_
Definition: unit.hpp:530
const std::string & type() const
Definition: attack_type.hpp:37
const std::vector< attack_type > & attacks() const
Definition: unit.hpp:271
long ref_count() const
Definition: unit.hpp:414
bool invisible(const map_location &loc, bool see_all=true) const
Definition: unit.cpp:2291
utils::string_map damage_table() const
Returns a map from attack types to resistances.
Definition: movetype.hpp:219
bool is_flying() const
Definition: unit.hpp:305
const std::string &parameters float amount
Definition: filter.cpp:132
std::string get_checksum(const unit &u)
Gets a checksum for a unit.
Definition: unit.cpp:2511
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:47
boost::scoped_ptr< std::string > usage_
Definition: unit.hpp:527
config abilities_
Definition: unit.hpp:524
std::vector< std::string > overlays_
Definition: unit.hpp:496
Encapsulates the map of the game.
Definition: location.hpp:38
bool hidden_
Definition: unit.hpp:520
const unit_ability & front() const
Definition: unit.hpp:82
std::vector< std::pair< std::string, std::string > > amla_icons() const
Definition: unit.cpp:1611
std::string default_anim_image() const
The default image to use for animation frames with no defined image.
Definition: unit.cpp:2267
int jamming_cost(const t_translation::t_terrain &terrain) const
Definition: unit.hpp:312
bool empty() const
Definition: unit.hpp:80
movetype movement_type_
Definition: unit.hpp:480
GLuint res
Definition: glew.h:9258
config filter_recall_
Definition: unit.hpp:492
void add_modification(const std::string &type, const config &modification, bool no_add=false)
Definition: unit.cpp:2133
const std::vector< std::string > & advances_to() const
Definition: unit.hpp:133
int max_attacks_
Definition: unit.hpp:485
bool getsHit_
Definition: unit.hpp:519
unit & clone(bool is_temporary=true)
Mark this unit as clone so it can be inserted to unit_map.
Definition: unit.cpp:2368
GLint left
Definition: glew.h:5907
void end_turn()
Definition: unit.cpp:1225
map_location::DIRECTION facing() const
Definition: unit.hpp:278
void remove_attacks_ai()
Definition: unit.cpp:2443
void set_name(const t_string &name)
Definition: unit.hpp:159
config & variables()
Definition: unit.hpp:366
void set_location(const map_location &loc)
To be called by unit_map or for temporary units only.
Definition: unit.hpp:288
const std::map< std::string, std::string > get_states() const
Definition: unit.cpp:1267
size_t modification_count(const std::string &type, const std::string &id) const
Definition: unit.cpp:1695
std::pair< const config *, map_location > unit_ability
The things contained within a unit_ability_list.
Definition: unit.hpp:43
double hp_bar_scaling_
Definition: unit.hpp:521
map_location interrupted_move_
Definition: unit.hpp:508
boost::scoped_ptr< unit_formula_manager > formula_man_
Definition: unit.hpp:474
int attacks_left() const
Definition: unit.hpp:230
bool hold_position() const
Definition: unit.hpp:226
iterator begin()
Definition: unit.hpp:74
bool canrecruit_
Definition: unit.hpp:460
void set_interrupted_move(const map_location &interrupted_move)
Definition: unit.hpp:348
void set_goto(const map_location &new_goto)
Definition: unit.hpp:291
void new_turn()
Definition: unit.cpp:1215
int experience_
Definition: unit.hpp:454
std::vector< attack_type > & attacks()
Definition: unit.hpp:272
bool resting() const
Definition: unit.hpp:242
void set_movement(int moves, bool unit_action=false)
Set the unit's remaining movement to moves.
Definition: unit.cpp:1148
n_unit::unit_id underlying_id_
Definition: unit.hpp:448
const std::string & variation() const
Definition: unit.hpp:155
void set_side(unsigned int new_side)
Definition: unit.hpp:204
double xp_bar_scaling_
Definition: unit.hpp:521
bool slowed() const
Definition: unit.hpp:216
bool loyal() const
Definition: unit.cpp:1515
void set_upkeep(t_upkeep v)
Definition: unit.hpp:300
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:40
int level() const
Definition: unit.hpp:175
bool take_hit(int damage)
Called on every draw.
Definition: unit.hpp:239
t_string description_
Definition: unit.hpp:526
int attacks_left_
Definition: unit.hpp:484
const config & recall_filter() const
Definition: unit.hpp:212
unit_ability_list get_abilities(const std::string &tag_name, const map_location &loc) const
Definition: abilities.cpp:168
const unit_ability & back() const
Definition: unit.hpp:84
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc) const
Definition: unit.cpp:1559
std::string big_profile() const
Definition: unit.cpp:1012
GLuint const GLchar * name
Definition: glew.h:1782
long ref_count_
Definition: unit.hpp:418
const std::string & effect_image_mods() const
Definition: unit.cpp:2439
Definition: display.hpp:43
bool can_advance() const
Definition: unit.hpp:323
std::pair< int, map_location > lowest(const std::string &key, int def=0) const
Definition: abilities.cpp:457
unit_formula_manager & formula_manager() const
Definition: unit.hpp:393
void set_advancements(std::vector< config > advancements)
Definition: unit.cpp:1685
int movement_
Definition: unit.hpp:476
int max_experience() const
Definition: unit.hpp:172
static state_t get_known_boolean_state_id(const std::string &state)
Definition: unit.cpp:1314
const std::vector< t_string > & trait_names() const
Definition: unit.hpp:280
int recall_cost() const
Definition: unit.hpp:177
SDL_Color hp_color() const
Colors for the unit's current hitpoints.
Definition: unit.cpp:1065
boost::scoped_ptr< std::string > ellipse_
Definition: unit.hpp:529
bool get_ability_bool(const std::string &tag_name) const
Returns true if the unit is currently under effect by an ability with this given TAG NAME...
Definition: unit.hpp:383
bool unrenamable_
Definition: unit.hpp:466
int level_
Definition: unit.hpp:457
bool ability_active(const std::string &ability, const config &cfg, const map_location &loc) const
Definition: abilities.cpp:309
bool unrenamable() const
Set to true for some scenario-specific units which should not be renamed.
Definition: unit.hpp:199
std::vector< attack_type > attacks_
Definition: unit.hpp:499
const movetype & movement_type() const
Definition: unit.hpp:321
int cost() const
Definition: unit.hpp:284
A variable-expanding proxy for the config class.
Definition: variable.hpp:36
bool is_fearless() const
Definition: unit.hpp:306
const unit_race * race_
The displayed name of the unit type.
Definition: unit.hpp:445
const_iterator end() const
Definition: unit.hpp:77
std::string variation_
Definition: unit.hpp:450
friend void intrusive_ptr_add_ref(const unit *)
Intrusive Pointer interface.
Definition: unit.cpp:164
bool emit_zoc_
Definition: unit.hpp:494
std::map< map_location, bool > invisibility_cache_
Hold the visibility status cache for a unit, when not uncovered.
Definition: unit.hpp:542
utils::string_map get_base_resistances() const
Definition: unit.hpp:320
void set_attacks(int left)
Definition: unit.hpp:233
static std::map< std::string, state_t > get_known_boolean_state_names()
Definition: unit.cpp:1324
void set_level(int level)
Definition: unit.hpp:176
std::string id_
Never nullptr, but may point to the null race.
Definition: unit.hpp:446
std::vector< t_string > trait_descriptions_
Definition: unit.hpp:505
void push_back(const unit_ability &ability)
Definition: unit.hpp:87
bool resting_
Definition: unit.hpp:483
const std::string & get_role() const
Definition: unit.hpp:265
bool has_ability_by_id(const std::string &ability) const
Definition: unit.cpp:1357
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
bool get_emit_zoc() const
Definition: unit.hpp:268
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
unit_ability_list get_abilities(const std::string &tag_name) const
Definition: unit.hpp:386
map_location loc_
Definition: unit.hpp:440
void remove_ability_by_id(const std::string &ability)
Definition: unit.cpp:1367
void set_experience(int xp)
Definition: unit.hpp:173
const unit_race * race() const
Never returns nullptr, but may point to the null race.
Definition: unit.hpp:371
virtual ~unit()
Definition: unit.cpp:708
void set_underlying_id(n_unit::id_manager &id_manager)
Definition: unit.cpp:2350
void toggle_hold_position()
Definition: unit.hpp:225
std::vector< std::string > get_ability_list() const
Definition: abilities.cpp:210
GLsizei const GLcharARB ** string
Definition: glew.h:4503
int side_
Definition: unit.hpp:468
int jamming_cost(const t_translation::t_terrain &terrain, bool slowed=false) const
Returns the cost to "jam" through the indicated terrain.
Definition: movetype.hpp:205
iterator end()
Definition: unit.hpp:76
const std::string & id() const
The id for this unit_type.
Definition: types.hpp:115
int movement_left(bool base_value) const
Providing a true parameter to movement_left() causes it to ignore incapacitation. ...
Definition: unit.hpp:222
bool end_turn_
Definition: unit.hpp:482
std::set< std::string > states_
Definition: unit.hpp:487
void set_advances_to(const std::vector< std::string > &advances_to)
Definition: unit.cpp:1136
std::string undead_variation_
Definition: unit.hpp:449
t_upkeep upkeep_raw() const
Definition: unit.hpp:299
int vision() const
Definition: unit.hpp:223
unit_ability & back()
Definition: unit.hpp:83
std::vector< std::string > get_traits_list() const
Definition: unit.cpp:883