Debian Codegraph @

engine/core/pathfinder/route.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_ROUTE_H
23 #define FIFE_ROUTE_H
24
25 // Standard C++ library includes
26 #include <list>
27
28 // 3rd party library includes
29
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34 #include "util/base/fifeclass.h"
35
36 namespace FIFE {
37
38 class Location;
39 class Object;
40
41 /** Defines different route status types for the search.
42 *
43 * ROUTE_CREATED means, route is created but has no path and no search.
44 * ROUTE_SEARCHING means, route is created but has no path and it is still being sought.
45 * ROUTE_SEARCHED means, route is created and the search completed, on the next step the route is solved.
46 * ROUTE_SOLVED means that a path could be found.
47 * ROUTE_FAILED means the search failed. No path could be found.
48 */
49 enum RouteStatus {
50 ROUTE_CREATED = 0,
51 ROUTE_SEARCHING,
52 ROUTE_SEARCHED,
53 ROUTE_SOLVED,
54 ROUTE_FAILED
55 };
56 typedef uint8_t RouteStatusInfo;
57
58 //! A path is a list with locations. Each location holds the coordinate for one cell.
59 typedef std::list<Location> Path;
60
61 /** A basic route.
62 * Holds the path and all related infos.
63 */
64 class Route : public FifeClass {
65 public:
66 /** Constructor
67 * @param start A const reference to the start location.
68 * @param end A const reference to the end/target location.
69 */
70 Route(const Location& start, const Location& end);
71
72 /** Destructor
73 */
74 ~Route();
75
76 /** Sets route status.
77 * @param status The seach status that should be set.
78 */
79 void setRouteStatus(RouteStatusInfo status);
80
81 /** Returns route status.
82 * @return The seach status that is set.
83 */
84 RouteStatusInfo getRouteStatus();
85
86 /** Sets the start location.
87 * @param node A const reference to the start location.
88 */
89 void setStartNode(const Location& node);
90
91 /** Returns the start location.
92 * @return A const reference to the start location.
93 */
94 const Location& getStartNode();
95
96 /** Sets the target location.
97 * @param node A const reference to the end location.
98 */
99 void setEndNode(const Location& node);
100
101 /** Returns the target location.
102 * @return A const reference to the end location.
103 */
104 const Location& getEndNode();
105
106 /** Returns current location.
107 * @return A const reference to the currently used location.
108 */
109 const Location& getCurrentNode();
110
111 /** Returns previous location.
112 * @return A const reference to the previous location.
113 */
114 const Location& getPreviousNode();
115
116 /** Returns next location.
117 * @return A const reference to the next location.
118 */
119 const Location& getNextNode();
120
121 /** Changes the position on the path.
122 * Changes the results of getCurrentNode(), getPreviousNode() and getPreviousNode().
123 * @param step A integer that indicates how much steps should be walked along the path, default is one.
124 * @return A boolean, true if the position could be changed, false otherwise e.g. at path end.
125 */
126 bool walkToNextNode(int32_t step = 1);
127
128 /** Gets if the end of the path was achieved.
129 * @return A boolean, if true the end is achieved, false otherwise.
130 */
131 bool reachedEnd();
132
133 /** Sets the path for the route.
134 * @param path A const reference to the path.
135 */
136 void setPath(const Path& path);
137
138 /** Returns the path.
139 * @return The path which contains all steps.
140 */
141 Path getPath();
142
143 /** Cuts path after the given length.
144 * @param length The new length of the path.
145 */
146 void cutPath(uint32_t length = 1);
147
148 /** Sets the route to replanned.
149 * @param replanned A boolean that indicates if true the route is replanned, otherwise false.
150 */
151 void setReplanned(bool replanned);
152
153 /** Gets if the route is replanned.
154 * @return A boolean, if true the route is replanned, otherwise false.
155 */
156 bool isReplanned();
157
158 /** Returns the length of the path.
159 * @return The path length.
160 */
161 uint32_t getPathLength();
162
163 /** Returns the walked steps.
164 * @return The number of walked steps.
165 */
166 uint32_t getWalkedLength();
167
168 /** Sets the session identifier.
169 * @param id A integer as identifier for the search session.
170 */
171 void setSessionId(int32_t id);
172
173 /** Returns the session identifier.
174 * @return A integer as identifier for the search session.
175 */
176 int32_t getSessionId();
177
178 /** Sets the current rotation.
179 * @param rotation The rotation as integer.
180 */
181 void setRotation(int32_t rotation);
182
183 /** Returns the current rotation.
184 * @return The rotation as integer.
185 */
186 int32_t getRotation();
187
188 /** Sets cost identifier which should be used for pathfinding.
189 * @param cost A const reference to the string that contains the identifier.
190 */
191 void setCostId(const std::string& cost);
192
193 /** Returns cost identifier which is used for pathfinding.
194 * @return A const reference to the string that contains the identifier.
195 */
196 const std::string& getCostId();
197
198 /** Gets if path is for a multi cell object.
199 * @return A boolean, true if path is for multi cell, otherwise false.
200 */
201 bool isMultiCell();
202
203 /** Sets occupied coordinates for multi cell object.
204 * @param area A const reference to a vector that contains the coordinates.
205 */
206 void setOccupiedArea(const std::vector<ModelCoordinate>& area);
207
208 /** Returns occupied coordinates for multi cell object.
209 * @return A const reference to a vector that contains the coordinates.
210 */
211 const std::vector<ModelCoordinate>& getOccupiedArea();
212
213 /** Returns relative coordinates for multi cell object based on rotation.
214 * @param rotation The angle which is used to determine the occupied coordinates.
215 * @return A const reference to a vector that contains the coordinates.
216 */
217 std::vector<ModelCoordinate> getOccupiedCells(int32_t rotation);
218
219 /** Returns z-step range from object. In case it is not limited -1 is returned.
220 * @return The z-step range as int.
221 */
222 int32_t getZStepRange();
223
224 bool isAreaLimited();
225 const std::list<std::string> getLimitedAreas();
226
227 /** Sets the route to ignore dynamic blocker.
228 * @param ignore A boolean that indicates if true the route ignores blocker, otherwise false.
229 */
230 void setDynamicBlockerIgnored(bool ignore);
231
232 /** Gets if the route ignores dynamic blocker.
233 * @return A boolean, if true the route ignores blocker, otherwise false.
234 */
235 bool isDynamicBlockerIgnored();
236
237 /** Returns the blocking locations of the path.
238 * Only useful in case the blocking ignore flag is set.
239 * @return A location list that contains all blocking locations of the path.
240 */
241 Path getBlockingPathLocations();
242
243 /** Sets the object, needed for multi cell and z-step range.
244 * @param obj A pointer to the object.
245 */
246 void setObject(Object* obj);
247
248 /** Returns the object, needed for multi cell and z-step range.
249 * @return A pointer to the object.
250 */
251 Object* getObject();
252
253 private:
254 //! path iterator
255 typedef Path::iterator PathIterator;
256
257 //! search status
258 RouteStatusInfo m_status;
259
260 //! start location
261 Location m_startNode;
262
263 //! end location
264 Location m_endNode;
265
266 //! path
267 Path m_path;
268
269 //! current position on the path
270 PathIterator m_current;
271
272 //! walked steps on the path
273 uint32_t m_walked;
274
275 //! session id of the search
276 int32_t m_sessionId;
277
278 //! current rotation
279 int32_t m_rotation;
280
281 //! is path replanned
282 bool m_replanned;
283
284 //! ignores dynamic blocker
285 bool m_ignoresBlocker;
286
287 //! used cost identifier
288 std::string m_costId;
289
290 //! occupied cells by multicell object
291 std::vector<ModelCoordinate> m_area;
292
293 //! pointer to multi object
294 Object* m_object;
295 };
296
297 } // FIFE
298
299 #endif