GrantUpgradeCreate.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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: GrantUpgradeCreate.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Kris Morness, April 2002
  25. // Desc: GrantUpgrade create module
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #define DEFINE_OBJECT_STATUS_NAMES
  30. #include "Common/Player.h"
  31. #include "Common/Upgrade.h"
  32. #include "Common/Xfer.h"
  33. #include "GameLogic/Module/GrantUpgradeCreate.h"
  34. #include "GameLogic/Object.h"
  35. // ------------------------------------------------------------------------------------------------
  36. // ------------------------------------------------------------------------------------------------
  37. GrantUpgradeCreateModuleData::GrantUpgradeCreateModuleData()
  38. {
  39. m_upgradeName = "";
  40. }
  41. // ------------------------------------------------------------------------------------------------
  42. // ------------------------------------------------------------------------------------------------
  43. void GrantUpgradeCreateModuleData::buildFieldParse(MultiIniFieldParse& p)
  44. {
  45. CreateModuleData::buildFieldParse(p);
  46. static const FieldParse dataFieldParse[] =
  47. {
  48. { "UpgradeToGrant", INI::parseAsciiString, NULL, offsetof( GrantUpgradeCreateModuleData, m_upgradeName ) },
  49. { "ExemptStatus", ObjectStatusMaskType::parseFromINI, NULL, offsetof( GrantUpgradeCreateModuleData, m_exemptStatus ) },
  50. { 0, 0, 0, 0 }
  51. };
  52. p.add(dataFieldParse);
  53. }
  54. ///////////////////////////////////////////////////////////////////////////////////////////////////
  55. ///////////////////////////////////////////////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////////////////////////////////
  57. //-------------------------------------------------------------------------------------------------
  58. //-------------------------------------------------------------------------------------------------
  59. GrantUpgradeCreate::GrantUpgradeCreate( Thing *thing, const ModuleData* moduleData ) : CreateModule( thing, moduleData )
  60. {
  61. } // end GrantUpgradeCreate
  62. //-------------------------------------------------------------------------------------------------
  63. //-------------------------------------------------------------------------------------------------
  64. GrantUpgradeCreate::~GrantUpgradeCreate( void )
  65. {
  66. } // end ~GrantUpgradeCreate
  67. //-------------------------------------------------------------------------------------------------
  68. /** The create callback. */
  69. //-------------------------------------------------------------------------------------------------
  70. void GrantUpgradeCreate::onCreate( void )
  71. {
  72. ObjectStatusMaskType exemptStatus = getGrantUpgradeCreateModuleData()->m_exemptStatus;
  73. ObjectStatusMaskType currentStatus = getObject()->getStatusBits();
  74. if( exemptStatus.test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
  75. {
  76. if( !currentStatus.test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
  77. {
  78. const UpgradeTemplate *upgradeTemplate = TheUpgradeCenter->findUpgrade( getGrantUpgradeCreateModuleData()->m_upgradeName );
  79. if( !upgradeTemplate )
  80. {
  81. DEBUG_ASSERTCRASH( 0, ("GrantUpdateCreate for %s can't find upgrade template %s.", getObject()->getName(), getGrantUpgradeCreateModuleData()->m_upgradeName ) );
  82. return;
  83. }
  84. Player *player = getObject()->getControllingPlayer();
  85. if( upgradeTemplate->getUpgradeType() == UPGRADE_TYPE_PLAYER )
  86. {
  87. // get the player
  88. player->addUpgrade( upgradeTemplate, UPGRADE_STATUS_COMPLETE );
  89. }
  90. else
  91. {
  92. getObject()->giveUpgrade( upgradeTemplate );
  93. }
  94. player->getAcademyStats()->recordUpgrade( upgradeTemplate, TRUE );
  95. }
  96. }
  97. } // end onCreate
  98. //-------------------------------------------------------------------------------------------------
  99. //-------------------------------------------------------------------------------------------------
  100. void GrantUpgradeCreate::onBuildComplete( void )
  101. {
  102. if( ! shouldDoOnBuildComplete() )
  103. return;
  104. CreateModule::onBuildComplete(); // extend
  105. const UpgradeTemplate *upgradeTemplate = TheUpgradeCenter->findUpgrade( getGrantUpgradeCreateModuleData()->m_upgradeName );
  106. if( !upgradeTemplate )
  107. {
  108. DEBUG_ASSERTCRASH( 0, ("GrantUpdateCreate for %s can't find upgrade template %s.", getObject()->getName(), getGrantUpgradeCreateModuleData()->m_upgradeName ) );
  109. return;
  110. }
  111. if( upgradeTemplate->getUpgradeType() == UPGRADE_TYPE_PLAYER )
  112. {
  113. // get the player
  114. Player *player = getObject()->getControllingPlayer();
  115. player->addUpgrade( upgradeTemplate, UPGRADE_STATUS_COMPLETE );
  116. }
  117. else
  118. {
  119. getObject()->giveUpgrade( upgradeTemplate );
  120. }
  121. } // end onBuildComplete
  122. // ------------------------------------------------------------------------------------------------
  123. /** CRC */
  124. // ------------------------------------------------------------------------------------------------
  125. void GrantUpgradeCreate::crc( Xfer *xfer )
  126. {
  127. // extend base class
  128. CreateModule::crc( xfer );
  129. } // end crc
  130. // ------------------------------------------------------------------------------------------------
  131. /** Xfer method
  132. * Version Info:
  133. * 1: Initial version */
  134. // ------------------------------------------------------------------------------------------------
  135. void GrantUpgradeCreate::xfer( Xfer *xfer )
  136. {
  137. // version
  138. XferVersion currentVersion = 1;
  139. XferVersion version = currentVersion;
  140. xfer->xferVersion( &version, currentVersion );
  141. // extend base class
  142. CreateModule::xfer( xfer );
  143. } // end xfer
  144. // ------------------------------------------------------------------------------------------------
  145. /** Load post process */
  146. // ------------------------------------------------------------------------------------------------
  147. void GrantUpgradeCreate::loadPostProcess( void )
  148. {
  149. // extend base class
  150. CreateModule::loadPostProcess();
  151. } // end loadPostProcess