RadarUpdate.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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: RadarUpdate.cpp //////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, April 2002
  25. // Desc: Updating a radar on an object
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/ModelState.h"
  30. #include "Common/Xfer.h"
  31. #include "GameClient/Drawable.h"
  32. #include "GameLogic/GameLogic.h"
  33. #include "GameLogic/Object.h"
  34. #include "GameLogic/Module/RadarUpdate.h"
  35. //-------------------------------------------------------------------------------------------------
  36. //-------------------------------------------------------------------------------------------------
  37. RadarUpdateModuleData::RadarUpdateModuleData( void )
  38. {
  39. m_radarExtendTime = 0.0f;
  40. } // end RadarUpdateModuleData
  41. ///////////////////////////////////////////////////////////////////////////////////////////////////
  42. ///////////////////////////////////////////////////////////////////////////////////////////////////
  43. ///////////////////////////////////////////////////////////////////////////////////////////////////
  44. //-------------------------------------------------------------------------------------------------
  45. //-------------------------------------------------------------------------------------------------
  46. RadarUpdate::RadarUpdate( Thing *thing, const ModuleData *moduleData )
  47. : UpdateModule( thing, moduleData )
  48. {
  49. m_radarActive = FALSE;
  50. m_extendDoneFrame = 0;
  51. m_extendComplete = FALSE;
  52. } // end RadarUpdate
  53. //-------------------------------------------------------------------------------------------------
  54. //-------------------------------------------------------------------------------------------------
  55. RadarUpdate::~RadarUpdate( void )
  56. {
  57. } // end RadarUpdate
  58. //-------------------------------------------------------------------------------------------------
  59. //-------------------------------------------------------------------------------------------------
  60. void RadarUpdate::extendRadar( void )
  61. {
  62. const RadarUpdateModuleData *modData = getRadarUpdateModuleData();
  63. // set the model condition for radar extension
  64. Drawable *draw = getObject()->getDrawable();
  65. if( draw )
  66. draw->setModelConditionState( MODELCONDITION_RADAR_EXTENDING );
  67. // mark the frame that the extension will be done on
  68. m_extendDoneFrame = TheGameLogic->getFrame() + modData->m_radarExtendTime;
  69. //Change this to make the radar active after extension...
  70. m_radarActive = true;
  71. } // end extendRadar
  72. //-------------------------------------------------------------------------------------------------
  73. //-------------------------------------------------------------------------------------------------
  74. UpdateSleepTime RadarUpdate::update( void )
  75. {
  76. /// @todo srj use SLEEPY_UPDATE here
  77. // if no extend frame nothing to do
  78. if( m_extendDoneFrame == 0 )
  79. return UPDATE_SLEEP_NONE;
  80. // check to see if our extension is already done
  81. if( m_extendComplete == TRUE )
  82. return UPDATE_SLEEP_NONE;
  83. // see if it's time to stop the extension
  84. if( TheGameLogic->getFrame() > m_extendDoneFrame )
  85. {
  86. // mark extend as done
  87. m_extendComplete = TRUE;
  88. m_extendDoneFrame = 0; // just to be clean
  89. // remove the extending condition and set the extened condition
  90. Drawable *draw = getObject()->getDrawable();
  91. if( draw )
  92. draw->clearAndSetModelConditionState( MODELCONDITION_RADAR_EXTENDING,
  93. MODELCONDITION_RADAR_UPGRADED );
  94. } // end if
  95. return UPDATE_SLEEP_NONE;
  96. } // end update
  97. // ------------------------------------------------------------------------------------------------
  98. /** CRC */
  99. // ------------------------------------------------------------------------------------------------
  100. void RadarUpdate::crc( Xfer *xfer )
  101. {
  102. // extend base class
  103. UpdateModule::crc( xfer );
  104. } // end crc
  105. // ------------------------------------------------------------------------------------------------
  106. /** Xfer method
  107. * Version Info:
  108. * 1: Initial version */
  109. // ------------------------------------------------------------------------------------------------
  110. void RadarUpdate::xfer( Xfer *xfer )
  111. {
  112. // version
  113. XferVersion currentVersion = 1;
  114. XferVersion version = currentVersion;
  115. xfer->xferVersion( &version, currentVersion );
  116. // extend base class
  117. UpdateModule::xfer( xfer );
  118. // extend done frame
  119. xfer->xferUnsignedInt( &m_extendDoneFrame );
  120. // extend complete
  121. xfer->xferBool( &m_extendComplete );
  122. // radar active
  123. xfer->xferBool( &m_radarActive );
  124. } // end xfer
  125. // ------------------------------------------------------------------------------------------------
  126. /** Load post process */
  127. // ------------------------------------------------------------------------------------------------
  128. void RadarUpdate::loadPostProcess( void )
  129. {
  130. // extend base class
  131. UpdateModule::loadPostProcess();
  132. } // end loadPostProcess