The Battle for Wesnoth  1.15.0-dev
Enumerations | Functions
Basic data setters and getters

Enumerations

enum  unit::state_t {
  unit::STATE_SLOWED = 0, unit::STATE_POISONED, unit::STATE_PETRIFIED, unit::STATE_UNCOVERED,
  unit::STATE_NOT_MOVED, unit::STATE_UNHEALABLE, unit::STATE_GUARDIAN, unit::STATE_UNKNOWN = -1
}
 Built-in status effects known to the engine. More...
 

Functions

int unit::side () const
 The side this unit belongs to. More...
 
void unit::set_side (unsigned int new_side)
 Sets the side this unit belongs to. More...
 
const unit_typeunit::type () const
 This unit's type, accounting for gender and variation. More...
 
const std::string & unit::type_id () const
 The id of this unit's type. More...
 
const t_stringunit::type_name () const
 Gets the translatable name of this unit's type. More...
 
const std::string & unit::id () const
 Gets this unit's id. More...
 
void unit::set_id (const std::string &id)
 Sets this unit's string ID. More...
 
std::size_t unit::underlying_id () const
 This unit's unique internal ID. More...
 
void unit::set_underlying_id (n_unit::id_manager &id_manager)
 Sets the internal ID. More...
 
const t_stringunit::name () const
 Gets this unit's translatable display name. More...
 
void unit::set_name (const t_string &name)
 Sets this unit's translatable display name. More...
 
void unit::rename (const std::string &name)
 Attempts to rename this unit's translatable display name, taking the 'unrenamable' flag into account. More...
 
bool unit::unrenamable () const
 Whether this unit can be renamed. More...
 
void unit::set_unrenamable (bool unrenamable)
 Sets the 'unrenamable' flag. More...
 
t_string unit::unit_description () const
 A detailed description of this unit. More...
 
unit_race::GENDER unit::gender () const
 The gender of this unit. More...
 
unit_type::ALIGNMENT unit::alignment () const
 The alignment of this unit. More...
 
void unit::set_alignment (unit_type::ALIGNMENT alignment)
 Sets the alignment of this unit. More...
 
const unit_raceunit::race () const
 Gets this unit's race. More...
 
int unit::hitpoints () const
 The current number of hitpoints this unit has. More...
 
int unit::max_hitpoints () const
 The max number of hitpoints this unit can have. More...
 
void unit::set_hitpoints (int hp)
 Sets the current hitpoint amount. More...
 
int unit::experience () const
 The current number of experience points this unit has. More...
 
int unit::max_experience () const
 The max number of experience points this unit can have. More...
 
unsigned int unit::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 unit::experience_overflow () const
 The number of experience points over max this unit has, or 0 if current XP < max XP. More...
 
void unit::set_experience (int xp)
 Sets the current experience point amount. More...
 
int unit::level () const
 The current level of this unit. More...
 
void unit::set_level (int level)
 Sets the current level of this unit. More...
 
const std::string & unit::variation () const
 The ID of the variation of this unit's type. More...
 
const std::string & unit::undead_variation () const
 The ID of the undead variation (ie, dwarf, swimmer) of this unit. More...
 
std::string unit::small_profile () const
 An optional profile image to display in Help. More...
 
std::string unit::big_profile () const
 An optional profile image displays when this unit is 'speaking' via [message]. More...
 
bool unit::can_recruit () const
 Whether this unit can recruit other units - ie, are they a leader unit. More...
 
void unit::set_can_recruit (bool canrecruit)
 Sets whether this unit can recruit other units. More...
 
const std::vector< std::string > & unit::recruits () const
 The type IDs of the other units this unit may recruit, if possible. More...
 
void unit::set_recruits (const std::vector< std::string > &recruits)
 Sets the recruit list. More...
 
int unit::cost () const
 How much gold is required to recruit this unit. More...
 
int unit::recall_cost () const
 How much gold it costs to recall this unit. More...
 
void unit::set_recall_cost (int recall_cost)
 Sets the cost of recalling this unit. More...
 
const configunit::recall_filter () const
 Gets the filter constraints upon which units this unit may recall, if able. More...
 
const std::string & unit::get_role () const
 Gets this unit's role. More...
 
void unit::set_role (const std::string &role)
 Sets a unit's role. More...
 
std::string unit::usage () const
 Gets this unit's usage. More...
 
void unit::set_usage (const std::string &usage)
 Sets this unit's usage. More...
 
configunit::variables ()
 Gets any user-defined variables this unit 'owns'. More...
 
const configunit::variables () const
 Const overload of variables. More...
 
bool unit::get_hidden () const
 Gets whether this unit is currently hidden on the map. More...
 
void unit::set_hidden (bool state) const
 Sets whether the unit is hidden on the map. More...
 
double unit::hp_bar_scaling () const
 The factor by which the HP bar should be scaled. More...
 
double unit::xp_bar_scaling () const
 The factor by which the XP bar should be scaled. More...
 
bool unit::hold_position () const
 Whether the unit has been instructed to hold its position. More...
 
void unit::toggle_hold_position ()
 Toggle the unit's hold position status. More...
 
void unit::set_user_end_turn (bool value=true)
 Set whether the user ended their turn. More...
 
void unit::toggle_user_end_turn ()
 Toggle whether the user ended their turn. More...
 
bool unit::user_end_turn () const
 Check whether the user ended their turn. More...
 
void unit::new_turn ()
 Refresh unit for the beginning of a turn. More...
 
void unit::end_turn ()
 Refresh unit for the end of a turn. More...
 
void unit::new_scenario ()
 Refresh unit for the beginning of a new scenario. More...
 
bool unit::take_hit (int damage)
 Damage the unit. More...
 
void unit::heal (int amount)
 Heal the unit The number of hitpoints to gain. More...
 
void unit::heal_fully ()
 Fully heal the unit, restoring it to max hitpoints. More...
 
const std::set< std::string > unit::get_states () const
 Get the status effects currently affecting the unit. More...
 
bool unit::get_state (const std::string &state) const
 Check if the unit is affected by a status effect. More...
 
void unit::set_state (const std::string &state, bool value)
 Set whether the unit is affected by a status effect. More...
 
void unit::set_state (state_t state, bool value)
 Set whether the unit is affected by a status effect. More...
 
bool unit::get_state (state_t state) const
 Check if the unit is affected by a status effect. More...
 
static state_t unit::get_known_boolean_state_id (const std::string &state)
 Convert a string status effect ID to a built-in status effect ID. More...
 
bool unit::poisoned () const
 Check if the unit has been poisoned. More...
 
bool unit::incapacitated () const
 Check if the unit has been petrified. More...
 
bool unit::slowed () const
 Check if the unit has been slowed. More...
 

Detailed Description

Enumeration Type Documentation

◆ state_t

Built-in status effects known to the engine.

Enumerator
STATE_SLOWED 

The unit is slowed - it moves slower and does less damage.

STATE_POISONED 

The unit is poisoned - it loses health each turn.

STATE_PETRIFIED 

The unit is petrified - it cannot move or be attacked.

STATE_UNCOVERED 

The unit is uncovered - it was hiding but has been spotted.

STATE_NOT_MOVED 

The unit has not moved.

Todo:
Explain better
STATE_UNHEALABLE 

The unit cannot be healed.

STATE_GUARDIAN 

The unit is a guardian - it won't move unless a target is sighted.

STATE_UNKNOWN 

A status effect not known to the engine.

Definition at line 740 of file unit.hpp.

Function Documentation

◆ alignment()

unit_type::ALIGNMENT unit::alignment ( ) const
inline

◆ big_profile()

std::string unit::big_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.

Definition at line 1024 of file unit.cpp.

References unit::absolute_image(), and unit::profile_.

Referenced by impl_unit_get().

◆ can_recruit()

bool unit::can_recruit ( ) const
inline

◆ cost()

int unit::cost ( ) const
inline

◆ end_turn()

void unit::end_turn ( )

◆ experience()

int unit::experience ( ) const
inline

◆ experience_overflow()

unsigned int unit::experience_overflow ( ) const
inline

The number of experience points over max this unit has, or 0 if current XP < max XP.

Definition at line 450 of file unit.hpp.

◆ experience_to_advance()

unsigned int unit::experience_to_advance ( ) const
inline

The number of experience points this unit needs to level up, or 0 if current XP > max XP.

Definition at line 444 of file unit.hpp.

Referenced by unit::xp_color().

◆ gender()

unit_race::GENDER unit::gender ( ) const
inline

◆ get_hidden()

bool unit::get_hidden ( ) const
inline

Gets whether this unit is currently hidden on the map.

Todo:
document hiddenness

Definition at line 601 of file unit.hpp.

Referenced by wfl::unit_callable::get_value(), impl_unit_get(), and unit_drawer::redraw_unit().

◆ get_known_boolean_state_id()

unit::state_t unit::get_known_boolean_state_id ( const std::string &  state)
static

Convert a string status effect ID to a built-in status effect ID.

Returns
the state_t representing the status, or STATE_UNKNOWN if it's not built-in

Definition at line 1338 of file unit.cpp.

References i, unit::known_boolean_state_names_, unit::STATE_GUARDIAN, unit::STATE_NOT_MOVED, unit::STATE_PETRIFIED, unit::STATE_POISONED, unit::STATE_SLOWED, unit::STATE_UNCOVERED, unit::STATE_UNHEALABLE, and unit::STATE_UNKNOWN.

Referenced by unit::get_state(), and unit::set_state().

◆ get_role()

const std::string& unit::get_role ( ) const
inline

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.

Definition at line 552 of file unit.hpp.

Referenced by wfl::unit_callable::get_value(), and impl_unit_get().

◆ get_state() [1/2]

bool unit::get_state ( const std::string &  state) const

◆ get_state() [2/2]

bool unit::get_state ( state_t  state) const

Check if the unit is affected by a status effect.

Parameters
stateThe status effect to check
Returns
true if the unit is affected by the status effect

Definition at line 1333 of file unit.cpp.

References unit::known_boolean_states_.

◆ get_states()

const std::set< std::string > unit::get_states ( ) const

Get the status effects currently affecting the unit.

Returns
A set of status keys

Definition at line 1293 of file unit.cpp.

References unit::get_state(), unit::known_boolean_state_names_, and unit::states_.

Referenced by wfl::unit_callable::get_value(), and unit::write().

◆ heal()

void unit::heal ( int  amount)

Heal the unit The number of hitpoints to gain.

Definition at line 1277 of file unit.cpp.

References unit::hit_points_, and unit::max_hitpoints().

◆ heal_fully()

void unit::heal_fully ( )
inline

Fully heal the unit, restoring it to max hitpoints.

Definition at line 712 of file unit.hpp.

Referenced by unit::apply_builtin_effect(), and unit::new_scenario().

◆ hitpoints()

int unit::hitpoints ( ) const
inline

◆ hold_position()

bool unit::hold_position ( ) const
inline

Whether the unit has been instructed to hold its position.

This excludes it from the unit cycling function.

Returns
true if it is holding position

Definition at line 632 of file unit.hpp.

◆ hp_bar_scaling()

double unit::hp_bar_scaling ( ) const
inline

The factor by which the HP bar should be scaled.

Todo:
: document further

Definition at line 613 of file unit.hpp.

Referenced by unit_drawer::redraw_unit().

◆ id()

const std::string& unit::id ( ) const
inline

◆ incapacitated()

bool unit::incapacitated ( ) const
inline

◆ level()

int unit::level ( ) const
inline

◆ max_experience()

int unit::max_experience ( ) const
inline

◆ max_hitpoints()

int unit::max_hitpoints ( ) const
inline

◆ name()

const t_string& unit::name ( ) const
inline

◆ new_scenario()

void unit::new_scenario ( )

Refresh unit for the beginning of a new scenario.

Definition at line 1262 of file unit.cpp.

References unit::expire_modifications(), unit::goto_, unit::heal_fully(), unit::set_state(), unit::STATE_GUARDIAN, unit::STATE_PETRIFIED, unit::STATE_POISONED, and unit::STATE_SLOWED.

◆ new_turn()

void unit::new_turn ( )

◆ poisoned()

bool unit::poisoned ( ) const
inline

Check if the unit has been poisoned.

Returns
true if it's poisoned

Definition at line 775 of file unit.hpp.

Referenced by unit_drawer::redraw_unit().

◆ race()

const unit_race* unit::race ( ) const
inline

Gets this unit's race.

Returns
A pointer to a unit_race object - never nullptr, but it may point to the null race.

Definition at line 408 of file unit.hpp.

Referenced by wfl::unit_callable::get_value(), impl_unit_get(), gui2::unit_preview_pane::set_displayed_unit(), and unit_race().

◆ recall_cost()

int unit::recall_cost ( ) const
inline

◆ recall_filter()

const config& unit::recall_filter ( ) const
inline

Gets the filter constraints upon which units this unit may recall, if able.

Definition at line 541 of file unit.hpp.

Referenced by wb::recall::check_validity(), actions::get_recalls(), and impl_unit_get().

◆ recruits()

const std::vector<std::string>& unit::recruits ( ) const
inline

The type IDs of the other units this unit may recruit, if possible.

Definition at line 514 of file unit.hpp.

Referenced by wb::recruit::check_validity(), actions::find_recall_location(), wfl::unit_callable::get_value(), impl_unit_get(), and unit::set_recruits().

◆ rename()

void unit::rename ( const std::string &  name)
inline

Attempts to rename this unit's translatable display name, taking the 'unrenamable' flag into account.

If a direct rename is desired, use set_name.

Todo:
should this also take a t_string?

Definition at line 349 of file unit.hpp.

◆ set_alignment()

void unit::set_alignment ( unit_type::ALIGNMENT  alignment)
inline

Sets the alignment of this unit.

Definition at line 397 of file unit.hpp.

Referenced by impl_unit_set().

◆ set_can_recruit()

void unit::set_can_recruit ( bool  canrecruit)
inline

Sets whether this unit can recruit other units.

Definition at line 508 of file unit.hpp.

Referenced by impl_unit_set().

◆ set_experience()

void unit::set_experience ( int  xp)
inline

Sets the current experience point amount.

Definition at line 456 of file unit.hpp.

Referenced by battle_context::choose_defender_weapon(), and impl_unit_set().

◆ set_hidden()

void unit::set_hidden ( bool  state) const

Sets whether the unit is hidden on the map.

Definition at line 2526 of file unit.cpp.

Referenced by impl_unit_set(), wb::temporary_unit_hider::temporary_unit_hider(), and wb::temporary_unit_hider::~temporary_unit_hider().

◆ set_hitpoints()

void unit::set_hitpoints ( int  hp)
inline

Sets the current hitpoint amount.

Definition at line 426 of file unit.hpp.

Referenced by impl_unit_set().

◆ set_id()

void unit::set_id ( const std::string &  id)
inline

Sets this unit's string ID.

Definition at line 311 of file unit.hpp.

Referenced by impl_unit_set().

◆ set_level()

void unit::set_level ( int  level)
inline

Sets the current level of this unit.

Definition at line 468 of file unit.hpp.

References game_config::images::level.

Referenced by impl_unit_set().

◆ set_name()

void unit::set_name ( const t_string name)
inline

Sets this unit's translatable display name.

This should only be used internally since it ignores the 'unrenamable' flag.

Definition at line 338 of file unit.hpp.

Referenced by impl_unit_set().

◆ set_recall_cost()

void unit::set_recall_cost ( int  recall_cost)
inline

Sets the cost of recalling this unit.

Definition at line 535 of file unit.hpp.

References game_config::recall_cost.

Referenced by impl_unit_set().

◆ set_recruits()

void unit::set_recruits ( const std::vector< std::string > &  recruits)

Sets the recruit list.

Definition at line 1147 of file unit.cpp.

References unit_type_data::check_types(), unit::recruit_list_, unit::recruits(), and unit_types.

Referenced by impl_unit_set(), and unit::init().

◆ set_role()

void unit::set_role ( const std::string &  role)
inline

Sets a unit's role.

Definition at line 558 of file unit.hpp.

Referenced by impl_unit_set().

◆ set_side()

void unit::set_side ( unsigned int  new_side)
inline

Sets the side this unit belongs to.

Definition at line 271 of file unit.hpp.

Referenced by impl_unit_set().

◆ set_state() [1/2]

void unit::set_state ( const std::string &  state,
bool  value 
)

Set whether the unit is affected by a status effect.

Parameters
stateThe status effect to change
valueWhether the unit should be affected by the status

Definition at line 1358 of file unit.cpp.

References unit::appearance_changed_, unit::get_known_boolean_state_id(), unit::STATE_UNKNOWN, and unit::states_.

Referenced by unit::add_modification(), unit::advance_to(), unit::apply_builtin_effect(), battle_context::choose_defender_weapon(), unit::end_turn(), impl_unit_status_set(), unit::init(), unit::new_scenario(), and unit::new_turn().

◆ set_state() [2/2]

void unit::set_state ( state_t  state,
bool  value 
)

Set whether the unit is affected by a status effect.

Parameters
stateThe status effect to change
valueWhether the unit should be affected by the status

Definition at line 1328 of file unit.cpp.

References unit::known_boolean_states_.

◆ set_underlying_id()

void unit::set_underlying_id ( n_unit::id_manager id_manager)
private

◆ set_unrenamable()

void unit::set_unrenamable ( bool  unrenamable)
inline

Sets the 'unrenamable' flag.

Usually used for scenario-specific units which should not be renamed.

Definition at line 369 of file unit.hpp.

◆ set_usage()

void unit::set_usage ( const std::string &  usage)
inline

Sets this unit's usage.

Definition at line 575 of file unit.hpp.

Referenced by unit::advance_to(), and unit::init().

◆ set_user_end_turn()

void unit::set_user_end_turn ( bool  value = true)
inline

Set whether the user ended their turn.

Todo:
Verify meaning and explain better

Definition at line 652 of file unit.hpp.

◆ side()

int unit::side ( ) const
inline

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.

Definition at line 265 of file unit.hpp.

Referenced by actions::actor_sighted(), pathfind::full_cost_map::add_unit(), gui2::dialogs::add_unit_entry(), attack_info(), game_state::can_recruit_from(), game_state::can_recruit_on(), can_see(), actions::shroud_clearer::clear_dest(), actions::shroud_clearer::clear_unit(), pathfind::shortest_path_calculator::cost(), wb::manager::create_temp_move(), gui2::dialogs::unit_recall::dismiss_unit(), ai::default_recruitment::recruitment::do_combat_analysis(), game_display::draw_hex_cursor(), pathfind::enemy_zoc(), ai::ai_default_rca::get_healing_phase::evaluate(), events::menu_handler::execute_gotos(), wb::find_actions_of(), actions::find_recruit_location(), pathfind::find_routes(), pathfind::find_vacant_castle(), wb::future_visible_unit(), ai::default_recruitment::recruitment::get_cost_map_of_side(), actions::get_recalls(), ai::move_result::get_unit(), ai::stopunit_result::get_unit(), ai::default_recruitment::recruitment::get_unit_ratio(), wfl::unit_callable::get_value(), impl_unit_get(), unit::init(), game_lua_kernel::intf_find_path(), game_lua_kernel::intf_find_reach(), ai::ai_default_rca::aspect_attacks::is_allowed_attacker(), ai::ai_default_rca::aspect_attacks::is_allowed_enemy(), unit::is_visible_to_team(), luaW_pushfaivariant(), pathfind::mark_route(), wb::path_cost(), pathfind::paths::paths(), unit_creator::post_create(), ai::readonly_context_impl::power_projection(), ai::ai_default_rca::aspect_attacks_base::rate_terrain(), unit_drawer::redraw_unit(), events::mouse_handler::show_attack_options(), pathfind::teleport_map::teleport_map(), display_context::unit_can_move(), unit_moves(), unit_side(), ai::default_recruitment::recruitment::update_important_hexes(), ai::default_recruitment::recruitment::update_own_units_count(), events::menu_handler::update_shroud_now(), and display_context::would_be_discovered().

◆ slowed()

bool unit::slowed ( ) const
inline

Check if the unit has been slowed.

Returns
true if it's slowed

Definition at line 793 of file unit.hpp.

Referenced by unit_drawer::redraw_unit().

◆ small_profile()

std::string unit::small_profile ( ) const

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.

Definition at line 1033 of file unit.cpp.

References unit::absolute_image(), unit::profile_, and unit::small_profile_.

Referenced by REPORT_GENERATOR().

◆ take_hit()

bool unit::take_hit ( int  damage)
inline

Damage the unit.

Returns
true if the unit dies as a result

Definition at line 697 of file unit.hpp.

◆ toggle_hold_position()

void unit::toggle_hold_position ( )
inline

Toggle the unit's hold position status.

Definition at line 640 of file unit.hpp.

◆ toggle_user_end_turn()

void unit::toggle_user_end_turn ( )
inline

Toggle whether the user ended their turn.

Todo:
Verify meaning and explain better

Definition at line 661 of file unit.hpp.

◆ type()

const unit_type& unit::type ( ) const
inline

◆ type_id()

const std::string& unit::type_id ( ) const
inline

◆ type_name()

const t_string& unit::type_name ( ) const
inline

◆ undead_variation()

const std::string& unit::undead_variation ( ) const
inline

The ID of the undead variation (ie, dwarf, swimmer) of this unit.

Definition at line 480 of file unit.hpp.

Referenced by battle_context_unit_stats::battle_context_unit_stats().

◆ underlying_id()

std::size_t unit::underlying_id ( ) const
inline

◆ unit_description()

t_string unit::unit_description ( ) const
inline

A detailed description of this unit.

Definition at line 375 of file unit.hpp.

Referenced by unit_type(), and unit::write().

◆ unrenamable()

bool unit::unrenamable ( ) const
inline

Whether this unit can be renamed.

This flag is considered by rename, but not set_name.

Definition at line 361 of file unit.hpp.

◆ usage()

std::string unit::usage ( ) const
inline

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

Definition at line 569 of file unit.hpp.

References unit_detail::get_or_default().

Referenced by wfl::unit_callable::get_value(), wfl::unit_type_callable::get_value(), and impl_unit_get().

◆ user_end_turn()

bool unit::user_end_turn ( ) const
inline

Check whether the user ended their turn.

Todo:
Verify meaning and explain better

Definition at line 673 of file unit.hpp.

Referenced by unit_drawer::redraw_unit(), and events::menu_handler::update_shroud_now().

◆ variables() [1/2]

config& unit::variables ( )
inline

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.

Definition at line 586 of file unit.hpp.

Referenced by wfl::unit_callable::get_value(), impl_unit_variables_get(), impl_unit_variables_set(), and unit::init().

◆ variables() [2/2]

const config& unit::variables ( ) const
inline

Const overload of variables.

Definition at line 592 of file unit.hpp.

◆ variation()

const std::string& unit::variation ( ) const
inline

The ID of the variation of this unit's type.

Definition at line 474 of file unit.hpp.

Referenced by wfl::unit_callable::get_value(), and impl_unit_get().

◆ xp_bar_scaling()

double unit::xp_bar_scaling ( ) const
inline

The factor by which the XP bar should be scaled.

Todo:
: document further

Definition at line 622 of file unit.hpp.

Referenced by unit_drawer::redraw_unit().