AutoHealBehavior.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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: AutoHealBehavior.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, December 2001
  25. // Desc: Update that heals itself
  26. //------------------------------------------
  27. // Modified by Kris Morness, September 2002
  28. // Kris: Added the ability to add effects, radius healing, and restricting the type of objects
  29. // subjected to the heal (or repair).
  30. ///////////////////////////////////////////////////////////////////////////////////////////////////
  31. #pragma once
  32. #ifndef __AutoHealBehavior_H_
  33. #define __AutoHealBehavior_H_
  34. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  35. #include "GameClient/ParticleSys.h"
  36. #include "GameLogic/Module/BehaviorModule.h"
  37. #include "GameLogic/Module/UpgradeModule.h"
  38. #include "GameLogic/Module/UpdateModule.h"
  39. #include "GameLogic/Module/DamageModule.h"
  40. #include "Common/BitFlagsIO.h"
  41. class ParticleSystem;
  42. class ParticleSystemTemplate;
  43. //-------------------------------------------------------------------------------------------------
  44. class AutoHealBehaviorModuleData : public UpdateModuleData
  45. {
  46. public:
  47. UpgradeMuxData m_upgradeMuxData;
  48. Bool m_initiallyActive;
  49. Bool m_singleBurst;
  50. Int m_healingAmount;
  51. UnsignedInt m_healingDelay;
  52. UnsignedInt m_startHealingDelay; ///< how long since our last damage till autoheal starts.
  53. Real m_radius; //If non-zero, then it becomes a area effect.
  54. Bool m_affectsWholePlayer; ///< I have more than a range, I try to affect everything the player owns
  55. Bool m_skipSelfForHealing; ///< Don't heal myself.
  56. KindOfMaskType m_kindOf; //Only these types can heal -- defaults to everything.
  57. KindOfMaskType m_forbiddenKindOf; //Only these types can heal -- defaults to everything.
  58. const ParticleSystemTemplate* m_radiusParticleSystemTmpl; //Optional particle system meant to apply to entire effect for entire duration.
  59. const ParticleSystemTemplate* m_unitHealPulseParticleSystemTmpl; //Optional particle system applying to each object getting healed each heal pulse.
  60. AutoHealBehaviorModuleData()
  61. {
  62. m_initiallyActive = false;
  63. m_singleBurst = FALSE;
  64. m_healingAmount = 0;
  65. m_healingDelay = UINT_MAX;
  66. m_startHealingDelay = 0;
  67. m_radius = 0.0f;
  68. m_radiusParticleSystemTmpl = NULL;
  69. m_unitHealPulseParticleSystemTmpl = NULL;
  70. m_affectsWholePlayer = FALSE;
  71. m_skipSelfForHealing = FALSE;
  72. SET_ALL_KINDOFMASK_BITS( m_kindOf );
  73. m_forbiddenKindOf.clear();
  74. }
  75. static void buildFieldParse(MultiIniFieldParse& p)
  76. {
  77. static const FieldParse dataFieldParse[] =
  78. {
  79. { "StartsActive", INI::parseBool, NULL, offsetof( AutoHealBehaviorModuleData, m_initiallyActive ) },
  80. { "SingleBurst", INI::parseBool, NULL, offsetof( AutoHealBehaviorModuleData, m_singleBurst ) },
  81. { "HealingAmount", INI::parseInt, NULL, offsetof( AutoHealBehaviorModuleData, m_healingAmount ) },
  82. { "HealingDelay", INI::parseDurationUnsignedInt, NULL, offsetof( AutoHealBehaviorModuleData, m_healingDelay ) },
  83. { "Radius", INI::parseReal, NULL, offsetof( AutoHealBehaviorModuleData, m_radius ) },
  84. { "KindOf", KindOfMaskType::parseFromINI, NULL, offsetof( AutoHealBehaviorModuleData, m_kindOf ) },
  85. { "ForbiddenKindOf", KindOfMaskType::parseFromINI, NULL, offsetof( AutoHealBehaviorModuleData, m_forbiddenKindOf ) },
  86. { "RadiusParticleSystemName", INI::parseParticleSystemTemplate, NULL, offsetof( AutoHealBehaviorModuleData, m_radiusParticleSystemTmpl ) },
  87. { "UnitHealPulseParticleSystemName", INI::parseParticleSystemTemplate, NULL, offsetof( AutoHealBehaviorModuleData, m_unitHealPulseParticleSystemTmpl ) },
  88. { "StartHealingDelay", INI::parseDurationUnsignedInt, NULL, offsetof( AutoHealBehaviorModuleData, m_startHealingDelay ) },
  89. { "AffectsWholePlayer", INI::parseBool, NULL, offsetof( AutoHealBehaviorModuleData, m_affectsWholePlayer ) },
  90. { "SkipSelfForHealing", INI::parseBool, NULL, offsetof( AutoHealBehaviorModuleData, m_skipSelfForHealing ) },
  91. { 0, 0, 0, 0 }
  92. };
  93. UpdateModuleData::buildFieldParse(p);
  94. p.add(dataFieldParse);
  95. p.add(UpgradeMuxData::getFieldParse(), offsetof( AutoHealBehaviorModuleData, m_upgradeMuxData ));
  96. }
  97. };
  98. //-------------------------------------------------------------------------------------------------
  99. //-------------------------------------------------------------------------------------------------
  100. class AutoHealBehavior : public UpdateModule,
  101. public UpgradeMux,
  102. public DamageModuleInterface
  103. {
  104. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( AutoHealBehavior, "AutoHealBehavior" )
  105. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( AutoHealBehavior, AutoHealBehaviorModuleData )
  106. public:
  107. AutoHealBehavior( Thing *thing, const ModuleData* moduleData );
  108. // virtual destructor prototype provided by memory pool declaration
  109. // module methods
  110. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | MODULEINTERFACE_UPGRADE | MODULEINTERFACE_DAMAGE; }
  111. // BehaviorModule
  112. virtual UpgradeModuleInterface* getUpgrade() { return this; }
  113. virtual DamageModuleInterface* getDamage() { return this; }
  114. // DamageModuleInterface
  115. virtual void onDamage( DamageInfo *damageInfo );
  116. virtual void onHealing( DamageInfo *damageInfo ) { }
  117. virtual void onBodyDamageStateChange(const DamageInfo* damageInfo, BodyDamageType oldState, BodyDamageType newState) { }
  118. // UpdateModuleInterface
  119. virtual UpdateSleepTime update();
  120. virtual DisabledMaskType getDisabledTypesToProcess() const { return MAKE_DISABLED_MASK( DISABLED_HELD ); }
  121. void stopHealing();
  122. void undoUpgrade(); ///<pretend like we have not been activated yet, so we can be reactivated later
  123. protected:
  124. virtual void upgradeImplementation()
  125. {
  126. setWakeFrame(getObject(), UPDATE_SLEEP_NONE);
  127. }
  128. virtual void getUpgradeActivationMasks(UpgradeMaskType& activation, UpgradeMaskType& conflicting) const
  129. {
  130. getAutoHealBehaviorModuleData()->m_upgradeMuxData.getUpgradeActivationMasks(activation, conflicting);
  131. }
  132. virtual void performUpgradeFX()
  133. {
  134. getAutoHealBehaviorModuleData()->m_upgradeMuxData.performUpgradeFX(getObject());
  135. }
  136. virtual void processUpgradeRemoval()
  137. {
  138. // I can't take it any more. Let the record show that I think the UpgradeMux multiple inheritence is CRAP.
  139. getAutoHealBehaviorModuleData()->m_upgradeMuxData.muxDataProcessUpgradeRemoval(getObject());
  140. }
  141. virtual Bool requiresAllActivationUpgrades() const
  142. {
  143. return getAutoHealBehaviorModuleData()->m_upgradeMuxData.m_requiresAllTriggers;
  144. }
  145. inline Bool isUpgradeActive() const { return isAlreadyUpgraded(); }
  146. virtual Bool isSubObjectsUpgrade() { return false; }
  147. private:
  148. void pulseHealObject( Object *obj );
  149. ParticleSystemID m_radiusParticleSystemID;
  150. UnsignedInt m_soonestHealFrame;/** I need to record this, because with multiple wake up sources,
  151. I can't rely solely on my sleeping. So this will guard onDamage's wake up.
  152. I could guard the act of healing, but that would defeat the gain of being
  153. a sleepy module. I never want to run update unless I am going to heal.
  154. */
  155. Bool m_stopped;
  156. };
  157. #endif // __AutoHealBehavior_H_