The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
recruit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
3  Part of the Battle for Wesnoth Project http://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 #ifndef WB_RECRUIT_HPP_
20 #define WB_RECRUIT_HPP_
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(size_t team_index, bool hidden, const std::string& unit_name, const map_location& recruit_hex);
37  recruit(config const&, 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(map_location const& 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  /** @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 
81  return boost::static_pointer_cast<recruit>(action::shared_from_this());
82  }
83 
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 }
104 
105 #endif /* WB_RECRUIT_HPP_ */
virtual ~recruit()
Definition: recruit.cpp:97
bool hidden() const
Definition: action.hpp:64
virtual config to_config() const
Constructs and returns a config object representing this object.
Definition: recruit.cpp:206
void init()
Definition: recruit.cpp:86
boost::shared_ptr< recruit > shared_from_this()
Definition: recruit.hpp:80
map_location const get_recruit_hex() const
Definition: recruit.hpp:74
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:106
virtual void apply_temp_modifier(unit_map &unit_map)
Applies temporarily the result of this action to the specified unit map.
Definition: recruit.cpp:121
virtual void do_hide()
Called by the non-virtual hide() and show(), respectively.
Definition: recruit.cpp:222
static config unit_name(const unit *u)
Definition: reports.cpp:133
virtual map_location get_numbering_hex() const
Definition: recruit.hpp:67
unit_ptr temp_unit_
Definition: recruit.hpp:87
virtual void draw_hex(map_location const &hex)
Gets called by display when drawing a hex, to allow actions to draw to the screen.
Definition: recruit.cpp:147
virtual unit_ptr get_unit() const
Definition: recruit.hpp:70
fake_unit_ptr fake_unit_
Definition: recruit.hpp:88
size_t team_index() const
Returns the index of the team that owns this action.
Definition: action.hpp:82
error
Possible errors.
Definition: action.hpp:104
unit_ptr create_corresponding_unit()
Definition: recruit.cpp:169
const GLdouble * v
Definition: glew.h:1359
virtual void do_show()
Definition: recruit.cpp:223
virtual void accept(visitor &v)
Definition: recruit.cpp:101
std::string unit_name_
Definition: recruit.hpp:84
Encapsulates the map of the game.
Definition: location.hpp:38
virtual void redraw()
Redrawing function, called each time the action situation might have changed.
Definition: recruit.cpp:163
virtual std::ostream & print(std::ostream &s) const
Definition: recruit.cpp:50
map_location recruit_hex_
Definition: recruit.hpp:85
recruit(size_t team_index, bool hidden, const std::string &unit_name, const map_location &recruit_hex)
Definition: recruit.cpp:56
Container associating units to locations.
Definition: map.hpp:90
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:33
Abstract base class for all the whiteboard planned actions.
Definition: action.hpp:33
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLdouble s
Definition: glew.h:1358
virtual void remove_temp_modifier(unit_map &unit_map)
Removes the result of this action from the specified unit map.
Definition: recruit.cpp:140
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
Definition: display.hpp:47
virtual error check_validity() const
Check the validity of the action.
Definition: recruit.cpp:182
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:32