The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
create.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
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  * Various functions related to the creation of units (recruits, recalls,
18  * and placed units).
19  */
20 
21 #ifndef ACTIONS_CREATE_H_INCLUDED
22 #define ACTIONS_CREATE_H_INCLUDED
23 
24 class config;
25 class team;
26 class unit_type;
27 class vconfig;
28 
29 #include "unit_creator.hpp"
30 
31 #include "map/location.hpp"
32 #include "units/ptr.hpp"
33 
34 #include <boost/tuple/tuple.hpp>
35 
36 namespace actions {
37 
38 /// The possible results of finding a location for recruiting (or recalling).
40  RECRUIT_NO_LEADER, /// No leaders exist
41  RECRUIT_NO_ABLE_LEADER, /// No leaders able to recall/recruit the given unit/type.
42  RECRUIT_NO_KEEP_LEADER, /// No able leaders are on a keep.
43  RECRUIT_NO_VACANCY, /// No vacant castle tiles around a leader on a keep.
44  RECRUIT_ALTERNATE_LOCATION, /// Recruitment OK, but not at the specified location.
45  RECRUIT_OK /// Recruitment OK.
46 };
47 
48 /**
49  * Checks if there is a location on which to place a recruited unit.
50  * A leader of the @a side must be on a keep connected by castle to a
51  * legal recruiting location to get an "OK" or "ALTERNATE_LOCATION" result.
52  *
53  * If "OK" is returned, then the location provided in @a recruit_location
54  * is legal. If "ALTERNATE_LOCATION" is returned, the provided location was
55  * illegal, so its value was replaced by a location where recruitment can
56  * occur.
57  *
58  * The location of the recruiting leader is stored in @a recruited_from.
59  * The incoming value of this parameter is used as a hint for finding a
60  * legal recruiter, but this hint is given lower priority than finding a
61  * leader who can recruit at recruit_location.
62  *
63  * The @a unit_type is needed in case this is a leader-specific recruit.
64  */
65 RECRUIT_CHECK check_recruit_location(const int side, map_location &recruit_location,
66  map_location& recruited_from,
67  const std::string& unit_type);
68 
69 /**
70  * Finds a location on which to place a unit.
71  * A leader of the @a side must be on a keep
72  * connected by castle to a legal recruiting location. Otherwise, an error
73  * message explaining this is returned.
74  *
75  * If no errors are encountered, the location where a unit can be recruited
76  * is stored in @a recruit_location. Its value is considered first, if it is a
77  * legal option.
78  * Also, the location of the recruiting leader is stored in @a recruited_from.
79  * The incoming value of recruited_from is used as a hint for finding a
80  * legal recruiter, but this hint is given lower priority than finding a
81  * leader who can recruit at recruit_location.
82  *
83  * The @a unit_type is needed in case this is a leader-specific recruit.
84  *
85  * @return an empty string on success. Otherwise a human-readable message
86  * describing the failure is returned.
87  */
88 std::string find_recruit_location(const int side, map_location &recruit_location, map_location& recruited_from, const std::string& unit_type);
89 
90 /**
91  * Checks if there is a location on which to recall @a unit_recall.
92  * A leader of the @a side must be on a keep connected by castle to a legal
93  * recalling location to get an "OK" or "ALTERNATE_LOCATION" result.
94  *
95  * If "OK" is returned, then the location provided in @a recall_location
96  * is legal. If "ALTERNATE_LOCATION" is returned, the provided location was
97  * illegal, so its value was replaced by a location where recalling can
98  * occur.
99  *
100  * The location of the recalling leader is stored in @a recall_from.
101  * The incoming value of this parameter is used as a hint for finding a
102  * legal recaller, but this hint is given lower priority than finding a
103  * leader who can recall at recall_location.
104  */
105 RECRUIT_CHECK check_recall_location(const int side, map_location& recall_location,
106  map_location& recall_from,
107  const unit &unit_recall);
108 
109 /**
110  * Finds a location on which to recall @a unit_recall.
111  * A leader of the @a side must be on a keep
112  * connected by castle to a legal recalling location. Otherwise, an error
113  * message explaining this is returned.
114  *
115  * If no errors are encountered, the location where a unit can be recalled
116  * is stored in @a recall_location. Its value is considered first, if it is a
117  * legal option.
118  * Also, the location of the recalling leader is stored in @a recall_from.
119  * The incoming value of this parameter is used as a hint for finding a
120  * legal recaller, but this hint is given lower priority than finding a
121  * leader who can recall at recall_location.
122  *
123  * @return an empty string on success. Otherwise a human-readable message
124  * describing the failure is returned.
125  */
126 std::string find_recall_location(const int side, map_location& recall_location, map_location& recall_from, const unit &unit_recall);
127 
128 /**
129  * Gets the recruitable units from a side's leaders' personal recruit lists who can recruit on or from a specific hex field.
130  * @param side of the leaders to search for their personal recruit lists.
131  * @param recruit_location the hex field being part of the castle the player wants to recruit on or from.
132  * @return a set of units that can be recruited either by the leader on @a recruit_location or by leaders on keeps connected by castle tiles to @a recruit_location.
133  */
134 const std::set<std::string> get_recruits(int side, const map_location &recruit_location);
135 
136 /**
137  * Gets the recallable units for a side, restricted by that side's leaders' personal abilities to recall on or from a specific hex field.
138  * If no leader is able to recall on or from the given location, the full recall list of the side is returned.
139  * @param side of the leaders to search for their personal recall filters.
140  * @param recall_loc the hex field being part of the castle the player wants to recruit on or from.
141  * @return a set of units that can be recalled by @a side on (or from) @a recall_loc or the full recall list of @a side.
142  */
143 std::vector<unit_const_ptr > get_recalls(int side, const map_location &recall_loc);
144 
145 /**
146  * Place a unit into the game.
147  * The unit will be placed on @a recruit_location, which should be retrieved
148  * through a call to recruit_location().
149  * @returns true if an event (or fog clearing) has mutated the game state.
150  */
151 typedef boost::tuple<bool /*event modified*/, int /*previous village owner side*/, bool /*capture bonus time*/> place_recruit_result;
152 place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_location, const map_location& recruited_from,
153  int cost, bool is_recall, bool show = false, bool fire_event = true, bool full_movement = false,
154  bool wml_triggered = false);
155 
156 /**
157  * Recruits a unit of the given type for the given side.
158  * This is the point at which the code merges for recruits originating from players,
159  * the AI, and replays. It starts just after the recruit location is successfully
160  * found, and it handles creating the unit, paying gold, firing events, tracking
161  * statistics, and (unless @a is_ai) updating the undo stack.
162  */
163 void recruit_unit(const unit_type & u_type, int side_num, const map_location & loc,
164  const map_location & from, bool show=true, bool use_undo=true);
165 
166 /**
167  * Recalls the unit with the indicated ID for the provided team.
168  * The ID can be a reference to data in the recall list.
169  * This is the point at which the code merges for recalls originating from players,
170  * the AI, and replays. It starts just after the recall location is successfully
171  * found, and it handles moving the unit to the board, paying gold, firing events,
172  * tracking statistics, updating the undo stack (unless @a use_undo is false), and
173  * recording the recall (unless @a use_recorder is false).
174  * @returns false if the recall could not be found in the team's recall list.
175  */
176 bool recall_unit(const std::string & id, team & current_team,
177  const map_location & loc, const map_location & from,
178  bool show=true, bool use_undo=true);
179 }//namespace actions
180 
181 #endif
place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_location, const map_location &recruited_from, int cost, bool is_recall, bool show, bool fire_event, bool full_movement, bool wml_triggered)
Definition: create.cpp:610
Definition: unit.hpp:95
No leaders exist.
Definition: create.hpp:41
Recruitment OK, but not at the specified location.
Definition: create.hpp:45
RECRUIT_CHECK
The possible results of finding a location for recruiting (or recalling).
Definition: create.hpp:39
std::vector< unit_const_ptr > get_recalls(int side, const map_location &recall_loc)
Gets the recallable units for a side, restricted by that side's leaders' personal abilities to recall...
Definition: create.cpp:163
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
void recruit_unit(const unit_type &u_type, int side_num, const map_location &loc, const map_location &from, bool show, bool use_undo)
Recruits a unit of the given type for the given side.
Definition: create.cpp:699
const std::set< std::string > get_recruits(int side, const map_location &recruit_loc)
Gets the recruitable units from a side's leaders' personal recruit lists who can recruit on or from a...
Definition: create.cpp:63
boost::tuple< bool, int, bool > place_recruit_result
Place a unit into the game.
Definition: create.hpp:151
No vacant castle tiles around a leader on a keep.
Definition: create.hpp:44
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
Definition: tip.cpp:133
Encapsulates the map of the game.
Definition: location.hpp:38
RECRUIT_CHECK check_recall_location(const int side, map_location &recall_location, map_location &recall_from, const unit &unit_recall)
Checks if there is a location on which to recall unit_recall.
Definition: create.cpp:276
No able leaders are on a keep.
Definition: create.hpp:43
Various functions related to the creation of units (recruits, recalls, and placed units)...
std::string find_recall_location(const int side, map_location &recall_location, map_location &recall_from, const unit &unit_recall)
Finds a location on which to recall unit_recall.
Definition: create.cpp:328
RECRUIT_CHECK check_recruit_location(const int side, map_location &recruit_location, map_location &recruited_from, const std::string &unit_type)
Checks if there is a location on which to place a recruited unit.
Definition: create.cpp:406
bool fire_event(const tevent event, std::vector< std::pair< twidget *, tevent > > &event_chain, twidget *dispatcher, twidget *widget, F functor)
Helper function for fire_event.
A variable-expanding proxy for the config class.
Definition: variable.hpp:36
std::string find_recruit_location(const int side, map_location &recruit_location, map_location &recruited_from, const std::string &unit_type)
Finds a location on which to place a unit.
Definition: create.cpp:464
bool recall_unit(const std::string &id, team &current_team, const map_location &loc, const map_location &from, bool show, bool use_undo)
Recalls the unit with the indicated ID for the provided team.
Definition: create.cpp:731
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
No leaders able to recall/recruit the given unit/type.
Definition: create.hpp:42