The Battle for Wesnoth  1.19.8+dev
helper.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "units/map.hpp"
19 #include "units/types.hpp"
20 
21 namespace unit_helper {
22 
23 /**
24  * Encapsulates the logic for deciding whether an iterator @a u points to
25  * a unit that can advance.
26  * @return true if the unit exists, has available advances, and can_advance().
27  */
29 
30 /**
31  * Determines the total number of available advancements (of any kind) for
32  * a given unit. This includes normal advances and modifiers.
33  * @return the total number of possible advancements.
34  */
36 
37 /**
38  * @return the name of the color encoding the weight of the unit's
39  * resistance value for presenting it to the player.
40  */
41 std::string resistance_color(const int resistance);
42 
43 /**
44  * @return the tooltip text showing a unit's level and what it can advance to.
45  */
46 std::string unit_level_tooltip(const unit &u);
47 
48 /**
49  * @return the tooltip text showing a unit type's level and what it can
50  * advance to.
51  */
52 std::string unit_level_tooltip(const unit_type &u);
53 
54 /**
55  * @return If active, do nothing. If inactive, surround with pango tag that
56  * changes font color to grey.
57  */
58 std::string maybe_inactive(const std::string& str, bool active);
59 
60 /**
61  * @return If unit recall cost is greater than team's recall cost,
62  * return a help markup string that shows the unit recall cost
63  * in red font color. If unit recall cost is less than team's cost,
64  * color in green instead. If equal, default color.
65  * In all cases, a gold icon using `<img>` tag is prepended to the formatted cost.
66  * Icon is greyscaled when unit recall cost > team recall cost.
67  * Eg. `<img src='themes/gold.png~GS()'/><span color='#ff0000'>40</span>`.
68  */
69 std::string format_cost_string(int unit_recall_cost, const int team_recall_cost);
70 
71 /**
72  * @return Help markup string with gold icon followed by unit_cost.
73  * Eg. `<img src='themes/gold.png'/>40`
74  */
75 std::string format_cost_string(int unit_cost);
76 
77 /**
78  * @return A pango formatted string representation of level.
79  * The applied formatting is different for each level.
80  * L0: level number in normal text, grey color
81  * L1: level number in normal text
82  * L2: level number in bold text
83  * L3: level number in bold, font color `#e2b776`
84  * L3+: level number in bold, font color `#dd6600`.
85  * If not recallable, return greyscaled versions.
86  * So, L0, L1: normal text, L2+: bold text
87  */
88 std::string format_level_string(const int level, bool recallable);
89 
90 /**
91  * @return A pango formatted string representation of "moves_left/moves_max",
92  * colored based on condition below:
93  * moves_left is zero: "moves_left/moves_max" colored in red
94  * moves_left is less than/equal to moves_max: "moves_left/moves_max" colored in green
95  * moves_left is greater than moves_max: "moves_left/moves_max" colored in yellow
96  */
97 std::string format_movement_string(const int moves_left, const int moves_max);
98 }
A single unit type that the player may recruit.
Definition: types.hpp:43
This class represents a single unit of a specific type.
Definition: unit.hpp:133
static std::string unit_level_tooltip(const int level, const std::vector< std::string > &adv_to_types, const std::vector< config > &adv_to_mods)
Definition: helper.cpp:55
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.
Definition: helper.cpp:34
std::string resistance_color(const int resistance)
Maps resistance <= -60 (resistance value <= -60%) to intense red.
Definition: helper.cpp:49
std::string format_level_string(const int level, bool recallable)
Definition: helper.cpp:120
std::string format_cost_string(int unit_recall_cost, const int team_recall_cost)
Definition: helper.cpp:96
std::string maybe_inactive(const std::string &str, bool active)
Definition: helper.cpp:91
int number_of_possible_advances(const unit &u)
Determines the total number of available advancements (of any kind) for a given unit.
Definition: helper.cpp:29
std::string format_movement_string(const int moves_left, const int moves_max)
Definition: helper.cpp:139
int moves_left
Definition: pathfind.cpp:156