ActiveBody.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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: ActiveBody.h /////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, November 2001
  25. // Desc: Active bodies have health, they can die and are affected by health
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __ACTIVEBODY_H_
  29. #define __ACTIVEBODY_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/DamageFX.h"
  32. #include "GameLogic/Module/BodyModule.h"
  33. #include "GameLogic/Damage.h"
  34. #include "GameLogic/Armor.h"
  35. #include "GameLogic/ArmorSet.h"
  36. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  37. class BodyParticleSystem;
  38. class ParticleSystemTemplate;
  39. //-------------------------------------------------------------------------------------------------
  40. /** Active body module */
  41. //-------------------------------------------------------------------------------------------------
  42. //-------------------------------------------------------------------------------------------------
  43. class ActiveBodyModuleData : public BodyModuleData
  44. {
  45. public:
  46. Real m_maxHealth;
  47. Real m_initialHealth;
  48. Real m_subdualDamageCap; ///< Subdual damage will never accumulate past this
  49. UnsignedInt m_subdualDamageHealRate; ///< Every this often, we drop subdual damage...
  50. Real m_subdualDamageHealAmount; ///< by this much.
  51. ActiveBodyModuleData();
  52. static void buildFieldParse(MultiIniFieldParse& p);
  53. };
  54. //-------------------------------------------------------------------------------------------------
  55. class ActiveBody : public BodyModule
  56. {
  57. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( ActiveBody, "ActiveBody" )
  58. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( ActiveBody, ActiveBodyModuleData )
  59. public:
  60. ActiveBody( Thing *thing, const ModuleData* moduleData );
  61. // virtual destructor prototype provided by memory pool declaration
  62. virtual void onDelete( void );
  63. virtual void attemptDamage( DamageInfo *damageInfo ); ///< try to damage this object
  64. virtual Real estimateDamage( DamageInfoInput& damageInfo ) const;
  65. virtual void attemptHealing( DamageInfo *damageInfo ); ///< try to heal this object
  66. virtual Real getHealth() const; ///< get current health
  67. virtual BodyDamageType getDamageState() const;
  68. virtual void setDamageState( BodyDamageType newState ); ///< control damage state directly. Will adjust hitpoints.
  69. virtual void setAflame( Bool setting );///< This is a major change like a damage state.
  70. virtual UnsignedInt getSubdualDamageHealRate() const;
  71. virtual Real getSubdualDamageHealAmount() const;
  72. virtual Bool hasAnySubdualDamage() const;
  73. virtual Real getCurrentSubdualDamageAmount() const { return m_currentSubdualDamage; }
  74. virtual const DamageInfo *getLastDamageInfo() const { return &m_lastDamageInfo; } ///< return info on last damage dealt to this object
  75. virtual UnsignedInt getLastDamageTimestamp() const { return m_lastDamageTimestamp; } ///< return frame of last damage dealt
  76. virtual UnsignedInt getLastHealingTimestamp() const { return m_lastHealingTimestamp; } ///< return frame of last damage dealt
  77. virtual ObjectID getClearableLastAttacker() const { return (m_lastDamageCleared ? INVALID_ID : m_lastDamageInfo.in.m_sourceID); }
  78. virtual void clearLastAttacker() { m_lastDamageCleared = true; }
  79. void onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLevel newLevel, Bool provideFeedback = TRUE );
  80. virtual void setArmorSetFlag(ArmorSetType ast) { m_curArmorSetFlags.set(ast, 1); }
  81. virtual void clearArmorSetFlag(ArmorSetType ast) { m_curArmorSetFlags.set(ast, 0); }
  82. virtual Bool testArmorSetFlag(ArmorSetType ast) { return m_curArmorSetFlags.test(ast); }
  83. virtual void setInitialHealth(Int initialPercent); ///< Sets the inital load health %.
  84. virtual void setMaxHealth( Real maxHealth, MaxHealthChangeType healthChangeType = SAME_CURRENTHEALTH ); ///< Sets the inital max health
  85. virtual Bool getFrontCrushed() const { return m_frontCrushed; }
  86. virtual Bool getBackCrushed() const { return m_backCrushed; }
  87. virtual void setFrontCrushed(Bool v) { m_frontCrushed = v; }
  88. virtual void setBackCrushed(Bool v) { m_backCrushed = v; }
  89. virtual Real getMaxHealth() const; ///< return max health
  90. virtual Real getInitialHealth() const; // return initial health
  91. virtual Real getPreviousHealth() const { return m_prevHealth; }
  92. virtual void setIndestructible( Bool indestructible );
  93. virtual Bool isIndestructible( void ) const { return m_indestructible; }
  94. virtual void internalChangeHealth( Real delta ); ///< change health
  95. virtual void evaluateVisualCondition();
  96. virtual void updateBodyParticleSystems( void );// made public for topple anf building collapse updates -ML
  97. // Subdual Damage
  98. virtual Bool isSubdued() const;
  99. virtual Bool canBeSubdued() const;
  100. virtual void onSubdualChange( Bool isNowSubdued );///< Override this if you want a totally different effect than DISABLED_SUBDUED
  101. protected:
  102. void validateArmorAndDamageFX() const;
  103. void doDamageFX( const DamageInfo *damageInfo );
  104. void createParticleSystems( const AsciiString &boneBaseName,
  105. const ParticleSystemTemplate *systemTemplate,
  106. Int maxSystems );
  107. void deleteAllParticleSystems( void );
  108. void setCorrectDamageState();
  109. Bool shouldRetaliate(Object *obj);
  110. Bool shouldRetaliateAgainstAggressor(Object *obj, Object *damager);
  111. virtual void internalAddSubdualDamage( Real delta ); ///< change health
  112. private:
  113. Real m_currentHealth; ///< health of the object
  114. Real m_prevHealth; ///< previous health value before current health change op
  115. Real m_maxHealth; ///< max health this object can have
  116. Real m_initialHealth; ///< starting health for this object
  117. Real m_currentSubdualDamage; ///< Starts at zero and goes up. Inherited modules will do something when "subdued".
  118. BodyDamageType m_curDamageState; ///< last known damage state
  119. UnsignedInt m_nextDamageFXTime;
  120. DamageType m_lastDamageFXDone;
  121. DamageInfo m_lastDamageInfo; ///< store the last DamageInfo object that we received
  122. UnsignedInt m_lastDamageTimestamp; ///< frame of last damage dealt
  123. UnsignedInt m_lastHealingTimestamp; ///< frame of last healing dealt
  124. Bool m_frontCrushed;
  125. Bool m_backCrushed;
  126. Bool m_lastDamageCleared;
  127. Bool m_indestructible; ///< is this object indestructible?
  128. BodyParticleSystem *m_particleSystems; ///< particle systems created and attached to this object
  129. /*
  130. Note, you MUST call validateArmorAndDamageFX() before accessing these fields.
  131. */
  132. ArmorSetFlags m_curArmorSetFlags;
  133. mutable const ArmorTemplateSet* m_curArmorSet;
  134. mutable Armor m_curArmor;
  135. mutable const DamageFX* m_curDamageFX;
  136. };
  137. #endif // __ACTIVEBODY_H_