BeaconClientUpdate.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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: BeaconClientUpdate.cpp //////////////////////////////////////////////////////////////////
  24. // Author: Matthew D. Campbell, August 2002
  25. // Desc: Beacon client update module
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
  29. #include "GameClient/Drawable.h"
  30. #include "GameClient/ParticleSys.h"
  31. #include "GameClient/Module/BeaconClientUpdate.h"
  32. #include "Common/Player.h"
  33. #include "Common/PlayerList.h"
  34. #include "Common/Radar.h"
  35. #include "Common/Xfer.h"
  36. #include "GameLogic/GameLogic.h"
  37. //-------------------------------------------------------------------------------------------------
  38. BeaconClientUpdateModuleData::BeaconClientUpdateModuleData() :
  39. m_framesBetweenRadarPulses(30),
  40. m_radarPulseDuration(15)
  41. {
  42. }
  43. //-------------------------------------------------------------------------------------------------
  44. BeaconClientUpdateModuleData::~BeaconClientUpdateModuleData()
  45. {
  46. }
  47. //-------------------------------------------------------------------------------------------------
  48. void BeaconClientUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  49. {
  50. ClientUpdateModuleData::buildFieldParse(p);
  51. static const FieldParse dataFieldParse[] =
  52. {
  53. { "RadarPulseFrequency", INI::parseDurationUnsignedInt, NULL, offsetof(BeaconClientUpdateModuleData, m_framesBetweenRadarPulses) },
  54. { "RadarPulseDuration", INI::parseDurationUnsignedInt, NULL, offsetof(BeaconClientUpdateModuleData, m_radarPulseDuration) },
  55. { 0, 0, 0, 0 }
  56. };
  57. p.add(dataFieldParse);
  58. }
  59. //-------------------------------------------------------------------------------------------------
  60. //-------------------------------------------------------------------------------------------------
  61. BeaconClientUpdate::BeaconClientUpdate( Thing *thing, const ModuleData* moduleData ) :
  62. ClientUpdateModule( thing, moduleData ),
  63. m_particleSystemID(INVALID_PARTICLE_SYSTEM_ID),
  64. m_lastRadarPulse(TheGameLogic->getFrame())
  65. {
  66. }
  67. //-------------------------------------------------------------------------------------------------
  68. //-------------------------------------------------------------------------------------------------
  69. BeaconClientUpdate::~BeaconClientUpdate( void )
  70. {
  71. }
  72. //-------------------------------------------------------------------------------------------------
  73. //-------------------------------------------------------------------------------------------------
  74. static ParticleSystem* createParticleSystem( Drawable *draw )
  75. {
  76. ParticleSystem *system = NULL;
  77. if (draw)
  78. {
  79. Object *obj = draw->getObject();
  80. if (obj)
  81. {
  82. AsciiString templateName;
  83. templateName.format("BeaconSmoke%6.6X", (0xffffff & obj->getIndicatorColor()));
  84. const ParticleSystemTemplate *particleTemplate = TheParticleSystemManager->findTemplate( templateName );
  85. DEBUG_ASSERTCRASH(particleTemplate, ("Could not find particle system %s\n", templateName.str()));
  86. if (particleTemplate)
  87. {
  88. system = TheParticleSystemManager->createParticleSystem( particleTemplate );
  89. if (system)
  90. system->attachToDrawable( draw );
  91. }
  92. else// This is a failsafe... if someone has monkeyed with the particle system names, or the MP house colors
  93. {// THis this will whip up a new particle system to match the house color provided
  94. templateName.format("BeaconSmokeFFFFFF");
  95. const ParticleSystemTemplate *failsafeTemplate = TheParticleSystemManager->findTemplate( templateName );
  96. DEBUG_ASSERTCRASH(failsafeTemplate, ("Doh, this is bad \n I Could not even find the white particle system to make a failsafe system out of."));
  97. if (failsafeTemplate)
  98. {
  99. system = TheParticleSystemManager->createParticleSystem( failsafeTemplate );
  100. if (system)
  101. {
  102. system->attachToDrawable( draw );
  103. system->tintAllColors( obj->getIndicatorColor() );
  104. }
  105. }
  106. }
  107. }
  108. }
  109. return system;
  110. }
  111. //-------------------------------------------------------------------------------------------------
  112. //-------------------------------------------------------------------------------------------------
  113. void BeaconClientUpdate::hideBeacon( void )
  114. {
  115. Drawable *draw = getDrawable();
  116. if (draw)
  117. {
  118. draw->setDrawableHidden( true );
  119. draw->setShadowsEnabled( false );
  120. }
  121. ParticleSystem *system;
  122. if (draw && m_particleSystemID == INVALID_PARTICLE_SYSTEM_ID)
  123. {
  124. system = createParticleSystem( draw );
  125. if (system)
  126. m_particleSystemID = system->getSystemID();
  127. }
  128. // clean up particle system
  129. if (m_particleSystemID != INVALID_PARTICLE_SYSTEM_ID)
  130. {
  131. ParticleSystem *system = TheParticleSystemManager->findParticleSystem( m_particleSystemID );
  132. if( system )
  133. system->stop();
  134. } // end if
  135. // DEBUG_LOG(("in hideBeacon(): draw=%d, m_particleSystemID=%d\n", draw, m_particleSystemID));
  136. }
  137. //-------------------------------------------------------------------------------------------------
  138. /** The client update callback. */
  139. //-------------------------------------------------------------------------------------------------
  140. void BeaconClientUpdate::clientUpdate( void )
  141. {
  142. Drawable *draw = getDrawable();
  143. if (!draw)
  144. return;
  145. if (m_particleSystemID == INVALID_PARTICLE_SYSTEM_ID)
  146. {
  147. ParticleSystem *system = createParticleSystem( draw );
  148. if( system )
  149. m_particleSystemID = system->getSystemID();
  150. }
  151. if (!draw->isDrawableEffectivelyHidden())
  152. {
  153. BeaconClientUpdateModuleData *moduleData = (BeaconClientUpdateModuleData *)getModuleData();
  154. if (TheGameLogic->getFrame() > m_lastRadarPulse + moduleData->m_framesBetweenRadarPulses)
  155. {
  156. TheRadar->createEvent( draw->getPosition(), RADAR_EVENT_BEACON_PULSE, moduleData->m_radarPulseDuration * SECONDS_PER_LOGICFRAME_REAL );
  157. m_lastRadarPulse = TheGameLogic->getFrame();
  158. }
  159. }
  160. }
  161. // ------------------------------------------------------------------------------------------------
  162. /** CRC */
  163. // ------------------------------------------------------------------------------------------------
  164. void BeaconClientUpdate::crc( Xfer *xfer )
  165. {
  166. // extend base class
  167. ClientUpdateModule::crc( xfer );
  168. } // end crc
  169. // ------------------------------------------------------------------------------------------------
  170. /** Xfer method
  171. * Version Info:
  172. * 1: Initial version */
  173. // ------------------------------------------------------------------------------------------------
  174. void BeaconClientUpdate::xfer( Xfer *xfer )
  175. {
  176. // version
  177. XferVersion currentVersion = 1;
  178. XferVersion version = currentVersion;
  179. xfer->xferVersion( &version, currentVersion );
  180. // extend base class
  181. ClientUpdateModule::xfer( xfer );
  182. // particle system ID
  183. xfer->xferUser( &m_particleSystemID, sizeof( ParticleSystemID ) );
  184. // last radar pulse
  185. xfer->xferUnsignedInt( &m_lastRadarPulse );
  186. } // end xfer
  187. // ------------------------------------------------------------------------------------------------
  188. /** Load post process */
  189. // ------------------------------------------------------------------------------------------------
  190. void BeaconClientUpdate::loadPostProcess( void )
  191. {
  192. // extend base class
  193. ClientUpdateModule::loadPostProcess();
  194. } // end loadPostProcess