SpyVisionUpdate.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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: SpyVisionUpdate.cpp /////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, September 2002
  25. // Desc: Special Power will spy on the vision of all enemy players.
  26. // Putting a SpecialPower in a behavior takes a big huge amount of code duplication and
  27. // has no precedent.
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  30. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  31. #include "Common/Player.h"
  32. #include "Common/PlayerList.h"
  33. #include "Common/Xfer.h"
  34. #include "GameLogic/GameLogic.h"
  35. #include "GameLogic/Module/SpyVisionUpdate.h"
  36. //-------------------------------------------------------------------------------------------------
  37. //-------------------------------------------------------------------------------------------------
  38. void SpyVisionUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  39. {
  40. UpdateModuleData::buildFieldParse(p);
  41. static const FieldParse dataFieldParse[] =
  42. {
  43. { 0, 0, 0, 0 }
  44. };
  45. p.add(dataFieldParse);
  46. }
  47. //-------------------------------------------------------------------------------------------------
  48. //-------------------------------------------------------------------------------------------------
  49. SpyVisionUpdate::SpyVisionUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
  50. {
  51. m_deactivateFrame = 0;
  52. setWakeFrame(getObject(), UPDATE_SLEEP_FOREVER);
  53. }
  54. //-------------------------------------------------------------------------------------------------
  55. //-------------------------------------------------------------------------------------------------
  56. SpyVisionUpdate::~SpyVisionUpdate( void )
  57. {
  58. }
  59. //-------------------------------------------------------------------------------------------------
  60. //-------------------------------------------------------------------------------------------------
  61. void SpyVisionUpdate::activateSpyVision( UnsignedInt duration )
  62. {
  63. UnsignedInt now = TheGameLogic->getFrame();
  64. m_deactivateFrame = now + duration;
  65. doActivationWork( TRUE );
  66. setWakeFrame( getObject(), UPDATE_SLEEP(duration) );
  67. }
  68. //-------------------------------------------------------------------------------------------------
  69. //-------------------------------------------------------------------------------------------------
  70. UpdateSleepTime SpyVisionUpdate::update( void )
  71. {
  72. if( m_deactivateFrame && (m_deactivateFrame <= TheGameLogic->getFrame()) )
  73. {
  74. // Turn off SpyVision.
  75. doActivationWork( FALSE );
  76. m_deactivateFrame = 0;
  77. }
  78. return UPDATE_SLEEP_FOREVER;
  79. }
  80. void SpyVisionUpdate::doActivationWork( Bool setting )
  81. {
  82. Player *ourPlayer = getObject()->getControllingPlayer();
  83. if( ourPlayer == NULL || ThePlayerList == NULL )
  84. return;
  85. for (Int i=0; i < ThePlayerList->getPlayerCount(); ++i)
  86. {
  87. Player *player = ThePlayerList->getNthPlayer(i);
  88. if( ourPlayer->getRelationship(player->getDefaultTeam()) == ENEMIES )
  89. {
  90. player->setUnitsVisionSpied( setting, ourPlayer->getPlayerIndex() );
  91. }
  92. }
  93. }
  94. void SpyVisionUpdate::onDelete( void )
  95. {
  96. // If I was left on at the time of death, then turn me off.
  97. if( m_deactivateFrame )
  98. doActivationWork( FALSE );
  99. }
  100. // ------------------------------------------------------------------------------------------------
  101. /** CRC */
  102. // ------------------------------------------------------------------------------------------------
  103. void SpyVisionUpdate::crc( Xfer *xfer )
  104. {
  105. // extend base class
  106. UpdateModule::crc( xfer );
  107. } // end crc
  108. // ------------------------------------------------------------------------------------------------
  109. /** Xfer method
  110. * Version Info:
  111. * 1: Initial version */
  112. // ------------------------------------------------------------------------------------------------
  113. void SpyVisionUpdate::xfer( Xfer *xfer )
  114. {
  115. // version
  116. XferVersion currentVersion = 1;
  117. XferVersion version = currentVersion;
  118. xfer->xferVersion( &version, currentVersion );
  119. // extend base class
  120. UpdateModule::xfer( xfer );
  121. // deactivate frame
  122. xfer->xferUnsignedInt( &m_deactivateFrame );
  123. } // end xfer
  124. // ------------------------------------------------------------------------------------------------
  125. /** Load post process */
  126. // ------------------------------------------------------------------------------------------------
  127. void SpyVisionUpdate::loadPostProcess( void )
  128. {
  129. // extend base class
  130. UpdateModule::loadPostProcess();
  131. } // end loadPostProcess