Path.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : wwphys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/Path.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/06/01 11:01a $*
  29. * *
  30. * $Revision:: 27 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __COMMANDO_PATH_H
  39. #define __COMMANDO_PATH_H
  40. #include "vector.h"
  41. #include "vector3.h"
  42. #include "hermitespline.h"
  43. #include "PathObject.h"
  44. #include "binheap.h"
  45. #include "refcount.h"
  46. /////////////////////////////////////////////////////////////////////////
  47. // Forward declarations
  48. /////////////////////////////////////////////////////////////////////////
  49. class WaypathClass;
  50. class WaypointClass;
  51. class PathSolveClass;
  52. class ChunkSaveClass;
  53. class ChunkLoadClass;
  54. /////////////////////////////////////////////////////////////////////////
  55. //
  56. // PathClass
  57. //
  58. /////////////////////////////////////////////////////////////////////////
  59. class PathClass : public RefCountClass
  60. {
  61. public:
  62. /////////////////////////////////////////////////////////////////////////
  63. // Public data types
  64. /////////////////////////////////////////////////////////////////////////
  65. typedef enum
  66. {
  67. STATE_TRAVERSING_PATH = 1,
  68. STATE_ACTION_REQUIRED,
  69. STATE_PATH_COMPLETE,
  70. FIRST_ERROR = 100,
  71. ERROR_DRIFTED_FROM_PATH,
  72. ERROR_GENERAL,
  73. ERROR_NOT_INITIALIZED,
  74. } STATE_DESC;
  75. typedef enum
  76. {
  77. LINEAR = 0,
  78. SPLINE
  79. } TRAVERSAL_TYPE;
  80. typedef enum
  81. {
  82. MOVE_X = 1,
  83. MOVE_Y = 2,
  84. MOVE_Z = 4,
  85. } MOVEMENT_DIRECTIONS;
  86. typedef enum
  87. {
  88. ACTION_NONE = 0,
  89. ACTION_JUMP,
  90. ACTION_LEAP,
  91. ACTION_LADDER,
  92. ACTION_MECHANISM
  93. } ACTION_ID;
  94. /////////////////////////////////////////////////////////////////////////
  95. // Public constructors/destructors
  96. /////////////////////////////////////////////////////////////////////////
  97. PathClass (void);
  98. ~PathClass (void);
  99. /////////////////////////////////////////////////////////////////////////
  100. // Public methods
  101. /////////////////////////////////////////////////////////////////////////
  102. //
  103. // Path evaluation
  104. //
  105. bool Evaluate_Next_Point (const Vector3 &curr_pos, Vector3 &new_pos);
  106. const Vector3 & Get_Start_Pos (void) const { return m_StartPos; }
  107. const Vector3 & Get_Dest_Pos (void) const { return m_DestPos; }
  108. const Vector3 & Get_Next_Pos (void) const { return m_ExpectedPos; }
  109. void Set_Movement_Radius (float radius) { m_MovementRadius = radius; }
  110. float Get_Movement_Radius (void) const { return m_MovementRadius; }
  111. float Get_Curve_Sharpness (Vector3 *position) const;
  112. float Get_Last_Eval_Time (void) const;
  113. float Get_Remaining_Path_Length (void);
  114. ACTION_ID Get_Action_Type (void);
  115. void Get_Action_Destination (Vector3 &dest);
  116. void Get_Action_Entrance (Vector3 &position);
  117. uint32 Get_Action_Mechanism (void);
  118. //
  119. // Velocity methods
  120. //
  121. float Get_Velocity (void) const { return m_Velocity; }
  122. void Set_Velocity (float velocity) { m_Velocity = velocity; }
  123. //
  124. // Traversal type methods
  125. //
  126. TRAVERSAL_TYPE Get_Traversal_Type (void) const;
  127. void Set_Traversal_Type (TRAVERSAL_TYPE type);
  128. //
  129. // Movement direction control
  130. //
  131. void Set_Movement_Directions (int directions) { m_MovementDirections = directions; }
  132. int Get_Movement_Directions (void) const { return m_MovementDirections; }
  133. //
  134. // Initialization methods
  135. //
  136. void Initialize (WaypathClass *waypath, int start_pt_id, int end_pt_id);
  137. void Initialize (PathSolveClass &path_solve);
  138. void Initialize (const Vector3 &start, const Vector3 &end);
  139. //
  140. // Initialization methods
  141. //
  142. STATE_DESC Get_State (void) const { return m_State; }
  143. //
  144. // Traversing object
  145. //
  146. void Set_Path_Object (PathObjectClass &path_object);
  147. void Get_Path_Object (PathObjectClass &path_object) const;
  148. //
  149. // Debug methods
  150. //
  151. void Display_Path (bool onoff = true);
  152. //
  153. // Save/load stuff
  154. //
  155. void Save (ChunkSaveClass &csave);
  156. void Load (ChunkLoadClass &cload);
  157. //
  158. // Debug support
  159. //
  160. static bool Are_Move_Vectors_Displayed (void) { return m_DisplayMoveVectors; }
  161. static void Display_Move_Vectors (bool onoff) { m_DisplayMoveVectors = onoff; }
  162. #ifdef WWDEBUG
  163. int Get_Path_Vector_Length(void) {return(m_PathActions.Length());};
  164. int Get_Path_Vector_Count(void) {return(m_PathActions.Count());};
  165. #endif //WWDEBUG
  166. protected:
  167. /////////////////////////////////////////////////////////////////////////
  168. // Protected data types
  169. /////////////////////////////////////////////////////////////////////////
  170. typedef struct _PATH_NODE
  171. {
  172. float time;
  173. float next_time;
  174. bool tighten_spline;
  175. ACTION_ID action_id;
  176. uint32 mechanism_id;
  177. Vector3 dest_pos;
  178. Vector3 pos;
  179. _PATH_NODE (void) :
  180. time (0),
  181. next_time (0),
  182. tighten_spline (false),
  183. action_id (ACTION_NONE),
  184. mechanism_id (0),
  185. dest_pos (0, 0, 0),
  186. pos (0, 0, 0) {}
  187. bool operator== (const _PATH_NODE &src) { return true; }
  188. bool operator!= (const _PATH_NODE &src) { return false; }
  189. } PATH_NODE;
  190. /////////////////////////////////////////////////////////////////////////
  191. // Protected methods
  192. /////////////////////////////////////////////////////////////////////////
  193. void Initialize_Spline (DynamicVectorClass<PATH_NODE> &node_list);
  194. void Initialize_Vehicle_Spline (DynamicVectorClass<PATH_NODE> &node_list);
  195. void Initialize_Human_Spline (DynamicVectorClass<PATH_NODE> &node_list);
  196. void Clip_Spline_To_Pathfind_Data (DynamicVectorClass<PATH_NODE> &node_list, PathSolveClass &path_solve);
  197. void Add_Waypath_Data (DynamicVectorClass<PATH_NODE> &node_list, WaypathClass *waypath, int start_index, int end_index);
  198. void Add_Waypoint_Info_To_Node_List (DynamicVectorClass<PATH_NODE> &node_list, WaypointClass *waypoint, WaypointClass *next_point);
  199. typedef DynamicVectorClass<AABoxClass *> BOX_LIST;
  200. bool Is_Point_In_Boxes (const Vector3 &point, BOX_LIST &box_list);
  201. void Clip_Control_Point (const Vector3 &start_point, Vector3 *point, BOX_LIST &sector_list, BOX_LIST &portal_list);
  202. //
  203. // Save/load methods
  204. //
  205. void Load_Variables (ChunkLoadClass &cload);
  206. private:
  207. /////////////////////////////////////////////////////////////////////////
  208. // Private member data
  209. /////////////////////////////////////////////////////////////////////////
  210. STATE_DESC m_State;
  211. TRAVERSAL_TYPE m_TraversalType;
  212. Vector3 m_StartPos;
  213. Vector3 m_DestPos;
  214. Vector3 m_ExpectedPos;
  215. float m_LookAheadDist;
  216. float m_LookAheadTime;
  217. float m_MovementRadius;
  218. float m_SplineTime;
  219. float m_Velocity;
  220. float m_TotalDist;
  221. DynamicVectorClass<PATH_NODE> m_PathActions;
  222. int m_CurrentAction;
  223. int m_MovementDirections;
  224. Curve3DClass * m_Spline;
  225. PathObjectClass m_PathObject;
  226. float m_StartTime;
  227. float m_EndTime;
  228. bool m_IsLooping;
  229. static bool m_DisplayMoveVectors;
  230. };
  231. /////////////////////////////////////////////////////////////////////////
  232. // Inlines
  233. /////////////////////////////////////////////////////////////////////////
  234. /////////////////////////////////////////////////////////////////////////
  235. // Get_Action_Type
  236. /////////////////////////////////////////////////////////////////////////
  237. inline PathClass::ACTION_ID
  238. PathClass::Get_Action_Type (void)
  239. {
  240. ACTION_ID retval = ACTION_NONE;
  241. if (m_CurrentAction >= 0 && m_CurrentAction < m_PathActions.Count ()) {
  242. retval = m_PathActions[m_CurrentAction].action_id;
  243. }
  244. return retval;
  245. }
  246. /////////////////////////////////////////////////////////////////////////
  247. // Get_Action_Destination
  248. /////////////////////////////////////////////////////////////////////////
  249. inline void
  250. PathClass::Get_Action_Destination (Vector3 &dest)
  251. {
  252. if (m_CurrentAction >= 0 && m_CurrentAction < m_PathActions.Count ()) {
  253. dest = m_PathActions[m_CurrentAction].dest_pos;
  254. }
  255. return ;
  256. }
  257. /////////////////////////////////////////////////////////////////////////
  258. // Get_Action_Entrance
  259. /////////////////////////////////////////////////////////////////////////
  260. inline void
  261. PathClass::Get_Action_Entrance (Vector3 &position)
  262. {
  263. if (m_CurrentAction >= 0 && m_CurrentAction < m_PathActions.Count ()) {
  264. position = m_PathActions[m_CurrentAction].pos;
  265. }
  266. return ;
  267. }
  268. /////////////////////////////////////////////////////////////////////////
  269. // Get_Action_Mechanism
  270. /////////////////////////////////////////////////////////////////////////
  271. inline uint32
  272. PathClass::Get_Action_Mechanism (void)
  273. {
  274. uint32 mechanism_id = 0;
  275. if (m_CurrentAction >= 0 && m_CurrentAction < m_PathActions.Count ()) {
  276. mechanism_id = m_PathActions[m_CurrentAction].mechanism_id;
  277. }
  278. return mechanism_id;
  279. }
  280. #endif //__COMMANDO_PATH_H