FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
routepather.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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_PATHFINDER_ROUTEPATHER
23 #define FIFE_PATHFINDER_ROUTEPATHER
24 
25 // Standard C++ library includes
26 #include <map>
27 #include <vector>
28 
29 // 3rd party library includes
30 
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
38 
39 namespace FIFE {
40 
41  class CellCache;
42  class RoutePatherSearch;
43  class Route;
44 
45  class RoutePather : public IPather {
46  public:
51  }
52 
60  Route* createRoute(const Location& start, const Location& end, bool immediate = false, const std::string& costId = "");
61 
69  bool solveRoute(Route* route, int32_t priority = MEDIUM_PRIORITY, bool immediate = false);
70 
79  bool followRoute(const Location& current, Route* route, double speed, Location& nextLocation);
80 
88  void update();
89 
98  bool cancelSession(const int32_t sessionId);
99 
103  void setMaxTicks(int32_t ticks);
104 
108  int32_t getMaxTicks();
109 
113  std::string getName() const;
114 
115  private:
117  typedef std::list<Location> Path;
118 
121 
123  typedef std::list<int32_t> SessionList;
124 
131  void addSessionId(const int32_t sessionId);
132 
137  int32_t makeSessionId();
138 
145  bool locationsEqual(const Location& a, const Location& b);
146 
154  bool sessionIdValid(const int32_t sessionId);
155 
161  bool invalidateSessionId(const int32_t sessionId);
162 
164  SessionQueue m_sessions;
165 
168 
171 
173  int32_t m_maxTicks;
174  };
175 }
176 #endif
int32_t m_nextFreeSessionId
The next free session id.
Definition: routepather.h:170
bool locationsEqual(const Location &a, const Location &b)
Are two locations equivalent from the perspective of pathing (same layer coordinates and layer)...
Definition: routepather.cpp:49
PriorityQueue< RoutePatherSearch *, int32_t > SessionQueue
Holds the searches and their priority.
Definition: routepather.h:120
bool solveRoute(Route *route, int32_t priority=MEDIUM_PRIORITY, bool immediate=false)
Solves the route to create a path.
std::list< int32_t > SessionList
Holds the sessions.
Definition: routepather.h:123
std::list< Location > Path
A path is a list with locations. Each location holds the coordinate for one cell. ...
Definition: routepather.h:117
bool sessionIdValid(const int32_t sessionId)
Determines if the given session Id is valid.
bool invalidateSessionId(const int32_t sessionId)
Removes a session id from the session map.
A basic route.
Definition: route.h:64
bool followRoute(const Location &current, Route *route, double speed, Location &nextLocation)
Follows the path of the route.
int32_t makeSessionId()
Makes a new session id.
Definition: routepather.cpp:45
std::string getName() const
Returns name of the pathfinder.
int32_t m_maxTicks
The maximum number of ticks allowed.
Definition: routepather.h:173
Route * createRoute(const Location &start, const Location &end, bool immediate=false, const std::string &costId="")
Creates a route between the start and end location that needs be solved.
bool cancelSession(const int32_t sessionId)
Cancels a session.
Definition: routepather.cpp:89
void addSessionId(const int32_t sessionId)
Adds a session id to the session map.
Definition: routepather.cpp:96
SessionList m_registeredSessionIds
A list of session ids that have been registered.
Definition: routepather.h:167
RoutePather()
Constructor.
Definition: routepather.h:50
int32_t getMaxTicks()
Returns maximal ticks (update steps) to solve routes.
SessionQueue m_sessions
A map of currently running sessions (searches).
Definition: routepather.h:164
void update()
Updates the route pather.
Definition: routepather.cpp:57
void setMaxTicks(int32_t ticks)
Sets maximal ticks (update steps) to solve routes.