| 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_MODEL_IPATHER_H |
| 23 |
#define FIFE_MODEL_IPATHER_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
#include <string> |
| 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 |
|
| 35 |
namespace FIFE { |
| 36 |
class Location; |
| 37 |
class Instance; |
| 38 |
class Route; |
| 39 |
|
| 40 |
//! A path is a list with locations. Each location holds the coordinate for one cell. |
| 41 |
typedef std::list<Location> Path; |
| 42 |
|
| 43 |
enum PriorityType { |
| 44 |
HIGH_PRIORITY, |
| 45 |
MEDIUM_PRIORITY, |
| 46 |
LOW_PRIORITY |
| 47 |
}; |
| 48 |
|
| 49 |
class IPather { |
| 50 |
public: |
| 51 |
virtual ~IPather() {}; |
| 52 |
|
| 53 |
/** Creates a route between the start and end location that needs be solved. |
| 54 |
* |
| 55 |
* @param start A const reference to the start location. |
| 56 |
* @param end A const reference to the target location. |
| 57 |
* @param immediate A optional boolean, if true the route bypass the max. ticks limit and solves the path immediately, otherwise false. |
| 58 |
* @param cost_id A const reference to the string that holds the cost identifier. You can use it optional then this cost id is used instead of the default cost. |
| 59 |
*/ |
| 60 |
virtual Route* createRoute(const Location& start, const Location& end, bool immediate = false, const std::string& cost_id = "") = 0; |
| 61 |
|
| 62 |
/** Solves the route to create a path. |
| 63 |
* |
| 64 |
* @param route A pointer to the route which should be solved. |
| 65 |
* @param priority The priority to assign to search (high are pushed to the front of the queue). @see PriorityType |
| 66 |
* @param immediate A optional boolean, if true the route bypass the max. ticks limit and solves the path immediately, otherwise false. |
| 67 |
* @return A boolean, if true the route could be solved, otherwise false. |
| 68 |
*/ |
| 69 |
virtual bool solveRoute(Route* route, int32_t priority = MEDIUM_PRIORITY, bool immediate = false) = 0; |
| 70 |
|
| 71 |
/** Follows the path of the route. |
| 72 |
* |
| 73 |
* @param current A const reference to the current location. |
| 74 |
* @param route A pointer to the route which should be followed. |
| 75 |
* @param speed A double which holds the speed. |
| 76 |
* @param nextLocation A reference to the next location returned by the pather. |
| 77 |
* @return A boolean, if true the route could be followed, otherwise false. |
| 78 |
*/ |
| 79 |
virtual bool followRoute(const Location& current, Route* route, double speed, Location& nextLocation) = 0; |
| 80 |
|
| 81 |
/** Updates the pather (should it need updating). |
| 82 |
* |
| 83 |
* The update method is called by the model. Pathfinders which require per loop updating |
| 84 |
* (in the case of pathfinders which implement A* for instance) should use this method |
| 85 |
* as an oppurtunity to update the search. Generally the method should be constrained to |
| 86 |
* a maximum amount of search updating to prevent this method from stalling the application. |
| 87 |
*/ |
| 88 |
virtual void update() = 0; |
| 89 |
|
| 90 |
/** Cancels a given session. |
| 91 |
* |
| 92 |
* This function is called when (for instance) the user changes their mind about |
| 93 |
* a destination while the agent is already moving, the old session needs to be |
| 94 |
* cancelled and a new one created. |
| 95 |
* |
| 96 |
* @param sessionId The id of the session to cancel. |
| 97 |
* @return A boolean to signify whether the session was successfully found and cancelled. |
| 98 |
*/ |
| 99 |
virtual bool cancelSession(const int32_t sessionId) = 0; |
| 100 |
|
| 101 |
/** Sets maximal ticks (update steps) to solve routes. @see update() |
| 102 |
* @param ticks A integer which holds the steps. default is 1000 |
| 103 |
*/ |
| 104 |
virtual void setMaxTicks(int32_t ticks) = 0; |
| 105 |
|
| 106 |
/** Returns maximal ticks (update steps) to solve routes. @see update() |
| 107 |
* @return A integer which holds the steps. default is 1000 |
| 108 |
*/ |
| 109 |
virtual int32_t getMaxTicks() = 0; |
| 110 |
|
| 111 |
/** Gets the name of this pather |
| 112 |
*/ |
| 113 |
virtual std::string getName() const = 0; |
| 114 |
}; |
| 115 |
} |
| 116 |
|
| 117 |
#endif |