The Battle for Wesnoth  1.15.2+dev
recall.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 "action.hpp"
22 #include "map/location.hpp"
23 
24 namespace wb
25 {
26 
27 class recall: public action
28 {
29 public:
30  recall(std::size_t team_index, bool hidden, const unit& unit, const map_location& recall_hex);
31  recall(const config&, bool hidden); // For deserialization
32  virtual ~recall();
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  /**
59  * Indicates whether this hex is the preferred hex to draw the numbering for this action.
60  */
61  virtual map_location get_numbering_hex() const { return recall_hex_; }
62 
63  /** @return pointer to a copy of the recall unit. */
64  virtual unit_ptr get_unit() const { return temp_unit_; }
65  virtual bool places_new_unit() const { return true; }
66  /** @return pointer to the fake unit used only for visuals */
67  virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }
68 
69  map_location const get_recall_hex() const { return recall_hex_; }
70 
71  virtual config to_config() const;
72 
73 protected:
74 
75  std::shared_ptr<recall> shared_from_this() {
76  return std::static_pointer_cast<recall>(action::shared_from_this());
77  }
78 
79 private:
80  void init();
81 
82  virtual void do_hide();
83  virtual void do_show();
84 
85  // This is the pointer to the real recall unit.
89 
93 };
94 
95 std::ostream& operator<<(std::ostream& s, recall_ptr recall);
96 std::ostream& operator<<(std::ostream& s, recall_const_ptr recall);
97 
98 }
virtual void do_show()
Definition: recall.cpp:267
This class represents a single unit of a specific type.
Definition: unit.hpp:99
fake_unit_ptr fake_unit_
Definition: recall.hpp:88
virtual bool places_new_unit() const
Returns true for recall and recruit actions.
Definition: recall.hpp:65
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: recall.cpp:266
int original_mp_
Definition: recall.hpp:90
std::shared_ptr< recall const > recall_const_ptr
Definition: typedefs.hpp:74
virtual void execute(bool &success, bool &complete)
Output parameters: success: Whether or not to continue an execute-all after this execution complete: ...
Definition: recall.cpp:119
virtual void accept(visitor &v)
Definition: recall.cpp:114
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: recall.cpp:180
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: recall.cpp:144
std::size_t team_index() const
Returns the index of the team that owns this action.
Definition: action.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: recall.cpp:194
error
Possible errors.
Definition: action.hpp:105
virtual map_location get_numbering_hex() const
Indicates whether this hex is the preferred hex to draw the numbering for this action.
Definition: recall.hpp:61
map_location recall_hex_
Definition: recall.hpp:87
std::shared_ptr< recall > shared_from_this()
Definition: recall.hpp:75
Encapsulates the map of the game.
Definition: location.hpp:42
virtual error check_validity() const
Check the validity of the action.
Definition: recall.cpp:222
virtual std::ostream & print(std::ostream &s) const
Definition: recall.cpp:55
virtual void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: recall.cpp:217
static map_location::DIRECTION s
map_location const get_recall_hex() const
Definition: recall.hpp:69
void init()
Definition: recall.cpp:101
boost::intrusive_ptr< unit > unit_ptr
Definition: ptr.hpp:29
bool hidden() const
Definition: action.hpp:63
virtual config to_config() const
Definition: recall.cpp:250
Container associating units to locations.
Definition: map.hpp:99
virtual ~recall()
Definition: recall.cpp:110
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:33
std::shared_ptr< recall > recall_ptr
Definition: typedefs.hpp:73
Abstract base class for all the whiteboard planned actions.
Definition: action.hpp:32
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
recall(std::size_t team_index, bool hidden, const unit &unit, const map_location &recall_hex)
Definition: recall.cpp:61
unit_ptr temp_unit_
Definition: recall.hpp:86
int original_ap_
Definition: recall.hpp:91
virtual fake_unit_ptr get_fake_unit()
Definition: recall.hpp:67
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
virtual unit_ptr get_unit() const
Definition: recall.hpp:64
int original_recall_pos_
Definition: recall.hpp:92
Definition: display.hpp:48
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses...
Definition: visitor.hpp:31