routepather.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_PATHFINDER_ROUTEPATHER
00023 #define FIFE_PATHFINDER_ROUTEPATHER
00024 
00025 // Standard C++ library includes
00026 #include <map>
00027 #include <vector>
00028 
00029 // 3rd party library includes
00030 
00031 // FIFE includes
00032 // These includes are split up in two parts, separated by one empty line
00033 // First block: files included from the FIFE root src directory
00034 // Second block: files included from the same folder
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         //The map the search is running on.
00163         Map*           m_map;
00164 
00165         //A map of currently running sessions (searches).
00166         SessionQueue   m_sessions;
00167 
00168         //A list of session ids that have been registered.
00169         SessionList    m_registeredSessionIds;
00170 
00171         //Calculated paths for the movement phase.
00172         PathMap        m_paths;
00173 
00174         //The endpoints for which those paths were calculated
00175         LocationMap        m_path_targets;
00176         
00177         //A map of searchspaces.
00178         SearchSpaceMap m_searchspaces; 
00179 
00180         //The next free session id.
00181         int            m_nextFreeSessionId;
00182 
00183         //The maximum number of ticks allowed.
00184         int            m_maxticks;
00185     };
00186 }
00187 #endif
Generated by  doxygen 1.6.2-20100208