GrantUpgradeCreate.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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: 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. m_exemptStatus = OBJECT_STATUS_NONE;
  41. }
  42. // ------------------------------------------------------------------------------------------------
  43. // ------------------------------------------------------------------------------------------------
  44. void GrantUpgradeCreateModuleData::buildFieldParse(MultiIniFieldParse& p)
  45. {
  46. CreateModuleData::buildFieldParse(p);
  47. static const FieldParse dataFieldParse[] =
  48. {
  49. { "UpgradeToGrant", INI::parseAsciiString, NULL, offsetof( GrantUpgradeCreateModuleData, m_upgradeName ) },
  50. { "ExemptStatus", INI::parseBitString32, TheObjectStatusBitNames, offsetof( GrantUpgradeCreateModuleData, m_exemptStatus ) },
  51. { 0, 0, 0, 0 }
  52. };
  53. p.add(dataFieldParse);
  54. }
  55. ///////////////////////////////////////////////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////////////////////////////////
  57. ///////////////////////////////////////////////////////////////////////////////////////////////////
  58. //-------------------------------------------------------------------------------------------------
  59. //-------------------------------------------------------------------------------------------------
  60. GrantUpgradeCreate::GrantUpgradeCreate( Thing *thing, const ModuleData* moduleData ) : CreateModule( thing, moduleData )
  61. {
  62. } // end GrantUpgradeCreate
  63. //-------------------------------------------------------------------------------------------------
  64. //-------------------------------------------------------------------------------------------------
  65. GrantUpgradeCreate::~GrantUpgradeCreate( void )
  66. {
  67. } // end ~GrantUpgradeCreate
  68. //-------------------------------------------------------------------------------------------------
  69. /** The create callback. */
  70. //-------------------------------------------------------------------------------------------------
  71. void GrantUpgradeCreate::onCreate( void )
  72. {
  73. ObjectStatusBits exemptStatus = (ObjectStatusBits)getGrantUpgradeCreateModuleData()->m_exemptStatus;
  74. ObjectStatusBits currentStatus = (ObjectStatusBits)getObject()->getStatusBits();
  75. if( BitTest( exemptStatus, OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE )
  76. {
  77. if( BitTest( currentStatus, OBJECT_STATUS_UNDER_CONSTRUCTION ) == FALSE )
  78. {
  79. const UpgradeTemplate *upgradeTemplate = TheUpgradeCenter->findUpgrade( getGrantUpgradeCreateModuleData()->m_upgradeName );
  80. if( !upgradeTemplate )
  81. {
  82. DEBUG_ASSERTCRASH( 0, ("GrantUpdateCreate for %s can't find upgrade template %s.", getObject()->getName(), getGrantUpgradeCreateModuleData()->m_upgradeName ) );
  83. return;
  84. }
  85. if( upgradeTemplate->getUpgradeType() == UPGRADE_TYPE_PLAYER )
  86. {
  87. // get the player
  88. Player *player = getObject()->getControllingPlayer();
  89. player->addUpgrade( upgradeTemplate, UPGRADE_STATUS_COMPLETE );
  90. }
  91. else
  92. {
  93. getObject()->giveUpgrade( upgradeTemplate );
  94. }
  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