FireWeaponWhenDeadBehavior.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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: FireWeaponWhenDeadBehavior.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 __FireWeaponWhenDeadBehavior_H_
  29. #define __FireWeaponWhenDeadBehavior_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/DieModule.h"
  33. #include "GameLogic/Module/UpgradeModule.h"
  34. //-------------------------------------------------------------------------------------------------
  35. class FireWeaponWhenDeadBehaviorModuleData : public BehaviorModuleData
  36. {
  37. public:
  38. UpgradeMuxData m_upgradeMuxData;
  39. Bool m_initiallyActive;
  40. DieMuxData m_dieMuxData;
  41. const WeaponTemplate* m_deathWeapon; ///< fire this weapon when we are damaged
  42. FireWeaponWhenDeadBehaviorModuleData()
  43. {
  44. m_initiallyActive = false;
  45. m_deathWeapon = NULL;
  46. }
  47. static void buildFieldParse(MultiIniFieldParse& p)
  48. {
  49. static const FieldParse dataFieldParse[] =
  50. {
  51. { "StartsActive", INI::parseBool, NULL, offsetof( FireWeaponWhenDeadBehaviorModuleData, m_initiallyActive ) },
  52. { "DeathWeapon", INI::parseWeaponTemplate, NULL, offsetof( FireWeaponWhenDeadBehaviorModuleData, m_deathWeapon ) },
  53. { 0, 0, 0, 0 }
  54. };
  55. BehaviorModuleData::buildFieldParse(p);
  56. p.add(dataFieldParse);
  57. p.add(UpgradeMuxData::getFieldParse(), offsetof( FireWeaponWhenDeadBehaviorModuleData, m_upgradeMuxData ));
  58. p.add(DieMuxData::getFieldParse(), offsetof( FireWeaponWhenDeadBehaviorModuleData, m_dieMuxData ));
  59. }
  60. };
  61. //-------------------------------------------------------------------------------------------------
  62. //-------------------------------------------------------------------------------------------------
  63. class FireWeaponWhenDeadBehavior : public BehaviorModule,
  64. public UpgradeMux,
  65. public DieModuleInterface
  66. {
  67. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( FireWeaponWhenDeadBehavior, "FireWeaponWhenDeadBehavior" )
  68. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( FireWeaponWhenDeadBehavior, FireWeaponWhenDeadBehaviorModuleData )
  69. public:
  70. FireWeaponWhenDeadBehavior( Thing *thing, const ModuleData* moduleData );
  71. // virtual destructor prototype provided by memory pool declaration
  72. // module methods
  73. static Int getInterfaceMask() { return BehaviorModule::getInterfaceMask() | (MODULEINTERFACE_UPGRADE) | (MODULEINTERFACE_DIE); }
  74. // BehaviorModule
  75. virtual UpgradeModuleInterface* getUpgrade() { return this; }
  76. virtual DieModuleInterface* getDie() { return this; }
  77. // DamageModuleInterface
  78. virtual void onDie( const DamageInfo *damageInfo );
  79. protected:
  80. virtual void upgradeImplementation()
  81. {
  82. // nothing!
  83. }
  84. virtual void getUpgradeActivationMasks(UpgradeMaskType& activation, UpgradeMaskType& conflicting) const
  85. {
  86. getFireWeaponWhenDeadBehaviorModuleData()->m_upgradeMuxData.getUpgradeActivationMasks(activation, conflicting);
  87. }
  88. virtual void performUpgradeFX()
  89. {
  90. getFireWeaponWhenDeadBehaviorModuleData()->m_upgradeMuxData.performUpgradeFX(getObject());
  91. }
  92. virtual void processUpgradeRemoval()
  93. {
  94. // I can't take it any more. Let the record show that I think the UpgradeMux multiple inheritence is CRAP.
  95. getFireWeaponWhenDeadBehaviorModuleData()->m_upgradeMuxData.muxDataProcessUpgradeRemoval(getObject());
  96. }
  97. virtual Bool requiresAllActivationUpgrades() const
  98. {
  99. return getFireWeaponWhenDeadBehaviorModuleData()->m_upgradeMuxData.m_requiresAllTriggers;
  100. }
  101. inline Bool isUpgradeActive() const { return isAlreadyUpgraded(); }
  102. virtual Bool isSubObjectsUpgrade() { return false; }
  103. };
  104. #endif // __FireWeaponWhenDeadBehavior_H_