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