The Battle for Wesnoth  1.19.13+dev
Functions
unit_helper Namespace Reference

Functions

int number_of_possible_advances (const unit &unit)
 Determines the total number of available advancements (of any kind) for a given unit. More...
 
bool will_certainly_advance (const unit_map::iterator &u)
 Encapsulates the logic for deciding whether an iterator u points to a unit that can advance. More...
 
std::string resistance_color (const int resistance)
 Maps resistance <= -60 (resistance value <= -60%) to intense red. More...
 
static std::string unit_level_tooltip (const int level, const std::vector< std::string > &adv_to_types, const std::vector< config > &adv_to_mods)
 
std::string unit_level_tooltip (const unit &u)
 
std::string unit_level_tooltip (const unit_type &type)
 
std::string maybe_inactive (const std::string &str, bool active)
 
std::string format_cost_string (int unit_recall_cost, bool active)
 
std::string format_cost_string (int unit_recall_cost, const int team_recall_cost)
 
std::string format_level_string (const int level, bool recallable)
 
std::string format_movement_string (const int moves_left, const int moves_max, bool active)
 
int planned_gold_spent (int side_number)
 
std::string check_recruit_purse (int unit_cost, int current_purse, int investments)
 
std::string check_recruit_list (const std::string &type, int side_number, const map_location &target_hex)
 
std::tuple< std::string, map_location, map_locationvalidate_recruit_target (const std::string &type, int side_number, const map_location &target_hex)
 Verifies that target_hex is a valid recruit location for the given side. More...
 

Function Documentation

◆ check_recruit_list()

std::string unit_helper::check_recruit_list ( const std::string &  type,
int  side_number,
const map_location target_hex 
)
Returns
an error message if the given unit is not on the given side's recruit list.

Definition at line 186 of file helper.cpp.

References utils::contains(), unit_type_data::find(), actions::get_recruits(), unit_type::type_name(), unit_types, and VGETTEXT.

Referenced by events::menu_handler::repeat_recruit().

◆ check_recruit_purse()

std::string unit_helper::check_recruit_purse ( int  unit_cost,
int  current_purse,
int  investments 
)
Returns
an error message if the given unit cost is unaffordable.

Definition at line 174 of file helper.cpp.

References _().

Referenced by events::menu_handler::recruit(), and events::menu_handler::repeat_recruit().

◆ format_cost_string() [1/2]

std::string unit_helper::format_cost_string ( int  unit_cost,
bool  active = true 
)
Returns
Help markup string with gold icon followed by unit_cost. Eg. ‘<img src='themes/gold.png’/>40` If active, do nothing. If inactive, surround with pango tag that changes font color to grey and grayscales the gold icon.

Definition at line 101 of file helper.cpp.

References markup::img(), and maybe_inactive().

Referenced by gui2::dialogs::units_dialog::build_recall_dialog(), and gui2::dialogs::units_dialog::build_recruit_dialog().

◆ format_cost_string() [2/2]

std::string unit_helper::format_cost_string ( int  unit_recall_cost,
const int  team_recall_cost 
)
Returns
If unit recall cost is greater than team's recall cost, return a help markup string that shows the unit recall cost in red font color. If unit recall cost is less than team's cost, color in green instead. If equal, default color. In all cases, a gold icon using <img> tag is prepended to the formatted cost. Icon is greyscaled when unit recall cost > team recall cost. Eg. ‘<img src='themes/gold.png~GS()’/>40`.

Definition at line 113 of file helper.cpp.

References font::BAD_COLOR, font::GOOD_COLOR, markup::img(), and markup::span_color().

◆ format_level_string()

std::string unit_helper::format_level_string ( const int  level,
bool  recallable 
)
Returns
A pango formatted string representation of level. The applied formatting is different for each level. L0: level number in normal text, grey color L1: level number in normal text L2: level number in bold text L3: level number in bold, font color #e2b776 L3+: level number in bold, font color #dd6600. If not recallable, return greyscaled versions. So, L0, L1: normal text, L2+: bold text

Definition at line 135 of file helper.cpp.

References markup::bold(), font::INACTIVE_COLOR, game_config::images::level, and markup::span_color().

Referenced by gui2::dialogs::units_dialog::build_recall_dialog(), and gui2::dialogs::units_dialog::build_unit_list_dialog().

◆ format_movement_string()

std::string unit_helper::format_movement_string ( const int  moves_left,
const int  moves_max,
const bool  active = true 
)
Returns
A pango formatted string representation of "moves_left/moves_max", colored based on condition below: moves_left is zero: "moves_left/moves_max" colored in red moves_left is less than/equal to moves_max: "moves_left/moves_max" colored in green moves_left is greater than moves_max: "moves_left/moves_max" colored in yellow active = false: "moves_left/moves_max" colored in grey, regardless of the previous conditions.

Definition at line 154 of file helper.cpp.

References font::BAD_COLOR, font::GOOD_COLOR, font::GRAY_COLOR, moves_left, markup::span_color(), and font::YELLOW_COLOR.

Referenced by gui2::dialogs::units_dialog::build_recall_dialog(), and gui2::dialogs::units_dialog::build_unit_list_dialog().

◆ maybe_inactive()

std::string unit_helper::maybe_inactive ( const std::string &  str,
bool  active 
)
Returns
If active, do nothing. If inactive, surround with pango tag that changes font color to grey.

Definition at line 96 of file helper.cpp.

References font::INACTIVE_COLOR, and markup::span_color().

Referenced by gui2::dialogs::units_dialog::build_recall_dialog(), gui2::dialogs::units_dialog::build_recruit_dialog(), and format_cost_string().

◆ number_of_possible_advances()

int unit_helper::number_of_possible_advances ( const unit unit)

Determines the total number of available advancements (of any kind) for a given unit.

This includes normal advances and modifiers.

Returns
the total number of possible advancements.

Definition at line 34 of file helper.cpp.

References unit::advances_to(), and unit::get_modification_advances().

Referenced by ai::helper_advance_unit(), and will_certainly_advance().

◆ planned_gold_spent()

int unit_helper::planned_gold_spent ( int  side_number)
Returns
the amount of gold tied up in the given side's planned actions.

Definition at line 167 of file helper.cpp.

References resources::controller, and play_controller::get_whiteboard().

Referenced by events::menu_handler::recruit(), and events::menu_handler::repeat_recruit().

◆ resistance_color()

std::string unit_helper::resistance_color ( const int  resistance)

Maps resistance <= -60 (resistance value <= -60%) to intense red.

Maps resistance >= 60 (resistance value >= 60%) to intense green. Intermediate values are affinely mapped to the red-to-green scale, with 0 (0%) being mapped to yellow. Compare attack_info_percent_color() in reports.cpp.

Returns
the name of the color encoding the weight of the unit's resistance value for presenting it to the player.

Definition at line 54 of file helper.cpp.

References game_config::red_to_green(), and color_t::to_hex_string().

Referenced by gui2::get_hp_tooltip(), and unit_hp().

◆ unit_level_tooltip() [1/3]

static std::string unit_helper::unit_level_tooltip ( const int  level,
const std::vector< std::string > &  adv_to_types,
const std::vector< config > &  adv_to_mods 
)
static

◆ unit_level_tooltip() [2/3]

std::string unit_helper::unit_level_tooltip ( const unit u)
Returns
the tooltip text showing a unit's level and what it can advance to.

Definition at line 83 of file helper.cpp.

References unit::advances_to_translated(), unit::get_modification_advances(), unit::level(), and unit_level_tooltip().

◆ unit_level_tooltip() [3/3]

std::string unit_helper::unit_level_tooltip ( const unit_type u)
Returns
the tooltip text showing a unit type's level and what it can advance to.

Definition at line 88 of file helper.cpp.

References unit_level_tooltip().

◆ validate_recruit_target()

std::tuple< std::string, map_location, map_location > unit_helper::validate_recruit_target ( const std::string &  type,
int  side_number,
const map_location target_hex 
)

Verifies that target_hex is a valid recruit location for the given side.

Returns
a tuple consisting of
  • any applicable error message
  • the valid recruit target hex
  • the valid recruit source hex

Definition at line 198 of file helper.cpp.

References actions::find_recruit_location(), and wfl::msg().

Referenced by events::menu_handler::do_recruit().

◆ will_certainly_advance()

bool unit_helper::will_certainly_advance ( const unit_map::iterator u)

Encapsulates the logic for deciding whether an iterator u points to a unit that can advance.

Returns
true if the unit exists, has available advances, and can_advance().

Definition at line 39 of file helper.cpp.

References number_of_possible_advances(), and unit_map::iterator_base< iter_types >::valid().

Referenced by ai::helper_advance_unit().