StructureToppleUpdate.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: StructureToppleUpdate.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Bryan Cleveland, March 2002
  25. // Desc: Update that will topple over a building and crush and destroy stuff that it hits.
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __StructureToppleUpdate_H_
  29. #define __StructureToppleUpdate_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/UpdateModule.h"
  33. #include "GameLogic/Module/DieModule.h"
  34. #include "Lib/BaseType.h"
  35. #include "Common/RandomValue.h"
  36. #include "GameClient/ParticleSys.h"
  37. class FXList;
  38. class ObjectCreationList;
  39. typedef std::vector<const ObjectCreationList*> OCLVec;
  40. //-------------------------------------------------------------------------------------------------
  41. struct FXBoneInfo
  42. {
  43. AsciiString boneName;
  44. const ParticleSystemTemplate* particleSystemTemplate;
  45. };
  46. typedef std::vector<FXBoneInfo> FXBoneInfoVector;
  47. //-------------------------------------------------------------------------------------------------
  48. struct AngleFXInfo
  49. {
  50. Real angle;
  51. FXList *fxList;
  52. };
  53. typedef std::vector<AngleFXInfo> AngleFXInfoVector;
  54. //-------------------------------------------------------------------------------------------------
  55. enum StructureTopplePhaseType
  56. {
  57. STPHASE_INITIAL = 0,
  58. STPHASE_DELAY,
  59. STPHASE_FINAL,
  60. ST_PHASE_COUNT // keep last
  61. };
  62. static const char *TheStructureTopplePhaseNames[] =
  63. {
  64. "INITIAL",
  65. "DELAY",
  66. "FINAL",
  67. NULL
  68. };
  69. //-------------------------------------------------------------------------------------------------
  70. class StructureToppleUpdateModuleData : public UpdateModuleData
  71. {
  72. public:
  73. DieMuxData m_dieMuxData;
  74. Int m_minToppleDelay;
  75. Int m_maxToppleDelay;
  76. Real m_structuralIntegrity;
  77. Real m_structuralDecay;
  78. DamageTypeFlags m_damageFXTypes; ///< flags used to play or not play the effects
  79. FXList *m_toppleStartFXList;
  80. FXList *m_toppleDelayFXList;
  81. FXList *m_toppleFXList;
  82. FXList *m_toppleDoneFXList;
  83. FXList *m_crushingFXList;
  84. AsciiString m_crushingWeaponName;
  85. Int m_minToppleBurstDelay;
  86. Int m_maxToppleBurstDelay;
  87. OCLVec m_ocls[ST_PHASE_COUNT];
  88. UnsignedInt m_oclCount[ST_PHASE_COUNT];
  89. FXBoneInfoVector fxbones; ///< Bone names and attached particle systems.
  90. AngleFXInfoVector angleFX;
  91. StructureToppleUpdateModuleData()
  92. {
  93. m_minToppleDelay = 0;
  94. m_maxToppleDelay = 0;
  95. m_minToppleBurstDelay = 0;
  96. m_maxToppleBurstDelay = 0;
  97. m_structuralIntegrity = 0.1f;
  98. m_structuralDecay = 0.0f;
  99. m_damageFXTypes = DAMAGE_TYPE_FLAGS_NONE;
  100. m_damageFXTypes.flip();
  101. m_toppleStartFXList = NULL;
  102. m_toppleDelayFXList = NULL;
  103. m_toppleDoneFXList = NULL;
  104. m_toppleFXList = NULL;
  105. m_crushingFXList = NULL;
  106. m_crushingWeaponName.set("");
  107. for (int i = 0; i < ST_PHASE_COUNT; ++i)
  108. {
  109. // init to one, so that if these are omitted, we choose exactly one of each.
  110. m_oclCount[i] = 1;
  111. }
  112. fxbones.clear();
  113. angleFX.clear();
  114. }
  115. static void buildFieldParse(MultiIniFieldParse& p);
  116. };
  117. //-------------------------------------------------------------------------------------------------
  118. //-------------------------------------------------------------------------------------------------
  119. class StructureToppleUpdate : public UpdateModule,
  120. public DieModuleInterface
  121. {
  122. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( StructureToppleUpdate, "StructureToppleUpdate" )
  123. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( StructureToppleUpdate, StructureToppleUpdateModuleData )
  124. public:
  125. StructureToppleUpdate( Thing *thing, const ModuleData* moduleData );
  126. // virtual destructor prototype provided by memory pool declaration
  127. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_DIE); }
  128. // BehaviorModule
  129. virtual DieModuleInterface* getDie() { return this; }
  130. // UpdateModuleInterface
  131. virtual UpdateSleepTime update();
  132. // DieModuleInterface
  133. virtual void onDie( const DamageInfo *damageInfo );
  134. protected:
  135. void beginStructureTopple( const DamageInfo *damageInfo );
  136. void applyCrushingDamage(Real theta);
  137. void doDamageLine(Object *building, const WeaponTemplate* wt, Real jcos, Real jsin, Real facingWidth, Real toppleAngle);
  138. void doToppleStartFX(Object *building, const DamageInfo *damageInfo);
  139. void doToppleDelayBurstFX();
  140. void doToppleDoneStuff();
  141. void doAngleFX(Real curAngle, Real newAngle);
  142. void doPhaseStuff(StructureTopplePhaseType stphase, const Coord3D *target);
  143. enum StructureToppleStateType {
  144. TOPPLESTATE_STANDING,
  145. TOPPLESTATE_WAITINGFORTOPPLESTART,
  146. TOPPLESTATE_TOPPLING,
  147. TOPPLESTATE_WAITINGFORDONE,
  148. TOPPLESTATE_DONE
  149. };
  150. UnsignedInt m_toppleFrame;
  151. Coord2D m_toppleDirection;
  152. StructureToppleStateType m_toppleState;
  153. Real m_toppleVelocity;
  154. Real m_accumulatedAngle;
  155. Real m_structuralIntegrity;
  156. Real m_lastCrushedLocation;
  157. Int m_nextBurstFrame;
  158. Coord3D m_delayBurstLocation;
  159. Real m_buildingHeight;
  160. };
  161. #endif // __StructureToppleUpdate_H_