The Battle for Wesnoth  1.15.2+dev
attack.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
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 /**
16  * @file
17  */
18 
19 #pragma once
20 
21 #include "move.hpp"
22 
23 namespace wb
24 {
25 
26 class attack: public move
27 {
28 public:
29  attack(std::size_t team_index, bool hidden, unit& mover, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
30  arrow_ptr arrow, fake_unit_ptr fake_unit);
31  attack(const config&, bool hidden); // For deserialization
32  virtual ~attack();
33 
34  virtual std::ostream& print(std::ostream& s) const;
35 
36  virtual void accept(visitor& v);
37 
38  virtual void execute(bool& success, bool& complete);
39 
40  /**
41  * Check the validity of the action.
42  *
43  * @return the error preventing the action from being executed.
44  * @retval OK if there isn't any error (the action can be executed.)
45  */
46  virtual error check_validity() const;
47 
48  /** Applies temporarily the result of this action to the specified unit map. */
49  virtual void apply_temp_modifier(unit_map& unit_map);
50  /** Removes the result of this action from the specified unit map. */
51  virtual void remove_temp_modifier(unit_map& unit_map);
52 
53  /** Gets called by display when drawing a hex, to allow actions to draw to the screen. */
54  virtual void draw_hex(const map_location& hex);
55  /** Redrawing function, called each time the action situation might have changed. */
56  virtual void redraw();
57 
58  const map_location& get_target_hex() const {return target_hex_; }
59 
60  virtual config to_config() const;
61 
62 protected:
63 
64  std::shared_ptr<attack> shared_from_this() {
65  return std::static_pointer_cast<attack>(move::shared_from_this());
66  }
67 
68 private:
69 
70  void init();
71 
72  virtual void do_hide() {invalidate();}
73  virtual void do_show() {invalidate();}
74 
75  ///invalidates the move-destination and attack-target hexes
76  void invalidate();
77 
78  ///the target of the attack
80 
84 };
85 
86 /** Dumps an attack on a stream, for debug purposes. */
87 std::ostream& operator<<(std::ostream &s, attack_ptr attack);
88 std::ostream& operator<<(std::ostream &s, attack_const_ptr attack);
89 
90 } // end namespace wb
map_location target_hex_
the target of the attack
Definition: attack.hpp:79
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: attack.cpp:150
virtual void execute(bool &success, bool &complete)
Output parameters: success: Whether or not to continue an execute-all after this execution complete: ...
Definition: attack.cpp:114
int weapon_choice_
Definition: attack.hpp:81
This class represents a single unit of a specific type.
Definition: unit.hpp:99
attack(std::size_t team_index, bool hidden, unit &mover, const map_location &target_hex, int weapon_choice, const pathfind::marked_route &route, arrow_ptr arrow, fake_unit_ptr fake_unit)
Definition: attack.cpp:55
int attack_movement_cost_
Definition: attack.hpp:82
virtual void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: attack.cpp:221
std::shared_ptr< attack > attack_ptr
Definition: typedefs.hpp:69
int temp_movement_subtracted_
Definition: attack.hpp:83
std::shared_ptr< attack const > attack_const_ptr
Definition: typedefs.hpp:70
std::shared_ptr< attack > shared_from_this()
Definition: attack.hpp:64
virtual void do_show()
Definition: attack.hpp:73
virtual error check_validity() const
Check the validity of the action.
Definition: attack.cpp:227
std::size_t team_index() const
Returns the index of the team that owns this action.
Definition: action.hpp:83
virtual ~attack()
Definition: attack.cpp:93
virtual void accept(visitor &v)
Definition: attack.cpp:98
Arrows destined to be drawn on the map.
Definition: arrow.hpp:29
error
Possible errors.
Definition: action.hpp:105
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:140
virtual config to_config() const
Constructs and returns a config object representing this object.
Definition: attack.cpp:255
Encapsulates the map of the game.
Definition: location.hpp:42
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: attack.cpp:175
static map_location::DIRECTION s
const map_location & get_target_hex() const
Definition: attack.hpp:58
std::shared_ptr< move > shared_from_this()
Definition: move.hpp:99
std::shared_ptr< arrow > arrow_ptr
Definition: typedefs.hpp:59
bool hidden() const
Definition: action.hpp:63
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: attack.hpp:72
Container associating units to locations.
Definition: map.hpp:99
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:33
virtual std::ostream & print(std::ostream &s) const
Definition: attack.cpp:48
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
virtual void draw_hex(const map_location &hex)
Gets called by display when drawing a hex, to allow actions to draw to the screen.
Definition: attack.cpp:190
void invalidate()
invalidates the move-destination and attack-target hexes
Definition: attack.cpp:104
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
A planned move, represented on the map by an arrow and a ghosted unit in the destination hex...
Definition: move.hpp:32
Definition: display.hpp:48
void init()
Definition: attack.cpp:88
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses...
Definition: visitor.hpp:31