The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
recall.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2010 - 2025
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
25namespace wb
26{
27
28class recall: public action
29{
30public:
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. */
51 /** Removes the result of this action from the specified 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 */
69
70 map_location const get_recall_hex() const { return recall_hex_; }
71
72 virtual config to_config() const;
73
74protected:
75
76 std::shared_ptr<recall> shared_from_this() {
77 return std::static_pointer_cast<recall>(action::shared_from_this());
78 }
79
80private:
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
96std::ostream& operator<<(std::ostream& s, const recall_ptr& recall);
97std::ostream& operator<<(std::ostream& s, const 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:157
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:39
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
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
std::shared_ptr< recall > shared_from_this()
Definition recall.hpp:76
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
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, const 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:46
static map_location::direction s