waypoint.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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/waypoint.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 4/17/01 8:42a $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "waypoint.h"
  36. #include "persistfactory.h"
  37. #include "wwphysids.h"
  38. #include "wwhack.h"
  39. #include "pathfindportal.h"
  40. DECLARE_FORCE_LINK(waypoint);
  41. //////////////////////////////////////////////////////////////////////////////
  42. // Persist factory
  43. //////////////////////////////////////////////////////////////////////////////
  44. SimplePersistFactoryClass<WaypointClass, PHYSICS_CHUNKID_WAYPOINT> _WaypointPersistFactory;
  45. enum
  46. {
  47. CHUNKID_VARIABLES = 0x04290112,
  48. CHUNKID_BASE_CLASS
  49. };
  50. enum
  51. {
  52. VARID_OLD_PTR = 0x01,
  53. VARID_FLAGS,
  54. VARID_POSITION,
  55. VARID_ID,
  56. VARID_ACTION_ID
  57. };
  58. ////////////////////////////////////////////////////////////////
  59. //
  60. // WaypointClass
  61. //
  62. ////////////////////////////////////////////////////////////////
  63. WaypointClass::WaypointClass (void)
  64. : m_ID (0),
  65. m_Position (0, 0, 0),
  66. m_Flags (0),
  67. m_ActionPortalID (-1)
  68. {
  69. return ;
  70. }
  71. ////////////////////////////////////////////////////////////////
  72. //
  73. // WaypointClass
  74. //
  75. ////////////////////////////////////////////////////////////////
  76. WaypointClass::WaypointClass (const WaypointClass &src)
  77. : m_ID (0),
  78. m_Position (0, 0, 0),
  79. m_Flags (0),
  80. m_ActionPortalID (-1)
  81. {
  82. (*this) = src;
  83. return ;
  84. }
  85. ////////////////////////////////////////////////////////////////
  86. //
  87. // WaypointClass
  88. //
  89. ////////////////////////////////////////////////////////////////
  90. WaypointClass::WaypointClass (const Vector3 &position)
  91. : m_ID (0),
  92. m_Position (position),
  93. m_Flags (0),
  94. m_ActionPortalID (-1)
  95. {
  96. return ;
  97. }
  98. ////////////////////////////////////////////////////////////////
  99. //
  100. // ~WaypointClass
  101. //
  102. ////////////////////////////////////////////////////////////////
  103. WaypointClass::~WaypointClass (void)
  104. {
  105. Free ();
  106. return ;
  107. }
  108. ////////////////////////////////////////////////////////////////
  109. //
  110. // Get_Factory
  111. //
  112. ////////////////////////////////////////////////////////////////
  113. const PersistFactoryClass &
  114. WaypointClass::Get_Factory (void) const
  115. {
  116. return _WaypointPersistFactory;
  117. }
  118. /////////////////////////////////////////////////////////////////
  119. //
  120. // Save
  121. //
  122. /////////////////////////////////////////////////////////////////
  123. bool
  124. WaypointClass::Save (ChunkSaveClass &csave)
  125. {
  126. csave.Begin_Chunk (CHUNKID_VARIABLES);
  127. WaypointClass *this_ptr = this;
  128. WRITE_MICRO_CHUNK (csave, VARID_OLD_PTR, this_ptr);
  129. WRITE_MICRO_CHUNK (csave, VARID_FLAGS, m_Flags);
  130. WRITE_MICRO_CHUNK (csave, VARID_POSITION, m_Position);
  131. WRITE_MICRO_CHUNK (csave, VARID_ID, m_ID);
  132. WRITE_MICRO_CHUNK (csave, VARID_ACTION_ID, m_ActionPortalID);
  133. csave.End_Chunk ();
  134. return true;
  135. }
  136. /////////////////////////////////////////////////////////////////
  137. //
  138. // Load
  139. //
  140. /////////////////////////////////////////////////////////////////
  141. bool
  142. WaypointClass::Load (ChunkLoadClass &cload)
  143. {
  144. while (cload.Open_Chunk ()) {
  145. switch (cload.Cur_Chunk_ID ()) {
  146. case CHUNKID_VARIABLES:
  147. Load_Variables (cload);
  148. break;
  149. }
  150. cload.Close_Chunk ();
  151. }
  152. return true;
  153. }
  154. ///////////////////////////////////////////////////////////////////////
  155. //
  156. // Load_Variables
  157. //
  158. ///////////////////////////////////////////////////////////////////////
  159. bool
  160. WaypointClass::Load_Variables (ChunkLoadClass &cload)
  161. {
  162. //
  163. // Loop through all the microchunks that define the variables
  164. //
  165. while (cload.Open_Micro_Chunk ()) {
  166. switch (cload.Cur_Micro_Chunk_ID ()) {
  167. READ_MICRO_CHUNK (cload, VARID_FLAGS, m_Flags);
  168. READ_MICRO_CHUNK (cload, VARID_POSITION, m_Position);
  169. READ_MICRO_CHUNK (cload, VARID_ID, m_ID);
  170. READ_MICRO_CHUNK (cload, VARID_ACTION_ID, m_ActionPortalID);
  171. case VARID_OLD_PTR:
  172. {
  173. //
  174. // Read the old pointer from the chunk and submit it
  175. // to the remapping system.
  176. //
  177. WaypointClass *old_ptr = NULL;
  178. cload.Read (&old_ptr, sizeof (old_ptr));
  179. SaveLoadSystemClass::Register_Pointer (old_ptr, this);
  180. }
  181. break;
  182. }
  183. cload.Close_Micro_Chunk ();
  184. }
  185. return true;
  186. }
  187. ///////////////////////////////////////////////////////////////////////
  188. //
  189. // operator=
  190. //
  191. ///////////////////////////////////////////////////////////////////////
  192. const WaypointClass &
  193. WaypointClass::operator= (const WaypointClass &src)
  194. {
  195. //
  196. // Simply copy the member data from the src class.
  197. // Note; This is included for extendibility, in
  198. // case this class every contains more then simple
  199. // variables.
  200. //
  201. m_ID = src.m_ID;
  202. m_Position = src.m_Position;
  203. m_Flags = src.m_Flags;
  204. m_ActionPortalID = src.m_ActionPortalID;
  205. return (*this);
  206. }
  207. ///////////////////////////////////////////////////////////////////////
  208. //
  209. // Get_Action_Portal
  210. //
  211. ///////////////////////////////////////////////////////////////////////
  212. PathfindActionPortalClass *
  213. WaypointClass::Get_Action_Portal (void)
  214. {
  215. //
  216. // Lookup the action portal
  217. //
  218. PathfindActionPortalClass *retval = NULL;
  219. PathfindPortalClass *portal = PathfindClass::Get_Instance ()->Peek_Portal (m_ActionPortalID);
  220. if (portal != NULL) {
  221. //
  222. // Check to ensure this portal is an action portal
  223. //
  224. retval = portal->As_PathfindActionPortalClass ();
  225. }
  226. return retval;
  227. }
  228. ///////////////////////////////////////////////////////////////////////
  229. //
  230. // Set_Action_Portal
  231. //
  232. ///////////////////////////////////////////////////////////////////////
  233. void
  234. WaypointClass::Set_Action_Portal (PathfindActionPortalClass *portal)
  235. {
  236. if (portal != NULL) {
  237. m_ActionPortalID = portal->Get_ID ();
  238. Set_Flag (FLAG_REQUIRES_ACTION, true);
  239. } else {
  240. m_ActionPortalID = -1;
  241. Set_Flag (FLAG_REQUIRES_ACTION, false);
  242. }
  243. return ;
  244. }