42 const
int best_weapon)
44 , selected_weapon_(-1)
45 , attacker_itor_(attacker_itor)
46 , defender_itor_(defender_itor)
47 , weapons_(std::move(weapons))
48 , best_weapon_(best_weapon)
54 const std::size_t
index = find_widget<listbox>(
get_window(),
"weapon_list",
false).get_selected_row();
61 find_widget<button>(&
window,
"damage_calculation",
false),
64 find_widget<unit_preview_pane>(&
window,
"attacker_pane",
false)
67 find_widget<unit_preview_pane>(&
window,
"defender_pane",
false)
72 listbox& weapon_list = find_widget<listbox>(&
window,
"weapon_list",
false);
79 for(
const auto & weapon :
weapons_) {
86 *defender.
weapon : *no_weapon;
91 const std::string attw_name = !attacker_weapon.
name().
empty() ? attacker_weapon.
name() :
" ";
92 const std::string defw_name = !defender_weapon.
name().
empty() ? defender_weapon.
name() :
" ";
94 std::string range = attacker_weapon.
range().empty() ? defender_weapon.
range() : attacker_weapon.
range();
113 std::pair<std::string, std::string> types = attacker_weapon.
damage_type();
114 std::string attw_type_second = types.second;
115 std::string attw_type = !(types.first).empty() ? types.first : attacker_weapon.
type();
116 if (!attw_type.empty()) {
119 if (!attw_type_second.empty()) {
120 attw_type_second =
", " +
string_table[
"type_" + attw_type_second];
122 std::pair<std::string, std::string> def_types = defender_weapon.
damage_type();
123 std::string defw_type_second = def_types.second;
124 std::string defw_type = !(def_types.first).empty() ? def_types.first : defender_weapon.
type();
125 if (!defw_type.empty()) {
128 if (!defw_type_second.empty()) {
129 defw_type_second =
", " +
string_table[
"type_" + defw_type_second];
132 const std::set<std::string> checking_tags_other = {
"damage_type",
"disable",
"berserk",
"drains",
"heal_on_hit",
"plague",
"slow",
"petrifies",
"firststrike",
"poison"};
139 std::string defw_specials = defender_attack ? defender_weapon.
weapon_specials() :
"";
140 std::string defw_specials_dmg = defender_attack ? defender_weapon.
weapon_specials_value({
"leadership",
"damage"}) :
"";
141 std::string defw_specials_atk = defender_attack ? defender_weapon.
weapon_specials_value({
"attacks",
"swarm"}) :
"";
142 std::string defw_specials_cth = defender_attack ? defender_weapon.
weapon_specials_value({
"chance_to_hit"}) :
"";
143 std::string defw_specials_others = defender_attack ? defender_weapon.
weapon_specials_value(checking_tags_other) :
"";
145 if(!attw_specials.empty()) {
146 attw_specials =
" " + attw_specials;
148 if(!attw_specials_dmg.empty()) {
149 attw_specials_dmg =
" " + attw_specials_dmg;
151 if(!attw_specials_atk.empty()) {
152 attw_specials_atk =
" " + attw_specials_atk;
154 if(!attw_specials_cth.empty()) {
155 attw_specials_cth =
" " + attw_specials_cth;
157 if(!attw_specials_others.empty()) {
158 attw_specials_others =
"\n" + (
"<b>" +
_(
"Other aspects: ") +
"</b>") +
"\n" + (
"<i>"+attw_specials_others+
"</i>");
160 if(!defw_specials.empty()) {
161 defw_specials =
" " + defw_specials;
163 if(!defw_specials_dmg.empty()) {
164 defw_specials_dmg =
" " + defw_specials_dmg;
166 if(!defw_specials_atk.empty()) {
167 defw_specials_atk =
" " + defw_specials_atk;
169 if(!defw_specials_cth.empty()) {
170 defw_specials_cth =
" " + defw_specials_cth;
172 if(!defw_specials_others.empty()) {
173 defw_specials_others =
"\n" + (
"<b>" +
_(
"Other aspects: ") +
"</b>") +
"\n" + (
"<i>"+defw_specials_others+
"</i>");
176 std::stringstream attacker_stats, defender_stats, attacker_tooltip, defender_tooltip;
179 attacker_stats <<
"<b>" << attw_name <<
"</b>" <<
"\n"
180 << attw_type << attw_type_second <<
"\n"
182 << attw_specials <<
"\n"
185 attacker_tooltip <<
_(
"Weapon: ") <<
"<b>" << attw_name <<
"</b>" <<
"\n"
186 <<
_(
"Type: ") << attw_type << attw_type_second <<
"\n"
187 <<
_(
"Damage: ") << attacker.
damage <<
"<i>" << attw_specials_dmg <<
"</i>" <<
"\n"
188 <<
_(
"Attacks: ") << attacker.
num_blows <<
"<i>" << attw_specials_atk <<
"</i>" <<
"\n"
190 << attw_specials_others;
192 defender_stats <<
"<b>" << defw_name <<
"</b>" <<
"\n"
193 << defw_type << defw_type_second <<
"\n"
195 << defw_specials <<
"\n"
198 defender_tooltip <<
_(
"Weapon: ") <<
"<b>" << defw_name <<
"</b>" <<
"\n"
199 <<
_(
"Type: ") << defw_type << defw_type_second <<
"\n"
200 <<
_(
"Damage: ") << defender.
damage <<
"<i>" << defw_specials_dmg <<
"</i>" <<
"\n"
201 <<
_(
"Attacks: ") << defender.
num_blows <<
"<i>" << defw_specials_atk <<
"</i>" <<
"\n"
203 << defw_specials_others;
208 item[
"use_markup"] =
"true";
210 item[
"label"] = attacker_weapon.
icon();
211 data.emplace(
"attacker_weapon_icon",
item);
213 item[
"tooltip"] = attacker_tooltip.str();
214 item[
"label"] = attacker_stats.str();
215 data.emplace(
"attacker_weapon",
item);
216 item[
"tooltip"] =
"";
221 item[
"tooltip"] = defender_attack ? defender_tooltip.str() :
"";
222 item[
"label"] = defender_stats.str();
223 data.emplace(
"defender_weapon",
item);
225 item[
"tooltip"] =
"";
226 item[
"label"] = defender_weapon.
icon();
227 data.emplace(
"defender_weapon_icon",
item);
std::string weapon_specials() const
Returns a comma-separated string of active names for the specials of *this.
const std::string & range() const
const std::string & type() const
std::string weapon_specials_value(const std::set< std::string > checking_tags) 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, std::string > damage_type() const
return a modified damage type and/or add a secondary_type for hybrid use if special is active.
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.
int get_retval() const
Returns the cached window exit code.
window * get_window()
Returns a pointer to the dialog's window.
This shows the dialog for attacking units.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
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.
unit_map::iterator attacker_itor_
Iterator pointing to the attacker.
void damage_calc_callback()
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
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.
base class of top level items, the only item which needs to store the final canvases to draw on.
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
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
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::pair< std::string, unsigned > item
void unit_attack(display *disp, game_board &board, const map_location &a, const map_location &b, int damage, const attack_type &attack, 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(const std::string &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...