The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
attack.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
3  Part of the Battle for Wesnoth Project http://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 #ifndef ATTACK_HPP_
20 #define ATTACK_HPP_
21 
22 #include "move.hpp"
23 
24 namespace wb
25 {
26 
27 class attack: public move
28 {
29 public:
30  attack(size_t team_index, bool hidden, unit& mover, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
31  arrow_ptr arrow, fake_unit_ptr fake_unit);
32  attack(config const&, bool hidden); // For deserialization
33  virtual ~attack();
34 
35  virtual std::ostream& print(std::ostream& s) const;
36 
37  virtual void accept(visitor& v);
38 
39  virtual void execute(bool& success, bool& complete);
40 
41  /**
42  * Check the validity of the action.
43  *
44  * @return the error preventing the action from being executed.
45  * @retval OK if there isn't any error (the action can be executed.)
46  */
47  virtual error check_validity() const;
48 
49  /** Applies temporarily the result of this action to the specified unit map. */
50  virtual void apply_temp_modifier(unit_map& unit_map);
51  /** Removes the result of this action from the specified unit map. */
52  virtual void remove_temp_modifier(unit_map& unit_map);
53 
54  /** Gets called by display when drawing a hex, to allow actions to draw to the screen. */
55  virtual void draw_hex(const map_location& hex);
56  /** Redrawing function, called each time the action situation might have changed. */
57  virtual void redraw();
58 
59  map_location const& get_target_hex() const {return target_hex_; }
60 
61  virtual config to_config() const;
62 
63 protected:
64 
66  return boost::static_pointer_cast<attack>(move::shared_from_this());
67  }
68 
69 private:
70 
71  void init();
72 
73  virtual void do_hide() {invalidate();}
74  virtual void do_show() {invalidate();}
75 
76  ///invalidates the move-destination and attack-target hexes
77  void invalidate();
78 
79  ///the target of the attack
81 
85 };
86 
87 /** Dumps an attack on a stream, for debug purposes. */
88 std::ostream& operator<<(std::ostream &s, attack_ptr attack);
89 std::ostream& operator<<(std::ostream &s, attack_const_ptr attack);
90 
91 } // end namespace wb
92 
93 #endif /* ATTACK_HPP_ */
map_location target_hex_
the target of the attack
Definition: attack.hpp:80
boost::shared_ptr< attack > shared_from_this()
Definition: attack.hpp:65
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: attack.cpp:149
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:113
int weapon_choice_
Definition: attack.hpp:82
Definition: unit.hpp:95
int attack_movement_cost_
Definition: attack.hpp:83
bool hidden() const
Definition: action.hpp:64
virtual void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: attack.cpp:239
virtual config to_config() const
Constructs and returns a config object representing this object.
Definition: attack.cpp:273
map_location const & get_target_hex() const
Definition: attack.hpp:59
int temp_movement_subtracted_
Definition: attack.hpp:84
virtual void do_show()
Definition: attack.hpp:74
virtual ~attack()
Definition: attack.cpp:92
virtual void accept(visitor &v)
Definition: attack.cpp:97
size_t team_index() const
Returns the index of the team that owns this action.
Definition: action.hpp:82
Arrows destined to be drawn on the map.
Definition: arrow.hpp:30
boost::shared_ptr< move > shared_from_this()
Definition: move.hpp:96
virtual error check_validity() const
Check the validity of the action.
Definition: attack.cpp:245
error
Possible errors.
Definition: action.hpp:104
const GLdouble * v
Definition: glew.h:1359
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:141
Encapsulates the map of the game.
Definition: location.hpp:38
virtual std::ostream & print(std::ostream &s) const
Definition: attack.cpp:48
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: attack.cpp:174
attack(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
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: attack.hpp:73
Container associating units to locations.
Definition: map.hpp:90
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:33
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
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:189
GLdouble s
Definition: glew.h:1358
void invalidate()
invalidates the move-destination and attack-target hexes
Definition: attack.cpp:103
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:33
Definition: display.hpp:47
void init()
Definition: attack.cpp:87
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses...
Definition: visitor.hpp:32