SpawnPointNode.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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/Tools/LevelEdit/SpawnPointNode.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/02/00 6:07p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "spawnernode.h"
  37. #include "spawnpointnode.h"
  38. #include "sceneeditor.h"
  39. #include "collisiongroups.h"
  40. #include "persistfactory.h"
  41. #include "editorchunkids.h"
  42. #include "preset.h"
  43. #include "chunkio.h"
  44. #include "nodemgr.h"
  45. #include "soldier.h"
  46. #include "modelutils.h"
  47. //////////////////////////////////////////////////////////////////////////////
  48. // Persist factory
  49. //////////////////////////////////////////////////////////////////////////////
  50. SimplePersistFactoryClass<SpawnPointNodeClass, CHUNKID_NODE_SPAWN_POINT> _SpawnPointNodePersistFactory;
  51. //////////////////////////////////////////////////////////////////////////////
  52. // Save/load constants
  53. //////////////////////////////////////////////////////////////////////////////
  54. enum
  55. {
  56. CHUNKID_VARIABLES = 0x05260946,
  57. CHUNKID_BASE_CLASS
  58. };
  59. enum
  60. {
  61. VARID_XXX = 0x01,
  62. };
  63. //////////////////////////////////////////////////////////////////////////////
  64. //
  65. // SpawnPointNodeClass
  66. //
  67. //////////////////////////////////////////////////////////////////////////////
  68. SpawnPointNodeClass::SpawnPointNodeClass (PresetClass *preset)
  69. : PhysObj (NULL),
  70. SpawnerNode (NULL),
  71. NodeClass (preset)
  72. {
  73. return ;
  74. }
  75. //////////////////////////////////////////////////////////////////////////////
  76. //
  77. // SpawnPointNodeClass
  78. //
  79. //////////////////////////////////////////////////////////////////////////////
  80. SpawnPointNodeClass::SpawnPointNodeClass (const SpawnPointNodeClass &src)
  81. : PhysObj (NULL),
  82. SpawnerNode (NULL),
  83. NodeClass (NULL)
  84. {
  85. *this = src;
  86. return ;
  87. }
  88. //////////////////////////////////////////////////////////////////////////////
  89. //
  90. // ~SpawnPointNodeClass
  91. //
  92. //////////////////////////////////////////////////////////////////////////////
  93. SpawnPointNodeClass::~SpawnPointNodeClass (void)
  94. {
  95. Remove_From_Scene ();
  96. MEMBER_RELEASE (PhysObj);
  97. return ;
  98. }
  99. //////////////////////////////////////////////////////////////////////////////
  100. //
  101. // Initialize
  102. //
  103. // Note: This may be called more than once. It is used as an 'initialize'
  104. // and a 're-initialize'.
  105. //
  106. //////////////////////////////////////////////////////////////////////////////
  107. void
  108. SpawnPointNodeClass::Initialize (void)
  109. {
  110. MEMBER_RELEASE (PhysObj);
  111. //
  112. // Create the spawn-point render object
  113. //
  114. RenderObjClass *render_obj = SpawnerNode->Get_Spawned_Model ();
  115. WWASSERT (render_obj != NULL);
  116. if (render_obj != NULL) {
  117. // Create the new physics object
  118. PhysObj = new DecorationPhysClass;
  119. //
  120. // Configure the physics object with information about
  121. // its new render object and collision data.
  122. //
  123. PhysObj->Set_Model (render_obj);
  124. PhysObj->Set_Transform (Matrix3D(1));
  125. PhysObj->Set_Collision_Group (EDITOR_COLLISION_GROUP);
  126. PhysObj->Peek_Model ()->Set_User_Data ((PVOID)&m_HitTestInfo, FALSE);
  127. PhysObj->Set_Transform (m_Transform);
  128. ::Set_Model_Collision_Type (PhysObj->Peek_Model (), COLLISION_TYPE_0);
  129. // Release our hold on the render object pointer
  130. MEMBER_RELEASE (render_obj);
  131. }
  132. return ;
  133. }
  134. ////////////////////////////////////////////////////////////////
  135. //
  136. // Get_Factory
  137. //
  138. ////////////////////////////////////////////////////////////////
  139. const PersistFactoryClass &
  140. SpawnPointNodeClass::Get_Factory (void) const
  141. {
  142. return _SpawnPointNodePersistFactory;
  143. }
  144. /////////////////////////////////////////////////////////////////
  145. //
  146. // Save
  147. //
  148. /////////////////////////////////////////////////////////////////
  149. bool
  150. SpawnPointNodeClass::Save (ChunkSaveClass &csave)
  151. {
  152. csave.Begin_Chunk (CHUNKID_BASE_CLASS);
  153. NodeClass::Save (csave);
  154. csave.End_Chunk ();
  155. csave.Begin_Chunk (CHUNKID_VARIABLES);
  156. csave.End_Chunk ();
  157. return true;
  158. }
  159. /////////////////////////////////////////////////////////////////
  160. //
  161. // Load
  162. //
  163. /////////////////////////////////////////////////////////////////
  164. bool
  165. SpawnPointNodeClass::Load (ChunkLoadClass &cload)
  166. {
  167. while (cload.Open_Chunk ()) {
  168. switch (cload.Cur_Chunk_ID ()) {
  169. case CHUNKID_BASE_CLASS:
  170. NodeClass::Load (cload);
  171. break;
  172. case CHUNKID_VARIABLES:
  173. Load_Variables (cload);
  174. break;
  175. }
  176. cload.Close_Chunk ();
  177. }
  178. return true;
  179. }
  180. ///////////////////////////////////////////////////////////////////////
  181. //
  182. // Load_Variables
  183. //
  184. ///////////////////////////////////////////////////////////////////////
  185. bool
  186. SpawnPointNodeClass::Load_Variables (ChunkLoadClass &cload)
  187. {
  188. //
  189. // Loop through all the microchunks that define the variables
  190. //
  191. while (cload.Open_Micro_Chunk ()) {
  192. /*switch (cload.Cur_Micro_Chunk_ID ()) {
  193. }*/
  194. cload.Close_Micro_Chunk ();
  195. }
  196. return true;
  197. }
  198. /////////////////////////////////////////////////////////////////
  199. //
  200. // operator=
  201. //
  202. /////////////////////////////////////////////////////////////////
  203. const SpawnPointNodeClass &
  204. SpawnPointNodeClass::operator= (const SpawnPointNodeClass &src)
  205. {
  206. NodeClass::operator= (src);
  207. return *this;
  208. }
  209. //////////////////////////////////////////////////////////////////////
  210. //
  211. // Pre_Export
  212. //
  213. //////////////////////////////////////////////////////////////////////
  214. void
  215. SpawnPointNodeClass::Pre_Export (void)
  216. {
  217. //
  218. // Remove ourselves from the 'system' so we don't get accidentally
  219. // saved during the export.
  220. //
  221. Add_Ref ();
  222. if (PhysObj != NULL && m_IsInScene) {
  223. ::Get_Scene_Editor ()->Remove_Object (PhysObj);
  224. }
  225. return ;
  226. }
  227. //////////////////////////////////////////////////////////////////////
  228. //
  229. // Post_Export
  230. //
  231. //////////////////////////////////////////////////////////////////////
  232. void
  233. SpawnPointNodeClass::Post_Export (void)
  234. {
  235. //
  236. // Put ourselves back into the system
  237. //
  238. if (PhysObj != NULL && m_IsInScene) {
  239. ::Get_Scene_Editor ()->Add_Dynamic_Object (PhysObj);
  240. }
  241. Release_Ref ();
  242. return ;
  243. }
  244. //////////////////////////////////////////////////////////////////////
  245. //
  246. // On_Delete
  247. //
  248. //////////////////////////////////////////////////////////////////////
  249. void
  250. SpawnPointNodeClass::On_Delete (void)
  251. {
  252. //
  253. // Remove ourselves from the spawner
  254. //
  255. if (SpawnerNode) {
  256. SpawnerNode->Remove_Spawn_Point (this);
  257. }
  258. return ;
  259. }