CashBountyPower.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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: CashBountyPower.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: CashBountyPower.cpp
  36. //
  37. // author: Steven Johnson
  38. //
  39. // purpose:
  40. //-----------------------------------------------------------------------------
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //-----------------------------------------------------------------------------
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. //-----------------------------------------------------------------------------
  45. //-----------------------------------------------------------------------------
  46. // USER INCLUDES //////////////////////////////////////////////////////////////
  47. //-----------------------------------------------------------------------------
  48. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  49. #include "Common/Player.h"
  50. #include "Common/Xfer.h"
  51. #include "GameLogic/Module/CashBountyPower.h"
  52. #include "GameLogic/Object.h"
  53. //-----------------------------------------------------------------------------
  54. // DEFINES ////////////////////////////////////////////////////////////////////
  55. //-----------------------------------------------------------------------------
  56. //-----------------------------------------------------------------------------
  57. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  58. //-----------------------------------------------------------------------------
  59. //-----------------------------------------------------------------------------
  60. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  61. //-----------------------------------------------------------------------------
  62. //-------------------------------------------------------------------------------------------------
  63. //-------------------------------------------------------------------------------------------------
  64. CashBountyPowerModuleData::CashBountyPowerModuleData()
  65. {
  66. #ifdef NOT_IN_USE
  67. m_upgrades.clear();
  68. #endif
  69. m_defaultBounty = 0.0;
  70. }
  71. #ifdef NOT_IN_USE
  72. //-------------------------------------------------------------------------------------------------
  73. //-------------------------------------------------------------------------------------------------
  74. static void parseBountyUpgradePair( INI* ini, void * /*instance*/, void *store, const void* /*userData*/ )
  75. {
  76. CashBountyPowerModuleData::Upgrades up;
  77. INI::parseScience(ini, NULL, &up.m_science, NULL);
  78. INI::parsePercentToReal(ini, NULL, &up.m_bounty, NULL);
  79. std::vector<CashBountyPowerModuleData::Upgrades>* s = (std::vector<CashBountyPowerModuleData::Upgrades>*)store;
  80. s->push_back(up);
  81. }
  82. #endif
  83. //-------------------------------------------------------------------------------------------------
  84. //-------------------------------------------------------------------------------------------------
  85. /* static */ void CashBountyPowerModuleData::buildFieldParse(MultiIniFieldParse& p)
  86. {
  87. SpecialPowerModuleData::buildFieldParse( p );
  88. static const FieldParse dataFieldParse[] =
  89. {
  90. #ifdef NOT_IN_USE
  91. { "UpgradeBounty", parseBountyUpgradePair, NULL, offsetof( CashBountyPowerModuleData, m_upgrades ) },
  92. #endif
  93. { "Bounty", INI::parsePercentToReal, NULL, offsetof( CashBountyPowerModuleData, m_defaultBounty ) },
  94. { 0, 0, 0, 0 }
  95. };
  96. p.add(dataFieldParse);
  97. } // end buildFieldParse
  98. ///////////////////////////////////////////////////////////////////////////////////////////////////
  99. ///////////////////////////////////////////////////////////////////////////////////////////////////
  100. ///////////////////////////////////////////////////////////////////////////////////////////////////
  101. //-------------------------------------------------------------------------------------------------
  102. //-------------------------------------------------------------------------------------------------
  103. CashBountyPower::CashBountyPower( Thing *thing, const ModuleData* moduleData ) :
  104. SpecialPowerModule( thing, moduleData )
  105. {
  106. } // end CashBountyPower
  107. //-------------------------------------------------------------------------------------------------
  108. //-------------------------------------------------------------------------------------------------
  109. CashBountyPower::~CashBountyPower()
  110. {
  111. } // end ~CashBountyPower
  112. //-------------------------------------------------------------------------------------------------
  113. //-------------------------------------------------------------------------------------------------
  114. void CashBountyPower::onObjectCreated()
  115. {
  116. Player* controller = getObject()->getControllingPlayer();
  117. if (controller && controller->hasScience(getRequiredScience()))
  118. {
  119. Real bounty = findBounty();
  120. if (bounty > controller->getCashBounty())
  121. controller->setCashBounty(bounty);
  122. }
  123. }
  124. //-------------------------------------------------------------------------------------------------
  125. //-------------------------------------------------------------------------------------------------
  126. Real CashBountyPower::findBounty() const
  127. {
  128. const CashBountyPowerModuleData* d = getCashBountyPowerModuleData();
  129. #ifdef NOT_IN_USE
  130. const Player* controller = getObject()->getControllingPlayer();
  131. if (controller != NULL)
  132. {
  133. for (std::vector<CashBountyPowerModuleData::Upgrades>::const_iterator it = d->m_upgrades.begin();
  134. it != d->m_upgrades.end();
  135. ++it)
  136. {
  137. if (controller->hasScience(it->m_science))
  138. return it->m_bounty;
  139. }
  140. }
  141. #endif
  142. return d->m_defaultBounty;
  143. }
  144. //-------------------------------------------------------------------------------------------------
  145. //-------------------------------------------------------------------------------------------------
  146. void CashBountyPower::onSpecialPowerCreation()
  147. {
  148. SpecialPowerModule::onSpecialPowerCreation();
  149. Player* controller = getObject()->getControllingPlayer();
  150. if (controller)
  151. {
  152. Real bounty = findBounty();
  153. if (bounty > controller->getCashBounty())
  154. controller->setCashBounty(bounty);
  155. }
  156. }
  157. // ------------------------------------------------------------------------------------------------
  158. /** CRC */
  159. // ------------------------------------------------------------------------------------------------
  160. void CashBountyPower::crc( Xfer *xfer )
  161. {
  162. // extend base class
  163. SpecialPowerModule::crc( xfer );
  164. } // end crc
  165. // ------------------------------------------------------------------------------------------------
  166. /** Xfer method
  167. * Version Info:
  168. * 1: Initial version */
  169. // ------------------------------------------------------------------------------------------------
  170. void CashBountyPower::xfer( Xfer *xfer )
  171. {
  172. // version
  173. XferVersion currentVersion = 1;
  174. XferVersion version = currentVersion;
  175. xfer->xferVersion( &version, currentVersion );
  176. // extend base class
  177. SpecialPowerModule::xfer( xfer );
  178. } // end xfer
  179. // ------------------------------------------------------------------------------------------------
  180. /** Load post process */
  181. // ------------------------------------------------------------------------------------------------
  182. void CashBountyPower::loadPostProcess( void )
  183. {
  184. // extend base class
  185. SpecialPowerModule::loadPostProcess();
  186. } // end loadPostProcess