The Battle for Wesnoth  1.19.5+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 = utils::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::trait_nonhidden_ids () const
 Gets the ids of the traits corresponding to those returned by trait_names() and trait_descriptions(). More...
 
std::vector< std::string > unit::get_modifications_list (const std::string &mod_type) const
 Gets a list of the modification this unit currently has. More...
 
std::vector< std::string > unit::get_traits_list () const
 Gets a list of the traits this unit currently has, including hidden traits. More...
 
std::vector< std::string > unit::get_objects_list () const
 
std::vector< std::string > unit::get_advancements_list () const
 
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...
 
void unit::set_loyal (bool loyal)
 
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 = utils::variant<upkeep_full, upkeep_loyal, int>

Definition at line 1182 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 2542 of file unit.cpp.

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

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

References config::add_child(), c, unit::can_recruit(), config::child_range(), config::erase(), 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_, s, utils::split(), t, and unit::type().

Referenced by unit::advance_to().

◆ get_advancements_list()

std::vector<std::string> unit::get_advancements_list ( ) const
inline

Definition at line 1145 of file unit.hpp.

References unit::get_modifications_list().

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

◆ get_modifications_list()

std::vector< std::string > unit::get_modifications_list ( const std::string &  mod_type) const

Gets a list of the modification this unit currently has.

Parameters
mod_typetype of modification.
Returns
A list of modification IDs.

Definition at line 934 of file unit.cpp.

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

Referenced by unit::get_advancements_list(), unit::get_objects_list(), and unit::get_traits_list().

◆ get_objects_list()

std::vector<std::string> unit::get_objects_list ( ) const
inline

Definition at line 1140 of file unit.hpp.

References unit::get_modifications_list().

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

◆ get_traits_list()

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

Gets a list of the traits this unit currently has, including hidden traits.

Returns
A list of trait IDs.

Definition at line 1135 of file unit.hpp.

References unit::get_modifications_list().

Referenced by gui2::dialogs::add_unit_entry(), unit_filter_impl::unit_filter_compound::fill(), wfl::unit_callable::get_value(), and UNIT_GETTER().

◆ is_fearless()

bool unit::is_fearless ( ) const
inline

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

Definition at line 1294 of file unit.hpp.

References unit::is_fearless_.

Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), wfl::unit_callable::get_value(), gui2::dialogs::attack_predictions::set_data(), unit_alignment(), and UNIT_GETTER().

◆ is_healthy()

bool unit::is_healthy ( ) const
inline

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

Definition at line 1300 of file unit.hpp.

References unit::is_healthy_.

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

◆ loyal()

bool unit::loyal ( ) const

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

Definition at line 1700 of file unit.cpp.

References unit::upkeep_.

Referenced by gui2::dialogs::unit_recall::dismiss_unit(), unit::set_loyal(), and editor::map_context::to_config().

◆ set_loyal()

void unit::set_loyal ( bool  loyal)

Definition at line 1705 of file unit.cpp.

References utils::erase(), unit::loyal(), unit::overlays_, and unit::upkeep_.

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

References unit::upkeep_.

Referenced by UNIT_SETTER().

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

References unit::trait_descriptions_.

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 1098 of file unit.hpp.

References unit::trait_names_.

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

◆ trait_nonhidden_ids()

std::vector<std::string> unit::trait_nonhidden_ids ( ) const
inline

Gets the ids of the traits corresponding to those returned by trait_names() and trait_descriptions().

Omits hidden traits, which are those with an empty name.

Returns
A list of trait IDs.

Definition at line 1119 of file unit.hpp.

References unit::trait_nonhidden_ids_.

Referenced by 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 1690 of file unit.cpp.

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

Referenced by unit_filter_impl::unit_filter_compound::fill(), wfl::unit_callable::get_value(), unit::parse_upkeep(), display_context::side_upkeep(), and unit::write_upkeep().

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

References unit::upkeep_.

Referenced by UNIT_GETTER().