LifetimeUpdate.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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: LifetimeUpdate.cpp ///////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, December 2001
  25. // Desc: Update that will count down a lifetime and destroy object when it reaches zero
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/RandomValue.h"
  30. #include "Common/Xfer.h"
  31. #include "GameLogic/GameLogic.h"
  32. #include "GameLogic/Module/LifetimeUpdate.h"
  33. #include "GameLogic/Object.h"
  34. #ifdef _INTERNAL
  35. // for occasional debugging...
  36. //#pragma optimize("", off)
  37. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  38. #endif
  39. //-------------------------------------------------------------------------------------------------
  40. //-------------------------------------------------------------------------------------------------
  41. LifetimeUpdate::LifetimeUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
  42. {
  43. const LifetimeUpdateModuleData* d = getLifetimeUpdateModuleData();
  44. // Added By Sadullah Nader
  45. // Initializations needed
  46. m_dieFrame = 0;
  47. //
  48. UnsignedInt delay;
  49. if( getObject()->isKindOf( KINDOF_HULK ) && TheGameLogic->getHulkMaxLifetimeOverride() != -1 )
  50. {
  51. delay = calcSleepDelay( TheGameLogic->getHulkMaxLifetimeOverride(), TheGameLogic->getHulkMaxLifetimeOverride() );
  52. }
  53. else
  54. {
  55. delay = calcSleepDelay(d->m_minFrames, d->m_maxFrames);
  56. }
  57. setWakeFrame(getObject(), UPDATE_SLEEP(delay));
  58. }
  59. //-------------------------------------------------------------------------------------------------
  60. //-------------------------------------------------------------------------------------------------
  61. LifetimeUpdate::~LifetimeUpdate( void )
  62. {
  63. }
  64. //-------------------------------------------------------------------------------------------------
  65. //-------------------------------------------------------------------------------------------------
  66. void LifetimeUpdate::setLifetimeRange( UnsignedInt minFrames, UnsignedInt maxFrames )
  67. {
  68. UnsignedInt delay = calcSleepDelay(minFrames, maxFrames);
  69. setWakeFrame(getObject(), UPDATE_SLEEP(delay));
  70. }
  71. //-------------------------------------------------------------------------------------------------
  72. //-------------------------------------------------------------------------------------------------
  73. UnsignedInt LifetimeUpdate::calcSleepDelay(UnsignedInt minFrames, UnsignedInt maxFrames)
  74. {
  75. UnsignedInt delay = GameLogicRandomValue( minFrames, maxFrames );
  76. if (delay < 1) delay = 1;
  77. m_dieFrame = TheGameLogic->getFrame() + delay;
  78. return delay;
  79. }
  80. //-------------------------------------------------------------------------------------------------
  81. //-------------------------------------------------------------------------------------------------
  82. UpdateSleepTime LifetimeUpdate::update( void )
  83. {
  84. // Kill (NOT destroy) if time is up
  85. getObject()->kill();
  86. return UPDATE_SLEEP_FOREVER;
  87. }
  88. // ------------------------------------------------------------------------------------------------
  89. /** CRC */
  90. // ------------------------------------------------------------------------------------------------
  91. void LifetimeUpdate::crc( Xfer *xfer )
  92. {
  93. // extend base class
  94. UpdateModule::crc( xfer );
  95. } // end crc
  96. // ------------------------------------------------------------------------------------------------
  97. /** Xfer method
  98. * Version Info:
  99. * 1: Initial version */
  100. // ------------------------------------------------------------------------------------------------
  101. void LifetimeUpdate::xfer( Xfer *xfer )
  102. {
  103. // version
  104. XferVersion currentVersion = 1;
  105. XferVersion version = currentVersion;
  106. xfer->xferVersion( &version, currentVersion );
  107. // extend base class
  108. UpdateModule::xfer( xfer );
  109. // die frame
  110. xfer->xferUnsignedInt( &m_dieFrame );
  111. } // end xfer
  112. // ------------------------------------------------------------------------------------------------
  113. /** Load post process */
  114. // ------------------------------------------------------------------------------------------------
  115. void LifetimeUpdate::loadPostProcess( void )
  116. {
  117. // extend base class
  118. UpdateModule::loadPostProcess();
  119. } // end loadPostProcess