The Battle for Wesnoth  1.19.0-dev
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
unit Class Reference

This class represents a single unit of a specific type. More...

#include <unit.hpp>

Inheritance diagram for unit:

Classes

struct  unit_ctor_t
 
struct  upkeep_full
 
struct  upkeep_loyal
 
class  upkeep_parser_visitor
 Visitor helper class to parse the upkeep value from a config. More...
 
struct  upkeep_type_visitor
 Visitor helper struct to fetch the upkeep type flag if applicable, or the the value otherwise. More...
 
class  upkeep_value_visitor
 Visitor helper class to fetch the appropriate upkeep value. More...
 

Public Types

enum  state_t {
  STATE_SLOWED = 0 , STATE_POISONED , STATE_PETRIFIED , STATE_UNCOVERED ,
  STATE_NOT_MOVED , STATE_UNHEALABLE , STATE_GUARDIAN , STATE_INVULNERABLE ,
  NUMBER_OF_STATES , STATE_UNKNOWN = -1
}
 Built-in status effects known to the engine. More...
 
using advances_to_t = std::vector< std::string >
 
using upkeep_t = utils::variant< upkeep_full, upkeep_loyal, int >
 

Public Member Functions

 unit (unit_ctor_t)
 
 unit ()=delete
 
unit_ptr clone () const
 
virtual ~unit ()
 
unitoperator= (const unit &)=delete
 
void advance_to (const unit_type &t, bool use_traits=false)
 Advances this unit to another type. More...
 
const advances_to_tadvances_to () const
 Gets the possible types this unit can advance to on level-up. More...
 
const std::vector< std::string > advances_to_translated () const
 Gets the names of the possible types this unit can advance to on level-up. More...
 
void set_advances_to (const std::vector< std::string > &advances_to)
 Sets this unit's advancement options. More...
 
bool can_advance () const
 Checks whether this unit has any options to advance to. More...
 
bool advances () const
 Checks whether this unit is eligible for level-up. More...
 
std::map< std::string, std::string > advancement_icons () const
 Gets and image path and and associated description for each advancement option. More...
 
std::vector< configget_modification_advances () const
 Gets any non-typed advanced options set by modifications. More...
 
std::vector< std::pair< std::string, std::string > > amla_icons () const
 Gets the image and description data for modification advancements. More...
 
const std::vector< config > & modification_advancements () const
 The raw, unparsed data for modification advancements. More...
 
void set_advancements (std::vector< config > advancements)
 Sets the raw modification advancement option data. More...
 
int side () const
 The side this unit belongs to. More...
 
void set_side (unsigned int new_side)
 Sets the side this unit belongs to. More...
 
const unit_typetype () const
 This unit's type, accounting for gender and variation. More...
 
const std::string & type_id () const
 The id of this unit's type. More...
 
const t_stringtype_name () const
 Gets the translatable name of this unit's type. More...
 
const std::string & id () const
 Gets this unit's id. More...
 
void set_id (const std::string &id)
 Sets this unit's string ID. More...
 
std::size_t underlying_id () const
 This unit's unique internal ID. More...
 
const t_stringname () const
 Gets this unit's translatable display name. More...
 
void set_name (const t_string &name)
 Sets this unit's translatable display name. More...
 
void rename (const std::string &name)
 Attempts to rename this unit's translatable display name, taking the 'unrenamable' flag into account. More...
 
bool unrenamable () const
 Whether this unit can be renamed. More...
 
void set_unrenamable (bool unrenamable)
 Sets the 'unrenamable' flag. More...
 
t_string unit_description () const
 A detailed description of this unit. More...
 
void set_unit_description (const t_string &new_desc)
 A detailed description of this unit. More...
 
std::vector< t_stringunit_special_notes () const
 The unit's special notes. More...
 
unit_race::GENDER gender () const
 The gender of this unit. More...
 
unit_alignments::type alignment () const
 The alignment of this unit. More...
 
void set_alignment (unit_alignments::type alignment)
 Sets the alignment of this unit. More...
 
const unit_racerace () const
 Gets this unit's race. More...
 
int hitpoints () const
 The current number of hitpoints this unit has. More...
 
int max_hitpoints () const
 The max number of hitpoints this unit can have. More...
 
void set_max_hitpoints (int value)
 
void set_hitpoints (int hp)
 Sets the current hitpoint amount. More...
 
int experience () const
 The current number of experience points this unit has. More...
 
int max_experience () const
 The max number of experience points this unit can have. More...
 
void set_max_experience (int value)
 
unsigned int experience_to_advance () const
 The number of experience points this unit needs to level up, or 0 if current XP > max XP. More...
 
unsigned int experience_overflow () const
 The number of experience points over max this unit has, or 0 if current XP < max XP. More...
 
void set_experience (int xp)
 Sets the current experience point amount. More...
 
int level () const
 The current level of this unit. More...
 
void set_level (int level)
 Sets the current level of this unit. More...
 
const std::string & variation () const
 The ID of the variation of this unit's type. More...
 
void set_undead_variation (const std::string &value)
 The ID of the undead variation (ie, dwarf, swimmer) of this unit. More...
 
const std::string & undead_variation () const
 
std::string small_profile () const
 An optional profile image to display in Help. More...
 
void set_small_profile (const std::string &value)
 
std::string big_profile () const
 An optional profile image displays when this unit is 'speaking' via [message]. More...
 
void set_big_profile (const std::string &value)
 
bool can_recruit () const
 Whether this unit can recruit other units - ie, are they a leader unit. More...
 
void set_can_recruit (bool canrecruit)
 Sets whether this unit can recruit other units. More...
 
const std::vector< std::string > & recruits () const
 The type IDs of the other units this unit may recruit, if possible. More...
 
void set_recruits (const std::vector< std::string > &recruits)
 Sets the recruit list. More...
 
int cost () const
 How much gold is required to recruit this unit. More...
 
int recall_cost () const
 How much gold it costs to recall this unit, or -1 if the side's default recall cost is used. More...
 
void set_recall_cost (int recall_cost)
 Sets the cost of recalling this unit. More...
 
const configrecall_filter () const
 Gets the filter constraints upon which units this unit may recall, if able. More...
 
void set_recall_filter (const config &filter)
 Sets the filter constraints upon which units this unit may recall, if able. More...
 
const std::string & get_role () const
 Gets this unit's role. More...
 
void set_role (const std::string &role)
 Sets a unit's role. More...
 
std::string usage () const
 Gets this unit's usage. More...
 
void set_usage (const std::string &usage)
 Sets this unit's usage. More...
 
configvariables ()
 Gets any user-defined variables this unit 'owns'. More...
 
const configvariables () const
 Const overload of variables. More...
 
bool get_hidden () const
 Gets whether this unit is currently hidden on the map. More...
 
void set_hidden (bool state) const
 Sets whether the unit is hidden on the map. More...
 
double hp_bar_scaling () const
 The factor by which the HP bar should be scaled. More...
 
double xp_bar_scaling () const
 The factor by which the XP bar should be scaled. More...
 
bool hold_position () const
 Whether the unit has been instructed to hold its position. More...
 
void toggle_hold_position ()
 Toggle the unit's hold position status. More...
 
void set_user_end_turn (bool value=true)
 Set whether the user ended their turn. More...
 
void toggle_user_end_turn ()
 Toggle whether the user ended their turn. More...
 
bool user_end_turn () const
 Check whether the user ended their turn. More...
 
void new_turn ()
 Refresh unit for the beginning of a turn. More...
 
void end_turn ()
 Refresh unit for the end of a turn. More...
 
void new_scenario ()
 Refresh unit for the beginning of a new scenario. More...
 
bool take_hit (int damage)
 Damage the unit. More...
 
void heal (int amount)
 Heal the unit. More...
 
void heal_fully ()
 Fully heal the unit, restoring it to max hitpoints. More...
 
const std::set< std::string > get_states () const
 Get the status effects currently affecting the unit. More...
 
bool get_state (const std::string &state) const
 Check if the unit is affected by a status effect. More...
 
void set_state (const std::string &state, bool value)
 Set whether the unit is affected by a status effect. More...
 
void set_state (state_t state, bool value)
 Set whether the unit is affected by a status effect. More...
 
bool get_state (state_t state) const
 Check if the unit is affected by a status effect. More...
 
bool poisoned () const
 Check if the unit has been poisoned. More...
 
bool incapacitated () const
 Check if the unit has been petrified. More...
 
bool slowed () const
 Check if the unit has been slowed. More...
 
attack_itors attacks ()
 Gets an iterator over this unit's attacks. More...
 
const_attack_itors attacks () const
 Const overload of attacks. More...
 
template<typename... Args>
attack_ptr add_attack (attack_itors::iterator position, Args &&... args)
 Adds a new attack to the unit. More...
 
bool remove_attack (attack_ptr atk)
 Remove an attack from the unit. More...
 
void remove_attacks_ai ()
 Set the unit to have no attacks left for this turn. More...
 
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. More...
 
int max_attacks () const
 The maximum number of attacks this unit may perform per turn, usually 1. More...
 
void set_max_attacks (int value)
 
int attacks_left () const
 Gets the remaining number of attacks this unit can perform this turn. More...
 
int attacks_left (bool base_value) const
 Gets the remaining number of attacks this unit can perform this turn. More...
 
void set_attacks (int left)
 Sets the number of attacks this unit has left this turn. More...
 
int defense_modifier (const t_translation::terrain_code &terrain) const
 The unit's defense on a given terrain. More...
 
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
 The unit's resistance against a given damage type. More...
 
int resistance_against (const attack_type &atk, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr) const
 The unit's resistance against a given attack. More...
 
utils::string_map_res get_base_resistances () const
 Gets resistances without any abilities applied. More...
 
void generate_traits (bool must_have_only=false)
 Applies mandatory traits (e.g. More...
 
const std::vector< t_string > & trait_names () const
 Gets the names of the currently registered traits. More...
 
const std::vector< t_string > & trait_descriptions () const
 Gets the descriptions of the currently registered traits. More...
 
std::vector< std::string > get_traits_list () const
 Gets a list of the traits this unit currently has. More...
 
void add_trait_description (const config &trait, const t_string &description)
 Register a trait's name and its description for the UI's use. More...
 
int upkeep () const
 Gets the amount of gold this unit costs a side per turn. More...
 
upkeep_t upkeep_raw () const
 Gets the raw variant controlling the upkeep value. More...
 
void set_upkeep (upkeep_t v)
 Sets the upkeep value to a specific value value. More...
 
bool loyal () const
 Gets whether this unit is loyal - ie, it costs no upkeep. More...
 
bool is_fearless () const
 Gets whether this unit is fearless - ie, unaffected by time of day. More...
 
bool is_healthy () const
 Gets whether this unit is healthy - ie, always rest heals. More...
 
int total_movement () const
 The maximum moves this unit has. More...
 
void set_total_movement (int value)
 
int movement_left () const
 Gets how far a unit can move, considering the incapacitated flag. More...
 
int movement_left (bool base_value) const
 Gets how far a unit can move. More...
 
void set_movement (int moves, bool unit_action=false)
 Set this unit's remaining movement to moves. More...
 
bool has_moved () const
 Checks if this unit has moved. More...
 
void remove_movement_ai ()
 Sets the unit to have no moves left for this turn. More...
 
bool resting () const
 Checks whether this unit is 'resting'. More...
 
void set_resting (bool rest)
 Sets this unit's resting status. More...
 
bool emits_zoc () const
 Tests whether the unit has a zone-of-control, considering incapacitated. More...
 
bool get_emit_zoc () const
 Gets the raw zone-of-control flag, disregarding incapacitated. More...
 
void set_emit_zoc (bool val)
 Sets the raw zone-of-control flag. More...
 
const map_locationget_location () const
 The current map location this unit is at. More...
 
void set_location (const map_location &loc)
 Sets this unit's map location. More...
 
map_location::DIRECTION facing () const
 The current direction this unit is facing within its hex. More...
 
void set_facing (map_location::DIRECTION dir) const
 The this unit's facing. More...
 
bool has_goto () const
 Gets whether this unit has a multi-turn destination set. More...
 
const map_locationget_goto () const
 The map location to which this unit is moving over multiple turns, if any. More...
 
void set_goto (const map_location &new_goto)
 Sets this unit's long term destination. More...
 
int vision () const
 Gets the unit's vision points. More...
 
int jamming () const
 Gets the unit's jamming points. More...
 
bool move_interrupted () const
 Check whether the unit's move has been interrupted. More...
 
const map_locationget_interrupted_move () const
 Get the target location of the unit's interrupted move. More...
 
void set_interrupted_move (const map_location &interrupted_move)
 Set the target location of the unit's interrupted move. More...
 
const movetypemovement_type () const
 Get the unit's movement type. More...
 
int movement_cost (const t_translation::terrain_code &terrain) const
 Get the unit's movement cost on a particular terrain. More...
 
int vision_cost (const t_translation::terrain_code &terrain) const
 Get the unit's vision cost on a particular terrain. More...
 
int jamming_cost (const t_translation::terrain_code &terrain) const
 Get the unit's jamming cost on a particular terrain. More...
 
bool is_flying () const
 Check if the unit is a flying unit. More...
 
configget_modifications ()
 Get the raw modifications. More...
 
const configget_modifications () const
 Set the raw modifications. More...
 
std::size_t modification_count (const std::string &type, const std::string &id) const
 Count modifications of a particular type. More...
 
void add_modification (const std::string &type, const config &modification, bool no_add=false)
 Add a new modification to the unit. More...
 
void expire_modifications (const std::string &duration)
 Clears those modifications whose duration has expired. More...
 
void apply_builtin_effect (std::string type, const config &effect)
 Apply a builtin effect to the unit. More...
 
std::string describe_builtin_effect (std::string type, const config &effect)
 Construct a string describing a built-in effect. More...
 
void apply_modifications ()
 Re-apply all saved modifications. More...
 
unit_animation_componentanim_comp () const
 
std::string absolute_image () const
 The name of the file to game_display (used in menus). More...
 
std::string default_anim_image () const
 The default image to use for animation frames with no defined image. More...
 
std::string image_halo () const
 Get the unit's halo image. More...
 
const std::vector< std::string > halo_or_icon_abilities (const std::string &image_type) const
 
const std::vector< std::string > halo_abilities () const
 Get the [halo] abilities halo image(s). More...
 
void set_image_halo (const std::string &halo)
 Set the unit's halo image. More...
 
std::string image_ellipse () const
 Get the unit's ellipse image. More...
 
void set_image_ellipse (const std::string &ellipse)
 Set the unit's ellipse image. More...
 
const std::string & flag_rgb () const
 Get the source color palette to use when recoloring the unit's image. More...
 
std::string TC_image_mods () const
 Constructs a recolor (RC) IPF string for this unit's team color. More...
 
const std::string & effect_image_mods () const
 Gets any IPF image mods applied by effects. More...
 
std::string image_mods () const
 Gets an IPF string containing all IPF image mods. More...
 
const std::vector< std::string > & overlays () const
 Get the unit's overlay images. More...
 
const std::vector< std::string > overlays_abilities () const
 Get the [overlay] ability overlay images. More...
 
color_t hp_color () const
 Color for this unit's current hitpoints. More...
 
color_t hp_color (int hitpoints) const
 Color for this unit's hitpoints. More...
 
color_t xp_color () const
 Color for this unit's XP. More...
 
bool get_ability_bool (const std::string &tag_name, const map_location &loc) const
 Checks whether this unit currently possesses or is affected by a given ability. More...
 
bool get_ability_bool (const std::string &tag_name) const
 Checks whether this unit currently possesses or is affected by a given ability. More...
 
unit_ability_list get_abilities (const std::string &tag_name, const map_location &loc) const
 Gets the unit's active abilities of a particular type if it were on a specified location. More...
 
unit_ability_list get_abilities (const std::string &tag_name) const
 Gets the unit's active abilities of a particular type. More...
 
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
 
unit_ability_list get_abilities_weapons (const std::string &tag_name, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
 
const configabilities () const
 
const std::set< std::string > & checking_tags () const
 
std::vector< std::tuple< std::string, t_string, t_string, t_string > > ability_tooltips () const
 Gets the names and descriptions of this unit's abilities. More...
 
std::vector< std::tuple< std::string, t_string, t_string, t_string > > ability_tooltips (boost::dynamic_bitset<> &active_list, const map_location &loc) const
 Gets the names and descriptions of this unit's abilities. More...
 
std::vector< std::string > get_ability_list () const
 Get a list of all abilities by ID. More...
 
bool has_ability_type (const std::string &ability) const
 Check if the unit has an ability of a specific type. More...
 
bool has_ability_by_id (const std::string &ability) const
 Check if the unit has an ability of a specific ID. More...
 
void remove_ability_by_id (const std::string &ability)
 Removes a unit's abilities with a specific ID. More...
 
void remove_ability_by_attribute (const config &filter)
 Removes a unit's abilities with a specific ID or other attribute. More...
 
bool ability_matches_filter (const config &cfg, const std::string &tag_name, const config &filter) const
 Verify what abilities attributes match with filter. More...
 
unit_formula_managerformula_manager () const
 Get the unit formula manager. More...
 
void generate_name ()
 Generates a random race-appropriate name if one has not already been provided. More...
 
bool invisible (const map_location &loc, bool see_all=true) const
 
bool is_visible_to_team (const team &team, bool const see_all=true) const
 
bool is_visible_to_team (const map_location &loc, const team &team, bool const see_all=true) const
 Return true if the unit would be visible to team if its location were loc. More...
 
void write (config &cfg, bool write_all=true) const
 Serializes the current unit metadata values. More...
 
unitmark_clone (bool is_temporary)
 Mark this unit as clone so it can be inserted to unit_map. More...
 
void set_appearance_changed (bool value)
 
bool appearance_changed () const
 
already added
bool get_self_ability_bool (const config &special, const std::string &tag_name, const map_location &loc) const
 Checks whether this unit currently possesses a given ability used like weapon. More...
 
bool get_self_ability_bool_weapon (const config &special, const std::string &tag_name, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
 Checks whether this unit currently possesses a given ability of leadership type. More...
 
bool get_adj_ability_bool (const config &special, const std::string &tag_name, int dir, const map_location &loc, const unit &from) const
 Checks whether this unit is affected by a given ability used like weapon. More...
 
bool get_adj_ability_bool_weapon (const config &special, const std::string &tag_name, int dir, const map_location &loc, const unit &from, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
 Checks whether this unit is affected by a given ability of leadership type. More...
 

Static Public Member Functions

static void clear_status_caches ()
 Clear this unit status cache for all units. More...
 
static const std::string & leader_crown ()
 The path to the leader crown overlay. More...
 
static unit_ptr create (const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
 Initializes a unit from a config. More...
 
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. More...
 
static state_t get_known_boolean_state_id (const std::string &state)
 Convert a string status effect ID to a built-in status effect ID. More...
 
static color_t hp_color_max ()
 
static color_t xp_color (int xp_to_advance, bool can_advance, bool has_amla)
 

Static Public Attributes

static const std::set< std::string > builtin_effects
 

Protected Attributes

map_location::DIRECTION facing_
 

Private Types

enum  UNIT_ATTRIBUTE {
  UA_MAX_HP , UA_MAX_MP , UA_MAX_AP , UA_MAX_XP ,
  UA_IS_HEALTHY , UA_IS_FEARLESS , UA_LEVEL , UA_MOVEMENT_TYPE ,
  UA_ZOC , UA_ADVANCE_TO , UA_ADVANCEMENTS , UA_ALIGNMENT ,
  UA_UNDEAD_VARIATION , UA_ATTACKS , UA_NOTES , UA_PROFILE ,
  UA_SMALL_PROFILE , UA_ABILITIES , UA_UPKEEP , UA_COUNT
}
 

Private Member Functions

void init (const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
 
void init (const unit_type &t, int side, bool real_unit, unit_race::GENDER gender=unit_race::NUM_GENDERS, const std::string &variation="")
 
 unit (const unit &u)
 
void set_attr_changed (UNIT_ATTRIBUTE attr)
 
bool get_attacks_changed () const
 
bool get_attr_changed (UNIT_ATTRIBUTE attr) const
 
void clear_changed_attributes ()
 
void set_underlying_id (n_unit::id_manager &id_manager)
 Sets the internal ID. More...
 
bool resistance_filter_matches (const config &cfg, bool attacker, const std::string &damage_name, int res) const
 
bool ability_active (const std::string &ability, const config &cfg, const map_location &loc) const
 Check if an ability is active. More...
 
bool ability_affects_adjacent (const std::string &ability, const config &cfg, int dir, const map_location &loc, const unit &from) const
 Check if an ability affects adjacent units. More...
 
bool ability_affects_self (const std::string &ability, const config &cfg, const map_location &loc) const
 Check if an ability affects the owning unit. More...
 
bool ability_affects_weapon (const config &cfg, const_attack_ptr weapon, bool is_opp) const
 filters the weapons that condition the use of abilities for combat ([resistance],[leadership] or abilities used like specials (deprecated in two last cases) More...
 
void parse_upkeep (const config::attribute_value &upkeep)
 
void write_upkeep (config::attribute_value &upkeep) const
 
void clear_visibility_cache () const
 Clears the cache. More...
 

Private Attributes

const std::set< std::string > checking_tags_ {"attacks", "damage", "chance_to_hit", "berserk", "swarm", "drains", "heal_on_hit", "plague", "slow", "petrifies", "firststrike", "poison", "damage_type"}
 
map_location loc_
 
std::vector< std::string > advances_to_
 
const unit_typetype_
 Never nullptr. More...
 
t_string type_name_
 The displayed name of this unit type. More...
 
const unit_racerace_
 Never nullptr, but may point to the null race. More...
 
std::string id_
 
t_string name_
 
n_unit::unit_id underlying_id_
 
std::string undead_variation_
 
std::string variation_
 
int hit_points_
 
int max_hit_points_
 
int experience_
 
int max_experience_
 
int level_
 
int recall_cost_
 
bool canrecruit_
 
std::vector< std::string > recruit_list_
 
unit_alignments::type alignment_
 
std::string flag_rgb_
 
std::string image_mods_
 
bool unrenamable_
 
int side_
 
unit_race::GENDER gender_
 
std::unique_ptr< unit_formula_managerformula_man_
 
int movement_
 
int max_movement_
 
int vision_
 
int jamming_
 
movetype movement_type_
 
bool hold_position_
 
bool end_turn_
 
bool resting_
 
int attacks_left_
 
int max_attacks_
 
std::set< std::string > states_
 
std::bitset< num_bool_statesknown_boolean_states_
 
config variables_
 
config events_
 
config filter_recall_
 
bool emit_zoc_
 
std::vector< std::string > overlays_
 
std::string role_
 
attack_list attacks_
 
std::vector< t_stringtrait_names_
 
std::vector< t_stringtrait_descriptions_
 
int unit_value_
 
map_location goto_
 
map_location interrupted_move_
 
bool is_fearless_
 
bool is_healthy_
 
utils::string_map modification_descriptions_
 
std::unique_ptr< unit_animation_componentanim_comp_
 
bool hidden_
 
double hp_bar_scaling_
 
double xp_bar_scaling_
 
config modifications_
 
config abilities_
 
std::vector< configadvancements_
 
t_string description_
 
std::vector< t_stringspecial_notes_
 
std::optional< std::string > usage_
 
std::optional< std::string > halo_
 
std::optional< std::string > ellipse_
 
bool random_traits_
 
bool generate_name_
 
upkeep_t upkeep_
 
std::string profile_
 
std::string small_profile_
 
bool appearance_changed_ = true
 
std::bitset< UA_COUNTchanged_attributes_
 
std::map< map_location, bool > invisibility_cache_
 Hold the visibility status cache for a unit, when not uncovered. More...
 

Static Private Attributes

static const std::size_t num_bool_states = state_t::NUMBER_OF_STATES
 
static std::map< std::string, state_tknown_boolean_state_names_
 

Friends

class unit_animation_component
 

Detailed Description

This class represents a single unit of a specific type.

Definition at line 132 of file unit.hpp.

Member Enumeration Documentation

◆ UNIT_ATTRIBUTE

enum unit::UNIT_ATTRIBUTE
private
Enumerator
UA_MAX_HP 
UA_MAX_MP 
UA_MAX_AP 
UA_MAX_XP 
UA_IS_HEALTHY 
UA_IS_FEARLESS 
UA_LEVEL 
UA_MOVEMENT_TYPE 
UA_ZOC 
UA_ADVANCE_TO 
UA_ADVANCEMENTS 
UA_ALIGNMENT 
UA_UNDEAD_VARIATION 
UA_ATTACKS 
UA_NOTES 
UA_PROFILE 
UA_SMALL_PROFILE 
UA_ABILITIES 
UA_UPKEEP 
UA_COUNT 

Definition at line 160 of file unit.hpp.

Constructor & Destructor Documentation

◆ unit() [1/3]

unit::unit ( const unit u)
private

Definition at line 242 of file unit.cpp.

References a, and attacks_.

◆ unit() [2/3]

unit::unit ( unit_ctor_t  )

Definition at line 323 of file unit.cpp.

◆ unit() [3/3]

unit::unit ( )
delete

Referenced by clone().

◆ ~unit()

unit::~unit ( )
virtual

Definition at line 729 of file unit.cpp.

References anim_comp_, DBG_UT, e, ERR_UT, and utils::get_unknown_exception_type().

Member Function Documentation

◆ clear_changed_attributes()

void unit::clear_changed_attributes ( )
private

Definition at line 2808 of file unit.cpp.

References attacks_, and changed_attributes_.

Referenced by advance_to().

◆ clear_status_caches()

void unit::clear_status_caches ( )
static

Clear this unit status cache for all units.

Currently only the hidden status of units is cached this way.

Definition at line 695 of file unit.cpp.

Referenced by game_lua_kernel::intf_teleport(), game_events::wml_event_pump::operator()(), editor::editor_action_unit_replace::perform_without_undo(), and actions::undo::move_action::undo().

◆ clone()

unit_ptr unit::clone ( ) const
inline

◆ create() [1/2]

static unit_ptr unit::create ( const config cfg,
bool  use_traits = false,
const vconfig vcfg = nullptr 
)
inlinestatic

◆ create() [2/2]

static unit_ptr unit::create ( const unit_type t,
int  side,
bool  real_unit,
unit_race::GENDER  gender = unit_race::NUM_GENDERS,
const std::string &  variation = "" 
)
inlinestatic

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)

Definition at line 213 of file unit.hpp.

References gender(), side(), t, and variation().

◆ get_attacks_changed()

bool unit::get_attacks_changed ( ) const
private

Definition at line 1550 of file unit.cpp.

References attacks_.

Referenced by write().

◆ get_attr_changed()

bool unit::get_attr_changed ( UNIT_ATTRIBUTE  attr) const
inlineprivate

Definition at line 192 of file unit.hpp.

References changed_attributes_.

Referenced by advance_to(), and write().

◆ init() [1/2]

void unit::init ( const config cfg,
bool  use_traits = false,
const vconfig vcfg = nullptr 
)
private

Definition at line 398 of file unit.cpp.

References abilities(), abilities_, config::add_child(), game_events::manager::add_events(), add_modification(), advance_to(), advancements_, alignment_, config::all_children_count(), anim_comp_, config::append(), ai::manager::append_active_ai_for_side(), config::append_children(), attacks_, attacks_left_, config::attribute_range(), game_config::images::blank, c, canrecruit_, vconfig::child(), config::child_or_empty(), config::child_range(), config::clear(), config::clear_children(), randomness::rng::default_instance(), unit_type::default_variation(), deprecated_message(), description_, e, config::empty(), events_, experience_, facing_, filter_recall_, unit_type_data::find_race(), formula_man_, resources::game_events, resources::gameboard, gender_, gender_value(), generate_gender(), generate_name(), generate_name_, config::get(), vconfig::get_children(), vconfig::get_config(), string_enums::enum_base< Definition >::get_enum(), randomness::rng::get_random_int(), ai::manager::get_singleton(), get_unit_type(), n_unit::id_manager::global_instance(), goto_, config::has_attribute(), config::has_child(), hidden_, hit_points_, unit_type::hp_bar_scaling(), hp_bar_scaling_, id(), id_, jamming_, level_, loc_, resources::lua_kernel, max_attacks_, max_experience_, max_hit_points_, max_movement_, movetype::merge(), modifications_, movement_, movement_type_, name_, map_location::NDIRECTIONS, vconfig::null(), unit_race::null_race, config::optional_child(), overlays(), utils::parenthetical_split(), map_location::parse_direction(), parse_upkeep(), PREEMPTIVE, race_, random_traits_, recall_cost_, resting_, role_, set_advances_to(), set_attr_changed(), set_big_profile(), set_emit_zoc(), set_image_ellipse(), set_image_halo(), set_level(), set_max_attacks(), set_max_experience(), set_max_hitpoints(), set_recruits(), set_small_profile(), set_state(), set_total_movement(), set_undead_variation(), set_underlying_id(), set_usage(), map_location::set_wml_x(), map_location::set_wml_y(), side(), side_, special_notes_, utils::split(), STATE_GUARDIAN, STATE_INVULNERABLE, config_attribute_value::t_str(), type_, UA_ABILITIES, UA_ADVANCEMENTS, UA_ALIGNMENT, UA_ATTACKS, UA_MOVEMENT_TYPE, UA_NOTES, underlying_id_, unit_types, unit_value_, unrenamable_, validate_side(), variables(), variables_, variation_, vision_, unit_type::xp_bar_scaling(), and xp_bar_scaling_.

◆ init() [2/2]

void unit::init ( const unit_type t,
int  side,
bool  real_unit,
unit_race::GENDER  gender = unit_race::NUM_GENDERS,
const std::string &  variation = "" 
)
private

◆ leader_crown()

const std::string & unit::leader_crown ( )
static

The path to the leader crown overlay.

Definition at line 1058 of file unit.cpp.

Referenced by gui2::dialogs::unit_recall::pre_show(), and gui2::unit_preview_pane::set_displayed_unit().

◆ operator=()

unit& unit::operator= ( const unit )
delete

◆ set_attr_changed()

void unit::set_attr_changed ( UNIT_ATTRIBUTE  attr)
inlineprivate

The documentation for this class was generated from the following files: