The Battle for Wesnoth  1.15.2+dev
recruit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
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 <string>
22 
23 #include "action.hpp"
24 #include "map/location.hpp"
25 
26 namespace wb
27 {
28 
29 /*
30  *
31  */
32 class recruit: public action
33 {
34 public:
35  recruit(std::size_t team_index, bool hidden, const std::string& unit_name, const map_location& recruit_hex);
36  recruit(const config&, bool hidden); // For deserialization
37  virtual ~recruit();
38 
39  virtual std::ostream& print(std::ostream& s) const;
40 
41  virtual void accept(visitor& v);
42 
43  virtual void execute(bool& success, bool& complete);
44 
45  /**
46  * Check the validity of the action.
47  *
48  * @return the error preventing the action from being executed.
49  * @retval OK if there isn't any error (the action can be executed.)
50  */
51  virtual error check_validity() const;
52 
53  /** Applies temporarily the result of this action to the specified unit map. */
54  virtual void apply_temp_modifier(unit_map& unit_map);
55  /** Removes the result of this action from the specified unit map. */
56  virtual void remove_temp_modifier(unit_map& unit_map);
57 
58  /** Gets called by display when drawing a hex, to allow actions to draw to the screen. */
59  virtual void draw_hex(const map_location& hex);
60  /** Redrawing function, called each time the action situation might have changed. */
61  virtual void redraw();
62 
63  /**
64  * @return the preferred hex to draw the numbering for this action.
65  */
66  virtual map_location get_numbering_hex() const { return recruit_hex_; }
67 
68  /** @return pointer to a fake unit representing the one that will eventually be recruited. */
69  virtual unit_ptr get_unit() const { return temp_unit_; }
70  virtual bool places_new_unit() const { return true; }
71  /** @return pointer to the fake unit used only for visuals */
72  virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }
73 
74  map_location const get_recruit_hex() const { return recruit_hex_; }
75 
76  virtual config to_config() const;
77 
78 protected:
79 
80  std::shared_ptr<recruit> shared_from_this() {
81  return std::static_pointer_cast<recruit>(action::shared_from_this());
82  }
83 
84  std::string unit_name_;
86  //Temp unit to insert in the future unit map when needed
89  int cost_;
90 
91 private:
92  void init();
93 
94  virtual void do_hide();
95  virtual void do_show();
96 
98 };
99 
100 std::ostream& operator<<(std::ostream& s, recruit_ptr recruit);
101 std::ostream& operator<<(std::ostream& s, recruit_const_ptr recruit);
102 
103 }
virtual error check_validity() const
Check the validity of the action.
Definition: recruit.cpp:203
virtual ~recruit()
Definition: recruit.cpp:100
std::shared_ptr< recruit const > recruit_const_ptr
Definition: typedefs.hpp:72
virtual unit_ptr get_unit() const
Definition: recruit.hpp:69
void init()
Definition: recruit.cpp:86
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:109
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: recruit.cpp:133
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: recruit.cpp:247
static config unit_name(const unit *u)
Definition: reports.cpp:151
std::size_t team_index() const
Returns the index of the team that owns this action.
Definition: action.hpp:83
virtual config to_config() const
Constructs and returns a config object representing this object.
Definition: recruit.cpp:231
unit_ptr temp_unit_
Definition: recruit.hpp:87
fake_unit_ptr fake_unit_
Definition: recruit.hpp:88
map_location const get_recruit_hex() const
Definition: recruit.hpp:74
std::shared_ptr< recruit > recruit_ptr
Definition: typedefs.hpp:71
error
Possible errors.
Definition: action.hpp:105
unit_ptr create_corresponding_unit()
Definition: recruit.cpp:190
recruit(std::size_t team_index, bool hidden, const std::string &unit_name, const map_location &recruit_hex)
Definition: recruit.cpp:56
virtual void do_show()
Definition: recruit.cpp:248
virtual void accept(visitor &v)
Definition: recruit.cpp:104
std::string unit_name_
Definition: recruit.hpp:84
Encapsulates the map of the game.
Definition: location.hpp:42
std::shared_ptr< recruit > shared_from_this()
Definition: recruit.hpp:80
static map_location::DIRECTION s
virtual void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: recruit.cpp:184
virtual std::ostream & print(std::ostream &s) const
Definition: recruit.cpp:50
virtual map_location get_numbering_hex() const
Definition: recruit.hpp:66
map_location recruit_hex_
Definition: recruit.hpp:85
boost::intrusive_ptr< unit > unit_ptr
Definition: ptr.hpp:29
bool hidden() const
Definition: action.hpp:63
Container associating units to locations.
Definition: map.hpp:99
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:33
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:168
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:68
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: recruit.cpp:156
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()
Definition: recruit.hpp:72
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses...
Definition: visitor.hpp:31
virtual bool places_new_unit() const
Returns true for recall and recruit actions.
Definition: recruit.hpp:70