DeletionUpdate.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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: DeletionUpdate.cpp /////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, August 2002
  25. // Desc: Update that will count down a lifetime and destroy object when it reaches zero
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h"
  29. #include "Common/RandomValue.h"
  30. #include "Common/Xfer.h"
  31. #include "GameLogic/GameLogic.h"
  32. #include "GameLogic/Object.h"
  33. #include "GameLogic/Module/DeletionUpdate.h"
  34. //-------------------------------------------------------------------------------------------------
  35. //-------------------------------------------------------------------------------------------------
  36. DeletionUpdate::DeletionUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
  37. {
  38. m_dieFrame = 0;
  39. const DeletionUpdateModuleData* d = getDeletionUpdateModuleData();
  40. UnsignedInt delay = calcSleepDelay(d->m_minFrames, d->m_maxFrames);
  41. setWakeFrame(getObject(), UPDATE_SLEEP(delay));
  42. }
  43. //-------------------------------------------------------------------------------------------------
  44. //-------------------------------------------------------------------------------------------------
  45. DeletionUpdate::~DeletionUpdate( void )
  46. {
  47. }
  48. //#define CRISS_CROSS_GEOMETRY
  49. //-------------------------------------------------------------------------------------------------
  50. //-------------------------------------------------------------------------------------------------
  51. void DeletionUpdate::setLifetimeRange( UnsignedInt minFrames, UnsignedInt maxFrames )
  52. {
  53. #if defined _DEBUG && defined CRISS_CROSS_GEOMETRY
  54. setWakeFrame(getObject(), UPDATE_SLEEP(2));
  55. #else
  56. UnsignedInt delay = calcSleepDelay(minFrames, maxFrames);
  57. setWakeFrame(getObject(), UPDATE_SLEEP(delay));
  58. #endif
  59. }
  60. //-------------------------------------------------------------------------------------------------
  61. //-------------------------------------------------------------------------------------------------
  62. UnsignedInt DeletionUpdate::calcSleepDelay(UnsignedInt minFrames, UnsignedInt maxFrames)
  63. {
  64. UnsignedInt delay = GameLogicRandomValue( minFrames, maxFrames );
  65. if (delay < 1) delay = 1;
  66. m_dieFrame = TheGameLogic->getFrame() + delay;
  67. return delay;
  68. }
  69. //-------------------------------------------------------------------------------------------------
  70. //-------------------------------------------------------------------------------------------------
  71. UpdateSleepTime DeletionUpdate::update( void )
  72. {
  73. // Destroy (NOT kill) if time is up
  74. #if defined _DEBUG && defined CRISS_CROSS_GEOMETRY
  75. Object *obj = getObject();
  76. if (obj)
  77. {
  78. GeometryInfo geom = geom=obj->getGeometryInfo();
  79. geom.setMajorRadius(obj->getGeometryInfo().getMinorRadius());// CRIS
  80. geom.setMinorRadius(obj->getGeometryInfo().getMajorRadius());// CROSS
  81. obj->setGeometryInfo(geom);
  82. }
  83. if (TheGameLogic->getFrame() > m_dieFrame)
  84. {
  85. TheGameLogic->destroyObject( getObject() );
  86. return UPDATE_SLEEP_FOREVER;
  87. }
  88. return UPDATE_SLEEP(2);
  89. #else
  90. TheGameLogic->destroyObject( getObject() );
  91. return UPDATE_SLEEP_FOREVER;
  92. #endif
  93. }
  94. // ------------------------------------------------------------------------------------------------
  95. /** CRC */
  96. // ------------------------------------------------------------------------------------------------
  97. void DeletionUpdate::crc( Xfer *xfer )
  98. {
  99. // extend base class
  100. UpdateModule::crc( xfer );
  101. } // end crc
  102. // ------------------------------------------------------------------------------------------------
  103. /** Xfer method
  104. * Version Info:
  105. * 1: Initial version */
  106. // ------------------------------------------------------------------------------------------------
  107. void DeletionUpdate::xfer( Xfer *xfer )
  108. {
  109. // version
  110. XferVersion currentVersion = 1;
  111. XferVersion version = currentVersion;
  112. xfer->xferVersion( &version, currentVersion );
  113. // extend base class
  114. UpdateModule::xfer( xfer );
  115. // die frame
  116. xfer->xferUnsignedInt( &m_dieFrame );
  117. } // end xfer
  118. // ------------------------------------------------------------------------------------------------
  119. /** Load post process */
  120. // ------------------------------------------------------------------------------------------------
  121. void DeletionUpdate::loadPostProcess( void )
  122. {
  123. // extend base class
  124. UpdateModule::loadPostProcess();
  125. } // end loadPostProcess