PowerPlantUpgrade.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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: PowerPlantUpgrade.cpp /////////////////////////////////////////////////////////////////////////////
  24. // Author: Amit Kumar, August 2002
  25. // Desc: Power plant 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 "GameClient/InGameUI.h"
  34. #include "GameLogic/Object.h"
  35. #include "GameLogic/Module/PowerPlantUpdate.h"
  36. #include "GameLogic/Module/PowerPlantUpgrade.h"
  37. //-------------------------------------------------------------------------------------------------
  38. //-------------------------------------------------------------------------------------------------
  39. PowerPlantUpgrade::PowerPlantUpgrade( Thing *thing, const ModuleData* moduleData ) :
  40. UpgradeModule( thing, moduleData )
  41. {
  42. } // end PowerPlantUpgrade
  43. //-------------------------------------------------------------------------------------------------
  44. //-------------------------------------------------------------------------------------------------
  45. PowerPlantUpgrade::~PowerPlantUpgrade( void )
  46. {
  47. } // end ~PowerPlantUpgrade
  48. //-------------------------------------------------------------------------------------------------
  49. //-------------------------------------------------------------------------------------------------
  50. void PowerPlantUpgrade::onDelete( void )
  51. {
  52. // if we haven't been upgraded there is nothing to clean up
  53. if( isAlreadyUpgraded() == FALSE )
  54. return;
  55. // remove the power bonus from the player
  56. Player *player = getObject()->getControllingPlayer();
  57. if( player )
  58. player->removePowerBonus( getObject() );
  59. // this upgrade module is now "not upgraded"
  60. setUpgradeExecuted(FALSE);
  61. } // end onDelete
  62. //-------------------------------------------------------------------------------------------------
  63. //-------------------------------------------------------------------------------------------------
  64. void PowerPlantUpgrade::onCapture( Player *oldOwner, Player *newOwner )
  65. {
  66. // do nothing if we haven't upgraded yet
  67. if( isAlreadyUpgraded() == FALSE )
  68. return;
  69. if (getObject()->isDisabled())
  70. return;
  71. // remove power bonus from old owner
  72. if( oldOwner )
  73. {
  74. oldOwner->removePowerBonus( getObject() );
  75. setUpgradeExecuted(FALSE);
  76. }
  77. // add power bonus to the new owner
  78. if( newOwner )
  79. {
  80. newOwner->addPowerBonus( getObject() );
  81. setUpgradeExecuted(TRUE);
  82. }
  83. } // end onCapture
  84. //-------------------------------------------------------------------------------------------------
  85. //-------------------------------------------------------------------------------------------------
  86. void PowerPlantUpgrade::upgradeImplementation( void )
  87. {
  88. Player *player = getObject()->getControllingPlayer();
  89. // add the new power production to the object
  90. if( player )
  91. player->addPowerBonus(getObject());
  92. PowerPlantUpdateInterface *ppui;
  93. for( BehaviorModule **umi = getObject()->getBehaviorModules(); *umi; ++umi)
  94. {
  95. ppui = (*umi)->getPowerPlantUpdateInterface();
  96. if( ppui )
  97. ppui->extendRods(TRUE);
  98. }
  99. } // end upgradeImplementation
  100. // ------------------------------------------------------------------------------------------------
  101. /** CRC */
  102. // ------------------------------------------------------------------------------------------------
  103. void PowerPlantUpgrade::crc( Xfer *xfer )
  104. {
  105. // extend base class
  106. UpgradeModule::crc( xfer );
  107. } // end crc
  108. // ------------------------------------------------------------------------------------------------
  109. /** Xfer method
  110. * Version Info:
  111. * 1: Initial version */
  112. // ------------------------------------------------------------------------------------------------
  113. void PowerPlantUpgrade::xfer( Xfer *xfer )
  114. {
  115. // version
  116. XferVersion currentVersion = 1;
  117. XferVersion version = currentVersion;
  118. xfer->xferVersion( &version, currentVersion );
  119. // extend base class
  120. UpgradeModule::xfer( xfer );
  121. } // end xfer
  122. // ------------------------------------------------------------------------------------------------
  123. /** Load post process */
  124. // ------------------------------------------------------------------------------------------------
  125. void PowerPlantUpgrade::loadPostProcess( void )
  126. {
  127. // extend base class
  128. UpgradeModule::loadPostProcess();
  129. // Most upgrade modules have state change effects that are themselves saved. This one is a fire and forget.
  130. // So we need to re-fire on load if we are turned on.
  131. if( isAlreadyUpgraded() )
  132. {
  133. Player *player = getObject()->getControllingPlayer();
  134. // add the new power production to the object
  135. if( player )
  136. player->addPowerBonus(getObject());
  137. }
  138. } // end loadPostProcess