PathfindPortal.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/PathfindPortal.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 4/18/01 12:33p $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __PATHFIND_PORTAL_H
  39. #define __PATHFIND_PORTAL_H
  40. #include "refcount.h"
  41. #include "aabox.h"
  42. #include "wwdebug.h"
  43. #include "pathfind.h"
  44. #include "path.h"
  45. #include "waypathposition.h"
  46. //////////////////////////////////////////////////////////////////////////
  47. // Forward declarations
  48. //////////////////////////////////////////////////////////////////////////
  49. class PathfindSectorClass;
  50. class PathNodeClass;
  51. class ChunkSaveClass;
  52. class ChunkLoadClass;
  53. class PathfindActionPortalClass;
  54. class PathfindWaypathPortalClass;
  55. //////////////////////////////////////////////////////////////////////////
  56. //
  57. // PathfindPortalClass
  58. //
  59. //////////////////////////////////////////////////////////////////////////
  60. class PathfindPortalClass : public RefCountClass
  61. {
  62. public:
  63. ////////////////////////////////////////////////////////////////////
  64. // Public constructors/destructors
  65. ////////////////////////////////////////////////////////////////////
  66. PathfindPortalClass (void)
  67. : m_DestSector1 ((uint16)-1),
  68. m_DestSector2 ((uint16)-1),
  69. m_HeapLocation (0),
  70. m_ClosedListPtr (NULL),
  71. m_ID (0) {}
  72. virtual ~PathfindPortalClass (void) {}
  73. ////////////////////////////////////////////////////////////////////
  74. // RTTI
  75. ////////////////////////////////////////////////////////////////////
  76. virtual PathfindActionPortalClass * As_PathfindActionPortalClass (void) { return NULL; }
  77. virtual PathfindWaypathPortalClass * As_PathfindWaypathPortalClass (void) { return NULL; }
  78. ////////////////////////////////////////////////////////////////////
  79. // Public methods
  80. ////////////////////////////////////////////////////////////////////
  81. void Get_Bounding_Box (AABoxClass &box) const;
  82. void Set_Bounding_Box (const AABoxClass &box);
  83. PathfindSectorClass *Peek_Dest_Sector (PathfindSectorClass *current_sector);
  84. void Add_Dest_Sector (int sector_index);
  85. void Add_Dest_Sector (PathfindSectorClass *sector);
  86. uint16 Get_Dest_Sector1 (void);
  87. uint16 Get_Dest_Sector2 (void);
  88. virtual PathClass::ACTION_ID Get_Action_Type (void) const { return PathClass::ACTION_NONE; }
  89. bool Is_Two_Way_Portal (void) const;
  90. virtual bool Does_Size_Matter (void) const { return true; }
  91. uint32 Get_ID (void) const { return m_ID; }
  92. void Set_ID (uint32 id) { m_ID = id; }
  93. //////////////////////////////////////////////////////////////////////
  94. // A-Star list methods
  95. //////////////////////////////////////////////////////////////////////
  96. uint32 Get_Heap_Location (void) const;
  97. void Set_Heap_Location (uint32 location);
  98. //////////////////////////////////////////////////////////////////////
  99. // Serialization methods
  100. //////////////////////////////////////////////////////////////////////
  101. virtual bool Save (ChunkSaveClass &chunk_save);
  102. virtual bool Load (ChunkLoadClass &chunk_load);
  103. void Resolve_IDs (void);
  104. PathNodeClass * m_ClosedListPtr;
  105. protected:
  106. //////////////////////////////////////////////////////////////////////
  107. // Protected methods
  108. //////////////////////////////////////////////////////////////////////
  109. bool Load_Variables (ChunkLoadClass &cload);
  110. private:
  111. ////////////////////////////////////////////////////////////////////
  112. // Private member data
  113. ////////////////////////////////////////////////////////////////////
  114. uint16 m_DestSector1;
  115. uint16 m_DestSector2;
  116. AABoxClass m_BoundingBox;
  117. uint32 m_ID;
  118. uint32 m_HeapLocation;
  119. };
  120. //////////////////////////////////////////////////////////////////////////
  121. // Get_Bounding_Box
  122. //////////////////////////////////////////////////////////////////////////
  123. inline void
  124. PathfindPortalClass::Get_Bounding_Box (AABoxClass &box) const
  125. {
  126. box = m_BoundingBox;
  127. return ;
  128. }
  129. //////////////////////////////////////////////////////////////////////////
  130. // Set_Bounding_Box
  131. //////////////////////////////////////////////////////////////////////////
  132. inline void
  133. PathfindPortalClass::Set_Bounding_Box (const AABoxClass &box)
  134. {
  135. m_BoundingBox = box;
  136. return ;
  137. }
  138. //////////////////////////////////////////////////////////////////////////
  139. // Add_Dest_Sector
  140. //////////////////////////////////////////////////////////////////////////
  141. inline void
  142. PathfindPortalClass::Add_Dest_Sector (int sector_index)
  143. {
  144. WWASSERT (m_DestSector1 == (uint16)-1 || m_DestSector2 == (uint16)-1);
  145. WWASSERT (sector_index != -1);
  146. if (m_DestSector1 == (uint16)-1) {
  147. m_DestSector1 = sector_index;
  148. } else {
  149. m_DestSector2 = sector_index;
  150. }
  151. return ;
  152. }
  153. //////////////////////////////////////////////////////////////////////////
  154. // Add_Dest_Sector
  155. //////////////////////////////////////////////////////////////////////////
  156. inline void
  157. PathfindPortalClass::Add_Dest_Sector (PathfindSectorClass *sector)
  158. {
  159. int index = PathfindClass::Get_Instance ()->Get_Sector_Index (sector);
  160. Add_Dest_Sector (index);
  161. return ;
  162. }
  163. //////////////////////////////////////////////////////////////////////////
  164. // Get_Dest_Sector1
  165. //////////////////////////////////////////////////////////////////////////
  166. inline uint16
  167. PathfindPortalClass::Get_Dest_Sector1 (void)
  168. {
  169. return m_DestSector1;
  170. }
  171. //////////////////////////////////////////////////////////////////////////
  172. // Get_Dest_Sector2
  173. //////////////////////////////////////////////////////////////////////////
  174. inline uint16
  175. PathfindPortalClass::Get_Dest_Sector2 (void)
  176. {
  177. return m_DestSector2;
  178. }
  179. //////////////////////////////////////////////////////////////////////////
  180. // Peek_Dest_Sector
  181. //////////////////////////////////////////////////////////////////////////
  182. inline PathfindSectorClass *
  183. PathfindPortalClass::Peek_Dest_Sector (PathfindSectorClass *current_sector)
  184. {
  185. //
  186. // Determine which destination sector to return
  187. //
  188. PathfindSectorClass *dest_sector = PathfindClass::Get_Instance ()->Peek_Sector (m_DestSector1);
  189. if (dest_sector == current_sector) {
  190. dest_sector = PathfindClass::Get_Instance ()->Peek_Sector (m_DestSector2);
  191. }
  192. return dest_sector;
  193. }
  194. //////////////////////////////////////////////////////////////////////////
  195. // Is_Two_Way_Portal
  196. //////////////////////////////////////////////////////////////////////////
  197. inline bool
  198. PathfindPortalClass::Is_Two_Way_Portal (void) const
  199. {
  200. return (m_DestSector1 != ((uint16)-1)) && (m_DestSector2 != ((uint16)-1));
  201. }
  202. //////////////////////////////////////////////////////////////////////////
  203. // Get_Heap_Location
  204. //////////////////////////////////////////////////////////////////////////
  205. inline uint32
  206. PathfindPortalClass::Get_Heap_Location (void) const
  207. {
  208. return m_HeapLocation;
  209. }
  210. //////////////////////////////////////////////////////////////////////////
  211. // Set_Heap_Location
  212. //////////////////////////////////////////////////////////////////////////
  213. inline void
  214. PathfindPortalClass::Set_Heap_Location (uint32 location)
  215. {
  216. m_HeapLocation = location;
  217. return ;
  218. }
  219. //////////////////////////////////////////////////////////////////////////
  220. //
  221. // PathfindActionPortalClass
  222. //
  223. //////////////////////////////////////////////////////////////////////////
  224. class PathfindActionPortalClass : public PathfindPortalClass
  225. {
  226. public:
  227. ////////////////////////////////////////////////////////////////////
  228. // Public constructors/destructors
  229. ////////////////////////////////////////////////////////////////////
  230. PathfindActionPortalClass (void)
  231. : m_Destination (0, 0, 0),
  232. m_EntranceSector (NULL),
  233. m_ExitPortal (NULL),
  234. m_EnterPortal (NULL),
  235. m_MechanismID (0),
  236. m_ActionID (PathClass::ACTION_NONE) { }
  237. ~PathfindActionPortalClass (void) { }
  238. ////////////////////////////////////////////////////////////////////
  239. // RTTI
  240. ////////////////////////////////////////////////////////////////////
  241. PathfindActionPortalClass *As_PathfindActionPortalClass (void) { return this; }
  242. ////////////////////////////////////////////////////////////////////
  243. // Public methods
  244. ////////////////////////////////////////////////////////////////////
  245. //
  246. // Action identification
  247. //
  248. PathClass::ACTION_ID Get_Action_Type (void) const { return m_ActionID; }
  249. void Set_Action_Type (PathClass::ACTION_ID action_id) { m_ActionID = action_id; }
  250. //
  251. // Mechanism information (in case we have to interact to do this action)
  252. //
  253. uint32 Get_Mechanism_ID (void) const { return m_MechanismID; }
  254. void Set_Mechanism_ID (uint32 id) { m_MechanismID = id; }
  255. //
  256. // Destination control (where do we end up at the end of this action?)
  257. //
  258. void Set_Destination (const Vector3 &pos) { m_Destination = pos; }
  259. const Vector3 & Get_Destination (void) const { return m_Destination; }
  260. //
  261. // Sector information
  262. //
  263. PathfindSectorClass * Get_Entrance_Sector (void) { return m_EntranceSector; }
  264. void Set_Entrance_Sector (PathfindSectorClass *sector) { m_EntranceSector = sector; }
  265. //
  266. // Enter information
  267. //
  268. PathfindActionPortalClass * Get_Enter_Portal (void) { return m_EnterPortal; }
  269. void Set_Enter_Portal (PathfindActionPortalClass *portal) { m_EnterPortal = portal; }
  270. //
  271. // Exit information
  272. //
  273. PathfindPortalClass * Get_Exit_Portal (void) { return m_ExitPortal; }
  274. void Set_Exit_Portal (PathfindPortalClass *portal) { m_ExitPortal = portal; }
  275. //
  276. // Serialization
  277. //
  278. bool Save (ChunkSaveClass &chunk_save);
  279. bool Load (ChunkLoadClass &chunk_load);
  280. protected:
  281. //////////////////////////////////////////////////////////////////////
  282. // Protected methods
  283. //////////////////////////////////////////////////////////////////////
  284. bool Load_Variables (ChunkLoadClass &cload);
  285. private:
  286. ////////////////////////////////////////////////////////////////////
  287. // Private member data
  288. ////////////////////////////////////////////////////////////////////
  289. Vector3 m_Destination;
  290. PathfindSectorClass * m_EntranceSector;
  291. uint32 m_MechanismID;
  292. PathClass::ACTION_ID m_ActionID;
  293. PathfindPortalClass * m_ExitPortal;
  294. PathfindActionPortalClass * m_EnterPortal;
  295. };
  296. //////////////////////////////////////////////////////////////////////////
  297. //
  298. // PathfindWaypathPortalClass
  299. //
  300. //////////////////////////////////////////////////////////////////////////
  301. class PathfindWaypathPortalClass : public PathfindPortalClass
  302. {
  303. public:
  304. ////////////////////////////////////////////////////////////////////
  305. // Public constructors/destructors
  306. ////////////////////////////////////////////////////////////////////
  307. PathfindWaypathPortalClass (void) {}
  308. ~PathfindWaypathPortalClass (void) {}
  309. ////////////////////////////////////////////////////////////////////
  310. // RTTI
  311. ////////////////////////////////////////////////////////////////////
  312. PathfindWaypathPortalClass *As_PathfindWaypathPortalClass (void) { return this; }
  313. ////////////////////////////////////////////////////////////////////
  314. // Public methods
  315. ////////////////////////////////////////////////////////////////////
  316. //
  317. // From PathfindPortalClass
  318. //
  319. bool Does_Size_Matter (void) const { return false; }
  320. //
  321. // Waypath information
  322. //
  323. void Set_Waypath_Pos (const WaypathPositionClass &pos) { WaypathPos = pos; }
  324. const WaypathPositionClass & Get_Waypath_Pos (void) const { return WaypathPos; }
  325. //
  326. // Serialization
  327. //
  328. bool Save (ChunkSaveClass &chunk_save);
  329. bool Load (ChunkLoadClass &chunk_load);
  330. protected:
  331. //////////////////////////////////////////////////////////////////////
  332. // Protected methods
  333. //////////////////////////////////////////////////////////////////////
  334. bool Load_Variables (ChunkLoadClass &cload);
  335. private:
  336. ////////////////////////////////////////////////////////////////////
  337. // Private member data
  338. ////////////////////////////////////////////////////////////////////
  339. WaypathPositionClass WaypathPos;
  340. };
  341. #endif //__PATHFIND_PORTAL_H