InactiveBody.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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: InactiveBody.cpp /////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, November 2001
  25. // Desc: An Inactive body module doesn't have any of the data storage for
  26. // health and damage etc ... it's an "Inactive" object that isn't
  27. // affected by matters of the body ... it's all in the mind!!!!
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  30. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  31. #include "Common/ThingTemplate.h"
  32. #include "Common/Xfer.h"
  33. #include "GameLogic/Module/InactiveBody.h"
  34. #include "GameLogic/Module/DieModule.h"
  35. #include "GameLogic/Damage.h"
  36. #include "GameLogic/GameLogic.h"
  37. #include "GameLogic/Object.h"
  38. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  39. //-------------------------------------------------------------------------------------------------
  40. //-------------------------------------------------------------------------------------------------
  41. InactiveBody::InactiveBody( Thing *thing, const ModuleData* moduleData )
  42. : BodyModule( thing, moduleData ), m_dieCalled(false)
  43. {
  44. getObject()->setEffectivelyDead(true);
  45. } // end InactiveBody
  46. //-------------------------------------------------------------------------------------------------
  47. //-------------------------------------------------------------------------------------------------
  48. InactiveBody::~InactiveBody( void )
  49. {
  50. } // end ~InactiveBody
  51. //-------------------------------------------------------------------------------------------------
  52. //-------------------------------------------------------------------------------------------------
  53. Real InactiveBody::estimateDamage( DamageInfoInput& damageInfo ) const
  54. {
  55. // Inactive bodies have no health so no damage can really be done
  56. Real amount = 0.0f;
  57. // exception!
  58. if (damageInfo.m_damageType == DAMAGE_UNRESISTABLE)
  59. {
  60. amount = damageInfo.m_amount;
  61. }
  62. return amount;
  63. }
  64. //-------------------------------------------------------------------------------------------------
  65. //-------------------------------------------------------------------------------------------------
  66. void InactiveBody::attemptDamage( DamageInfo *damageInfo )
  67. {
  68. if( damageInfo == NULL )
  69. return;
  70. if( damageInfo->in.m_damageType == DAMAGE_HEALING )
  71. {
  72. // Healing and Damage are separate, so this shouldn't happen
  73. attemptHealing( damageInfo );
  74. return;
  75. }
  76. // Inactive bodies have no health so no damage can really be done
  77. damageInfo->out.m_actualDamageDealt = 0.0f;
  78. damageInfo->out.m_actualDamageClipped = 0.0f;
  79. damageInfo->out.m_noEffect = true;
  80. // exception: damage type KILL always wipes us out
  81. if (damageInfo->in.m_damageType == DAMAGE_UNRESISTABLE)
  82. {
  83. DEBUG_ASSERTCRASH(!getObject()->getTemplate()->isPrerequisite(), ("Prerequisites should not have InactiveBody"));
  84. damageInfo->out.m_noEffect = false;
  85. // since we have no Health, we do not call DamageModules, nor do DamageFX.
  86. // however, we DO process DieModules.
  87. if (!m_dieCalled)
  88. {
  89. getObject()->onDie( damageInfo );
  90. m_dieCalled = true;
  91. }
  92. }
  93. }
  94. //-------------------------------------------------------------------------------------------------
  95. //-------------------------------------------------------------------------------------------------
  96. void InactiveBody::attemptHealing( DamageInfo *damageInfo )
  97. {
  98. if( damageInfo == NULL )
  99. return;
  100. if( damageInfo->in.m_damageType != DAMAGE_HEALING )
  101. {
  102. // Healing and Damage are separate, so this shouldn't happen
  103. attemptDamage( damageInfo );
  104. return;
  105. }
  106. // Inactive bodies have no health so no damage can really be done
  107. damageInfo->out.m_actualDamageDealt = 0.0f;
  108. damageInfo->out.m_actualDamageClipped = 0.0f;
  109. damageInfo->out.m_noEffect = true;
  110. }
  111. //-------------------------------------------------------------------------------------------------
  112. //-------------------------------------------------------------------------------------------------
  113. void InactiveBody::internalChangeHealth( Real delta )
  114. {
  115. // Inactive bodies have no health to increase or decrease
  116. }
  117. //-------------------------------------------------------------------------------------------------
  118. //-------------------------------------------------------------------------------------------------
  119. Real InactiveBody::getHealth() const
  120. {
  121. // Inactive bodies have no health to get
  122. return 0.0f;
  123. } // end getHealth
  124. //-------------------------------------------------------------------------------------------------
  125. //-------------------------------------------------------------------------------------------------
  126. BodyDamageType InactiveBody::getDamageState() const
  127. {
  128. return BODY_PRISTINE;
  129. }
  130. // ------------------------------------------------------------------------------------------------
  131. // ------------------------------------------------------------------------------------------------
  132. void InactiveBody::setDamageState( BodyDamageType ) ///< control damage state directly. Will adjust hitpoints.
  133. {
  134. }
  135. // ------------------------------------------------------------------------------------------------
  136. /** CRC */
  137. // ------------------------------------------------------------------------------------------------
  138. void InactiveBody::crc( Xfer *xfer )
  139. {
  140. // extend base class
  141. BodyModule::crc( xfer );
  142. } // end crc
  143. // ------------------------------------------------------------------------------------------------
  144. /** Xfer method
  145. * Version Info:
  146. * 1: Initial version */
  147. // ------------------------------------------------------------------------------------------------
  148. void InactiveBody::xfer( Xfer *xfer )
  149. {
  150. // version
  151. XferVersion currentVersion = 1;
  152. XferVersion version = currentVersion;
  153. xfer->xferVersion( &version, currentVersion );
  154. // base class
  155. BodyModule::xfer( xfer );
  156. } // end xfer
  157. // ------------------------------------------------------------------------------------------------
  158. /** Load post process */
  159. // ------------------------------------------------------------------------------------------------
  160. void InactiveBody::loadPostProcess( void )
  161. {
  162. // extend base class
  163. BodyModule::loadPostProcess();
  164. } // end loadPostProcess