DieModule.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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: DieModule.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, September 2001
  25. // Desc:
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __DieModule_H_
  29. #define __DieModule_H_
  30. #include "Common/Module.h"
  31. #include "GameLogic/Damage.h"
  32. #include "GameLogic/Module/BehaviorModule.h"
  33. #include "Common/ObjectStatusTypes.h"
  34. //-------------------------------------------------------------------------------------------------
  35. /** OBJECT DIE MODULE base class */
  36. //-------------------------------------------------------------------------------------------------
  37. //-------------------------------------------------------------------------------------------------
  38. class DieModuleInterface
  39. {
  40. public:
  41. virtual void onDie( const DamageInfo *damageInfo ) = 0;
  42. };
  43. //-------------------------------------------------------------------------------------------------
  44. class DieMuxData // does NOT inherit from ModuleData.
  45. {
  46. public:
  47. DeathTypeFlags m_deathTypes;
  48. VeterancyLevelFlags m_veterancyLevels;
  49. ObjectStatusMaskType m_exemptStatus; ///< die module is ignored if any of these status bits are set
  50. ObjectStatusMaskType m_requiredStatus; ///< die module is ignored if any of these status bits are clear
  51. DieMuxData();
  52. static const FieldParse* getFieldParse();
  53. Bool isDieApplicable(const Object* obj, const DamageInfo *damageInfo) const;
  54. };
  55. //-------------------------------------------------------------------------------------------------
  56. //-------------------------------------------------------------------------------------------------
  57. //-------------------------------------------------------------------------------------------------
  58. class DieModuleData : public BehaviorModuleData
  59. {
  60. public:
  61. DieMuxData m_dieMuxData;
  62. static void buildFieldParse(MultiIniFieldParse& p)
  63. {
  64. BehaviorModuleData::buildFieldParse(p);
  65. p.add(DieMuxData::getFieldParse(), offsetof( DieModuleData, m_dieMuxData ));
  66. }
  67. inline Bool isDieApplicable(const Object* obj, const DamageInfo *damageInfo) const { return m_dieMuxData.isDieApplicable(obj, damageInfo); }
  68. };
  69. //-------------------------------------------------------------------------------------------------
  70. class DieModule : public BehaviorModule, public DieModuleInterface
  71. {
  72. MEMORY_POOL_GLUE_ABC( DieModule )
  73. MAKE_STANDARD_MODULE_MACRO_ABC( DieModule )
  74. MAKE_STANDARD_MODULE_DATA_MACRO_ABC(DieModule, DieModuleData)
  75. public:
  76. DieModule( Thing *thing, const ModuleData* moduleData );
  77. // virtual destructor prototype defined by MemoryPoolObject
  78. static Int getInterfaceMask() { return MODULEINTERFACE_DIE; }
  79. // BehaviorModule
  80. virtual DieModuleInterface* getDie() { return this; }
  81. void onDie( const DamageInfo *damageInfo ) = 0;
  82. protected:
  83. Bool isDieApplicable(const DamageInfo *damageInfo) const { return getDieModuleData()->isDieApplicable(getObject(), damageInfo); }
  84. };
  85. inline DieModule::DieModule( Thing *thing, const ModuleData* moduleData ) : BehaviorModule( thing, moduleData ) { }
  86. inline DieModule::~DieModule() { }
  87. #endif