AutoDepositUpdate.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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: AutoDepositUpdate.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: AutoDepositUpdate.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: The meat of the auto deposit update module
  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/BuildAssistant.h"
  51. #include "Common/Thing.h"
  52. #include "Common/ThingTemplate.h"
  53. #include "Common/INI.h"
  54. #include "Common/RandomValue.h"
  55. #include "Common/Player.h"
  56. #include "Common/Xfer.h"
  57. #include "GameLogic/GameLogic.h"
  58. #include "GameLogic/Module/AutoDepositUpdate.h"
  59. #include "GameLogic/Module/AIUpdate.h"
  60. #include "GameLogic/Object.h"
  61. #include "GameClient/InGameUI.h"
  62. #include "GameClient/Color.h"
  63. #include "GameClient/GameText.h"
  64. //-----------------------------------------------------------------------------
  65. // DEFINES ////////////////////////////////////////////////////////////////////
  66. //-----------------------------------------------------------------------------
  67. //-----------------------------------------------------------------------------
  68. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  69. //-----------------------------------------------------------------------------
  70. AutoDepositUpdate::AutoDepositUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
  71. {
  72. m_depositOnFrame = TheGameLogic->getFrame() + getAutoDepositUpdateModuleData()->m_depositFrame;
  73. m_awardInitialCaptureBonus = FALSE;
  74. m_initialized = FALSE;
  75. }
  76. //-------------------------------------------------------------------------------------------------
  77. //-------------------------------------------------------------------------------------------------
  78. AutoDepositUpdate::~AutoDepositUpdate( void )
  79. {
  80. }
  81. //-------------------------------------------------------------------------------------------------
  82. //-------------------------------------------------------------------------------------------------
  83. void AutoDepositUpdate::awardInitialCaptureBonus( Player *player )
  84. {
  85. m_depositOnFrame = TheGameLogic->getFrame() + getAutoDepositUpdateModuleData()->m_depositFrame;
  86. if(!player || !m_awardInitialCaptureBonus || getAutoDepositUpdateModuleData()->m_initialCaptureBonus <= 0)
  87. return;
  88. player->getMoney()->deposit( getAutoDepositUpdateModuleData()->m_initialCaptureBonus );
  89. player->getScoreKeeper()->addMoneyEarned( getAutoDepositUpdateModuleData()->m_initialCaptureBonus );
  90. //Display cash income floating over the blacklotus
  91. if(getAutoDepositUpdateModuleData()->m_initialCaptureBonus > 0)
  92. {
  93. UnicodeString moneyString;
  94. moneyString.format( TheGameText->fetch( "GUI:AddCash" ), getAutoDepositUpdateModuleData()->m_initialCaptureBonus );
  95. Coord3D pos;
  96. pos.set( getObject()->getPosition() );
  97. pos.z += 10.0f; //add a little z to make it show up above the unit.
  98. Color color = player->getPlayerColor() | GameMakeColor( 0, 0, 0, 230 );
  99. TheInGameUI->addFloatingText( moneyString, &pos, color );
  100. }
  101. m_awardInitialCaptureBonus = FALSE;
  102. }
  103. //-------------------------------------------------------------------------------------------------
  104. //-------------------------------------------------------------------------------------------------
  105. UpdateSleepTime AutoDepositUpdate::update( void )
  106. {
  107. /// @todo srj use SLEEPY_UPDATE here
  108. if( TheGameLogic->getFrame() >= m_depositOnFrame)
  109. {
  110. if (!m_initialized) {
  111. // Note - we have to set these in update, because during load the team is set,
  112. // and we don't want to award initial bonus on load. jba :)
  113. m_awardInitialCaptureBonus = TRUE;
  114. m_initialized = TRUE;
  115. }
  116. m_depositOnFrame = TheGameLogic->getFrame() + getAutoDepositUpdateModuleData()->m_depositFrame;
  117. if(getObject()->isNeutralControlled() || getAutoDepositUpdateModuleData()->m_depositAmount <= 0 )
  118. return UPDATE_SLEEP_NONE;
  119. // makes sure that buildings under construction do not get a bonus CCB
  120. if( getObject()->getConstructionPercent() != CONSTRUCTION_COMPLETE )
  121. return UPDATE_SLEEP_NONE;
  122. getObject()->getControllingPlayer()->getMoney()->deposit( getAutoDepositUpdateModuleData()->m_depositAmount);
  123. getObject()->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( getAutoDepositUpdateModuleData()->m_depositAmount);
  124. //Display cash income floating over the blacklotus
  125. if(getAutoDepositUpdateModuleData()->m_depositAmount > 0)
  126. {
  127. UnicodeString moneyString;
  128. moneyString.format( TheGameText->fetch( "GUI:AddCash" ), getAutoDepositUpdateModuleData()->m_depositAmount );
  129. Coord3D pos;
  130. pos.set( getObject()->getPosition() );
  131. pos.z += 10.0f; //add a little z to make it show up above the unit.
  132. Color color = getObject()->getControllingPlayer()->getPlayerColor() | GameMakeColor( 0, 0, 0, 230 );
  133. TheInGameUI->addFloatingText( moneyString, &pos, color );
  134. }
  135. }
  136. return UPDATE_SLEEP_NONE;
  137. }
  138. // ------------------------------------------------------------------------------------------------
  139. /** CRC */
  140. // ------------------------------------------------------------------------------------------------
  141. void AutoDepositUpdate::crc( Xfer *xfer )
  142. {
  143. // extend base class
  144. UpdateModule::crc( xfer );
  145. } // end crc
  146. // ------------------------------------------------------------------------------------------------
  147. /** Xfer method
  148. * Version Info:
  149. * 1: Initial version */
  150. // ------------------------------------------------------------------------------------------------
  151. void AutoDepositUpdate::xfer( Xfer *xfer )
  152. {
  153. // version
  154. XferVersion currentVersion = 2;
  155. XferVersion version = currentVersion;
  156. xfer->xferVersion( &version, currentVersion );
  157. // extend base class
  158. UpdateModule::xfer( xfer );
  159. // deposit on frame
  160. xfer->xferUnsignedInt( &m_depositOnFrame );
  161. // award initial capture bonus
  162. xfer->xferBool( &m_awardInitialCaptureBonus );
  163. if (version>1) {
  164. xfer->xferBool(&m_initialized);
  165. }
  166. } // end xfer
  167. // ------------------------------------------------------------------------------------------------
  168. /** Load post process */
  169. // ------------------------------------------------------------------------------------------------
  170. void AutoDepositUpdate::loadPostProcess( void )
  171. {
  172. // extend base class
  173. UpdateModule::loadPostProcess();
  174. } // end loadPostProcess