The Battle for Wesnoth  1.17.0-dev
unit_attack.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
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 "actions/attack.hpp"
20 #include "units/map.hpp"
21 
22 namespace gui2::dialogs
23 {
24 
25 /**
26  * @ingroup GUIWindowDefinitionWML
27  *
28  * This shows the dialog for attacking units.
29  * Key |Type |Mandatory|Description
30  * ------------------|--------------|---------|-----------
31  * attacker_portrait | @ref image |no |Shows the portrait of the attacking unit.
32  * attacker_icon | @ref image |no |Shows the icon of the attacking unit.
33  * attacker_name | control |no |Shows the name of the attacking unit.
34  * defender_portrait | @ref image |no |Shows the portrait of the defending unit.
35  * defender_icon | @ref image |no |Shows the icon of the defending unit.
36  * defender_name | control |no |Shows the name of the defending unit.
37  * weapon_list | @ref listbox |yes |The list with weapons to choose from.
38  * attacker_weapon | control |no |The weapon for the attacker to use.
39  * defender_weapon | control |no |The weapon for the defender to use.
40  */
41 class unit_attack : public modal_dialog
42 {
43 public:
44  unit_attack(const unit_map::iterator& attacker_itor,
45  const unit_map::iterator& defender_itor,
46  std::vector<battle_context>&& weapons,
47  const int best_weapon);
48 
49  /***** ***** ***** setters / getters for members ***** ****** *****/
50 
51  int get_selected_weapon() const
52  {
53  return selected_weapon_;
54  }
55 
56 private:
57  virtual const std::string& window_id() const override;
58 
59  virtual void pre_show(window& window) override;
60 
61  virtual void post_show(window& window) override;
62 
63  void damage_calc_callback();
64 
65  /** The index of the selected weapon. */
67 
68  /** Iterator pointing to the attacker. */
70 
71  /** Iterator pointing to the defender. */
73 
74  /** List of all battle contexts used for getting the weapons. */
75  std::vector<battle_context> weapons_;
76 
77  /** The best weapon, aka the one high-lighted. */
79 };
80 
81 } // namespace dialogs
int best_weapon_
The best weapon, aka the one high-lighted.
Definition: unit_attack.hpp:78
virtual const std::string & window_id() const override
The id of the window to build.
Various functions that implement attacks and attack calculations.
std::vector< battle_context > weapons_
List of all battle contexts used for getting the weapons.
Definition: unit_attack.hpp:75
unit_attack(const unit_map::iterator &attacker_itor, const unit_map::iterator &defender_itor, std::vector< battle_context > &&weapons, const int best_weapon)
Definition: unit_attack.cpp:45
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
int selected_weapon_
The index of the selected weapon.
Definition: unit_attack.hpp:66
This shows the dialog for attacking units.
Definition: unit_attack.hpp:41
unit_map::iterator attacker_itor_
Iterator pointing to the attacker.
Definition: unit_attack.hpp:69
Abstract base class for all modal dialogs.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: unit_attack.cpp:63
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
unit_map::iterator defender_itor_
Iterator pointing to the defender.
Definition: unit_attack.hpp:72