The Battle for Wesnoth  1.19.5+dev
recall.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
3  by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  */
19 
20 #pragma once
21 
22 #include "action.hpp"
23 #include "map/location.hpp"
24 
25 namespace wb
26 {
27 
28 class recall: public action
29 {
30 public:
31  recall(std::size_t team_index, bool hidden, const unit& unit, const map_location& recall_hex);
32  recall(const config&, bool hidden); // For deserialization
33  virtual ~recall();
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  /**
60  * Indicates whether this hex is the preferred hex to draw the numbering for this action.
61  */
62  virtual map_location get_numbering_hex() const { return recall_hex_; }
63 
64  /** @return pointer to a copy of the recall unit. */
65  virtual unit_ptr get_unit() const { return temp_unit_; }
66  virtual bool places_new_unit() const { return true; }
67  /** @return pointer to the fake unit used only for visuals */
68  virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }
69 
70  map_location const get_recall_hex() const { return recall_hex_; }
71 
72  virtual config to_config() const;
73 
74 protected:
75 
76  std::shared_ptr<recall> shared_from_this() {
77  return std::static_pointer_cast<recall>(action::shared_from_this());
78  }
79 
80 private:
81  void init();
82 
83  virtual void do_hide();
84  virtual void do_show();
85 
86  // This is the pointer to the real recall unit.
90 
94 };
95 
96 std::ostream& operator<<(std::ostream& s, recall_ptr recall);
97 std::ostream& operator<<(std::ostream& s, recall_const_ptr recall);
98 
99 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
Container associating units to locations.
Definition: map.hpp:98
This class represents a single unit of a specific type.
Definition: unit.hpp:133
Abstract base class for all the whiteboard planned actions.
Definition: action.hpp:34
bool hidden() const
Definition: action.hpp:64
std::size_t team_index() const
Returns the index of the team that owns this action.
Definition: action.hpp:84
error
Possible errors.
Definition: action.hpp:107
std::shared_ptr< recall > shared_from_this()
Definition: recall.hpp:76
unit_ptr temp_unit_
Definition: recall.hpp:87
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: recall.cpp:174
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:116
virtual ~recall()
Definition: recall.cpp:107
map_location recall_hex_
Definition: recall.hpp:88
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: recall.cpp:138
int original_mp_
Definition: recall.hpp:91
virtual fake_unit_ptr get_fake_unit()
Definition: recall.hpp:68
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: recall.cpp:260
virtual void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: recall.cpp:211
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:62
int original_recall_pos_
Definition: recall.hpp:93
virtual bool places_new_unit() const
Returns true for recall and recruit actions.
Definition: recall.hpp:66
void init()
Definition: recall.cpp:98
virtual std::ostream & print(std::ostream &s) const
Definition: recall.cpp:52
virtual void do_show()
Definition: recall.cpp:261
virtual error check_validity() const
Check the validity of the action.
Definition: recall.cpp:216
map_location const get_recall_hex() const
Definition: recall.hpp:70
recall(std::size_t team_index, bool hidden, const unit &unit, const map_location &recall_hex)
Definition: recall.cpp:58
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:188
virtual unit_ptr get_unit() const
Definition: recall.hpp:65
virtual void accept(visitor &v)
Definition: recall.cpp:111
virtual config to_config() const
Definition: recall.cpp:244
int original_ap_
Definition: recall.hpp:92
fake_unit_ptr fake_unit_
Definition: recall.hpp:89
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses.
Definition: visitor.hpp:33
Definition: display.hpp:45
std::shared_ptr< recall const > recall_const_ptr
Definition: typedefs.hpp:75
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:34
std::shared_ptr< recall > recall_ptr
Definition: typedefs.hpp:74
std::shared_ptr< unit > unit_ptr
Definition: ptr.hpp:26
Encapsulates the map of the game.
Definition: location.hpp:45
static map_location::direction s