The Battle for Wesnoth  1.19.0-dev
recruit.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 <string>
23 
24 #include "action.hpp"
25 #include "map/location.hpp"
26 
27 namespace wb
28 {
29 
30 /*
31  *
32  */
33 class recruit: public action
34 {
35 public:
36  recruit(std::size_t team_index, bool hidden, const std::string& unit_name, const map_location& recruit_hex);
37  recruit(const config&, bool hidden); // For deserialization
38  virtual ~recruit();
39 
40  virtual std::ostream& print(std::ostream& s) const;
41 
42  virtual void accept(visitor& v);
43 
44  virtual void execute(bool& success, bool& complete);
45 
46  /**
47  * Check the validity of the action.
48  *
49  * @return the error preventing the action from being executed.
50  * @retval OK if there isn't any error (the action can be executed.)
51  */
52  virtual error check_validity() const;
53 
54  /** Applies temporarily the result of this action to the specified unit map. */
55  virtual void apply_temp_modifier(unit_map& unit_map);
56  /** Removes the result of this action from the specified unit map. */
57  virtual void remove_temp_modifier(unit_map& unit_map);
58 
59  /** Gets called by display when drawing a hex, to allow actions to draw to the screen. */
60  virtual void draw_hex(const map_location& hex);
61  /** Redrawing function, called each time the action situation might have changed. */
62  virtual void redraw();
63 
64  /**
65  * @return the preferred hex to draw the numbering for this action.
66  */
67  virtual map_location get_numbering_hex() const { return recruit_hex_; }
68 
69  /** @return pointer to a fake unit representing the one that will eventually be recruited. */
70  virtual unit_ptr get_unit() const { return temp_unit_; }
71  virtual bool places_new_unit() const { return true; }
72  /** @return pointer to the fake unit used only for visuals */
73  virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }
74 
75  map_location const get_recruit_hex() const { return recruit_hex_; }
76 
77  virtual config to_config() const;
78 
79 protected:
80 
81  std::shared_ptr<recruit> shared_from_this() {
82  return std::static_pointer_cast<recruit>(action::shared_from_this());
83  }
84 
85  std::string unit_name_;
87  //Temp unit to insert in the future unit map when needed
90  int cost_;
91 
92 private:
93  void init();
94 
95  virtual void do_hide();
96  virtual void do_show();
97 
99 };
100 
101 std::ostream& operator<<(std::ostream& s, recruit_ptr recruit);
102 std::ostream& operator<<(std::ostream& s, recruit_const_ptr recruit);
103 
104 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
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
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
virtual bool places_new_unit() const
Returns true for recall and recruit actions.
Definition: recruit.hpp:71
virtual fake_unit_ptr get_fake_unit()
Definition: recruit.hpp:73
virtual error check_validity() const
Check the validity of the action.
Definition: recruit.cpp:202
virtual unit_ptr get_unit() const
Definition: recruit.hpp:70
std::string unit_name_
Definition: recruit.hpp:85
virtual map_location get_numbering_hex() const
Definition: recruit.hpp:67
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: recruit.cpp:246
fake_unit_ptr fake_unit_
Definition: recruit.hpp:89
std::shared_ptr< recruit > shared_from_this()
Definition: recruit.hpp:81
virtual std::ostream & print(std::ostream &s) const
Definition: recruit.cpp:49
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: recruit.cpp:167
map_location const get_recruit_hex() const
Definition: recruit.hpp:75
virtual config to_config() const
Constructs and returns a config object representing this object.
Definition: recruit.cpp:230
map_location recruit_hex_
Definition: recruit.hpp:86
unit_ptr temp_unit_
Definition: recruit.hpp:88
virtual void do_show()
Definition: recruit.cpp:247
virtual void execute(bool &success, bool &complete)
Output parameters: success: Whether or not to continue an execute-all after this execution complete: ...
Definition: recruit.cpp:108
recruit(std::size_t team_index, bool hidden, const std::string &unit_name, const map_location &recruit_hex)
Definition: recruit.cpp:55
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: recruit.cpp:132
void init()
Definition: recruit.cpp:85
virtual ~recruit()
Definition: recruit.cpp:99
unit_ptr create_corresponding_unit()
Definition: recruit.cpp:189
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: recruit.cpp:155
virtual void accept(visitor &v)
Definition: recruit.cpp:103
virtual void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: recruit.cpp:183
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< recruit > recruit_ptr
Definition: typedefs.hpp:72
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:34
std::shared_ptr< recruit const > recruit_const_ptr
Definition: typedefs.hpp:73
std::shared_ptr< unit > unit_ptr
Definition: ptr.hpp:26
static config unit_name(const unit *u)
Definition: reports.cpp:157
Encapsulates the map of the game.
Definition: location.hpp:38
static map_location::DIRECTION s