The Battle for Wesnoth  1.15.6+dev
Classes | Typedefs | Functions
Trait and upkeep functions

Classes

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

Typedefs

using unit::upkeep_t = boost::variant< upkeep_full, upkeep_loyal, int >
 

Functions

void unit::generate_traits (bool must_have_only=false)
 Applies mandatory traits (e.g. More...
 
const std::vector< t_string > & unit::trait_names () const
 Gets the names of the currently registered traits. More...
 
const std::vector< t_string > & unit::trait_descriptions () const
 Gets the descriptions of the currently registered traits. More...
 
std::vector< std::string > unit::get_traits_list () const
 Gets a list of the traits this unit currently has. More...
 
void unit::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 unit::upkeep () const
 Gets the amount of gold this unit costs a side per turn. More...
 
upkeep_t unit::upkeep_raw () const
 Gets the raw variant controlling the upkeep value. More...
 
void unit::set_upkeep (upkeep_t v)
 Sets the upkeep value to a specific value value. More...
 
bool unit::loyal () const
 Gets whether this unit is loyal - ie, it costs no upkeep. More...
 
bool unit::is_fearless () const
 Gets whether this unit is fearless - ie, unaffected by time of day. More...
 
bool unit::is_healthy () const
 Gets whether this unit is healthy - ie, always rest heals. More...
 

Detailed Description

Typedef Documentation

◆ upkeep_t

using unit::upkeep_t = boost::variant<upkeep_full, upkeep_loyal, int>

Definition at line 1176 of file unit.hpp.

Function Documentation

◆ add_trait_description()

void unit::add_trait_description ( const config trait,
const t_string description 
)

Register a trait's name and its description for the UI's use.

The resulting data can be fetched with trait_names and trait_descriptions.

Parameters
traitA config containing the trait's attributes.
descriptionThe translatable description of the trait.

Definition at line 2396 of file unit.cpp.

References t_string::empty(), unit_race::FEMALE, unit::gender_, gender_string(), unit::name(), mariadb::value::string, unit::trait_descriptions_, and unit::trait_names_.

Referenced by unit::add_modification().

◆ generate_traits()

void unit::generate_traits ( bool  must_have_only = false)

Applies mandatory traits (e.g.

undead, mechanical) to a unit and then fills in the remaining traits traits until no more are available (leaders have a restricted set of available traits) or the unit has its maximum number of traits.

This routine does not apply the effects of added traits to a unit; that must be done by the caller.

Note that random numbers used in config files don't work in multiplayer, so leaders should be barred from all random traits until that is fixed. Later the restrictions will be based on play balance.

Parameters
must_have_onlyWhether random or optional traits should be included or not. If false only mandatory traits will be used.

Definition at line 814 of file unit.cpp.

References config::add_child(), unit::can_recruit(), config::child_range(), randomness::generator, randomness::rng::get_random_int(), unit_type::log_id(), LOG_UT, unit::modifications_, unit_type::num_traits(), unit_type::possible_traits(), unit::random_traits_, mariadb::value::string, t, and unit::type().

Referenced by unit::advance_to().

◆ get_traits_list()

std::vector< std::string > unit::get_traits_list ( ) const

Gets a list of the traits this unit currently has.

Returns
A list of trait IDs.

Definition at line 871 of file unit.cpp.

References config::child_range(), and unit::modifications_.

Referenced by gui2::dialogs::add_unit_entry(), wfl::unit_callable::get_value(), and unit_traits().

◆ is_fearless()

bool unit::is_fearless ( ) const
inline

Gets whether this unit is fearless - ie, unaffected by time of day.

Definition at line 1233 of file unit.hpp.

Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), gui2::dialogs::attack_predictions::set_data(), and unit_alignment().

◆ is_healthy()

bool unit::is_healthy ( ) const
inline

Gets whether this unit is healthy - ie, always rest heals.

Definition at line 1239 of file unit.hpp.

◆ loyal()

bool unit::loyal ( ) const

Gets whether this unit is loyal - ie, it costs no upkeep.

Definition at line 1612 of file unit.cpp.

References unit::upkeep_.

Referenced by gui2::dialogs::unit_recall::dismiss_unit().

◆ set_upkeep()

void unit::set_upkeep ( upkeep_t  v)
inline

Sets the upkeep value to a specific value value.

Does not necessarily need to be numeric

Definition at line 1224 of file unit.hpp.

◆ trait_descriptions()

const std::vector<t_string>& unit::trait_descriptions ( ) const
inline

Gets the descriptions of the currently registered traits.

Returns
A list of translatable trait descriptions.

Definition at line 1088 of file unit.hpp.

Referenced by gui2::unit_preview_pane::set_displayed_unit(), and unit_traits().

◆ trait_names()

const std::vector<t_string>& unit::trait_names ( ) const
inline

Gets the names of the currently registered traits.

Returns
A list of translatable trait names.

Definition at line 1078 of file unit.hpp.

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

◆ upkeep()

int unit::upkeep ( ) const

Gets the amount of gold this unit costs a side per turn.

This fetches an actual numeric gold value:

  • If can_recruit is true, no upkeep is paid (0 is returned).
  • If a special upkeep flag is set, the associated gold amount is returned (see upkeep_value_visitor).
  • If a numeric value is already set, it is returned directly.
Returns
A gold value, evaluated based on the state of upkeep_raw.

Definition at line 1602 of file unit.cpp.

References variable_info_implementation::apply_visitor(), unit::can_recruit(), and unit::upkeep_.

Referenced by wfl::unit_callable::get_value().

◆ upkeep_raw()

upkeep_t unit::upkeep_raw ( ) const
inline

Gets the raw variant controlling the upkeep value.

This should not usually be called directly. To get an actual numeric value of upkeep use upkeep.

Definition at line 1218 of file unit.hpp.