PathfindPortal.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 4/20/01 8:49a $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "pathfindportal.h"
  36. #include "pathfindsector.h"
  37. #include "pathfind.h"
  38. #include "chunkio.h"
  39. #include "saveload.h"
  40. ///////////////////////////////////////////////////////////////////////////
  41. // Save/Load stuff
  42. ///////////////////////////////////////////////////////////////////////////
  43. enum
  44. {
  45. CHUNKID_VARIABLES = 0x01060654,
  46. CHUNKID_PARENT
  47. };
  48. enum
  49. {
  50. VARID_BOUNDING_BOX = 1,
  51. XXXXX_ACTION_REQUIRED,
  52. VARID_DEST_SECTOR1,
  53. VARID_DEST_SECTOR2,
  54. VARID_ID,
  55. VARID_OLD_PTR
  56. };
  57. enum
  58. {
  59. ACTION_VARID_DESTINATION = 1,
  60. ACTION_VARID_MECHANISM_ID,
  61. ACTION_VARID_ACTION_ID,
  62. ACTION_VARID_EXIT_PORTAL,
  63. ACTION_VARID_ENTER_PORTAL
  64. };
  65. enum
  66. {
  67. WPATH_VARID_WAYPATH_POS = 1,
  68. };
  69. ///////////////////////////////////////////////////////////////////////////
  70. //
  71. // Save
  72. //
  73. ///////////////////////////////////////////////////////////////////////////
  74. bool
  75. PathfindPortalClass::Save (ChunkSaveClass &csave)
  76. {
  77. csave.Begin_Chunk (CHUNKID_VARIABLES);
  78. //
  79. // Write the bounding box out to the chunk
  80. //
  81. WRITE_MICRO_CHUNK (csave, VARID_BOUNDING_BOX, m_BoundingBox);
  82. WRITE_MICRO_CHUNK (csave, VARID_DEST_SECTOR1, m_DestSector1);
  83. WRITE_MICRO_CHUNK (csave, VARID_DEST_SECTOR2, m_DestSector2);
  84. WRITE_MICRO_CHUNK (csave, VARID_ID, m_ID);
  85. PathfindPortalClass *this_ptr = this;
  86. WRITE_MICRO_CHUNK (csave, VARID_OLD_PTR, this_ptr);
  87. csave.End_Chunk ();
  88. return true;
  89. }
  90. ///////////////////////////////////////////////////////////////////////////
  91. //
  92. // Load
  93. //
  94. ///////////////////////////////////////////////////////////////////////////
  95. bool
  96. PathfindPortalClass::Load (ChunkLoadClass &cload)
  97. {
  98. //
  99. // Read all the chunks...
  100. //
  101. while (cload.Open_Chunk ()) {
  102. switch (cload.Cur_Chunk_ID ()) {
  103. case CHUNKID_VARIABLES:
  104. Load_Variables (cload);
  105. break;
  106. default:
  107. WWDEBUG_SAY (("Unknown chunk ID 0x%X", cload.Cur_Chunk_ID ()));
  108. break;
  109. }
  110. cload.Close_Chunk ();
  111. }
  112. return true;
  113. }
  114. ///////////////////////////////////////////////////////////////////////////
  115. //
  116. // Load_Variables
  117. //
  118. ///////////////////////////////////////////////////////////////////////////
  119. bool
  120. PathfindPortalClass::Load_Variables (ChunkLoadClass &cload)
  121. {
  122. PathfindPortalClass *old_ptr = NULL;
  123. //
  124. // Read all the micro chunks...
  125. //
  126. while (cload.Open_Micro_Chunk ()) {
  127. switch (cload.Cur_Micro_Chunk_ID ()) {
  128. READ_MICRO_CHUNK (cload, VARID_BOUNDING_BOX, m_BoundingBox);
  129. READ_MICRO_CHUNK (cload, VARID_DEST_SECTOR1, m_DestSector1);
  130. READ_MICRO_CHUNK (cload, VARID_DEST_SECTOR2, m_DestSector2);
  131. READ_MICRO_CHUNK (cload, VARID_ID, m_ID);
  132. READ_MICRO_CHUNK (cload, VARID_OLD_PTR, old_ptr);
  133. default:
  134. WWDEBUG_SAY (("Unknown micro chunk ID 0x%X", cload.Cur_Micro_Chunk_ID ()));
  135. break;
  136. }
  137. cload.Close_Micro_Chunk ();
  138. }
  139. //
  140. // Register our old ptr so other objects can remap to us
  141. //
  142. if (old_ptr != NULL) {
  143. SaveLoadSystemClass::Register_Pointer (old_ptr, this);
  144. }
  145. return true;
  146. }
  147. ///////////////////////////////////////////////////////////////////////////
  148. //
  149. // Save
  150. //
  151. ///////////////////////////////////////////////////////////////////////////
  152. bool
  153. PathfindActionPortalClass::Save (ChunkSaveClass &csave)
  154. {
  155. //
  156. // Save the parent to its own chunk
  157. //
  158. csave.Begin_Chunk (CHUNKID_PARENT);
  159. PathfindPortalClass::Save (csave);
  160. csave.End_Chunk ();
  161. //
  162. // Save each variable to its own micro-chunk
  163. //
  164. csave.Begin_Chunk (CHUNKID_VARIABLES);
  165. WRITE_MICRO_CHUNK (csave, ACTION_VARID_DESTINATION, m_Destination);
  166. WRITE_MICRO_CHUNK (csave, ACTION_VARID_MECHANISM_ID, m_MechanismID);
  167. WRITE_MICRO_CHUNK (csave, ACTION_VARID_ACTION_ID, m_ActionID);
  168. WRITE_MICRO_CHUNK (csave, ACTION_VARID_EXIT_PORTAL, m_ExitPortal);
  169. WRITE_MICRO_CHUNK (csave, ACTION_VARID_ENTER_PORTAL, m_EnterPortal);
  170. csave.End_Chunk ();
  171. return true;
  172. }
  173. ///////////////////////////////////////////////////////////////////////////
  174. //
  175. // Load
  176. //
  177. ///////////////////////////////////////////////////////////////////////////
  178. bool
  179. PathfindActionPortalClass::Load (ChunkLoadClass &cload)
  180. {
  181. //
  182. // Read all the chunks...
  183. //
  184. while (cload.Open_Chunk ()) {
  185. switch (cload.Cur_Chunk_ID ()) {
  186. case CHUNKID_PARENT:
  187. PathfindPortalClass::Load (cload);
  188. break;
  189. case CHUNKID_VARIABLES:
  190. Load_Variables (cload);
  191. break;
  192. default:
  193. WWASSERT (0);
  194. WWDEBUG_SAY (("Unknown chunk ID 0x%X", cload.Cur_Chunk_ID ()));
  195. break;
  196. }
  197. cload.Close_Chunk ();
  198. }
  199. return true;
  200. }
  201. ///////////////////////////////////////////////////////////////////////////
  202. //
  203. // Load_Variables
  204. //
  205. ///////////////////////////////////////////////////////////////////////////
  206. bool
  207. PathfindActionPortalClass::Load_Variables (ChunkLoadClass &cload)
  208. {
  209. //
  210. // Read all the micro chunks...
  211. //
  212. while (cload.Open_Micro_Chunk ()) {
  213. switch (cload.Cur_Micro_Chunk_ID ()) {
  214. READ_MICRO_CHUNK (cload, ACTION_VARID_DESTINATION, m_Destination);
  215. READ_MICRO_CHUNK (cload, ACTION_VARID_MECHANISM_ID, m_MechanismID);
  216. READ_MICRO_CHUNK (cload, ACTION_VARID_ACTION_ID, m_ActionID);
  217. READ_MICRO_CHUNK (cload, ACTION_VARID_EXIT_PORTAL, m_ExitPortal);
  218. READ_MICRO_CHUNK (cload, ACTION_VARID_ENTER_PORTAL, m_EnterPortal);
  219. default:
  220. WWASSERT (0);
  221. WWDEBUG_SAY (("Unknown micro chunk ID 0x%X", cload.Cur_Micro_Chunk_ID ()));
  222. break;
  223. }
  224. cload.Close_Micro_Chunk ();
  225. }
  226. //
  227. // Note: These portals ARE ref-counted, but due to a cyclic ref-counting
  228. // problem, we don't want a reference on them. This is why we don't
  229. // do a ref-counted pointer remap.
  230. //
  231. if (m_EnterPortal != NULL) {
  232. REQUEST_POINTER_REMAP ((void **)&m_EnterPortal);
  233. }
  234. if (m_ExitPortal != NULL) {
  235. REQUEST_POINTER_REMAP ((void **)&m_ExitPortal);
  236. }
  237. return true;
  238. }
  239. ///////////////////////////////////////////////////////////////////////////
  240. //
  241. // Save
  242. //
  243. ///////////////////////////////////////////////////////////////////////////
  244. bool
  245. PathfindWaypathPortalClass::Save (ChunkSaveClass &csave)
  246. {
  247. //
  248. // Save the parent to its own chunk
  249. //
  250. csave.Begin_Chunk (CHUNKID_PARENT);
  251. PathfindPortalClass::Save (csave);
  252. csave.End_Chunk ();
  253. //
  254. // Save each variable to its own micro-chunk
  255. //
  256. csave.Begin_Chunk (CHUNKID_VARIABLES);
  257. WRITE_MICRO_CHUNK (csave, WPATH_VARID_WAYPATH_POS, WaypathPos);
  258. csave.End_Chunk ();
  259. return true;
  260. }
  261. ///////////////////////////////////////////////////////////////////////////
  262. //
  263. // Load
  264. //
  265. ///////////////////////////////////////////////////////////////////////////
  266. bool
  267. PathfindWaypathPortalClass::Load (ChunkLoadClass &cload)
  268. {
  269. //
  270. // Read all the chunks...
  271. //
  272. while (cload.Open_Chunk ()) {
  273. switch (cload.Cur_Chunk_ID ()) {
  274. case CHUNKID_PARENT:
  275. PathfindPortalClass::Load (cload);
  276. break;
  277. case CHUNKID_VARIABLES:
  278. Load_Variables (cload);
  279. break;
  280. default:
  281. WWASSERT (0);
  282. WWDEBUG_SAY (("Unknown chunk ID 0x%X", cload.Cur_Chunk_ID ()));
  283. break;
  284. }
  285. cload.Close_Chunk ();
  286. }
  287. return true;
  288. }
  289. ///////////////////////////////////////////////////////////////////////////
  290. //
  291. // Load_Variables
  292. //
  293. ///////////////////////////////////////////////////////////////////////////
  294. bool
  295. PathfindWaypathPortalClass::Load_Variables (ChunkLoadClass &cload)
  296. {
  297. //
  298. // Read all the micro chunks...
  299. //
  300. while (cload.Open_Micro_Chunk ()) {
  301. switch (cload.Cur_Micro_Chunk_ID ()) {
  302. READ_MICRO_CHUNK (cload, WPATH_VARID_WAYPATH_POS, WaypathPos);
  303. default:
  304. WWASSERT (0);
  305. WWDEBUG_SAY (("Unknown micro chunk ID 0x%X", cload.Cur_Micro_Chunk_ID ()));
  306. break;
  307. }
  308. cload.Close_Micro_Chunk ();
  309. }
  310. return true;
  311. }