FireWeaponWhenDamagedBehavior.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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: FireWeaponWhenDamagedBehavior.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, June 2002
  25. // Desc: Update that will count down a lifetime and destroy object when it reaches zero
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __FireWeaponWhenDamagedBehavior_H_
  29. #define __FireWeaponWhenDamagedBehavior_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/UpgradeModule.h"
  33. #include "GameLogic/Module/UpdateModule.h"
  34. #include "GameLogic/Module/DamageModule.h"
  35. #include "GameLogic/Weapon.h"
  36. //-------------------------------------------------------------------------------------------------
  37. class FireWeaponWhenDamagedBehaviorModuleData : public UpdateModuleData
  38. {
  39. public:
  40. UpgradeMuxData m_upgradeMuxData;
  41. Bool m_initiallyActive;
  42. DamageTypeFlags m_damageTypes;
  43. Real m_damageAmount;
  44. const WeaponTemplate* m_reactionWeaponPristine;///< fire these weapons only when damage is received
  45. const WeaponTemplate* m_reactionWeaponDamaged;
  46. const WeaponTemplate* m_reactionWeaponReallyDamaged;
  47. const WeaponTemplate* m_reactionWeaponRubble;
  48. const WeaponTemplate* m_continuousWeaponPristine;///< fire these weapons continuously, versus just onDamage
  49. const WeaponTemplate* m_continuousWeaponDamaged;
  50. const WeaponTemplate* m_continuousWeaponReallyDamaged;
  51. const WeaponTemplate* m_continuousWeaponRubble;
  52. FireWeaponWhenDamagedBehaviorModuleData()
  53. {
  54. m_initiallyActive = false;
  55. m_reactionWeaponPristine = NULL;
  56. m_reactionWeaponDamaged = NULL;
  57. m_reactionWeaponReallyDamaged = NULL;
  58. m_reactionWeaponRubble = NULL;
  59. m_continuousWeaponPristine = NULL;
  60. m_continuousWeaponDamaged = NULL;
  61. m_continuousWeaponReallyDamaged = NULL;
  62. m_continuousWeaponRubble = NULL;
  63. m_damageTypes = DAMAGE_TYPE_FLAGS_ALL;
  64. m_damageAmount = 0;
  65. }
  66. static void buildFieldParse(MultiIniFieldParse& p)
  67. {
  68. static const FieldParse dataFieldParse[] =
  69. {
  70. { "StartsActive", INI::parseBool, NULL, offsetof( FireWeaponWhenDamagedBehaviorModuleData, m_initiallyActive ) },
  71. { "ReactionWeaponPristine", INI::parseWeaponTemplate, NULL, offsetof(FireWeaponWhenDamagedBehaviorModuleData, m_reactionWeaponPristine) },
  72. { "ReactionWeaponDamaged", INI::parseWeaponTemplate, NULL, offsetof(FireWeaponWhenDamagedBehaviorModuleData, m_reactionWeaponDamaged) },
  73. { "ReactionWeaponReallyDamaged", INI::parseWeaponTemplate, NULL, offsetof(FireWeaponWhenDamagedBehaviorModuleData, m_reactionWeaponReallyDamaged) },
  74. { "ReactionWeaponRubble", INI::parseWeaponTemplate, NULL, offsetof(FireWeaponWhenDamagedBehaviorModuleData, m_reactionWeaponRubble) },
  75. { "ContinuousWeaponPristine", INI::parseWeaponTemplate, NULL, offsetof(FireWeaponWhenDamagedBehaviorModuleData, m_continuousWeaponPristine) },
  76. { "ContinuousWeaponDamaged", INI::parseWeaponTemplate, NULL, offsetof(FireWeaponWhenDamagedBehaviorModuleData, m_continuousWeaponDamaged) },
  77. { "ContinuousWeaponReallyDamaged", INI::parseWeaponTemplate, NULL, offsetof(FireWeaponWhenDamagedBehaviorModuleData,m_continuousWeaponReallyDamaged) },
  78. { "ContinuousWeaponRubble", INI::parseWeaponTemplate, NULL, offsetof(FireWeaponWhenDamagedBehaviorModuleData, m_continuousWeaponRubble) },
  79. { "DamageTypes", INI::parseDamageTypeFlags, NULL, offsetof( FireWeaponWhenDamagedBehaviorModuleData, m_damageTypes ) },
  80. { "DamageAmount", INI::parseReal, NULL, offsetof( FireWeaponWhenDamagedBehaviorModuleData, m_damageAmount ) },
  81. { 0, 0, 0, 0 }
  82. };
  83. UpdateModuleData::buildFieldParse(p);
  84. p.add(dataFieldParse);
  85. p.add(UpgradeMuxData::getFieldParse(), offsetof( FireWeaponWhenDamagedBehaviorModuleData, m_upgradeMuxData ));
  86. }
  87. private:
  88. };
  89. //-------------------------------------------------------------------------------------------------
  90. //-------------------------------------------------------------------------------------------------
  91. class FireWeaponWhenDamagedBehavior : public UpdateModule,
  92. public UpgradeMux,
  93. public DamageModuleInterface
  94. {
  95. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( FireWeaponWhenDamagedBehavior, "FireWeaponWhenDamagedBehavior" )
  96. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( FireWeaponWhenDamagedBehavior, FireWeaponWhenDamagedBehaviorModuleData )
  97. public:
  98. FireWeaponWhenDamagedBehavior( Thing *thing, const ModuleData* moduleData );
  99. // virtual destructor prototype provided by memory pool declaration
  100. // module methids
  101. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_UPGRADE) | (MODULEINTERFACE_DAMAGE); }
  102. // BehaviorModule
  103. virtual UpgradeModuleInterface* getUpgrade() { return this; }
  104. virtual DamageModuleInterface* getDamage() { return this; }
  105. // DamageModuleInterface
  106. virtual void onDamage( DamageInfo *damageInfo );
  107. virtual void onHealing( DamageInfo *damageInfo ) { }
  108. virtual void onBodyDamageStateChange(const DamageInfo* damageInfo, BodyDamageType oldState, BodyDamageType newState) { }
  109. // UpdateModuleInterface
  110. virtual UpdateSleepTime update();
  111. protected:
  112. virtual void upgradeImplementation()
  113. {
  114. setWakeFrame(getObject(), UPDATE_SLEEP_NONE);
  115. }
  116. virtual void getUpgradeActivationMasks(UpgradeMaskType& activation, UpgradeMaskType& conflicting) const
  117. {
  118. getFireWeaponWhenDamagedBehaviorModuleData()->m_upgradeMuxData.getUpgradeActivationMasks(activation, conflicting);
  119. }
  120. virtual void performUpgradeFX()
  121. {
  122. getFireWeaponWhenDamagedBehaviorModuleData()->m_upgradeMuxData.performUpgradeFX(getObject());
  123. }
  124. virtual void processUpgradeRemoval()
  125. {
  126. // I can't take it any more. Let the record show that I think the UpgradeMux multiple inheritence is CRAP.
  127. getFireWeaponWhenDamagedBehaviorModuleData()->m_upgradeMuxData.muxDataProcessUpgradeRemoval(getObject());
  128. }
  129. virtual Bool requiresAllActivationUpgrades() const
  130. {
  131. return getFireWeaponWhenDamagedBehaviorModuleData()->m_upgradeMuxData.m_requiresAllTriggers;
  132. }
  133. inline Bool isUpgradeActive() const { return isAlreadyUpgraded(); }
  134. virtual Bool isSubObjectsUpgrade() { return false; }
  135. private:
  136. Weapon *m_reactionWeaponPristine;
  137. Weapon *m_reactionWeaponDamaged;
  138. Weapon *m_reactionWeaponReallyDamaged;
  139. Weapon *m_reactionWeaponRubble;
  140. Weapon *m_continuousWeaponPristine;
  141. Weapon *m_continuousWeaponDamaged;
  142. Weapon *m_continuousWeaponReallyDamaged;
  143. Weapon *m_continuousWeaponRubble;
  144. };
  145. #endif // __FireWeaponWhenDamagedBehavior_H_