The Battle for Wesnoth  1.15.12+dev
unit_attack.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "actions/attack.hpp"
19 #include "units/map.hpp"
20 
21 namespace gui2::dialogs
22 {
23 
24 /**
25  * @ingroup GUIWindowDefinitionWML
26  *
27  * This shows the dialog for attacking units.
28  * Key |Type |Mandatory|Description
29  * ------------------|--------------|---------|-----------
30  * attacker_portrait | @ref image |no |Shows the portrait of the attacking unit.
31  * attacker_icon | @ref image |no |Shows the icon of the attacking unit.
32  * attacker_name | control |no |Shows the name of the attacking unit.
33  * defender_portrait | @ref image |no |Shows the portrait of the defending unit.
34  * defender_icon | @ref image |no |Shows the icon of the defending unit.
35  * defender_name | control |no |Shows the name of the defending unit.
36  * weapon_list | @ref listbox |yes |The list with weapons to choose from.
37  * attacker_weapon | control |no |The weapon for the attacker to use.
38  * defender_weapon | control |no |The weapon for the defender to use.
39  */
40 class unit_attack : public modal_dialog
41 {
42 public:
43  unit_attack(const unit_map::iterator& attacker_itor,
44  const unit_map::iterator& defender_itor,
45  std::vector<battle_context>&& weapons,
46  const int best_weapon);
47 
48  /***** ***** ***** setters / getters for members ***** ****** *****/
49 
50  int get_selected_weapon() const
51  {
52  return selected_weapon_;
53  }
54 
55 private:
56  virtual const std::string& window_id() const override;
57 
58  virtual void pre_show(window& window) override;
59 
60  virtual void post_show(window& window) override;
61 
62  void damage_calc_callback();
63 
64  /** The index of the selected weapon. */
66 
67  /** Iterator pointing to the attacker. */
69 
70  /** Iterator pointing to the defender. */
72 
73  /** List of all battle contexts used for getting the weapons. */
74  std::vector<battle_context> weapons_;
75 
76  /** The best weapon, aka the one high-lighted. */
78 };
79 
80 } // namespace dialogs
int best_weapon_
The best weapon, aka the one high-lighted.
Definition: unit_attack.hpp:77
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:74
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:44
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:65
This shows the dialog for attacking units.
Definition: unit_attack.hpp:40
unit_map::iterator attacker_itor_
Iterator pointing to the attacker.
Definition: unit_attack.hpp:68
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:62
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64
unit_map::iterator defender_itor_
Iterator pointing to the defender.
Definition: unit_attack.hpp:71