The Battle for Wesnoth  1.19.5+dev
suppose_dead.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2024
3  by Tommy Schmitz
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 
24 namespace wb {
25 
26 /**
27  * A planned action that temporarily removes a unit from the map
28  * for planning purposes
29  */
30 class suppose_dead: public action
31 {
32 public:
33  suppose_dead(std::size_t team_index, bool hidden, unit& curr_unit, const map_location& loc);
34  suppose_dead(const config&, bool hidden); // For deserialization
35  virtual ~suppose_dead();
36 
37  /** Return the unit targeted by this action. Null if unit doesn't exist. */
38  virtual unit_ptr get_unit() const;
39  /** @return null pointer */
40  virtual fake_unit_ptr get_fake_unit() { return fake_unit_ptr(); }
41  /** Return the location at which this action was planned. */
42  virtual map_location get_source_hex() const { return loc_; }
43 
44  virtual std::ostream& print(std::ostream& s) const;
45 
46  virtual void accept(visitor &v);
47 
48  virtual void execute(bool& success, bool& complete);
49 
50  /**
51  * Check the validity of the action.
52  *
53  * @return the error preventing the action from being executed.
54  * @retval OK if there isn't any error (the action can be executed.)
55  */
56  virtual error check_validity() const;
57 
58  /** Applies temporarily the result of this action to the specified unit map. */
59  virtual void apply_temp_modifier(unit_map& unit_map);
60  /** Removes the result of this action from the specified unit map. */
61  virtual void remove_temp_modifier(unit_map& unit_map);
62 
63  /** Gets called by display when drawing a hex, to allow actions to draw to the screen. */
64  virtual void draw_hex(const map_location& hex);
65  /** Redrawing function, called each time the action situation might have changed. */
66  virtual void redraw();
67 
68  virtual map_location get_numbering_hex() const { return loc_; }
69 
70  virtual config to_config() const;
71 
72 protected:
73 
74  std::shared_ptr<suppose_dead> shared_from_this() {
75  return std::static_pointer_cast<suppose_dead>(action::shared_from_this());
76  }
77 
78  std::size_t unit_underlying_id_;
79  std::string unit_id_;
81 
82 private:
83  void init();
84 };
85 
86 /** Dumps a suppose_dead on a stream, for debug purposes. */
87 std::ostream &operator<<(std::ostream &s, suppose_dead_ptr sup_d);
88 std::ostream &operator<<(std::ostream &s, suppose_dead_const_ptr sup_d);
89 } // end namespace wb
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
A planned action that temporarily removes a unit from the map for planning purposes.
virtual void accept(visitor &v)
std::size_t unit_underlying_id_
virtual fake_unit_ptr get_fake_unit()
virtual map_location get_numbering_hex() const
virtual unit_ptr get_unit() const
Return the unit targeted by this action.
virtual void execute(bool &success, bool &complete)
Output parameters: success: Whether or not to continue an execute-all after this execution complete: ...
virtual error check_validity() const
Check the validity of the action.
virtual std::ostream & print(std::ostream &s) const
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
suppose_dead(std::size_t team_index, bool hidden, unit &curr_unit, const map_location &loc)
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
std::string unit_id_
std::shared_ptr< suppose_dead > shared_from_this()
virtual void redraw()
Redrawing function, called each time the action situation might have changed.
virtual ~suppose_dead()
virtual void draw_hex(const map_location &hex)
Gets called by display when drawing a hex, to allow actions to draw to the screen.
virtual map_location get_source_hex() const
Return the location at which this action was planned.
map_location loc_
virtual config to_config() const
Constructs and returns a config object representing this object.
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< suppose_dead > suppose_dead_ptr
Definition: typedefs.hpp:76
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:34
std::shared_ptr< suppose_dead const > suppose_dead_const_ptr
Definition: typedefs.hpp:77
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