CostModifierUpgrade.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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: CostModifierUpgrade.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Aug 2002
  34. //
  35. // Filename: CostModifierUpgrade.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: Upgrade that modifies the cost by a certain percentage
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. //-----------------------------------------------------------------------------
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. // USER INCLUDES //////////////////////////////////////////////////////////////
  48. //-----------------------------------------------------------------------------
  49. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  50. #include "Common/player.h"
  51. #include "Common/Xfer.h"
  52. #include "GameLogic/Module/CostModifierUpgrade.h"
  53. #include "GameLogic/Object.h"
  54. #include "Common/BitFlagsIO.h"
  55. //-----------------------------------------------------------------------------
  56. // DEFINES ////////////////////////////////////////////////////////////////////
  57. //-----------------------------------------------------------------------------
  58. //-----------------------------------------------------------------------------
  59. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  60. //-----------------------------------------------------------------------------
  61. //-----------------------------------------------------------------------------
  62. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  63. //-----------------------------------------------------------------------------
  64. //-------------------------------------------------------------------------------------------------
  65. //-------------------------------------------------------------------------------------------------
  66. CostModifierUpgradeModuleData::CostModifierUpgradeModuleData( void )
  67. {
  68. m_kindOf = KINDOFMASK_NONE;
  69. m_percentage = 0;
  70. } // end CostModifierUpgradeModuleData
  71. //-------------------------------------------------------------------------------------------------
  72. //-------------------------------------------------------------------------------------------------
  73. /* static */ void CostModifierUpgradeModuleData::buildFieldParse(MultiIniFieldParse& p)
  74. {
  75. UpgradeModuleData::buildFieldParse( p );
  76. static const FieldParse dataFieldParse[] =
  77. {
  78. { "EffectKindOf", KindOfMaskType::parseFromINI, NULL, offsetof( CostModifierUpgradeModuleData, m_kindOf ) },
  79. { "Percentage", INI::parsePercentToReal, NULL, offsetof( CostModifierUpgradeModuleData, m_percentage ) },
  80. { 0, 0, 0, 0 }
  81. };
  82. p.add(dataFieldParse);
  83. } // end buildFieldParse
  84. ///////////////////////////////////////////////////////////////////////////////////////////////////
  85. ///////////////////////////////////////////////////////////////////////////////////////////////////
  86. ///////////////////////////////////////////////////////////////////////////////////////////////////
  87. //-------------------------------------------------------------------------------------------------
  88. //-------------------------------------------------------------------------------------------------
  89. CostModifierUpgrade::CostModifierUpgrade( Thing *thing, const ModuleData* moduleData ) :
  90. UpgradeModule( thing, moduleData )
  91. {
  92. } // end CostModifierUpgrade
  93. //-------------------------------------------------------------------------------------------------
  94. //-------------------------------------------------------------------------------------------------
  95. CostModifierUpgrade::~CostModifierUpgrade( void )
  96. {
  97. } // end ~CostModifierUpgrade
  98. //-------------------------------------------------------------------------------------------------
  99. //-------------------------------------------------------------------------------------------------
  100. void CostModifierUpgrade::onDelete( void )
  101. {
  102. // if we haven't been upgraded there is nothing to clean up
  103. if( isAlreadyUpgraded() == FALSE )
  104. return;
  105. // remove the radar from the player
  106. Player *player = getObject()->getControllingPlayer();
  107. if( player )
  108. player->removeKindOfProductionCostChange(getCostModifierUpgradeModuleData()->m_kindOf,getCostModifierUpgradeModuleData()->m_percentage );
  109. // this upgrade module is now "not upgraded"
  110. setUpgradeExecuted(FALSE);
  111. } // end onDelete
  112. //-------------------------------------------------------------------------------------------------
  113. //-------------------------------------------------------------------------------------------------
  114. void CostModifierUpgrade::onCapture( Player *oldOwner, Player *newOwner )
  115. {
  116. // do nothing if we haven't upgraded yet
  117. if( isAlreadyUpgraded() == FALSE )
  118. return;
  119. // remove radar from old player and add to new player
  120. if( oldOwner )
  121. {
  122. oldOwner->removeKindOfProductionCostChange(getCostModifierUpgradeModuleData()->m_kindOf,getCostModifierUpgradeModuleData()->m_percentage );
  123. setUpgradeExecuted(FALSE);
  124. } // end if
  125. if( newOwner )
  126. {
  127. newOwner->addKindOfProductionCostChange(getCostModifierUpgradeModuleData()->m_kindOf,getCostModifierUpgradeModuleData()->m_percentage );
  128. setUpgradeExecuted(TRUE);
  129. } // end if
  130. } // end onCapture
  131. //-------------------------------------------------------------------------------------------------
  132. //-------------------------------------------------------------------------------------------------
  133. void CostModifierUpgrade::upgradeImplementation( void )
  134. {
  135. Player *player = getObject()->getControllingPlayer();
  136. // update the player with another TypeOfProductionCostChange
  137. player->addKindOfProductionCostChange(getCostModifierUpgradeModuleData()->m_kindOf,getCostModifierUpgradeModuleData()->m_percentage );
  138. } // end upgradeImplementation
  139. // ------------------------------------------------------------------------------------------------
  140. /** CRC */
  141. // ------------------------------------------------------------------------------------------------
  142. void CostModifierUpgrade::crc( Xfer *xfer )
  143. {
  144. // extend base class
  145. UpgradeModule::crc( xfer );
  146. } // end crc
  147. // ------------------------------------------------------------------------------------------------
  148. /** Xfer method
  149. * Version Info:
  150. * 1: Initial version */
  151. // ------------------------------------------------------------------------------------------------
  152. void CostModifierUpgrade::xfer( Xfer *xfer )
  153. {
  154. // version
  155. XferVersion currentVersion = 1;
  156. XferVersion version = currentVersion;
  157. xfer->xferVersion( &version, currentVersion );
  158. // extend base class
  159. UpgradeModule::xfer( xfer );
  160. } // end xfer
  161. // ------------------------------------------------------------------------------------------------
  162. /** Load post process */
  163. // ------------------------------------------------------------------------------------------------
  164. void CostModifierUpgrade::loadPostProcess( void )
  165. {
  166. // extend base class
  167. UpgradeModule::loadPostProcess();
  168. } // end loadPostProcess