ProneUpdate.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. ** Command & Conquer Generals(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: ProneUpdate.cpp //////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, March 2002
  25. // Desc: Update module to encapsulate what it means to be "prone"
  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 "GameClient/Drawable.h"
  31. #include "GameLogic/Damage.h"
  32. #include "GameLogic/Object.h"
  33. #include "GameLogic/Module/ProneUpdate.h"
  34. //-------------------------------------------------------------------------------------------------
  35. //-------------------------------------------------------------------------------------------------
  36. ProneUpdateModuleData::ProneUpdateModuleData() :
  37. m_damageToFramesRatio(1.0f)
  38. {
  39. }
  40. //-------------------------------------------------------------------------------------------------
  41. /*static*/ void ProneUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  42. {
  43. ModuleData::buildFieldParse(p);
  44. static const FieldParse dataFieldParse[] =
  45. {
  46. { "DamageToFramesRatio", INI::parseReal, NULL, offsetof(ProneUpdateModuleData, m_damageToFramesRatio) },
  47. { 0, 0, 0, 0 }
  48. };
  49. p.add(dataFieldParse);
  50. }
  51. //-------------------------------------------------------------------------------------------------
  52. ProneUpdate::ProneUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
  53. {
  54. m_proneFrames = 0;
  55. }
  56. //-------------------------------------------------------------------------------------------------
  57. //-------------------------------------------------------------------------------------------------
  58. ProneUpdate::~ProneUpdate( void )
  59. {
  60. }
  61. //-------------------------------------------------------------------------------------------------
  62. /** The update callback. */
  63. //-------------------------------------------------------------------------------------------------
  64. UpdateSleepTime ProneUpdate::update( void )
  65. {
  66. /// @todo srj use SLEEPY_UPDATE here
  67. if( m_proneFrames > 0 )
  68. {
  69. m_proneFrames--;
  70. if( m_proneFrames == 0 )
  71. stopProneEffects();
  72. }
  73. return UPDATE_SLEEP_NONE;
  74. }
  75. //-------------------------------------------------------------------------------------------------
  76. //-------------------------------------------------------------------------------------------------
  77. void ProneUpdate::goProne( const DamageInfo *damageInfo )
  78. {
  79. //add to the prone time
  80. Bool wasProne = (m_proneFrames > 0);
  81. Int damageTaken = damageInfo->out.m_actualDamageDealt;
  82. m_proneFrames += damageTaken * getProneUpdateModuleData()->m_damageToFramesRatio;
  83. if( !wasProne && (m_proneFrames > 0) )
  84. startProneEffects();
  85. }
  86. //-------------------------------------------------------------------------------------------------
  87. //-------------------------------------------------------------------------------------------------
  88. void ProneUpdate::startProneEffects()
  89. {
  90. Object *me = getObject();
  91. me->getDrawable()->setModelConditionState( MODELCONDITION_PRONE );
  92. me->setStatus( OBJECT_STATUS_NO_ATTACK );
  93. }
  94. //-------------------------------------------------------------------------------------------------
  95. //-------------------------------------------------------------------------------------------------
  96. void ProneUpdate::stopProneEffects()
  97. {
  98. Object *me = getObject();
  99. me->getDrawable()->clearModelConditionState( MODELCONDITION_PRONE );
  100. me->clearStatus( OBJECT_STATUS_NO_ATTACK );
  101. }
  102. // ------------------------------------------------------------------------------------------------
  103. /** CRC */
  104. // ------------------------------------------------------------------------------------------------
  105. void ProneUpdate::crc( Xfer *xfer )
  106. {
  107. // extend base class
  108. UpdateModule::crc( xfer );
  109. } // end crc
  110. // ------------------------------------------------------------------------------------------------
  111. /** Xfer method
  112. * Version Info:
  113. * 1: Initial version */
  114. // ------------------------------------------------------------------------------------------------
  115. void ProneUpdate::xfer( Xfer *xfer )
  116. {
  117. // version
  118. XferVersion currentVersion = 1;
  119. XferVersion version = currentVersion;
  120. xfer->xferVersion( &version, currentVersion );
  121. // extend base class
  122. UpdateModule::xfer( xfer );
  123. // prone frames
  124. xfer->xferInt( &m_proneFrames );
  125. } // end xfer
  126. // ------------------------------------------------------------------------------------------------
  127. /** Load post process */
  128. // ------------------------------------------------------------------------------------------------
  129. void ProneUpdate::loadPostProcess( void )
  130. {
  131. // extend base class
  132. UpdateModule::loadPostProcess();
  133. } // end loadPostProcess