UndeadBody.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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: UndeadBody.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, June 2003
  25. // Desc: First death is intercepted and sets flags and setMaxHealth. Second death is handled normally.
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/Xfer.h"
  30. #include "GameLogic/Module/UndeadBody.h"
  31. #include "GameLogic/Object.h"
  32. #include "GameLogic/Module/SlowDeathBehavior.h"
  33. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  34. //-------------------------------------------------------------------------------------------------
  35. void UndeadBodyModuleData::buildFieldParse(MultiIniFieldParse& p)
  36. {
  37. ActiveBodyModuleData::buildFieldParse(p);
  38. static const FieldParse dataFieldParse[] =
  39. {
  40. { "SecondLifeMaxHealth", INI::parseReal, NULL, offsetof( UndeadBodyModuleData, m_secondLifeMaxHealth ) },
  41. { 0, 0, 0, 0 }
  42. };
  43. p.add(dataFieldParse);
  44. }
  45. //-------------------------------------------------------------------------------------------------
  46. //-------------------------------------------------------------------------------------------------
  47. UndeadBodyModuleData::UndeadBodyModuleData()
  48. {
  49. m_secondLifeMaxHealth = 1;
  50. }
  51. //-------------------------------------------------------------------------------------------------
  52. //-------------------------------------------------------------------------------------------------
  53. UndeadBody::UndeadBody( Thing *thing, const ModuleData* moduleData )
  54. : ActiveBody( thing, moduleData )
  55. {
  56. m_isSecondLife = FALSE;
  57. }
  58. //-------------------------------------------------------------------------------------------------
  59. //-------------------------------------------------------------------------------------------------
  60. UndeadBody::~UndeadBody( void )
  61. {
  62. }
  63. // ------------------------------------------------------------------------------------------------
  64. // ------------------------------------------------------------------------------------------------
  65. void UndeadBody::attemptDamage( DamageInfo *damageInfo )
  66. {
  67. // If we are on our first life, see if this damage will kill us. If it will, bind it to one hitpoint
  68. // remaining, then go ahead and take it.
  69. Bool shouldStartSecondLife = FALSE;
  70. if( damageInfo->in.m_damageType != DAMAGE_UNRESISTABLE
  71. && !m_isSecondLife
  72. && damageInfo->in.m_amount >= getHealth()
  73. && IsHealthDamagingDamage(damageInfo->in.m_damageType)
  74. )
  75. {
  76. damageInfo->in.m_amount = min( damageInfo->in.m_amount, getHealth() - 1 );
  77. shouldStartSecondLife = TRUE;
  78. }
  79. ActiveBody::attemptDamage(damageInfo);
  80. // After we take it (which allows for damaging special effects), we will do our modifications to the body module
  81. if( shouldStartSecondLife )
  82. startSecondLife(damageInfo);
  83. }
  84. // ------------------------------------------------------------------------------------------------
  85. // ------------------------------------------------------------------------------------------------
  86. void UndeadBody::startSecondLife(DamageInfo *damageInfo)
  87. {
  88. const UndeadBodyModuleData *data = getUndeadBodyModuleData();
  89. // Flag module as no longer intercepting damage
  90. m_isSecondLife = TRUE;
  91. // Modify ActiveBody's max health and initial health
  92. setMaxHealth(data->m_secondLifeMaxHealth, FULLY_HEAL);
  93. // Set Armor set flag to use second life armor
  94. setArmorSetFlag(ARMORSET_SECOND_LIFE);
  95. // Fire the Slow Death module. The fact that this is not the result of an onDie will cause the special behavior
  96. Int total = 0;
  97. for( BehaviorModule** update = getObject()->getBehaviorModules(); *update; ++update )
  98. {
  99. SlowDeathBehaviorInterface* sdu = (*update)->getSlowDeathBehaviorInterface();
  100. if (sdu != NULL && sdu->isDieApplicable(damageInfo) )
  101. {
  102. total += sdu->getProbabilityModifier( damageInfo );
  103. }
  104. }
  105. DEBUG_ASSERTCRASH(total > 0, ("Hmm, this is wrong"));
  106. // this returns a value from 1...total, inclusive
  107. Int roll = GameLogicRandomValue(1, total);
  108. for( update = getObject()->getBehaviorModules(); *update; ++update)
  109. {
  110. SlowDeathBehaviorInterface* sdu = (*update)->getSlowDeathBehaviorInterface();
  111. if (sdu != NULL && sdu->isDieApplicable(damageInfo))
  112. {
  113. roll -= sdu->getProbabilityModifier( damageInfo );
  114. if (roll <= 0)
  115. {
  116. sdu->beginSlowDeath(damageInfo);
  117. return;
  118. }
  119. }
  120. }
  121. }
  122. // ------------------------------------------------------------------------------------------------
  123. /** CRC */
  124. // ------------------------------------------------------------------------------------------------
  125. void UndeadBody::crc( Xfer *xfer )
  126. {
  127. // extend base class
  128. ActiveBody::crc( xfer );
  129. } // end crc
  130. // ------------------------------------------------------------------------------------------------
  131. /** Xfer method
  132. * Version Info:
  133. * 1: Initial version */
  134. // ------------------------------------------------------------------------------------------------
  135. void UndeadBody::xfer( Xfer *xfer )
  136. {
  137. // version
  138. XferVersion currentVersion = 1;
  139. XferVersion version = currentVersion;
  140. xfer->xferVersion( &version, currentVersion );
  141. // extend base class
  142. ActiveBody::xfer( xfer );
  143. xfer->xferBool(&m_isSecondLife);
  144. } // end xfer
  145. // ------------------------------------------------------------------------------------------------
  146. /** Load post process */
  147. // ------------------------------------------------------------------------------------------------
  148. void UndeadBody::loadPostProcess( void )
  149. {
  150. // extend base class
  151. ActiveBody::loadPostProcess();
  152. } // end loadPostProcess