SupplyCenterDockUpdate.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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: SupplyCenterDockUpdate.h /////////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood Feb 2002
  25. // Desc: The action of this dock update is taking boxes and turning them into money for my ownerplayer
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #include "Common/Player.h"
  29. #include "Common/Xfer.h"
  30. #include "GameLogic/Module/SupplyCenterDockUpdate.h"
  31. #include "GameLogic/Module/SupplyTruckAIUpdate.h"
  32. #include "GameClient/Color.h"
  33. #include "GameClient/InGameUI.h"
  34. #include "GameClient/GameText.h"
  35. #ifdef _INTERNAL
  36. // for occasional debugging...
  37. //#pragma optimize("", off)
  38. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  39. #endif
  40. // ------------------------------------------------------------------------------------------------
  41. // ------------------------------------------------------------------------------------------------
  42. SupplyCenterDockUpdateModuleData::SupplyCenterDockUpdateModuleData( void )
  43. {
  44. m_grantTemporaryStealthFrames = 0;
  45. }
  46. // ------------------------------------------------------------------------------------------------
  47. // ------------------------------------------------------------------------------------------------
  48. /*static*/ void SupplyCenterDockUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  49. {
  50. DockUpdateModuleData::buildFieldParse( p );
  51. static const FieldParse dataFieldParse[] =
  52. {
  53. { "GrantTemporaryStealth", INI::parseDurationUnsignedInt, NULL, offsetof( SupplyCenterDockUpdateModuleData, m_grantTemporaryStealthFrames ) },
  54. { 0, 0, 0, 0 }
  55. };
  56. p.add(dataFieldParse);
  57. } // end buildFieldParse
  58. ///////////////////////////////////////////////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////////////////////////
  60. ///////////////////////////////////////////////////////////////////////////////////////////////////
  61. // ------------------------------------------------------------------------------------------------
  62. // ------------------------------------------------------------------------------------------------
  63. SupplyCenterDockUpdate::SupplyCenterDockUpdate( Thing *thing, const ModuleData* moduleData ) : DockUpdate( thing, moduleData )
  64. {
  65. }
  66. // ------------------------------------------------------------------------------------------------
  67. // ------------------------------------------------------------------------------------------------
  68. SupplyCenterDockUpdate::~SupplyCenterDockUpdate()
  69. {
  70. }
  71. // ------------------------------------------------------------------------------------------------
  72. // ------------------------------------------------------------------------------------------------
  73. Bool SupplyCenterDockUpdate::action( Object* docker, Object *drone )
  74. {
  75. const SupplyCenterDockUpdateModuleData *data = getSupplyCenterDockUpdateModuleData();
  76. SupplyTruckAIInterface* supplyTruckAI = NULL;
  77. if( docker->getAIUpdateInterface() == NULL )
  78. return FALSE;
  79. supplyTruckAI = docker->getAIUpdateInterface()->getSupplyTruckAIInterface();
  80. DEBUG_ASSERTCRASH( supplyTruckAI != NULL, ("Something Docking with a Supply Center must have a Supply-truck like AIUpdate") );
  81. if( supplyTruckAI == NULL )
  82. return FALSE;
  83. UnsignedInt value = 0;
  84. Player *ownerPlayer = getObject()->getControllingPlayer();
  85. while( supplyTruckAI->loseOneBox() )
  86. value += ownerPlayer->getSupplyBoxValue();
  87. // Add money boost from upgrades that give extra money
  88. value += supplyTruckAI->getUpgradedSupplyBoost();
  89. if( value > 0)
  90. {
  91. Money *ownerPlayerMoney = ownerPlayer->getMoney();
  92. ownerPlayerMoney->deposit(value);
  93. ownerPlayer->getScoreKeeper()->addMoneyEarned(value);
  94. if( data->m_grantTemporaryStealthFrames > 0 )
  95. {
  96. StealthUpdate *stealth = docker->getStealth();
  97. //Only grant temporary stealth to the default stealth update. It's
  98. //possible that another type of stealth was granted... like the
  99. //GPS scrambler. We want that to take precendence.
  100. if( getObject()->testStatus( OBJECT_STATUS_STEALTHED ) )
  101. {
  102. if( !stealth )
  103. {
  104. DEBUG_CRASH( ("SupplyCenterDockUpdate::action() -- It shouldn't be possible for a unit to be OBJECT_STATUS_STEALTHED without a StealthUpdate module!") );
  105. }
  106. else if( stealth->isTemporaryGrant() || !docker->testStatus( OBJECT_STATUS_CAN_STEALTH ) )
  107. {
  108. stealth->receiveGrant( TRUE, data->m_grantTemporaryStealthFrames );
  109. }
  110. }
  111. }
  112. }
  113. Bool displayMoney = value > 0 ? TRUE : FALSE;
  114. if( getObject()->testStatus(OBJECT_STATUS_STEALTHED) )
  115. {
  116. // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!
  117. if( !getObject()->isLocallyControlled() && !getObject()->testStatus(OBJECT_STATUS_DETECTED) )
  118. {
  119. displayMoney = FALSE;
  120. }
  121. }
  122. if( displayMoney )
  123. {
  124. // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!
  125. // Setup info for adding a floating text
  126. Coord3D pos;
  127. const Coord3D *dockerPos;
  128. UnicodeString moneys;
  129. moneys.format( TheGameText->fetch( "GUI:AddCash" ), value );
  130. dockerPos = docker->getPosition();
  131. pos.x = dockerPos->x;
  132. pos.y = dockerPos->y;
  133. pos.z = TheTerrainLogic->getGroundHeight(pos.x, pos.y);//dockerPos->z + docker->getGeometryInfo().getHeight();
  134. Color color = ownerPlayer->getPlayerColor() | GameMakeColor( 0, 0, 0, 230 );
  135. TheInGameUI->addFloatingText(moneys, &pos, color);
  136. }
  137. return FALSE;
  138. }
  139. // ------------------------------------------------------------------------------------------------
  140. // ------------------------------------------------------------------------------------------------
  141. UpdateSleepTime SupplyCenterDockUpdate::update()
  142. {
  143. //extend
  144. UpdateSleepTime result = DockUpdate::update();
  145. #ifdef _DEBUG_ECONOMY
  146. static const NameKeyType key_SupplyCenterCreate = NAMEKEY("SupplyCenterCreate");
  147. SupplyCenterCreate* create = (SupplyCenterCreate*)getObject()->findCreateModule(key_SupplyCenterCreate);
  148. DEBUG_ASSERTCRASH( create && ! create->shouldDoOnBuildComplete(), ("A Supply center did not call onBuildComplete.") );
  149. #endif
  150. return result;
  151. }
  152. // ------------------------------------------------------------------------------------------------
  153. /** CRC */
  154. // ------------------------------------------------------------------------------------------------
  155. void SupplyCenterDockUpdate::crc( Xfer *xfer )
  156. {
  157. // extend base class
  158. DockUpdate::crc( xfer );
  159. } // end crc
  160. // ------------------------------------------------------------------------------------------------
  161. /** Xfer method
  162. * Version Info:
  163. * 1: Initial version */
  164. // ------------------------------------------------------------------------------------------------
  165. void SupplyCenterDockUpdate::xfer( Xfer *xfer )
  166. {
  167. // version
  168. XferVersion currentVersion = 1;
  169. XferVersion version = currentVersion;
  170. xfer->xferVersion( &version, currentVersion );
  171. // extend base class
  172. DockUpdate::xfer( xfer );
  173. } // end xfer
  174. // ------------------------------------------------------------------------------------------------
  175. /** Load post process */
  176. // ------------------------------------------------------------------------------------------------
  177. void SupplyCenterDockUpdate::loadPostProcess( void )
  178. {
  179. // extend base class
  180. DockUpdate::loadPostProcess();
  181. } // end loadPostProcess