RadarUpgrade.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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: RadarUpgrade.cpp /////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, March 2002
  25. // Desc: Radar upgrades
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/ModelState.h"
  30. #include "Common/Player.h"
  31. #include "Common/Xfer.h"
  32. #include "GameClient/Drawable.h"
  33. #include "GameLogic/Object.h"
  34. #include "GameLogic/Module/RadarUpdate.h"
  35. #include "GameLogic/Module/RadarUpgrade.h"
  36. //-------------------------------------------------------------------------------------------------
  37. //-------------------------------------------------------------------------------------------------
  38. void RadarUpgradeModuleData::buildFieldParse(MultiIniFieldParse& p)
  39. {
  40. UpgradeModuleData::buildFieldParse(p);
  41. static const FieldParse dataFieldParse[] =
  42. {
  43. { "DisableProof", INI::parseBool, NULL, offsetof( RadarUpgradeModuleData, m_isDisableProof ) },
  44. { 0, 0, 0, 0 }
  45. };
  46. p.add(dataFieldParse);
  47. }
  48. //-------------------------------------------------------------------------------------------------
  49. //-------------------------------------------------------------------------------------------------
  50. RadarUpgrade::RadarUpgrade( Thing *thing, const ModuleData* moduleData ) :
  51. UpgradeModule( thing, moduleData )
  52. {
  53. } // end RadarUpgrade
  54. //-------------------------------------------------------------------------------------------------
  55. //-------------------------------------------------------------------------------------------------
  56. RadarUpgrade::~RadarUpgrade( void )
  57. {
  58. } // end ~RadarUpgrade
  59. //-------------------------------------------------------------------------------------------------
  60. //-------------------------------------------------------------------------------------------------
  61. void RadarUpgrade::onDelete( void )
  62. {
  63. const RadarUpgradeModuleData *md = getRadarUpgradeModuleData();
  64. // if we haven't been upgraded there is nothing to clean up
  65. if( isAlreadyUpgraded() == FALSE )
  66. return;
  67. // If we're currently disabled, we shouldn't do anything, because we've already done it.
  68. if ( getObject()->isDisabled() )
  69. return;
  70. // remove the radar from the player
  71. Player *player = getObject()->getControllingPlayer();
  72. if( player )
  73. player->removeRadar( md->m_isDisableProof );
  74. // this upgrade module is now "not upgraded"
  75. setUpgradeExecuted(FALSE);
  76. } // end onDelete
  77. //-------------------------------------------------------------------------------------------------
  78. //-------------------------------------------------------------------------------------------------
  79. void RadarUpgrade::onCapture( Player *oldOwner, Player *newOwner )
  80. {
  81. const RadarUpgradeModuleData *md = getRadarUpgradeModuleData();
  82. // do nothing if we haven't upgraded yet
  83. if( isAlreadyUpgraded() == FALSE )
  84. return;
  85. // If we're currently disabled, we shouldn't do anything, because we've already done it.
  86. if ( getObject()->isDisabled() )
  87. return;
  88. // remove radar from old player and add to new player
  89. if( oldOwner )
  90. {
  91. oldOwner->removeRadar( md->m_isDisableProof );
  92. setUpgradeExecuted(FALSE);
  93. } // end if
  94. if( newOwner )
  95. {
  96. newOwner->addRadar( md->m_isDisableProof );
  97. setUpgradeExecuted(TRUE);
  98. } // end if
  99. } // end onCapture
  100. //-------------------------------------------------------------------------------------------------
  101. //-------------------------------------------------------------------------------------------------
  102. void RadarUpgrade::upgradeImplementation( void )
  103. {
  104. const RadarUpgradeModuleData *md = getRadarUpgradeModuleData();
  105. Player *player = getObject()->getControllingPlayer();
  106. // update the player with another radar facility
  107. player->addRadar( md->m_isDisableProof );
  108. // find the radar update module of this object
  109. NameKeyType radarUpdateKey = NAMEKEY( "RadarUpdate" );
  110. RadarUpdate *radarUpdate = (RadarUpdate *)getObject()->findUpdateModule( radarUpdateKey );
  111. if( radarUpdate )
  112. radarUpdate->extendRadar();
  113. } // end upgradeImplementation
  114. // ------------------------------------------------------------------------------------------------
  115. /** CRC */
  116. // ------------------------------------------------------------------------------------------------
  117. void RadarUpgrade::crc( Xfer *xfer )
  118. {
  119. // extend base class
  120. UpgradeModule::crc( xfer );
  121. } // end crc
  122. // ------------------------------------------------------------------------------------------------
  123. /** Xfer method
  124. * Version Info:
  125. * 1: Initial version */
  126. // ------------------------------------------------------------------------------------------------
  127. void RadarUpgrade::xfer( Xfer *xfer )
  128. {
  129. // version
  130. XferVersion currentVersion = 1;
  131. XferVersion version = currentVersion;
  132. xfer->xferVersion( &version, currentVersion );
  133. // extend base class
  134. UpgradeModule::xfer( xfer );
  135. } // end xfer
  136. // ------------------------------------------------------------------------------------------------
  137. /** Load post process */
  138. // ------------------------------------------------------------------------------------------------
  139. void RadarUpgrade::loadPostProcess( void )
  140. {
  141. // extend base class
  142. UpgradeModule::loadPostProcess();
  143. } // end loadPostProcess