The Battle for Wesnoth  1.15.12+dev
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
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,
12  See the COPYING file for more details.
13  */
15 /**
16  * @file
17  */
19 #pragma once
21 #include "move.hpp"
23 namespace wb
24 {
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();
34  virtual std::ostream& print(std::ostream& s) const;
36  virtual void accept(visitor& v);
38  virtual void execute(bool& success, bool& complete);
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;
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);
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();
58  const map_location& get_target_hex() const {return target_hex_; }
60  virtual config to_config() const;
62 protected:
64  std::shared_ptr<attack> shared_from_this() {
65  return std::static_pointer_cast<attack>(move::shared_from_this());
66  }
68 private:
70  void init();
72  virtual void do_hide() {invalidate();}
73  virtual void do_show() {invalidate();}
75  /** invalidates the move-destination and attack-target hexes */
76  void invalidate();
78  /** the target of the attack */
84 };
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);
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:120
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
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:37
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:103
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:97
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:59
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:34
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