routepather.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_PATHFINDER_ROUTEPATHER
00023 #define FIFE_PATHFINDER_ROUTEPATHER
00024
00025
00026 #include <map>
00027 #include <vector>
00028
00029
00030
00031
00032
00033
00034
00035 #include "model/metamodel/abstractpather.h"
00036 #include "model/structures/location.h"
00037 #include "model/structures/map.h"
00038 #include "util/structures/priorityqueue.h"
00039
00040 namespace FIFE {
00041
00042 class Search;
00043 class SearchSpace;
00044 class RoutePatherSearch;
00045
00046 class RoutePather : public AbstractPather {
00047 public:
00051 RoutePather() : m_map(0), m_nextFreeSessionId(0), m_maxticks(1000) {
00052 }
00053
00054 void setMap(Map* map);
00055 int getNextLocation(const Instance* instance, const Location& target,
00056 double distance_to_travel, Location& nextLocation,
00057 Location& facingLocation, int session_id=-1,
00058 int priority = MEDIUM_PRIORITY);
00059
00066 void update();
00067
00076 bool cancelSession(const int session_id);
00077
00083 bool addSearchSpace(SearchSpace* search_space);
00084
00090 SearchSpace* getSearchSpace(Layer * const layer);
00091
00092 std::string getName() const { return "RoutePather"; };
00093 private:
00094 typedef std::list<Location> Path;
00095 typedef PriorityQueue<RoutePatherSearch*, int> SessionQueue;
00096 typedef std::list<int> SessionList;
00097 typedef std::map<int, Path> PathMap;
00098 typedef std::map<Layer*, SearchSpace*> SearchSpaceMap;
00099 typedef std::map<int, Location> LocationMap;
00111 bool followPath(const Instance* instance, Path& path, double speed, Location& nextLocation, Location& facingLocation);
00112
00119 void addSessionId(const int sessionId);
00120
00129 void makePlan(const Instance *instance, const Location& target, int session_id, int priority);
00130
00134 int makeSessionId();
00135
00137 bool locationsEqual(const Location &a, const Location &b);
00138
00144 bool testStep(const Instance *instance, Path& path);
00145
00153 bool sessionIdValid(const int sessionId);
00154
00160 bool invalidateSessionId(const int sessionId);
00161
00162
00163 Map* m_map;
00164
00165
00166 SessionQueue m_sessions;
00167
00168
00169 SessionList m_registeredSessionIds;
00170
00171
00172 PathMap m_paths;
00173
00174
00175 LocationMap m_path_targets;
00176
00177
00178 SearchSpaceMap m_searchspaces;
00179
00180
00181 int m_nextFreeSessionId;
00182
00183
00184 int m_maxticks;
00185 };
00186 }
00187 #endif