1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef I_PATH_MANAGER_H 4 #define I_PATH_MANAGER_H 5 6 #include <boost/cstdint.hpp> /* Replace with <stdint.h> if appropriate */ 7 8 #include "PFSTypes.h" 9 #include "System/type2.h" 10 #include "System/float3.h" 11 12 struct MoveDef; 13 class CSolidObject; 14 15 class IPathManager { 16 public: 17 static IPathManager* GetInstance(unsigned int type); 18 ~IPathManager()19 virtual ~IPathManager() {} 20 21 virtual unsigned int GetPathFinderType() const = 0; GetPathCheckSum()22 virtual boost::uint32_t GetPathCheckSum() const { return 0; } 23 Finalize()24 virtual boost::int64_t Finalize() { return 0; } 25 26 /** 27 * returns if a path was changed after RequestPath returned its pathID 28 * this can happen eg. if a PathManager reacts to TerrainChange events 29 * (by re-requesting affected paths without changing their ID's) 30 */ PathUpdated(unsigned int pathID)31 virtual bool PathUpdated(unsigned int pathID) { return false; } 32 Update()33 virtual void Update() {} UpdatePath(const CSolidObject * owner,unsigned int pathID)34 virtual void UpdatePath(const CSolidObject* owner, unsigned int pathID) {} 35 36 /** 37 * When a path is no longer used, call this function to release it from 38 * memory. 39 * @param pathID 40 * The path-id returned by RequestPath. 41 */ DeletePath(unsigned int pathID)42 virtual void DeletePath(unsigned int pathID) {} 43 44 /** 45 * Returns the next waypoint of the path. 46 * 47 * @param pathID 48 * The path-id returned by RequestPath. 49 * @param callerPos 50 * The current position of the user of the path. 51 * This extra information is needed to keep the path connected to its 52 * user. 53 * @param minDistance 54 * Could be used to set a minimum required distance between callerPos 55 * and the returned waypoint. 56 * @param numRetries 57 * Dont set this, used internally 58 * @param owner 59 * The unit the path is used for, or NULL. 60 * @param synced 61 * Whether this evaluation has to run synced or unsynced. 62 * If false, this call may not change any state of the path manager 63 * that could alter paths requested in the future. 64 * example: if (synced == false) turn of heat-mapping 65 * @return 66 * the next waypoint of the path, or (-1,-1,-1) in case no new 67 * waypoint could be found. 68 */ NextWayPoint(const CSolidObject * owner,unsigned int pathID,unsigned int numRetries,float3 callerPos,float radius,bool synced)69 virtual float3 NextWayPoint( 70 const CSolidObject* owner, 71 unsigned int pathID, 72 unsigned int numRetries, 73 float3 callerPos, 74 float radius, 75 bool synced 76 ) { return ZeroVector; } 77 78 79 /** 80 * Returns all waypoints of a path. Different segments of a path might 81 * have different resolutions, or each segment might be represented at 82 * multiple different resolution levels. In the former case, a subset 83 * of waypoints (those belonging to i-th resolution path SEGMENTS) are 84 * stored between points[starts[i]] and points[starts[i + 1]], while in 85 * the latter case ALL waypoints (of the i-th resolution PATH) are stored 86 * between points[starts[i]] and points[starts[i + 1]] 87 * 88 * @param pathID 89 * The path-id returned by RequestPath. 90 * @param points 91 * The list of waypoints. 92 * @param starts 93 * The list of starting indices for the different resolutions 94 */ GetPathWayPoints(unsigned int pathID,std::vector<float3> & points,std::vector<int> & starts)95 virtual void GetPathWayPoints( 96 unsigned int pathID, 97 std::vector<float3>& points, 98 std::vector<int>& starts 99 ) const {} 100 101 102 /** 103 * Generate a path from startPos to the target defined by 104 * (goalPos, goalRadius). 105 * If no complete path from startPos to goalPos could be found, 106 * then a path getting as "close" as possible to target is generated. 107 * 108 * @param moveDef 109 * Defines the move details of the unit to use the path. 110 * @param startPos 111 * The starting location of the requested path. 112 * @param goalPos 113 * The center of the path goal area. 114 * @param goalRadius 115 * Use goalRadius to define a goal area within any square that could 116 * be accepted as path goal. 117 * If a singular goal position is wanted, use goalRadius = 0. 118 * @param caller 119 * The unit or feature the path will be used for. 120 * @param synced 121 * Whether this evaluation has to run synced or unsynced. 122 * If false, this call may not change any state of the path manager 123 * that could alter paths requested in the future. 124 * example: if (synced == false) turn off heat-mapping 125 * @return 126 * a path-id >= 1 on success, 0 on failure 127 * Failure means, no path getting "closer" to goalPos then startPos 128 * could be found 129 */ RequestPath(CSolidObject * caller,const MoveDef * moveDef,const float3 & startPos,const float3 & goalPos,float goalRadius,bool synced)130 virtual unsigned int RequestPath( 131 CSolidObject* caller, 132 const MoveDef* moveDef, 133 const float3& startPos, 134 const float3& goalPos, 135 float goalRadius, 136 bool synced 137 ) { return 0; } 138 139 /** 140 * Whenever there are any changes in the terrain 141 * (examples: explosions, new buildings, etc.) 142 * this function will be called. 143 * @param x1 144 * First corners X-axis value, defining the rectangular area 145 * affected by the changes. 146 * @param z1 147 * First corners Z-axis value, defining the rectangular area 148 * affected by the changes. 149 * @param x2 150 * Second corners X-axis value, defining the rectangular area 151 * affected by the changes. 152 * @param z2 153 * Second corners Z-axis value, defining the rectangular area 154 * affected by the changes. 155 * @param type see @TerrainChangeTypes 156 */ TerrainChange(unsigned int x1,unsigned int z1,unsigned int x2,unsigned int z2,unsigned int type)157 virtual void TerrainChange(unsigned int x1, unsigned int z1, unsigned int x2, unsigned int z2, unsigned int type) {} 158 SetNodeExtraCosts(const float * costs,unsigned int sizex,unsigned int sizez,bool synced)159 virtual bool SetNodeExtraCosts(const float* costs, unsigned int sizex, unsigned int sizez, bool synced) { return false; } SetNodeExtraCost(unsigned int x,unsigned int z,float cost,bool synced)160 virtual bool SetNodeExtraCost(unsigned int x, unsigned int z, float cost, bool synced) { return false; } GetNodeExtraCost(unsigned int x,unsigned int z,bool synced)161 virtual float GetNodeExtraCost(unsigned int x, unsigned int z, bool synced) const { return 0.0f; } GetNodeExtraCosts(bool synced)162 virtual const float* GetNodeExtraCosts(bool synced) const { return NULL; } 163 GetNumQueuedUpdates()164 virtual int2 GetNumQueuedUpdates() const { return (int2(0, 0)); } 165 }; 166 167 extern IPathManager* pathManager; 168 169 #endif 170