buildingchildnode.cpp 8.1 KB

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