41 const
int best_weapon)
43 , selected_weapon_(-1)
44 , attacker_itor_(attacker_itor)
45 , defender_itor_(defender_itor)
46 , weapons_(std::move(weapons))
47 , best_weapon_(best_weapon)
53 const std::size_t
index = find_widget<listbox>(
"weapon_list").get_selected_row();
60 find_widget<button>(
"damage_calculation"),
63 find_widget<unit_preview_pane>(
"attacker_pane")
66 find_widget<unit_preview_pane>(
"defender_pane")
71 listbox& weapon_list = find_widget<listbox>(
"weapon_list");
78 for(
const auto & weapon :
weapons_) {
85 *defender.
weapon : *no_weapon;
90 const std::string attw_name = !attacker_weapon.
name().
empty() ? attacker_weapon.
name() :
" ";
91 const std::string defw_name = !defender_weapon.
name().
empty() ? defender_weapon.
name() :
" ";
93 std::string range = attacker_weapon.
range().empty() ? defender_weapon.
range() : attacker_weapon.
range();
113 std::string attw_type = !(types).empty() ? types : attacker_weapon.
type();
114 if (!attw_type.empty()) {
118 std::string defw_type = !(def_types).empty() ? def_types : defender_weapon.
type();
119 if (!defw_type.empty()) {
123 const std::set<std::string> checking_tags_other = {
"damage_type",
"disable",
"berserk",
"drains",
"heal_on_hit",
"plague",
"slow",
"petrifies",
"firststrike",
"poison"};
130 std::string defw_specials = defender_attack ? defender_weapon.
weapon_specials() :
"";
131 std::string defw_specials_dmg = defender_attack ? defender_weapon.
weapon_specials_value({
"leadership",
"damage"}) :
"";
132 std::string defw_specials_atk = defender_attack ? defender_weapon.
weapon_specials_value({
"attacks",
"swarm"}) :
"";
133 std::string defw_specials_cth = defender_attack ? defender_weapon.
weapon_specials_value({
"chance_to_hit"}) :
"";
134 std::string defw_specials_others = defender_attack ? defender_weapon.
weapon_specials_value(checking_tags_other) :
"";
136 if(!attw_specials.empty()) {
137 attw_specials =
" " + attw_specials;
139 if(!attw_specials_dmg.empty()) {
140 attw_specials_dmg =
" " + attw_specials_dmg;
142 if(!attw_specials_atk.empty()) {
143 attw_specials_atk =
" " + attw_specials_atk;
145 if(!attw_specials_cth.empty()) {
146 attw_specials_cth =
" " + attw_specials_cth;
148 if(!attw_specials_others.empty()) {
151 if(!defw_specials.empty()) {
152 defw_specials =
" " + defw_specials;
154 if(!defw_specials_dmg.empty()) {
155 defw_specials_dmg =
" " + defw_specials_dmg;
157 if(!defw_specials_atk.empty()) {
158 defw_specials_atk =
" " + defw_specials_atk;
160 if(!defw_specials_cth.empty()) {
161 defw_specials_cth =
" " + defw_specials_cth;
163 if(!defw_specials_others.empty()) {
167 std::stringstream attacker_stats, defender_stats, attacker_tooltip, defender_tooltip;
173 << attw_specials <<
"\n"
176 attacker_tooltip <<
_(
"Weapon: ") <<
markup::bold(attw_name) <<
"\n"
177 <<
_(
"Type: ") << attw_type <<
"\n"
186 << defw_specials <<
"\n"
189 defender_tooltip <<
_(
"Weapon: ") <<
markup::bold(defw_name) <<
"\n"
190 <<
_(
"Type: ") << defw_type <<
"\n"
195 << defw_specials_others;
200 item[
"use_markup"] =
"true";
202 item[
"label"] = attacker_weapon.
icon();
203 data.emplace(
"attacker_weapon_icon", item);
205 item[
"tooltip"] = attacker_tooltip.str();
206 item[
"label"] = attacker_stats.str();
207 data.emplace(
"attacker_weapon", item);
208 item[
"tooltip"] =
"";
211 data.emplace(
"range", item);
213 item[
"tooltip"] = defender_attack ? defender_tooltip.str() :
"";
214 item[
"label"] = defender_stats.str();
215 data.emplace(
"defender_weapon", item);
217 item[
"tooltip"] =
"";
218 item[
"label"] = defender_weapon.
icon();
219 data.emplace(
"defender_weapon_icon", item);
std::string weapon_specials() const
Returns a comma-separated string of active names for the specials of *this.
std::string weapon_specials_value(const std::set< std::string > &checking_tags) const
const std::string & range() const
const std::string & type() const
const t_string & name() const
specials_context_t specials_context(unit_const_ptr self, unit_const_ptr other, const map_location &unit_loc, const map_location &other_loc, bool attacking, const_attack_ptr other_attack) const
const std::string & icon() const
std::pair< std::string, int > effective_damage_type() const
The type of attack used and the resistance value that does the most damage.
Computes the statistics of a battle between an attacker and a defender unit.
A config object defines a single node in a WML file, with access to child nodes.
Abstract base class for all modal dialogs.
virtual void post_show() override
Actions to be taken after the window has been shown.
int selected_weapon_
The index of the selected weapon.
unit_map::iterator defender_itor_
Iterator pointing to the defender.
int best_weapon_
The best weapon, aka the one high-lighted.
virtual void pre_show() override
Actions to be taken before showing the window.
unit_map::iterator attacker_itor_
Iterator pointing to the attacker.
void damage_calc_callback()
std::vector< battle_context > weapons_
List of all battle contexts used for getting the weapons.
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
bool select_row(const unsigned row, const bool select=true)
Selects a row.
unsigned get_item_count() const
Returns the number of items in the listbox.
void keyboard_capture(widget *widget)
Container associating units to locations.
static std::string _(const char *str)
symbol_table string_table
const std::string unicode_em_dash
const std::string weapon_numbers_sep
color_t red_to_green(double val, bool for_text)
Return a color corresponding to the value val red for val=0.0 to green for val=100....
REGISTER_DIALOG(editor_edit_unit)
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
@ OK
Dialog was closed with the OK button.
std::string italic(Args &&... data)
Applies italic Pango markup to the input.
std::string bold(Args &&... data)
Applies bold Pango markup to the input.
std::string span_color(const color_t &color, Args &&... data)
Applies Pango markup to the input specifying its display color.
void unit_attack(display *disp, game_board &board, const map_location &a, const map_location &b, int damage, const attack_type &attack, const const_attack_ptr &secondary_attack, int swing, const std::string &hit_text, int drain_amount, const std::string &att_text, const std::vector< std::string > *extra_hit_sounds, bool attacking)
Make the unit on tile 'a' attack the unit on tile 'b'.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
std::string::const_iterator iterator
std::shared_ptr< const attack_type > const_attack_ptr
Structure describing the statistics of a unit involved in the battle.
unsigned int num_blows
Effective number of blows, takes swarm into account.
const_attack_ptr weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
int damage
Effective damage of the weapon (all factors accounted for).
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
The basic class for representing 8-bit RGB or RGBA colour values.
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...