SpyVisionSpecialPower.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: SpyVisionSpecialPower.cpp /////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, September 2002
  25. // Desc: Special Power will spy on the vision of all enemy players.
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/Xfer.h"
  30. #include "GameLogic/Object.h"
  31. #include "GameLogic/Module/ContainModule.h"
  32. #include "GameLogic/Module/SpyVisionSpecialPower.h"
  33. #include "GameLogic/Module/SpyVisionUpdate.h"
  34. // ------------------------------------------------------------------------------------------------
  35. // ------------------------------------------------------------------------------------------------
  36. SpyVisionSpecialPowerModuleData::SpyVisionSpecialPowerModuleData( void )
  37. {
  38. m_baseDurationInFrames = 0;
  39. m_bonusDurationPerCapturedInFrames = 0;
  40. m_maxDurationInFrames = 0;
  41. }
  42. // ------------------------------------------------------------------------------------------------
  43. // ------------------------------------------------------------------------------------------------
  44. void SpyVisionSpecialPowerModuleData::buildFieldParse( MultiIniFieldParse &p )
  45. {
  46. SpecialPowerModuleData::buildFieldParse( p );
  47. static const FieldParse dataFieldParse[] =
  48. {
  49. { "BaseDuration", INI::parseDurationUnsignedInt, NULL, offsetof( SpyVisionSpecialPowerModuleData, m_baseDurationInFrames ) },
  50. { "BonusDurationPerCaptured", INI::parseDurationUnsignedInt, NULL, offsetof( SpyVisionSpecialPowerModuleData, m_bonusDurationPerCapturedInFrames ) },
  51. { "MaxDuration", INI::parseDurationUnsignedInt, NULL, offsetof( SpyVisionSpecialPowerModuleData, m_maxDurationInFrames ) },
  52. { 0, 0, 0, 0 }
  53. };
  54. p.add( dataFieldParse );
  55. } // end buildFieldParse
  56. ///////////////////////////////////////////////////////////////////////////////////////////////////
  57. ///////////////////////////////////////////////////////////////////////////////////////////////////
  58. ///////////////////////////////////////////////////////////////////////////////////////////////////
  59. // ------------------------------------------------------------------------------------------------
  60. // ------------------------------------------------------------------------------------------------
  61. SpyVisionSpecialPower::SpyVisionSpecialPower( Thing *thing, const ModuleData *moduleData )
  62. : SpecialPowerModule( thing, moduleData )
  63. {
  64. }
  65. // ------------------------------------------------------------------------------------------------
  66. // ------------------------------------------------------------------------------------------------
  67. SpyVisionSpecialPower::~SpyVisionSpecialPower( void )
  68. {
  69. }
  70. // ------------------------------------------------------------------------------------------------
  71. // ------------------------------------------------------------------------------------------------
  72. void SpyVisionSpecialPower::doSpecialPower( UnsignedInt commandOptions )
  73. {
  74. if (getObject()->isDisabled())
  75. return;
  76. // call the base class action cause we are *EXTENDING* functionality
  77. SpecialPowerModule::doSpecialPower( commandOptions );
  78. // get the source of this power
  79. Object *source = getObject();
  80. // get module data
  81. const SpyVisionSpecialPowerModuleData *modData = getSpyVisionSpecialPowerModuleData();
  82. //
  83. // the SpyVision special power increases in range and duration of effect the more
  84. // units we have captured within us
  85. //
  86. UnsignedInt duration = modData->m_baseDurationInFrames;
  87. ContainModuleInterface *contain = source->getContain();
  88. if( contain )
  89. {
  90. // for every captured unit we get a bonus
  91. duration += contain->getContainCount() * modData->m_bonusDurationPerCapturedInFrames;
  92. // cap at the max
  93. if( duration > modData->m_maxDurationInFrames )
  94. duration = modData->m_maxDurationInFrames;
  95. }
  96. static const NameKeyType key_SpyVisionUpdate = NAMEKEY( "SpyVisionUpdate" );
  97. SpyVisionUpdate *update = (SpyVisionUpdate*)source->findUpdateModule( key_SpyVisionUpdate );
  98. if( !update )
  99. {
  100. return;
  101. }
  102. update->activateSpyVision( duration );
  103. }
  104. // ------------------------------------------------------------------------------------------------
  105. /** CRC */
  106. // ------------------------------------------------------------------------------------------------
  107. void SpyVisionSpecialPower::crc( Xfer *xfer )
  108. {
  109. // extend base class
  110. SpecialPowerModule::crc( xfer );
  111. } // end crc
  112. // ------------------------------------------------------------------------------------------------
  113. /** Xfer method
  114. * Version Info:
  115. * 1: Initial version */
  116. // ------------------------------------------------------------------------------------------------
  117. void SpyVisionSpecialPower::xfer( Xfer *xfer )
  118. {
  119. // version
  120. XferVersion currentVersion = 1;
  121. XferVersion version = currentVersion;
  122. xfer->xferVersion( &version, currentVersion );
  123. // extend base class
  124. SpecialPowerModule::xfer( xfer );
  125. } // end xfer
  126. // ------------------------------------------------------------------------------------------------
  127. /** Load post process */
  128. // ------------------------------------------------------------------------------------------------
  129. void SpyVisionSpecialPower::loadPostProcess( void )
  130. {
  131. // extend base class
  132. SpecialPowerModule::loadPostProcess();
  133. } // end loadPostProcess