CommandSetUpgrade.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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: CommandSetUpgrade.cpp /////////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, September 2002
  25. // Desc: UpgradeModule that sets a new override string for Command Set look ups
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #include "Common/Xfer.h"
  29. #include "Common/Player.h"
  30. #include "GameClient/ControlBar.h"
  31. #include "GameLogic/Module/CommandSetUpgrade.h"
  32. #include "GameLogic/Object.h"
  33. // ------------------------------------------------------------------------------------------------
  34. // ------------------------------------------------------------------------------------------------
  35. void CommandSetUpgradeModuleData::buildFieldParse(MultiIniFieldParse& p)
  36. {
  37. UpgradeModuleData::buildFieldParse(p);
  38. static const FieldParse dataFieldParse[] =
  39. {
  40. { "CommandSet", INI::parseAsciiString, NULL, offsetof( CommandSetUpgradeModuleData, m_newCommandSet ) },
  41. { "CommandSetAlt", INI::parseAsciiString, NULL, offsetof( CommandSetUpgradeModuleData, m_newCommandSetAlt ) },
  42. { "TriggerAlt", INI::parseAsciiString, NULL, offsetof( CommandSetUpgradeModuleData, m_triggerAlt ) },
  43. { 0, 0, 0, 0 }
  44. };
  45. p.add(dataFieldParse);
  46. }
  47. //-------------------------------------------------------------------------------------------------
  48. //-------------------------------------------------------------------------------------------------
  49. CommandSetUpgrade::CommandSetUpgrade( Thing *thing, const ModuleData* moduleData ) : UpgradeModule( thing, moduleData )
  50. {
  51. }
  52. //-------------------------------------------------------------------------------------------------
  53. //-------------------------------------------------------------------------------------------------
  54. CommandSetUpgrade::~CommandSetUpgrade( void )
  55. {
  56. }
  57. //-------------------------------------------------------------------------------------------------
  58. //-------------------------------------------------------------------------------------------------
  59. void CommandSetUpgrade::upgradeImplementation( )
  60. {
  61. Object *obj = getObject();
  62. const char * upgradeAlt = getCommandSetUpgradeModuleData()->m_triggerAlt.str();
  63. const UpgradeTemplate *upgradeTemplate = TheUpgradeCenter->findUpgrade( upgradeAlt );
  64. if (upgradeTemplate)
  65. {
  66. UpgradeMaskType upgradeMask = upgradeTemplate->getUpgradeMask();
  67. // See if upgrade is found in the player completed upgrades
  68. Player *player = obj->getControllingPlayer();
  69. if (player)
  70. {
  71. UpgradeMaskType playerMask = player->getCompletedUpgradeMask();
  72. if (playerMask.testForAny(upgradeMask))
  73. {
  74. obj->setCommandSetStringOverride( getCommandSetUpgradeModuleData()->m_newCommandSetAlt );
  75. TheControlBar->markUIDirty();// Refresh the UI in case we are selected
  76. return;
  77. }
  78. }
  79. // See if upgrade is found in the object completed upgrades
  80. UpgradeMaskType objMask = obj->getObjectCompletedUpgradeMask();
  81. if (objMask.testForAny(upgradeMask))
  82. {
  83. obj->setCommandSetStringOverride( getCommandSetUpgradeModuleData()->m_newCommandSetAlt );
  84. TheControlBar->markUIDirty();// Refresh the UI in case we are selected
  85. return;
  86. }
  87. }
  88. obj->setCommandSetStringOverride( getCommandSetUpgradeModuleData()->m_newCommandSet );
  89. TheControlBar->markUIDirty();// Refresh the UI in case we are selected
  90. }
  91. // ------------------------------------------------------------------------------------------------
  92. /** CRC */
  93. // ------------------------------------------------------------------------------------------------
  94. void CommandSetUpgrade::crc( Xfer *xfer )
  95. {
  96. // extend base class
  97. UpgradeModule::crc( xfer );
  98. } // end crc
  99. // ------------------------------------------------------------------------------------------------
  100. /** Xfer method
  101. * Version Info:
  102. * 1: Initial version */
  103. // ------------------------------------------------------------------------------------------------
  104. void CommandSetUpgrade::xfer( Xfer *xfer )
  105. {
  106. // version
  107. XferVersion currentVersion = 1;
  108. XferVersion version = currentVersion;
  109. xfer->xferVersion( &version, currentVersion );
  110. // extend base class
  111. UpgradeModule::xfer( xfer );
  112. } // end xfer
  113. // ------------------------------------------------------------------------------------------------
  114. /** Load post process */
  115. // ------------------------------------------------------------------------------------------------
  116. void CommandSetUpgrade::loadPostProcess( void )
  117. {
  118. // extend base class
  119. UpgradeModule::loadPostProcess();
  120. } // end loadPostProcess