/
unit.hpp
1468 lines (1209 loc) · 36.1 KB
/
unit.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef UNIT_H_INCLUDED
#define UNIT_H_INCLUDED
#include "units/id.hpp"
#include "units/ptr.hpp"
#include "units/types.hpp"
#include <bitset>
#include <boost/dynamic_bitset_fwd.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/variant.hpp>
class display;
class display_context;
class gamemap;
class team;
class unit_animation_component;
class unit_formula_manager;
class vconfig;
struct color_t;
namespace unit_detail
{
template<typename T>
const T& get_or_default(const std::unique_ptr<T>& v)
{
if(v) {
return *v;
} else {
static const T def;
return def;
}
}
}
// Data typedef for unit_ability_list.
using unit_ability = std::pair<const config*, map_location>;
class unit_ability_list
{
public:
unit_ability_list() : cfgs_() {}
// Implemented in unit_abilities.cpp
std::pair<int, map_location> highest(const std::string& key, int def=0) const;
std::pair<int, map_location> lowest(const std::string& key, int def=0) const;
// The following make this class usable with standard library algorithms and such
typedef std::vector<unit_ability>::iterator iterator;
typedef std::vector<unit_ability>::const_iterator const_iterator;
iterator begin() { return cfgs_.begin(); }
const_iterator begin() const { return cfgs_.begin(); }
iterator end() { return cfgs_.end(); }
const_iterator end() const { return cfgs_.end(); }
// Vector access
bool empty() const { return cfgs_.empty(); }
unit_ability& front() { return cfgs_.front(); }
const unit_ability& front() const { return cfgs_.front(); }
unit_ability& back() { return cfgs_.back(); }
const unit_ability& back() const { return cfgs_.back(); }
iterator erase(const iterator& erase_it) { return cfgs_.erase(erase_it); }
void push_back(const unit_ability& ability) { cfgs_.push_back(ability); }
private:
// Data
std::vector<unit_ability> cfgs_;
};
/**
* This class represents a *single* unit of a specific type.
*/
class unit
{
public:
/**
* Clear this unit status cache for all units. Currently only the hidden
* status of units is cached this way.
*/
static void clear_status_caches();
/** The path to the leader crown overlay. */
static const std::string& leader_crown();
/** Initializes a unit from a config */
unit(const config& cfg, bool use_traits = false, const vconfig* vcfg = nullptr);
/**
* Initializes a unit from a unit type.
*
* Only real_unit-s should have random traits, name and gender (to prevent OOS caused by RNG calls)
*/
unit(const unit_type& t, int side, bool real_unit, unit_race::GENDER gender = unit_race::NUM_GENDERS);
// Copy constructor
unit(const unit& u);
virtual ~unit();
void swap(unit&);
unit& operator=(unit);
/*** *** *** *** *** *** Advancement functions *** *** *** *** *** ***/
/** Advances this unit to another type */
void advance_to(const unit_type& t, bool use_traits = false);
/**
* Gets the possible types this unit can advance to on level-up.
*
* @returns A list of type IDs this unit may advance to.
*/
const std::vector<std::string>& advances_to() const
{
return advances_to_;
}
/**
* Gets the names of the possible types this unit can advance to on level-up.
*
* @returns A list of the names of the types this unit may advance to.
*/
const std::vector<std::string> advances_to_translated() const;
/**
* Sets this unit's advancement options.
*
* @param advances_to A list of new type IDs this unit may advance to.
*/
void set_advances_to(const std::vector<std::string>& advances_to);
/**
* Checks whether this unit has any options to advance to.
*
* This considers both whether it has types to advance to OR whether any modifications
* specify non-type advancement options.
*
* Note this does not consider unit experience at all, it only checks option availability.
* See @ref advances if an experience check is necessary.
*/
bool can_advance() const
{
return !advances_to_.empty() || !get_modification_advances().empty();
}
/**
* Checks whether this unit is eligible for level-up.
*
* @retval true This unit has sufficient experience to level up and has advancement
* options available.
*/
bool advances() const
{
return experience_ >= max_experience() && can_advance();
}
/**
* Gets and image path and and associated description for each advancement option.
*
* Covers both type and modification-based advancements.
*
* @returns A data map, in image/description format. If the option is a unit type,
* advancement, the key is the type's image and the value the type ID.
*
* If the option is a modification, the key and value are set from config data
* (see @ref get_modification_advances).
*/
std::map<std::string, std::string> advancement_icons() const;
/**
* Gets any non-typed advanced options set by modifications.
*
* These are usually used to give a unit special advancement options that don't invole transforming to a
* new type.
*
* Note this is not the raw option data. Parsing is performed to ensure each option appears only once.
* Use @ref modification_advancements is the raw data is needed.
*
* @returns A config list of options data. Each option is unique.
*/
std::vector<config> get_modification_advances() const;
/**
* Gets the image and description data for modification advancements.
*
* @returns A list of pairs of the image paths(first) and descriptions (second) for
* each advancement option.
*/
std::vector<std::pair<std::string, std::string>> amla_icons() const;
/** The raw, unparsed data for modification advancements. */
using advancements_list= boost::ptr_vector<config>;
const advancements_list& modification_advancements() const
{
return advancements_;
}
/** Sets the raw modification advancement option data */
void set_advancements(std::vector<config> advancements);
/*** *** *** *** *** *** Basic data setters and getters *** *** *** *** *** ***/
public:
/**
* The side this unit belongs to.
*
* Note that side numbers starts from 1, not 0, so be sure to subtract 1 if using as a container index.
*/
int side() const
{
return side_;
}
/** Sets the side this unit belongs to. */
void set_side(unsigned int new_side)
{
side_ = new_side;
}
/** This unit's type, accounting for gender and variation. */
const unit_type& type() const
{
return *type_;
}
/**
* The id of this unit's type.
*
* If you are dealing with creating units (e.g. recruitment), this is not what you want, as a
* variation can change this; use type().base_id() instead.
*/
const std::string& type_id() const
{
return type_->id();
}
/** Gets the translatable name of this unit's type. */
const t_string& type_name() const
{
return type_name_;
}
/**
* Gets this unit's id.
*
* This is a unique string usually set by WML. It should *not* be used for internal tracking in
* the unit_map. Use @ref underlying_id for that.
*/
const std::string& id() const
{
if(id_.empty()) {
return type_name();
}
return id_;
}
/** Sets this unit's string ID. */
void set_id(const std::string& id)
{
id_ = id;
}
#ifdef HAVE_CXX14
[[deprecated("Use comparison against id() instead")]]
#endif
bool matches_id(const std::string& unit_id) const
{
return id_ == unit_id;
}
/** This unit's unique internal ID. This should *not* be used for user-facing operations. */
size_t underlying_id() const
{
return underlying_id_.value;
}
private:
/** Sets the internal ID. */
void set_underlying_id(n_unit::id_manager& id_manager);
public:
/** Gets this unit's translatable display name. */
const t_string& name() const
{
return name_;
}
/**
* Sets this unit's translatable display name.
*
* This should only be used internally since it ignores the 'unrenamable' flag.
*/
void set_name(const t_string& name)
{
name_ = name;
}
/**
* Attemps to this unit's translatable display name, taking the 'unrenamable' flag into account.
*
* If a direct rename is desired, use @ref set_name.
* @todo should this also take a t_string?
*/
void rename(const std::string& name)
{
if(!unrenamable_) {
name_ = name;
}
}
/**
* Whether this unit can be renamed.
*
* This flag is considered by @ref rename, but not @ref set_name.
*/
bool unrenamable() const
{
return unrenamable_;
}
/**
* Sets the 'unrenamable' flag. Usually used for scenario-specific units which should not be renamed.
*/
void set_unrenamable(bool unrenamable)
{
unrenamable_ = unrenamable;
}
/** A detailed description of this unit. */
t_string unit_description() const
{
return description_;
}
/** The gender of this unit. */
unit_race::GENDER gender() const
{
return gender_;
}
/**
* The alignment of this unit.
*
* This affects the time of day during which this unit's attacks do the most damage.
*/
unit_type::ALIGNMENT alignment() const
{
return alignment_;
}
/** Sets the alignment of this unit. */
void set_alignment(unit_type::ALIGNMENT alignment)
{
alignment_ = alignment;
}
/**
* Gets this unit's race.
*
* @returns A pointer to a unit_race object - never nullptr, but it may point
* to the null race.
*/
const unit_race* race() const
{
return race_;
}
/** The current number of hitpoints this unit has. */
int hitpoints() const
{
return hit_points_;
}
/** The max number of hitpoints this unit can have. */
int max_hitpoints() const
{
return max_hit_points_;
}
/** Sets the current hitpoint amount. */
void set_hitpoints(int hp)
{
hit_points_ = hp;
}
/** The current number of experience points this unit has. */
int experience() const
{
return experience_;
}
/** The max number of experience points this unit can have. */
int max_experience() const
{
return max_experience_;
}
/** Sets the current experience point amount. */
void set_experience(int xp)
{
experience_ = xp;
}
/** The current level of this unit. */
int level() const
{
return level_;
}
/** Sets the current level of this unit. */
void set_level(int level)
{
level_ = level;
}
/** The ID of the variation of this unit's type. */
const std::string& variation() const
{
return variation_;
}
/** The ID of the undead variation (ie, dwarf, swimmer) of this unit. */
const std::string& undead_variation() const
{
return undead_variation_;
}
/**
* An optional profile image to display in Help.
*
* @returns The specified image, this unit's type's sprite image if empty
* or 'unit_image' was set.
*/
std::string small_profile() const;
/**
* An optional profile image displays when this unit is 'speaking' via [message].
*
* @returns The specified image, this unit's type's sprite image if empty
* or 'unit_image' was set.
*/
std::string big_profile() const;
/** Whether this unit can recruit other units - ie, are they a leader unit. */
bool can_recruit() const
{
return canrecruit_;
}
/** Sets whether this unit can recruit other units. */
void set_can_recruit(bool canrecruit)
{
canrecruit_ = canrecruit;
}
/** The type IDs of the other units this unit may recruit, if possible. */
const std::vector<std::string>& recruits() const
{
return recruit_list_;
}
/** Sets the recruit list. */
void set_recruits(const std::vector<std::string>& recruits);
/** How much gold is required to recruit this unit. */
int cost() const
{
return unit_value_;
}
/** How much gold it costs to recall this unit. */
int recall_cost() const
{
return recall_cost_;
}
/** Sets the cost of recalling this unit. */
void set_recall_cost(int recall_cost)
{
recall_cost_ = recall_cost;
}
/** Gets the filter contraints upon which units this unit may recall, if able. */
const config& recall_filter() const
{
return filter_recall_;
}
/**
* Gets this unit's role.
*
* A role is a special string flag usually used to represent a unit's purpose in a scenario.
* It can be filtered on.
*/
const std::string& get_role() const
{
return role_;
}
/** Sets a unit's role */
void set_role(const std::string& role)
{
role_ = role;
}
/**
* Gets this unit's usage. This is relevant to the AI.
*
* Usage refers to how the AI may consider utilizing this unit in combat.
* @todo document further
*/
std::string usage() const
{
return unit_detail::get_or_default(usage_);
}
/** Sets this unit's usage. */
void set_usage(const std::string& usage)
{
usage_.reset(new std::string(usage));
}
/**
* Gets any user-defined variables this unit 'owns'.
*
* These are accessible via WML if the unit's data is serialized to a variable. They're strictly
* user-facing; internal engine calculations shouldn't use this.
*/
config& variables()
{
return variables_;
}
/** Const overload of @ref variables. */
const config& variables() const
{
return variables_;
}
/**
* Gets whether this unit is currently hidden on the map.
* @todo document hiddenness
*/
bool get_hidden() const
{
return hidden_;
}
/** Sets whether the unit is hidden on the map. */
void set_hidden(bool state) const;
/**
* The factor by which the HP bar should be scaled.
* @todo: document further
*/
double hp_bar_scaling() const
{
return hp_bar_scaling_;
}
/**
* The factor by which the XP bar should be scaled.
* @todo: document further
*/
double xp_bar_scaling() const
{
return xp_bar_scaling_;
}
bool hold_position() const
{
return hold_position_;
}
void toggle_hold_position()
{
hold_position_ = !hold_position_;
if(hold_position_) {
end_turn_ = true;
}
}
void set_user_end_turn(bool value = true)
{
end_turn_ = value;
}
void toggle_user_end_turn()
{
end_turn_ = !end_turn_;
if(!end_turn_) {
hold_position_ = false;
}
}
bool user_end_turn() const
{
return end_turn_;
}
void new_turn();
void end_turn();
void new_scenario();
bool take_hit(int damage)
{
hit_points_ -= damage;
return hit_points_ <= 0;
}
void heal(int amount);
void heal_fully()
{
hit_points_ = max_hitpoints();
}
const std::set<std::string> get_states() const;
bool get_state(const std::string& state) const;
void set_state(const std::string& state, bool value);
enum state_t {
STATE_SLOWED = 0,
STATE_POISONED,
STATE_PETRIFIED,
STATE_UNCOVERED,
STATE_NOT_MOVED,
STATE_UNHEALABLE,
STATE_GUARDIAN,
STATE_UNKNOWN = -1
};
void set_state(state_t state, bool value);
bool get_state(state_t state) const;
static state_t get_known_boolean_state_id(const std::string& state);
bool poisoned() const
{
return get_state(STATE_POISONED);
}
bool incapacitated() const
{
return get_state(STATE_PETRIFIED);
}
bool slowed() const
{
return get_state(STATE_SLOWED);
}
/*** *** *** *** *** *** Attack and resistance functions. *** *** *** *** *** ***/
public:
/** Gets an iterator over this unit's attacks. */
attack_itors attacks()
{
return make_attack_itors(attacks_);
}
/** Const overload of @ref attacks. */
const_attack_itors attacks() const
{
return make_attack_itors(attacks_);
}
template<typename... Args>
attack_ptr add_attack(attack_itors::iterator position, Args... args)
{
return *attacks_.emplace(position.base(), new attack_type(args...));
}
bool remove_attack(attack_ptr atk);
void remove_attacks_ai();
/**
* Calculates the damage this unit would take from a certain attack.
*
* @param attack The attack to consider.
* @param attacker Whether this unit should be considered the attacker.
* @param loc TODO: what does this do?
*
* @returns The expected damage.
*/
int damage_from(const attack_type& attack, bool attacker, const map_location& loc) const
{
return resistance_against(attack, attacker, loc);
}
/** The maximum number of attacks this unit may perform per turn, usually 1. */
int max_attacks() const
{
return max_attacks_;
}
/**
* Gets the remaining number of attacks this unit can perform this turn.
*
* If the 'incapacitated' is set, this will always be 0.
*/
int attacks_left() const
{
return (attacks_left_ == 0 || incapacitated()) ? 0 : attacks_left_;
}
/** Sets the number of attacks this unit has left this turn. */
void set_attacks(int left)
{
attacks_left_ = std::max<int>(0, left);
}
int defense_modifier(const t_translation::terrain_code& terrain) const;
int resistance_against(const std::string& damage_name, bool attacker, const map_location& loc) const;
int resistance_against(const attack_type& damage_type, bool attacker, const map_location& loc) const
{
return resistance_against(damage_type.type(), attacker, loc);
}
/** Gets resistances without any abilities applied. */
utils::string_map get_base_resistances() const
{
return movement_type_.damage_table();
}
private:
bool resistance_filter_matches(const config& cfg, bool attacker, const std::string& damage_name, int res) const;
/*** *** *** *** *** *** Trait and upkeep functions. *** *** *** *** *** ***/
public:
/**
* Applies mandatory traits (e.g. undead, mechanical) to a unit and then fills in the remaining traits
* traits until no more are available (leaders have a restricted set of available traits) or the unit has
* its maximum number of traits.
*
* This routine does not apply the effects of added traits to a unit; that must be done by the caller.
*
* Note that random numbers used in config files don't work in multiplayer, so leaders should be barred
* from all random traits until that is fixed. Later the restrictions will be based on play balance.
*
* @param must_have_only Whether random or optional traits should be included or not. If false only
* mandatory traits will be used.
*/
void generate_traits(bool must_have_only = false);
/**
* Gets the names of the currently registered traits.
*
* @returns A list of translatable trait names.
*/
const std::vector<t_string>& trait_names() const
{
return trait_names_;
}
/**
* Gets the descriptions of the currently registered traits.
*
* @returns A list of translatable trait descriptions.
*/
const std::vector<t_string>& trait_descriptions() const
{
return trait_descriptions_;
}
/**
* Gets a list of the traits this unit currently has.
*
* @returns A list of trait IDs.
*/
std::vector<std::string> get_traits_list() const;
/**
* Register a trait's name and its description for the UI's use.
*
* The resulting data can be fetched with @ref trait_names and @ref trait_descriptions.
*
* @param trait A config containing the trait's attributes.
* @param description The translatable description of the trait.
*/
void add_trait_description(const config& trait, const t_string& description);
/**
* Gets the amount of gold this unit costs a side per turn.
*
* This fetches an actual numeric gold value:
* - If @rec can_recruit is true, no upkeep is paid (0 is returned).
* - If a special upkeep flag is set, the associated gold amount is returned (see @ref upkeep_value_visitor).
* - If a numeric value is already set, it is returned directly.
*
* @returns A gold value, evaluated based on the state of @ref upkeep_raw.
*/
int upkeep() const;
struct upkeep_full
{
static std::string type() { static std::string v = "full"; return v; }
};
struct upkeep_loyal
{
static std::string type() { static std::string v = "loyal"; return v; }
};
/** Visitor helper class to fetch the appropriate upkeep value. */
class upkeep_value_visitor : public boost::static_visitor<int>
{
public:
explicit upkeep_value_visitor(const unit& unit) : u_(unit) {}
/** Full upkeep equals the unit's level. */
int operator()(const upkeep_full&) const
{
return u_.level();
}
/** Loyal units cost no upkeep. */
int operator()(const upkeep_loyal&) const
{
return 0;
}
int operator()(int v) const
{
return v;
}
private:
const unit& u_;
};
/** Visitor helper struct to fetch the upkeep type flag if applicable, or the the value otherwise. */
struct upkeep_type_visitor : public boost::static_visitor<std::string>
{
template<typename T>
typename std::enable_if<!std::is_same<int, T>::value, std::string>::type
operator()(T& v) const
{
// Any special upkeep type should have an associated @ref type getter in its helper struct.
return v.type();
}
std::string operator()(int v) const
{
return std::to_string(v);
}
};
using upkeep_t = boost::variant<upkeep_full, upkeep_loyal, int>;
/**
* Gets the raw variant controlling the upkeep value.
*
* This should not usually be called directly. To get an actual numeric value of upkeep use @ref upkeep.
*/
upkeep_t upkeep_raw() const
{
return upkeep_;
}
/** Sets the upkeep value to a specific value value. Does not necessarily need to be numeric */
void set_upkeep(upkeep_t v)
{
upkeep_ = v;
}
/** Gets whether this unit is loyal - ie, it costs no upkeep. */
bool loyal() const;
bool is_fearless() const
{
return is_fearless_;
}
bool is_healthy() const
{
return is_healthy_;
}
/*** *** *** *** *** *** Movement and location functions. *** *** *** *** *** ***/
public:
/** The maximum moves this unit has. */
int total_movement() const
{
return max_movement_;
}
/**
* Gets how far a unit can move, considering the `incapacitated` flag.
*
* @returns The remaining movement, or zero if incapacitated.
*/
int movement_left() const
{
return (movement_ == 0 || incapacitated()) ? 0 : movement_;
}
/**
* Gets how far a unit can move.
*
* @param base_value If true, consider the `incapacitated` flag.
*
* @returns If @a base_value is false, the raw value is returned.
*/
int movement_left(bool base_value) const
{
return base_value ? movement_ : movement_left();
}
/**
* Set this unit's remaining movement to @a moves.
*
* This does not affect maximum movement.
*
* @param moves The new number of moves
* @param unit_action If to true, the "end turn" and "hold position" flags will be cleared
* (as they should be if a unit acts, as opposed to the movement being set
* by the engine for other reasons).
*/
void set_movement(int moves, bool unit_action = false);
/** Checks if this unit has moved. */
bool has_moved() const
{
return movement_left() != total_movement();
}
void remove_movement_ai();
/**
* Checks whether this unit is 'resting'.
*
* Resting refers to whether this unit has not moved yet this turn. Note that this can be true even
* if @ref movement_left is not equal to @ref total_movement.
*/
bool resting() const
{
return resting_;
}
/** Sets this unit's resting status. */
void set_resting(bool rest)
{
resting_ = rest;
}
/** Tests whether the unit has a zone-of-control, considering @ref incapacitated. */
bool emits_zoc() const
{
return emit_zoc_ && !incapacitated();
}
/** Gets the raw zone-of-control flag, disregarding @ref incapacitated. */
bool get_emit_zoc() const
{
return emit_zoc_;
}
/** Sets the raw zone-of-control flag. */
void set_emit_zoc(bool val)
{
emit_zoc_ = val;
}
/** The current map location this unit is at. */
const map_location& get_location() const
{
return loc_;
}
/**
* Sets this unit's map location.
*
* Note this should only be called by unit_map or for temporary units.
*/
void set_location(const map_location& loc)
{
loc_ = loc;
}
/** The current directin this unit is facing within its hex. */