SlowDeathBehavior.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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: SlowDeathBehavior.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, December 2001
  25. // Desc: Update that will count down a lifetime and destroy object when it reaches zero
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __SlowDeathBehavior_H_
  29. #define __SlowDeathBehavior_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/DieModule.h"
  33. #include "GameLogic/Module/UpdateModule.h"
  34. class FXList;
  35. class ObjectCreationList;
  36. class WeaponTemplate;
  37. class DamageInfo;
  38. //-------------------------------------------------------------------------------------------------
  39. typedef std::vector<const FXList*> FXListVec;
  40. typedef std::vector<const ObjectCreationList*> OCLVec;
  41. typedef std::vector<const WeaponTemplate*> WeaponTemplateVec;
  42. //-------------------------------------------------------------------------------------------------
  43. enum SlowDeathPhaseType
  44. {
  45. SDPHASE_INITIAL = 0,
  46. SDPHASE_MIDPOINT,
  47. SDPHASE_FINAL,
  48. SD_PHASE_COUNT // keep last
  49. };
  50. #ifdef DEFINE_SLOWDEATHPHASE_NAMES
  51. static const char *TheSlowDeathPhaseNames[] =
  52. {
  53. "INITIAL",
  54. "MIDPOINT",
  55. "FINAL",
  56. NULL
  57. };
  58. #endif
  59. //-------------------------------------------------------------------------------------------------
  60. class SlowDeathBehaviorModuleData : public UpdateModuleData
  61. {
  62. public:
  63. DieMuxData m_dieMuxData;
  64. Real m_sinkRate;
  65. Int m_probabilityModifier;
  66. Real m_modifierBonusPerOverkillPercent;
  67. UnsignedInt m_sinkDelay;
  68. UnsignedInt m_sinkDelayVariance;
  69. Real m_destructionAltitude;
  70. UnsignedInt m_destructionDelay;
  71. UnsignedInt m_destructionDelayVariance;
  72. FXListVec m_fx[SD_PHASE_COUNT];
  73. OCLVec m_ocls[SD_PHASE_COUNT];
  74. WeaponTemplateVec m_weapons[SD_PHASE_COUNT];
  75. Real m_flingForce;
  76. Real m_flingForceVariance;
  77. Real m_flingPitch;
  78. Real m_flingPitchVariance;
  79. enum
  80. {
  81. //flags used by m_maskOfLoadedEffects
  82. HAS_FX = 1,
  83. HAS_OCL = 2,
  84. HAS_WEAPON = 4,
  85. HAS_NON_LOD_EFFECTS = (HAS_OCL | HAS_WEAPON)
  86. };
  87. Byte m_maskOfLoadedEffects; ///<used to keep track of whether m_fx,m_ocls,m_weapons actually contain anything.
  88. SlowDeathBehaviorModuleData();
  89. static void buildFieldParse(MultiIniFieldParse& p);
  90. inline Bool hasNonLodEffects() const
  91. {
  92. return (m_maskOfLoadedEffects & SlowDeathBehaviorModuleData::HAS_NON_LOD_EFFECTS) != 0;
  93. }
  94. private:
  95. };
  96. //-------------------------------------------------------------------------------------------------
  97. //-------------------------------------------------------------------------------------------------
  98. class SlowDeathBehaviorInterface
  99. {
  100. public:
  101. virtual void beginSlowDeath( const DamageInfo *damageInfo ) = 0;
  102. virtual Int getProbabilityModifier( const DamageInfo *damageInfo ) const = 0;
  103. virtual Bool isDieApplicable(const DamageInfo *damageInfo) const = 0;
  104. };
  105. //-------------------------------------------------------------------------------------------------
  106. //-------------------------------------------------------------------------------------------------
  107. class SlowDeathBehavior : public UpdateModule,
  108. public DieModuleInterface,
  109. public SlowDeathBehaviorInterface
  110. {
  111. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( SlowDeathBehavior, "SlowDeathBehavior" )
  112. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( SlowDeathBehavior, SlowDeathBehaviorModuleData )
  113. public:
  114. SlowDeathBehavior( Thing *thing, const ModuleData* moduleData );
  115. // virtual destructor prototype provided by memory pool declaration
  116. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_DIE); }
  117. // BehaviorModule
  118. virtual DieModuleInterface* getDie() { return this; }
  119. // UpdateModuleInterface
  120. virtual UpdateSleepTime update();
  121. virtual SlowDeathBehaviorInterface* getSlowDeathBehaviorInterface() { return this; }
  122. // Disabled conditions to process -- all
  123. virtual DisabledMaskType getDisabledTypesToProcess() const { return DISABLEDMASK_ALL; }
  124. // DieModuleInterface
  125. virtual void onDie( const DamageInfo *damageInfo );
  126. // SlowDeathBehaviorInterface
  127. virtual void beginSlowDeath( const DamageInfo *damageInfo );
  128. virtual Int getProbabilityModifier( const DamageInfo *damageInfo ) const;
  129. virtual Bool isDieApplicable(const DamageInfo *damageInfo) const { return getSlowDeathBehaviorModuleData()->m_dieMuxData.isDieApplicable(getObject(), damageInfo); }
  130. protected:
  131. void doPhaseStuff(SlowDeathPhaseType sdphase);
  132. inline Bool isSlowDeathActivated() const { return (m_flags & (1<<SLOW_DEATH_ACTIVATED)) != 0; }
  133. inline UnsignedInt getDestructionFrame() const { return m_destructionFrame; }
  134. private:
  135. enum
  136. {
  137. SLOW_DEATH_ACTIVATED,
  138. MIDPOINT_EXECUTED,
  139. FLUNG_INTO_AIR,
  140. BOUNCED
  141. };
  142. UnsignedInt m_sinkFrame; ///< Frame to be sunken into the ground on
  143. UnsignedInt m_midpointFrame; ///< The midpoint is between .25 through life and .75 through life (eg)
  144. UnsignedInt m_destructionFrame;
  145. Real m_acceleratedTimeScale; ///<used to speedup deaths when needed to improve game performance.
  146. UnsignedInt m_flags;
  147. };
  148. #endif // __SlowDeathBehavior_H_