FIFE  2008.0
routepather.h
1 /***************************************************************************
2  * Copyright (C) 2006-2011 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
35 #include "model/metamodel/ipather.h"
36 #include "model/structures/location.h"
37 #include "model/structures/map.h"
38 #include "util/structures/priorityqueue.h"
39 
40 namespace FIFE {
41 
42  class Search;
43  class SearchSpace;
44  class RoutePatherSearch;
45 
46  class RoutePather : public IPather {
47  public:
51  RoutePather() : m_map(0), m_nextFreeSessionId(0), m_maxticks(1000) {
52  }
53 
54  void setMap(Map* map);
55  int32_t getNextLocation(const Instance* instance, const Location& target,
56  double distance_to_travel, Location& nextLocation,
57  Location& facingLocation, int32_t session_id=-1,
58  int32_t priority = MEDIUM_PRIORITY);
59 
66  void update();
67 
76  bool cancelSession(const int32_t session_id);
77 
83  bool addSearchSpace(SearchSpace* search_space);
84 
90  SearchSpace* getSearchSpace(Layer * const layer);
91 
92  std::string getName() const { return "RoutePather"; };
93  private:
94  typedef std::list<Location> Path;
95  typedef PriorityQueue<RoutePatherSearch*, int32_t> SessionQueue;
96  typedef std::list<int32_t> SessionList;
97  typedef std::map<int32_t, Path> PathMap;
98  typedef std::map<Layer*, SearchSpace*> SearchSpaceMap;
99  typedef std::map<int32_t, Location> LocationMap;
111  bool followPath(const Instance* instance, Path& path, double speed, Location& nextLocation, Location& facingLocation);
112 
119  void addSessionId(const int32_t sessionId);
120 
129  void makePlan(const Instance *instance, const Location& target, int32_t session_id, int32_t priority);
130 
134  int32_t makeSessionId();
135 
137  bool locationsEqual(const Location &a, const Location &b);
138 
144  bool testStep(const Instance *instance, Path& path);
145 
153  bool sessionIdValid(const int32_t sessionId);
154 
160  bool invalidateSessionId(const int32_t sessionId);
161 
162  //The map the search is running on.
163  Map* m_map;
164 
165  //A map of currently running sessions (searches).
166  SessionQueue m_sessions;
167 
168  //A list of session ids that have been registered.
169  SessionList m_registeredSessionIds;
170 
171  //Calculated paths for the movement phase.
172  PathMap m_paths;
173 
174  //The endpoints for which those paths were calculated
175  LocationMap m_path_targets;
176 
177  //A map of searchspaces.
178  SearchSpaceMap m_searchspaces;
179 
180  //The next free session id.
181  int32_t m_nextFreeSessionId;
182 
183  //The maximum number of ticks allowed.
184  int32_t m_maxticks;
185  };
186 }
187 #endif
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39