SupplyCenterDockUpdate.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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: 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. // ------------------------------------------------------------------------------------------------
  36. // ------------------------------------------------------------------------------------------------
  37. SupplyCenterDockUpdateModuleData::SupplyCenterDockUpdateModuleData( void )
  38. {
  39. }
  40. // ------------------------------------------------------------------------------------------------
  41. // ------------------------------------------------------------------------------------------------
  42. /*static*/ void SupplyCenterDockUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  43. {
  44. DockUpdateModuleData::buildFieldParse( p );
  45. static const FieldParse dataFieldParse[] =
  46. {
  47. { 0, 0, 0, 0 }
  48. };
  49. p.add(dataFieldParse);
  50. } // end buildFieldParse
  51. ///////////////////////////////////////////////////////////////////////////////////////////////////
  52. ///////////////////////////////////////////////////////////////////////////////////////////////////
  53. ///////////////////////////////////////////////////////////////////////////////////////////////////
  54. // ------------------------------------------------------------------------------------------------
  55. // ------------------------------------------------------------------------------------------------
  56. SupplyCenterDockUpdate::SupplyCenterDockUpdate( Thing *thing, const ModuleData* moduleData ) : DockUpdate( thing, moduleData )
  57. {
  58. }
  59. // ------------------------------------------------------------------------------------------------
  60. // ------------------------------------------------------------------------------------------------
  61. SupplyCenterDockUpdate::~SupplyCenterDockUpdate()
  62. {
  63. }
  64. // ------------------------------------------------------------------------------------------------
  65. // ------------------------------------------------------------------------------------------------
  66. Bool SupplyCenterDockUpdate::action( Object* docker, Object *drone )
  67. {
  68. SupplyTruckAIInterface* supplyTruckAI = NULL;
  69. if( docker->getAIUpdateInterface() == NULL )
  70. return FALSE;
  71. supplyTruckAI = docker->getAIUpdateInterface()->getSupplyTruckAIInterface();
  72. DEBUG_ASSERTCRASH( supplyTruckAI != NULL, ("Something Docking with a Supply Center must have a Supply-truck like AIUpdate") );
  73. if( supplyTruckAI == NULL )
  74. return FALSE;
  75. UnsignedInt value = 0;
  76. Player *ownerPlayer = getObject()->getControllingPlayer();
  77. while( supplyTruckAI->loseOneBox() )
  78. value += ownerPlayer->getSupplyBoxValue();
  79. if( value > 0 )
  80. {
  81. Money *ownerPlayerMoney = ownerPlayer->getMoney();
  82. ownerPlayerMoney->deposit(value);
  83. ownerPlayer->getScoreKeeper()->addMoneyEarned(value);
  84. // Setup info for adding a floating text
  85. Coord3D pos;
  86. const Coord3D *dockerPos;
  87. UnicodeString moneys;
  88. moneys.format( TheGameText->fetch( "GUI:AddCash" ), value );
  89. dockerPos = docker->getPosition();
  90. pos.x = dockerPos->x;
  91. pos.y = dockerPos->y;
  92. pos.z = TheTerrainLogic->getGroundHeight(pos.x, pos.y);//dockerPos->z + docker->getGeometryInfo().getHeight();
  93. Color color = ownerPlayer->getPlayerColor() | GameMakeColor( 0, 0, 0, 230 );
  94. TheInGameUI->addFloatingText(moneys, &pos, color);
  95. }
  96. return FALSE;
  97. }
  98. // ------------------------------------------------------------------------------------------------
  99. // ------------------------------------------------------------------------------------------------
  100. UpdateSleepTime SupplyCenterDockUpdate::update()
  101. {
  102. //extend
  103. UpdateSleepTime result = DockUpdate::update();
  104. #ifdef _DEBUG_ECONOMY
  105. static const NameKeyType key_SupplyCenterCreate = NAMEKEY("SupplyCenterCreate");
  106. SupplyCenterCreate* create = (SupplyCenterCreate*)getObject()->findCreateModule(key_SupplyCenterCreate);
  107. DEBUG_ASSERTCRASH( create && ! create->shouldDoOnBuildComplete(), ("A Supply center did not call onBuildComplete.") );
  108. #endif
  109. return result;
  110. }
  111. // ------------------------------------------------------------------------------------------------
  112. /** CRC */
  113. // ------------------------------------------------------------------------------------------------
  114. void SupplyCenterDockUpdate::crc( Xfer *xfer )
  115. {
  116. // extend base class
  117. DockUpdate::crc( xfer );
  118. } // end crc
  119. // ------------------------------------------------------------------------------------------------
  120. /** Xfer method
  121. * Version Info:
  122. * 1: Initial version */
  123. // ------------------------------------------------------------------------------------------------
  124. void SupplyCenterDockUpdate::xfer( Xfer *xfer )
  125. {
  126. // version
  127. XferVersion currentVersion = 1;
  128. XferVersion version = currentVersion;
  129. xfer->xferVersion( &version, currentVersion );
  130. // extend base class
  131. DockUpdate::xfer( xfer );
  132. } // end xfer
  133. // ------------------------------------------------------------------------------------------------
  134. /** Load post process */
  135. // ------------------------------------------------------------------------------------------------
  136. void SupplyCenterDockUpdate::loadPostProcess( void )
  137. {
  138. // extend base class
  139. DockUpdate::loadPostProcess();
  140. } // end loadPostProcess