CoverAttackPointNode.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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/CoverAttackPointNode.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 5/22/01 11:17a $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "coverspotnode.h"
  37. #include "coverattackpointnode.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. #include "soldier.h"
  47. #include "presetmgr.h"
  48. //////////////////////////////////////////////////////////////////////////////
  49. // Persist factory
  50. //////////////////////////////////////////////////////////////////////////////
  51. SimplePersistFactoryClass<CoverAttackPointNodeClass, CHUNKID_NODE_COVER_ATTACK_POINT> _CoverAttackPointNodePersistFactory;
  52. enum
  53. {
  54. CHUNKID_VARIABLES = 0x05260946,
  55. CHUNKID_BASE_CLASS
  56. };
  57. enum
  58. {
  59. VARID_REQUIRES_CROUCH = 0x01,
  60. VARID_ATTACK_POINT,
  61. };
  62. //////////////////////////////////////////////////////////////////////////////
  63. // Static member initialization
  64. //////////////////////////////////////////////////////////////////////////////
  65. PhysClass * CoverAttackPointNodeClass::_TheCollisionObj = NULL;
  66. int CoverAttackPointNodeClass::_InstanceCount = 0;
  67. //////////////////////////////////////////////////////////////////////////////
  68. //
  69. // CoverAttackPointNodeClass
  70. //
  71. //////////////////////////////////////////////////////////////////////////////
  72. CoverAttackPointNodeClass::CoverAttackPointNodeClass (PresetClass *preset)
  73. : m_PhysObj (NULL),
  74. m_CoverSpot (NULL),
  75. NodeClass (preset)
  76. {
  77. _InstanceCount ++;
  78. return ;
  79. }
  80. //////////////////////////////////////////////////////////////////////////////
  81. //
  82. // CoverAttackPointNodeClass
  83. //
  84. //////////////////////////////////////////////////////////////////////////////
  85. CoverAttackPointNodeClass::CoverAttackPointNodeClass (const CoverAttackPointNodeClass &src)
  86. : m_PhysObj (NULL),
  87. m_CoverSpot (NULL),
  88. NodeClass (NULL)
  89. {
  90. _InstanceCount ++;
  91. *this = src;
  92. return ;
  93. }
  94. //////////////////////////////////////////////////////////////////////////////
  95. //
  96. // ~CoverAttackPointNodeClass
  97. //
  98. //////////////////////////////////////////////////////////////////////////////
  99. CoverAttackPointNodeClass::~CoverAttackPointNodeClass (void)
  100. {
  101. Remove_From_Scene ();
  102. MEMBER_RELEASE (m_PhysObj);
  103. //
  104. // Free the collision object when all instances have gone away
  105. //
  106. _InstanceCount --;
  107. if (_InstanceCount == 0) {
  108. MEMBER_RELEASE (_TheCollisionObj);
  109. }
  110. return ;
  111. }
  112. //////////////////////////////////////////////////////////////////////////////
  113. //
  114. // Initialize
  115. //
  116. // Note: This may be called more than once. It is used as an 'initialize'
  117. // and a 're-initialize'.
  118. //
  119. //////////////////////////////////////////////////////////////////////////////
  120. void
  121. CoverAttackPointNodeClass::Initialize (void)
  122. {
  123. MEMBER_RELEASE (m_PhysObj);
  124. //
  125. // Create the attack-point render object
  126. //
  127. RenderObjClass *render_obj = ::Create_Render_Obj ("WAY_B");
  128. WWASSERT (render_obj != NULL);
  129. if (render_obj != NULL) {
  130. // Create the new physics object
  131. m_PhysObj = new DecorationPhysClass;
  132. //
  133. // Configure the physics object with information about
  134. // its new render object and collision data.
  135. //
  136. m_PhysObj->Set_Model (render_obj);
  137. m_PhysObj->Set_Transform (Matrix3D(1));
  138. m_PhysObj->Set_Collision_Group (EDITOR_COLLISION_GROUP);
  139. m_PhysObj->Peek_Model ()->Set_User_Data ((PVOID)&m_HitTestInfo, FALSE);
  140. m_PhysObj->Set_Transform (m_Transform);
  141. ::Set_Model_Collision_Type (m_PhysObj->Peek_Model (), COLLISION_TYPE_0);
  142. // Release our hold on the render object pointer
  143. MEMBER_RELEASE (render_obj);
  144. }
  145. if (_TheCollisionObj == NULL) {
  146. //
  147. // Create the collision physics object
  148. //
  149. PresetClass *preset = PresetMgrClass::Find_Preset ("Walk-Thru");
  150. if (preset != NULL && preset->Get_Definition () != NULL) {
  151. //
  152. // Load the assets for this preset and get its definition
  153. //
  154. preset->Load_All_Assets ();
  155. SoldierGameObjDef *definition = (SoldierGameObjDef *)preset->Get_Definition ();
  156. //
  157. // Create the collision physics object
  158. //
  159. SoldierGameObj *game_obj = new SoldierGameObj;
  160. game_obj->Init (*definition);
  161. MEMBER_ADD (_TheCollisionObj, game_obj->Peek_Physical_Object ());
  162. game_obj->Set_Delete_Pending ();
  163. }
  164. }
  165. return ;
  166. }
  167. ////////////////////////////////////////////////////////////////
  168. //
  169. // Get_Factory
  170. //
  171. ////////////////////////////////////////////////////////////////
  172. const PersistFactoryClass &
  173. CoverAttackPointNodeClass::Get_Factory (void) const
  174. {
  175. return _CoverAttackPointNodePersistFactory;
  176. }
  177. /////////////////////////////////////////////////////////////////
  178. //
  179. // Save
  180. //
  181. /////////////////////////////////////////////////////////////////
  182. bool
  183. CoverAttackPointNodeClass::Save (ChunkSaveClass &csave)
  184. {
  185. csave.Begin_Chunk (CHUNKID_BASE_CLASS);
  186. NodeClass::Save (csave);
  187. csave.End_Chunk ();
  188. csave.Begin_Chunk (CHUNKID_VARIABLES);
  189. csave.End_Chunk ();
  190. return true;
  191. }
  192. /////////////////////////////////////////////////////////////////
  193. //
  194. // Load
  195. //
  196. /////////////////////////////////////////////////////////////////
  197. bool
  198. CoverAttackPointNodeClass::Load (ChunkLoadClass &cload)
  199. {
  200. while (cload.Open_Chunk ()) {
  201. switch (cload.Cur_Chunk_ID ()) {
  202. case CHUNKID_BASE_CLASS:
  203. NodeClass::Load (cload);
  204. break;
  205. case CHUNKID_VARIABLES:
  206. Load_Variables (cload);
  207. break;
  208. }
  209. cload.Close_Chunk ();
  210. }
  211. return true;
  212. }
  213. ///////////////////////////////////////////////////////////////////////
  214. //
  215. // Load_Variables
  216. //
  217. ///////////////////////////////////////////////////////////////////////
  218. bool
  219. CoverAttackPointNodeClass::Load_Variables (ChunkLoadClass &cload)
  220. {
  221. //
  222. // Loop through all the microchunks that define the variables
  223. //
  224. while (cload.Open_Micro_Chunk ()) {
  225. /*switch (cload.Cur_Micro_Chunk_ID ()) {
  226. }*/
  227. cload.Close_Micro_Chunk ();
  228. }
  229. return true;
  230. }
  231. /////////////////////////////////////////////////////////////////
  232. //
  233. // operator=
  234. //
  235. /////////////////////////////////////////////////////////////////
  236. const CoverAttackPointNodeClass &
  237. CoverAttackPointNodeClass::operator= (const CoverAttackPointNodeClass &src)
  238. {
  239. NodeClass::operator= (src);
  240. return *this;
  241. }
  242. //////////////////////////////////////////////////////////////////////
  243. //
  244. // Pre_Export
  245. //
  246. //////////////////////////////////////////////////////////////////////
  247. void
  248. CoverAttackPointNodeClass::Pre_Export (void)
  249. {
  250. //
  251. // Remove ourselves from the 'system' so we don't get accidentally
  252. // saved during the export.
  253. //
  254. Add_Ref ();
  255. if (m_PhysObj != NULL && m_IsInScene) {
  256. ::Get_Scene_Editor ()->Remove_Object (m_PhysObj);
  257. }
  258. return ;
  259. }
  260. //////////////////////////////////////////////////////////////////////
  261. //
  262. // Post_Export
  263. //
  264. //////////////////////////////////////////////////////////////////////
  265. void
  266. CoverAttackPointNodeClass::Post_Export (void)
  267. {
  268. //
  269. // Put ourselves back into the system
  270. //
  271. if (m_PhysObj != NULL && m_IsInScene) {
  272. ::Get_Scene_Editor ()->Add_Dynamic_Object (m_PhysObj);
  273. }
  274. Release_Ref ();
  275. return ;
  276. }
  277. //////////////////////////////////////////////////////////////////////
  278. //
  279. // On_Delete
  280. //
  281. //////////////////////////////////////////////////////////////////////
  282. void
  283. CoverAttackPointNodeClass::On_Delete (void)
  284. {
  285. //
  286. // Remove ourselves from the cover spot
  287. //
  288. if (m_CoverSpot) {
  289. m_CoverSpot->Remove_Attack_Point (this);
  290. }
  291. return ;
  292. }
  293. //////////////////////////////////////////////////////////////////////
  294. //
  295. // Peek_Collision_Obj
  296. //
  297. //////////////////////////////////////////////////////////////////////
  298. PhysClass *
  299. CoverAttackPointNodeClass::Peek_Collision_Obj (void) const
  300. {
  301. if (_TheCollisionObj != NULL) {
  302. _TheCollisionObj->Set_Transform (m_Transform);
  303. }
  304. return _TheCollisionObj;
  305. }