shakeablestaticphys.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/shakeablestaticphys.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 8/17/01 7:02p $*
  31. * *
  32. * $Revision:: 3 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "shakeablestaticphys.h"
  38. #include "simpledefinitionfactory.h"
  39. #include "persistfactory.h"
  40. #include "wwphysids.h"
  41. #include "hanim.h"
  42. #include "wwdebug.h"
  43. #include "wwhack.h"
  44. DECLARE_FORCE_LINK( shakeablestaticphys );
  45. /*
  46. ** Chunk Id's used by ShakeableStaticPhysClass
  47. */
  48. enum
  49. {
  50. SHAKEABLESTATICPHYS_CHUNK_STATICANIMPHYS = 7311740,
  51. };
  52. /*
  53. ** Chunk Id's used by ShakeableStaticPhysDefClass
  54. */
  55. enum
  56. {
  57. SHAKEABLESTATICPHYSDEF_CHUNK_STATICANIMPHYSDEF = 7311734,
  58. };
  59. /************************************************************************************************
  60. **
  61. ** ShakeableStaticPhysDefClass Implementation
  62. **
  63. ************************************************************************************************/
  64. SimplePersistFactoryClass<ShakeableStaticPhysDefClass, PHYSICS_CHUNKID_SHAKEABLESTATICPHYSDEF> _ShakeableStaticPhysDefPersistFactory;
  65. //(gth) for now, not publishing this class to the editor. I need to find a solution for
  66. //how to detect when a vehicle collides with this object (vehicles don't actually find out
  67. //who they collide with!) Also, maybe the feature provided by this class could be rolled into
  68. //StaticAnim instead of requiring a whole new class...
  69. #if 0
  70. DECLARE_DEFINITION_FACTORY(ShakeableStaticPhysDefClass, CLASSID_SHAKEABLESTATICPHYSDEF, "ShakeableStaticPhys") _ShakeableStaticPhysDefDefFactory;
  71. #endif
  72. ShakeableStaticPhysDefClass::ShakeableStaticPhysDefClass(void)
  73. {
  74. }
  75. uint32 ShakeableStaticPhysDefClass::Get_Class_ID(void) const
  76. {
  77. return CLASSID_SHAKEABLESTATICPHYSDEF;
  78. }
  79. bool ShakeableStaticPhysDefClass::Is_Type(const char * type_name)
  80. {
  81. if (stricmp(type_name,ShakeableStaticPhysDefClass::Get_Type_Name()) == 0) {
  82. return true;
  83. } else {
  84. return StaticAnimPhysDefClass::Is_Type(type_name);
  85. }
  86. }
  87. PersistClass * ShakeableStaticPhysDefClass::Create(void) const
  88. {
  89. ShakeableStaticPhysClass * obj = new ShakeableStaticPhysClass;
  90. obj->Init(*this);
  91. return obj;
  92. }
  93. bool ShakeableStaticPhysDefClass::Save(ChunkSaveClass & csave)
  94. {
  95. csave.Begin_Chunk(SHAKEABLESTATICPHYSDEF_CHUNK_STATICANIMPHYSDEF);
  96. StaticAnimPhysDefClass::Save(csave);
  97. csave.End_Chunk();
  98. return true;
  99. }
  100. bool ShakeableStaticPhysDefClass::Load( ChunkLoadClass &cload )
  101. {
  102. while (cload.Open_Chunk()) {
  103. switch(cload.Cur_Chunk_ID()) {
  104. case SHAKEABLESTATICPHYSDEF_CHUNK_STATICANIMPHYSDEF:
  105. StaticAnimPhysDefClass::Load( cload );
  106. break;
  107. default:
  108. WWDEBUG_SAY(( "Unrecognized ShakeableStaticPhysDef chunkID\n" ));
  109. break;
  110. }
  111. cload.Close_Chunk();
  112. }
  113. return true;
  114. }
  115. const PersistFactoryClass & ShakeableStaticPhysDefClass::Get_Factory (void) const
  116. {
  117. return _ShakeableStaticPhysDefPersistFactory;
  118. }
  119. /************************************************************************************************
  120. **
  121. ** ShakeableStaticPhysClass Implementation
  122. **
  123. ************************************************************************************************/
  124. SimplePersistFactoryClass<ShakeableStaticPhysClass, PHYSICS_CHUNKID_SHAKEABLESTATICPHYS> _ShakeableStaticPhysPersistFactory;
  125. const PersistFactoryClass & ShakeableStaticPhysClass::Get_Factory (void) const
  126. {
  127. return _ShakeableStaticPhysPersistFactory;
  128. }
  129. ShakeableStaticPhysClass::ShakeableStaticPhysClass(void)
  130. {
  131. }
  132. ShakeableStaticPhysClass::~ShakeableStaticPhysClass( void )
  133. {
  134. }
  135. void ShakeableStaticPhysClass::Init( const ShakeableStaticPhysDefClass & def )
  136. {
  137. StaticAnimPhysClass::Init(def);
  138. }
  139. void ShakeableStaticPhysClass::Play_Animation(void)
  140. {
  141. /*
  142. ** When a vehicle collides with this object, it will call this function
  143. ** to cause the shake animation to play. We simply set the current frame
  144. ** number to the start of the animation and set the target frame number
  145. ** to the end of the animation...
  146. */
  147. AnimCollisionManagerClass & anim_mgr = Get_Animation_Manager();
  148. HAnimClass * anim = anim_mgr.Peek_Animation();
  149. if (anim != NULL) {
  150. anim_mgr.Set_Current_Frame(0);
  151. anim_mgr.Set_Animation_Mode(AnimCollisionManagerClass::ANIMATE_TARGET);
  152. anim_mgr.Set_Target_Frame(anim->Get_Num_Frames()-1);
  153. }
  154. }
  155. bool ShakeableStaticPhysClass::Save( ChunkSaveClass & csave )
  156. {
  157. /*
  158. ** Save the parent class data
  159. */
  160. csave.Begin_Chunk(SHAKEABLESTATICPHYS_CHUNK_STATICANIMPHYS);
  161. StaticAnimPhysClass::Save( csave );
  162. csave.End_Chunk();
  163. return true;
  164. }
  165. bool ShakeableStaticPhysClass::Load(ChunkLoadClass & cload)
  166. {
  167. while (cload.Open_Chunk()) {
  168. switch(cload.Cur_Chunk_ID()) {
  169. case SHAKEABLESTATICPHYS_CHUNK_STATICANIMPHYS:
  170. StaticAnimPhysClass::Load( cload );
  171. break;
  172. default:
  173. WWDEBUG_SAY(( "Unrecognized ShakeableStaticPhys chunkID\n" ));
  174. break;
  175. }
  176. cload.Close_Chunk();
  177. }
  178. return true;
  179. }