specialeffectsgameobj.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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 : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/specialeffectsgameobj.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/15/02 2:33p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "specialeffectsgameobj.h"
  36. #include "combatchunkid.h"
  37. #include "wwaudio.h"
  38. #include "hanim.h"
  39. #include "assetmgr.h"
  40. #include "wwhack.h"
  41. #include "persistfactory.h"
  42. #include "simpledefinitionfactory.h"
  43. #include "chunkio.h"
  44. #include "rendobj.h"
  45. #include "timemgr.h"
  46. #include "debug.h"
  47. #include "phys.h"
  48. #include "combat.h"
  49. #include "wwprofile.h"
  50. DECLARE_FORCE_LINK (SpecialEffects)
  51. ///////////////////////////////////////////////////////////////////////////
  52. // Persist and Editable framework support
  53. ///////////////////////////////////////////////////////////////////////////
  54. SimplePersistFactoryClass <SpecialEffectsGameObj, CHUNKID_GAME_OBJECT_SPECIAL_EFFECTS> _SpecialEffectsGameObjPersistFactory;
  55. SimplePersistFactoryClass <SpecialEffectsGameObjDef, CHUNKID_GAME_OBJECT_DEF_SPECIAL_EFFECTS> _SpecialEffectsGameObjDefPersistFactory;
  56. DECLARE_DEFINITION_FACTORY (SpecialEffectsGameObjDef, CLASSID_GAME_OBJECT_DEF_SPECIAL_EFFECTS, "Special Effects") _SpecialEffectsGameObjDefDefFactory;
  57. ///////////////////////////////////////////////////////////////////////////
  58. // Constants
  59. ///////////////////////////////////////////////////////////////////////////
  60. enum
  61. {
  62. CHUNKID_DEF_PARENT = 0x09010212,
  63. CHUNKID_DEF_VARIABLES,
  64. VARID_DEF_ANIMATION_NAME = 1,
  65. VARID_DEF_SOUNDID,
  66. };
  67. enum
  68. {
  69. CHUNKID_PARENT = 0x09010236,
  70. CHUNKID_VARIABLES,
  71. VARID_LIFE_REMAINING = 1,
  72. VARID_IS_INITIALIZED
  73. };
  74. ///////////////////////////////////////////////////////////////////////////
  75. //
  76. // SpecialEffectsGameObjDef
  77. //
  78. ///////////////////////////////////////////////////////////////////////////
  79. SpecialEffectsGameObjDef::SpecialEffectsGameObjDef (void) :
  80. SoundDefID (0)
  81. {
  82. MODEL_DEF_PARAM(SpecialEffectsGameObjDef, PhysDefID, "TimedDecorationPhysDef");
  83. EDITABLE_PARAM (SpecialEffectsGameObjDef, ParameterClass::TYPE_STRING, AnimationName);
  84. EDITABLE_PARAM (SpecialEffectsGameObjDef, ParameterClass::TYPE_SOUNDDEFINITIONID, SoundDefID);
  85. return ;
  86. }
  87. ///////////////////////////////////////////////////////////////////////////
  88. //
  89. // ~SpecialEffectsGameObjDef
  90. //
  91. ///////////////////////////////////////////////////////////////////////////
  92. SpecialEffectsGameObjDef::~SpecialEffectsGameObjDef (void)
  93. {
  94. return ;
  95. }
  96. ///////////////////////////////////////////////////////////////////////////
  97. //
  98. // Get_Class_ID
  99. //
  100. ///////////////////////////////////////////////////////////////////////////
  101. uint32
  102. SpecialEffectsGameObjDef::Get_Class_ID (void) const
  103. {
  104. return CLASSID_GAME_OBJECT_DEF_SPECIAL_EFFECTS;
  105. }
  106. ///////////////////////////////////////////////////////////////////////////
  107. //
  108. // Create
  109. //
  110. ///////////////////////////////////////////////////////////////////////////
  111. PersistClass *
  112. SpecialEffectsGameObjDef::Create (void) const
  113. {
  114. SpecialEffectsGameObj *obj = new SpecialEffectsGameObj;
  115. obj->Init (*this);
  116. return obj;
  117. }
  118. ///////////////////////////////////////////////////////////////////////////
  119. //
  120. // Save
  121. //
  122. ///////////////////////////////////////////////////////////////////////////
  123. bool
  124. SpecialEffectsGameObjDef::Save (ChunkSaveClass &csave)
  125. {
  126. csave.Begin_Chunk (CHUNKID_DEF_PARENT);
  127. PhysicalGameObjDef::Save (csave);
  128. csave.End_Chunk ();
  129. csave.Begin_Chunk (CHUNKID_DEF_VARIABLES);
  130. Save_Variables (csave);
  131. csave.End_Chunk ();
  132. return true;
  133. }
  134. ///////////////////////////////////////////////////////////////////////////
  135. //
  136. // Load
  137. //
  138. ///////////////////////////////////////////////////////////////////////////
  139. bool
  140. SpecialEffectsGameObjDef::Load (ChunkLoadClass &cload)
  141. {
  142. while (cload.Open_Chunk ()) {
  143. switch(cload.Cur_Chunk_ID ()) {
  144. case CHUNKID_DEF_PARENT:
  145. PhysicalGameObjDef::Load (cload);
  146. break;
  147. case CHUNKID_DEF_VARIABLES:
  148. Load_Variables (cload);
  149. break;
  150. default:
  151. Debug_Say (("Unrecognized SpecialEffectsGameObjDef chunk ID\n"));
  152. break;
  153. }
  154. cload.Close_Chunk ();
  155. }
  156. return true;
  157. }
  158. ///////////////////////////////////////////////////////////////////////////
  159. //
  160. // Save_Variables
  161. //
  162. ///////////////////////////////////////////////////////////////////////////
  163. void
  164. SpecialEffectsGameObjDef::Save_Variables (ChunkSaveClass &csave)
  165. {
  166. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_DEF_ANIMATION_NAME, AnimationName);
  167. WRITE_MICRO_CHUNK (csave, VARID_DEF_SOUNDID, SoundDefID);
  168. return ;
  169. }
  170. ///////////////////////////////////////////////////////////////////////////
  171. //
  172. // Load_Variables
  173. //
  174. ///////////////////////////////////////////////////////////////////////////
  175. void
  176. SpecialEffectsGameObjDef::Load_Variables (ChunkLoadClass &cload)
  177. {
  178. while (cload.Open_Micro_Chunk()) {
  179. switch (cload.Cur_Micro_Chunk_ID()) {
  180. READ_MICRO_CHUNK_WWSTRING (cload, VARID_DEF_ANIMATION_NAME, AnimationName);
  181. READ_MICRO_CHUNK (cload, VARID_DEF_SOUNDID, SoundDefID);
  182. default:
  183. Debug_Say (("Unrecognized SpecialEffectsGameObjDef Variable chunkID %d\n", cload.Cur_Micro_Chunk_ID ()));
  184. break;
  185. }
  186. cload.Close_Micro_Chunk ();
  187. }
  188. return ;
  189. }
  190. ///////////////////////////////////////////////////////////////////////////
  191. //
  192. // Get_Factory
  193. //
  194. ///////////////////////////////////////////////////////////////////////////
  195. const PersistFactoryClass &
  196. SpecialEffectsGameObjDef::Get_Factory (void) const
  197. {
  198. return _SpecialEffectsGameObjDefPersistFactory;
  199. }
  200. /*
  201. **
  202. ** Start of SpecialEffectsGameObj
  203. **
  204. */
  205. ///////////////////////////////////////////////////////////////////////////
  206. //
  207. // SpecialEffectsGameObj
  208. //
  209. ///////////////////////////////////////////////////////////////////////////
  210. SpecialEffectsGameObj::SpecialEffectsGameObj (void) :
  211. LifeRemaining (-1.0F),
  212. IsInitialized (false)
  213. {
  214. return ;
  215. }
  216. ///////////////////////////////////////////////////////////////////////////
  217. //
  218. // ~SpecialEffectsGameObj
  219. //
  220. ///////////////////////////////////////////////////////////////////////////
  221. SpecialEffectsGameObj::~SpecialEffectsGameObj (void)
  222. {
  223. return ;
  224. }
  225. ///////////////////////////////////////////////////////////////////////////
  226. //
  227. // Get_Factory
  228. //
  229. ///////////////////////////////////////////////////////////////////////////
  230. const PersistFactoryClass &
  231. SpecialEffectsGameObj::Get_Factory (void) const
  232. {
  233. return _SpecialEffectsGameObjPersistFactory;
  234. }
  235. ////////////////////////////////////////////////////////////////
  236. //
  237. // Init
  238. //
  239. ////////////////////////////////////////////////////////////////
  240. void SpecialEffectsGameObj::Init( void )
  241. {
  242. Init( Get_Definition() );
  243. }
  244. ///////////////////////////////////////////////////////////////////////////
  245. //
  246. // Init
  247. //
  248. ///////////////////////////////////////////////////////////////////////////
  249. void
  250. SpecialEffectsGameObj::Init (const SpecialEffectsGameObjDef &definition)
  251. {
  252. PhysicalGameObj::Init (definition);
  253. //
  254. // Make sure collisions are turned off on this effect
  255. //
  256. PhysClass *phys_obj = Peek_Physical_Object();
  257. if (phys_obj != NULL) {
  258. phys_obj->Set_Collision_Group( UNCOLLIDEABLE_GROUP );
  259. }
  260. return ;
  261. }
  262. ///////////////////////////////////////////////////////////////////////////
  263. //
  264. // Get_Definition
  265. //
  266. ///////////////////////////////////////////////////////////////////////////
  267. const SpecialEffectsGameObjDef &
  268. SpecialEffectsGameObj::Get_Definition (void) const
  269. {
  270. return (const SpecialEffectsGameObjDef &)BaseGameObj::Get_Definition();
  271. }
  272. ///////////////////////////////////////////////////////////////////////////
  273. //
  274. // Save
  275. //
  276. ///////////////////////////////////////////////////////////////////////////
  277. bool
  278. SpecialEffectsGameObj::Save (ChunkSaveClass & csave)
  279. {
  280. csave.Begin_Chunk (CHUNKID_PARENT);
  281. PhysicalGameObj::Save (csave);
  282. csave.End_Chunk ();
  283. csave.Begin_Chunk (CHUNKID_VARIABLES);
  284. Save_Variables (csave);
  285. csave.End_Chunk ();
  286. return true;
  287. }
  288. ///////////////////////////////////////////////////////////////////////////
  289. //
  290. // Load
  291. //
  292. ///////////////////////////////////////////////////////////////////////////
  293. bool
  294. SpecialEffectsGameObj::Load (ChunkLoadClass &cload)
  295. {
  296. while (cload.Open_Chunk ()) {
  297. switch(cload.Cur_Chunk_ID ()) {
  298. case CHUNKID_PARENT:
  299. PhysicalGameObj::Load (cload);
  300. break;
  301. case CHUNKID_VARIABLES:
  302. Load_Variables (cload);
  303. break;
  304. default:
  305. Debug_Say (("Unrecognized SpecialEffectsGameObj chunk ID\n"));
  306. break;
  307. }
  308. cload.Close_Chunk ();
  309. }
  310. return true;
  311. }
  312. ///////////////////////////////////////////////////////////////////////////
  313. //
  314. // Do_Effect
  315. //
  316. ///////////////////////////////////////////////////////////////////////////
  317. void
  318. SpecialEffectsGameObj::Do_Effect (void)
  319. {
  320. //
  321. // Make sure we have a render object
  322. //
  323. RenderObjClass *model = Peek_Model ();
  324. WWASSERT (model != NULL);
  325. if (model != NULL) {
  326. //
  327. // Should we play an animation?
  328. //
  329. const StringClass &anim_name = Get_Definition ().AnimationName;
  330. if (anim_name.Get_Length () > 0) {
  331. //
  332. // Load the animation
  333. //
  334. HAnimClass *animation = WW3DAssetManager::Get_Instance ()->Get_HAnim (anim_name);
  335. if (animation != NULL) {
  336. LifeRemaining = animation->Get_Total_Time ();
  337. model->Set_Animation (animation, 0, RenderObjClass::ANIM_MODE_ONCE);
  338. REF_PTR_RELEASE(animation);
  339. }
  340. }
  341. //
  342. // Should we play a sound?
  343. //
  344. if (Get_Definition ().SoundDefID > 0) {
  345. WWAudioClass::Get_Instance()->Create_Instant_Sound (Get_Definition ().SoundDefID, Get_Transform ());
  346. }
  347. }
  348. return ;
  349. }
  350. ///////////////////////////////////////////////////////////////////////////
  351. //
  352. // Save_Variables
  353. //
  354. ///////////////////////////////////////////////////////////////////////////
  355. void
  356. SpecialEffectsGameObj::Save_Variables (ChunkSaveClass &csave)
  357. {
  358. WRITE_MICRO_CHUNK (csave, VARID_LIFE_REMAINING, LifeRemaining);
  359. WRITE_MICRO_CHUNK (csave, VARID_IS_INITIALIZED, IsInitialized);
  360. return ;
  361. }
  362. ///////////////////////////////////////////////////////////////////////////
  363. //
  364. // Load_Variables
  365. //
  366. ///////////////////////////////////////////////////////////////////////////
  367. void
  368. SpecialEffectsGameObj::Load_Variables (ChunkLoadClass &cload)
  369. {
  370. while (cload.Open_Micro_Chunk()) {
  371. switch (cload.Cur_Micro_Chunk_ID()) {
  372. READ_MICRO_CHUNK (cload, VARID_LIFE_REMAINING, LifeRemaining);
  373. READ_MICRO_CHUNK (cload, VARID_IS_INITIALIZED, IsInitialized);
  374. default:
  375. Debug_Say (("Unrecognized SpecialEffectsGameObj Variable chunkID %d\n", cload.Cur_Micro_Chunk_ID ()));
  376. break;
  377. }
  378. cload.Close_Micro_Chunk ();
  379. }
  380. return ;
  381. }
  382. ///////////////////////////////////////////////////////////////////////////
  383. //
  384. // Think
  385. //
  386. ///////////////////////////////////////////////////////////////////////////
  387. void
  388. SpecialEffectsGameObj::Think (void)
  389. {
  390. WWPROFILE( "SpecialEffects Think" );
  391. //
  392. // Kick off the special effect
  393. //
  394. if (IsInitialized == false) {
  395. Do_Effect ();
  396. IsInitialized = true;
  397. }
  398. //
  399. // Check to see if we should make ourselves go away
  400. //
  401. if (LifeRemaining >= 0) {
  402. LifeRemaining -= TimeManager::Get_Frame_Seconds ();
  403. if (LifeRemaining <= 0) {
  404. Set_Delete_Pending ();
  405. }
  406. }
  407. return ;
  408. }