The Battle for Wesnoth  1.15.2+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>

Classes

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_UNKNOWN = -1
}
 Built-in status effects known to the engine. More...
 
using advances_to_t = std::vector< std::string >
 
using advancements_list = boost::ptr_vector< config >
 
using upkeep_t = boost::variant< upkeep_full, upkeep_loyal, int >
 

Public Member Functions

unit_ptr clone () const
 
unit_ptr shared_from_this ()
 
virtual ~unit ()
 
void swap (unit &)
 Swap, for copy and swap idiom. More...
 
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 advancements_listmodification_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...
 
const std::vector< t_string > & unit_special_notes () const
 The unit's special notes. More...
 
unit_race::GENDER gender () const
 The gender of this unit. More...
 
unit_type::ALIGNMENT alignment () const
 The alignment of this unit. More...
 
void set_alignment (unit_type::ALIGNMENT 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 The number of hitpoints to gain. 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 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 directin 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...
 
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...
 
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_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) 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_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
 Gets the unit's active abilities of a particular type. More...
 
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...
 
bool abilities_filter_matches (const config &cfg, bool attacker, int res) const
 
bool ability_filter_fighter (const std::string &ability, const std::string &filter_attacker, const config &cfg, const map_location &loc, const unit &u2) const
 
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...
 
long ref_count () const
 
void set_appearance_changed (bool value)
 
bool appearance_changed () const
 

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)
 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 Public Attributes

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

Protected Attributes

long ref_count_
 
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)
 
 unit (const unit &u)
 
 unit ()
 
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
 
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

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_type::ALIGNMENT 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_
 
advancements_list advancements_
 
t_string description_
 
std::vector< t_stringspecial_notes_
 
std::unique_ptr< std::string > usage_
 
std::unique_ptr< std::string > halo_
 
std::unique_ptr< 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 = 7
 
static std::map< std::string, state_tknown_boolean_state_names_
 

Friends

class unit_animation_component
 
void intrusive_ptr_add_ref (const unit *)
 Intrusive Pointer interface. More...
 
void intrusive_ptr_release (const unit *)
 

Detailed Description

This class represents a single unit of a specific type.

Definition at line 99 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 119 of file unit.hpp.

Constructor & Destructor Documentation

◆ unit() [1/2]

unit::unit ( const unit u)
private

Definition at line 298 of file unit.cpp.

References a, and attacks_.

◆ unit() [2/2]

unit::unit ( )
private

Definition at line 379 of file unit.cpp.

Referenced by apply_builtin_effect().

◆ ~unit()

unit::~unit ( )
virtual

Definition at line 753 of file unit.cpp.

References anim_comp_, e, ERR_UT, and gui2::event::find().

Member Function Documentation

◆ appearance_changed()

bool unit::appearance_changed ( ) const
inline

Definition at line 1755 of file unit.hpp.

◆ clear_changed_attributes()

void unit::clear_changed_attributes ( )
private

Definition at line 2673 of file unit.cpp.

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 719 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().

◆ clear_visibility_cache()

void unit::clear_visibility_cache ( ) const
inlineprivate

Clears the cache.

Since we don't change the state of the object we're marked const (also required since the objects in the cache need to be marked const).

Definition at line 1899 of file unit.hpp.

References swap().

◆ 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 
)
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 167 of file unit.hpp.

◆ get_attacks_changed()

bool unit::get_attacks_changed ( ) const
private

Definition at line 1438 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 148 of file unit.hpp.

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 455 of file unit.cpp.

References abilities_, config::add_child(), game_config::add_color_info(), game_events::manager::add_events(), add_modification(), advance_to(), advancements_, alignment_, anim_comp_, config::append(), attacks_, attacks_left_, config::attribute_range(), c, canrecruit_, vconfig::child(), config::child(), config::child_or_empty(), config::child_range(), config::clear(), 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_, generate_gender(), generate_name(), generate_name_, config::get(), vconfig::get_children(), vconfig::get_config(), randomness::rng::get_random_int(), 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_, jamming_, level_, loc_, 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, 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_, special_notes_, utils::split(), STATE_GUARDIAN, 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 
)
private

◆ leader_crown()

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

The path to the leader crown overlay.

Definition at line 1076 of file unit.cpp.

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

◆ operator=()

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

◆ parse_upkeep()

void unit::parse_upkeep ( const config::attribute_value upkeep)
private

Definition at line 2654 of file unit.cpp.

References config_attribute_value::apply_visitor(), e, config_attribute_value::empty(), and WRN_UT.

Referenced by advance_to(), and init().

◆ ref_count()

long unit::ref_count ( ) const
inline

Definition at line 1746 of file unit.hpp.

References intrusive_ptr_add_ref(), and intrusive_ptr_release().

◆ set_appearance_changed()

void unit::set_appearance_changed ( bool  value)
inline

Definition at line 1754 of file unit.hpp.

◆ set_attr_changed()

void unit::set_attr_changed ( UNIT_ATTRIBUTE  attr)
inlineprivate

◆ shared_from_this()

unit_ptr unit::shared_from_this ( )
inline

Definition at line 179 of file unit.hpp.

References swap().

Referenced by game_lua_kernel::intf_simulate_combat().

◆ swap()

void unit::swap ( unit o)

◆ write_upkeep()

void unit::write_upkeep ( config::attribute_value upkeep) const
private

Definition at line 2668 of file unit.cpp.

References variable_info_implementation::apply_visitor().

Referenced by write().

Friends And Related Function Documentation

◆ intrusive_ptr_add_ref

void intrusive_ptr_add_ref ( const unit u)
friend

Intrusive Pointer interface.

Definition at line 215 of file unit.cpp.

◆ intrusive_ptr_release

void intrusive_ptr_release ( const unit u)
friend

Definition at line 230 of file unit.cpp.

◆ unit_animation_component

friend class unit_animation_component
friend

Definition at line 1853 of file unit.hpp.

Member Data Documentation

◆ abilities_

config unit::abilities_
private

◆ advancements_

advancements_list unit::advancements_
private

Definition at line 1863 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), set_advancements(), and write().

◆ advances_to_

std::vector<std::string> unit::advances_to_
private

◆ alignment_

unit_type::ALIGNMENT unit::alignment_
private

Definition at line 1791 of file unit.hpp.

Referenced by advance_to(), init(), swap(), and write().

◆ anim_comp_

std::unique_ptr<unit_animation_component> unit::anim_comp_
private

Definition at line 1855 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), expire_modifications(), init(), swap(), and ~unit().

◆ appearance_changed_

bool unit::appearance_changed_ = true
mutableprivate

Definition at line 1881 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), set_facing(), and set_state().

◆ attacks_

attack_list unit::attacks_
private

◆ attacks_left_

int unit::attacks_left_
private

Definition at line 1815 of file unit.hpp.

Referenced by init(), new_turn(), swap(), and write().

◆ canrecruit_

bool unit::canrecruit_
private

Definition at line 1789 of file unit.hpp.

Referenced by init(), and swap().

◆ changed_attributes_

std::bitset<UA_COUNT> unit::changed_attributes_
private

Definition at line 1882 of file unit.hpp.

◆ description_

t_string unit::description_
private

Definition at line 1865 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), and write().

◆ ellipse_

std::unique_ptr<std::string> unit::ellipse_
private

Definition at line 1870 of file unit.hpp.

Referenced by advance_to(), and write().

◆ emit_zoc_

bool unit::emit_zoc_
private

Definition at line 1829 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), swap(), and write().

◆ end_turn_

bool unit::end_turn_
private

Definition at line 1812 of file unit.hpp.

Referenced by new_turn(), set_movement(), and swap().

◆ events_

config unit::events_
private

Definition at line 1826 of file unit.hpp.

Referenced by init(), swap(), and write().

◆ experience_

int unit::experience_
private

Definition at line 1783 of file unit.hpp.

Referenced by apply_builtin_effect(), init(), swap(), and write().

◆ facing_

map_location::DIRECTION unit::facing_
mutableprotected

Definition at line 1839 of file unit.hpp.

Referenced by init(), set_facing(), unit_animation_component::start_animation(), swap(), and write().

◆ filter_recall_

config unit::filter_recall_
private

Definition at line 1827 of file unit.hpp.

Referenced by init(), swap(), and write().

◆ flag_rgb_

std::string unit::flag_rgb_
private

Definition at line 1793 of file unit.hpp.

Referenced by advance_to(), flag_rgb(), swap(), and write().

◆ formula_man_

std::unique_ptr<unit_formula_manager> unit::formula_man_
private

Definition at line 1802 of file unit.hpp.

Referenced by init(), swap(), and write().

◆ gender_

unit_race::GENDER unit::gender_
private

Definition at line 1800 of file unit.hpp.

Referenced by add_trait_description(), advance_to(), generate_name(), init(), swap(), and write().

◆ generate_name_

bool unit::generate_name_
private

Definition at line 1873 of file unit.hpp.

Referenced by advance_to(), generate_name(), init(), and write().

◆ goto_

map_location unit::goto_
private

Definition at line 1846 of file unit.hpp.

Referenced by init(), new_scenario(), swap(), and write().

◆ halo_

std::unique_ptr<std::string> unit::halo_
private

Definition at line 1869 of file unit.hpp.

Referenced by write().

◆ hidden_

bool unit::hidden_
mutableprivate

Definition at line 1857 of file unit.hpp.

Referenced by init(), swap(), and write().

◆ hit_points_

int unit::hit_points_
private

Definition at line 1781 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), expire_modifications(), heal(), init(), swap(), and write().

◆ hold_position_

bool unit::hold_position_
private

Definition at line 1811 of file unit.hpp.

Referenced by new_turn(), set_movement(), and swap().

◆ hp_bar_scaling_

double unit::hp_bar_scaling_
private

Definition at line 1858 of file unit.hpp.

Referenced by advance_to(), and init().

◆ id_

std::string unit::id_
private

Definition at line 1774 of file unit.hpp.

Referenced by init(), mark_clone(), set_underlying_id(), swap(), and write().

◆ image_mods_

std::string unit::image_mods_
private

Definition at line 1794 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), and swap().

◆ interrupted_move_

map_location unit::interrupted_move_
private

Definition at line 1846 of file unit.hpp.

Referenced by swap().

◆ invisibility_cache_

std::map<map_location, bool> unit::invisibility_cache_
mutableprivate

Hold the visibility status cache for a unit, when not uncovered.

This is mutable since it is a cache.

Definition at line 1891 of file unit.hpp.

Referenced by invisible(), and swap().

◆ is_fearless_

bool unit::is_fearless_
private

Definition at line 1848 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), and swap().

◆ is_healthy_

bool unit::is_healthy_
private

Definition at line 1848 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), and swap().

◆ jamming_

int unit::jamming_
private

Definition at line 1807 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), swap(), and write().

◆ known_boolean_state_names_

std::map< std::string, unit::state_t > unit::known_boolean_state_names_
staticprivate
Initial value:
{
{"slowed", STATE_SLOWED},
{"poisoned", STATE_POISONED},
{"petrified", STATE_PETRIFIED},
{"uncovered", STATE_UNCOVERED},
{"not_moved", STATE_NOT_MOVED},
{"unhealable", STATE_UNHEALABLE},
{"guardian", STATE_GUARDIAN},
}

Definition at line 1823 of file unit.hpp.

Referenced by get_known_boolean_state_id(), and get_states().

◆ known_boolean_states_

std::bitset<num_bool_states> unit::known_boolean_states_
private

Definition at line 1822 of file unit.hpp.

Referenced by get_state(), set_state(), and swap().

◆ level_

int unit::level_
private

Definition at line 1786 of file unit.hpp.

Referenced by add_modification(), advance_to(), init(), swap(), and write().

◆ loc_

map_location unit::loc_
private

◆ max_attacks_

int unit::max_attacks_
private

Definition at line 1816 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), new_turn(), swap(), and write().

◆ max_experience_

int unit::max_experience_
private

Definition at line 1784 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), swap(), and write().

◆ max_hit_points_

int unit::max_hit_points_
private

Definition at line 1782 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), swap(), and write().

◆ max_movement_

int unit::max_movement_
private

Definition at line 1805 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), expire_modifications(), init(), swap(), and write().

◆ modification_descriptions_

utils::string_map unit::modification_descriptions_
private

Definition at line 1850 of file unit.hpp.

Referenced by advance_to(), and swap().

◆ modifications_

config unit::modifications_
private

◆ movement_

int unit::movement_
private

◆ movement_type_

movetype unit::movement_type_
private

◆ name_

t_string unit::name_
private

Definition at line 1775 of file unit.hpp.

Referenced by generate_name(), init(), swap(), and write().

◆ num_bool_states

const std::size_t unit::num_bool_states = 7
staticprivate

Definition at line 1820 of file unit.hpp.

◆ overlays_

std::vector<std::string> unit::overlays_
private

Definition at line 1831 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), and swap().

◆ profile_

std::string unit::profile_
private

Definition at line 1877 of file unit.hpp.

Referenced by advance_to(), big_profile(), small_profile(), and write().

◆ race_

const unit_race* unit::race_
private

Never nullptr, but may point to the null race.

Definition at line 1772 of file unit.hpp.

Referenced by advance_to(), generate_name(), init(), swap(), and write().

◆ random_traits_

bool unit::random_traits_
private

Definition at line 1872 of file unit.hpp.

Referenced by advance_to(), generate_traits(), init(), and write().

◆ recall_cost_

int unit::recall_cost_
private

Definition at line 1788 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), swap(), and write().

◆ recruit_list_

std::vector<std::string> unit::recruit_list_
private

Definition at line 1790 of file unit.hpp.

Referenced by set_recruits(), swap(), and write().

◆ ref_count_

long unit::ref_count_
mutableprotected

Definition at line 1758 of file unit.hpp.

Referenced by intrusive_ptr_add_ref(), and intrusive_ptr_release().

◆ resting_

bool unit::resting_
private

Definition at line 1813 of file unit.hpp.

Referenced by end_turn(), init(), swap(), and write().

◆ role_

std::string unit::role_
private

Definition at line 1833 of file unit.hpp.

Referenced by init(), swap(), and write().

◆ side_

int unit::side_
private

Definition at line 1798 of file unit.hpp.

Referenced by apply_builtin_effect(), init(), invisible(), swap(), and write().

◆ small_profile_

std::string unit::small_profile_
private

Definition at line 1878 of file unit.hpp.

Referenced by advance_to(), small_profile(), and write().

◆ special_notes_

std::vector<t_string> unit::special_notes_
private

Definition at line 1866 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), and write().

◆ states_

std::set<std::string> unit::states_
private

Definition at line 1818 of file unit.hpp.

Referenced by get_state(), get_states(), set_state(), and swap().

◆ trait_descriptions_

std::vector<t_string> unit::trait_descriptions_
private

Definition at line 1843 of file unit.hpp.

Referenced by add_trait_description(), advance_to(), and swap().

◆ trait_names_

std::vector<t_string> unit::trait_names_
private

Definition at line 1842 of file unit.hpp.

Referenced by add_trait_description(), advance_to(), and swap().

◆ type_

const unit_type* unit::type_
private

Never nullptr.

Adjusted for gender and variation.

Definition at line 1766 of file unit.hpp.

Referenced by advance_to(), init(), and swap().

◆ type_name_

t_string unit::type_name_
private

The displayed name of this unit type.

Definition at line 1769 of file unit.hpp.

Referenced by advance_to(), swap(), and write().

◆ undead_variation_

std::string unit::undead_variation_
private

Definition at line 1778 of file unit.hpp.

Referenced by advance_to(), swap(), and write().

◆ underlying_id_

n_unit::unit_id unit::underlying_id_
private

Definition at line 1776 of file unit.hpp.

Referenced by init(), is_visible_to_team(), mark_clone(), set_underlying_id(), swap(), and write().

◆ unit_value_

int unit::unit_value_
private

Definition at line 1845 of file unit.hpp.

Referenced by advance_to(), init(), swap(), and write().

◆ unrenamable_

bool unit::unrenamable_
private

Definition at line 1796 of file unit.hpp.

Referenced by init(), swap(), and write().

◆ upkeep_

upkeep_t unit::upkeep_
private

Definition at line 1875 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), loyal(), and upkeep().

◆ usage_

std::unique_ptr<std::string> unit::usage_
private

Definition at line 1868 of file unit.hpp.

Referenced by write().

◆ variables_

config unit::variables_
private

Definition at line 1825 of file unit.hpp.

Referenced by apply_modifications(), init(), swap(), and write().

◆ variation_

std::string unit::variation_
private

Definition at line 1779 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), swap(), and write().

◆ vision_

int unit::vision_
private

Definition at line 1806 of file unit.hpp.

Referenced by advance_to(), apply_builtin_effect(), init(), swap(), and write().

◆ xp_bar_scaling_

double unit::xp_bar_scaling_
private

Definition at line 1858 of file unit.hpp.

Referenced by advance_to(), and init().


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