SubObjectsUpgrade.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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: SubObjectsUpgrade.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Created: September 2002
  34. //
  35. // Filename: SubObjectsUpgrade.cpp
  36. //
  37. // Author: Kris Morness
  38. //
  39. // Purpose: Shows or hides a list of subobjects based on upgrade statii. It
  40. // will override any animation subobjects states.
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  45. #define DEFINE_OBJECT_STATUS_NAMES
  46. #include "Common/Player.h"
  47. #include "Common/Xfer.h"
  48. #include "GameClient/Drawable.h"
  49. #include "GameLogic/Object.h"
  50. #include "GameLogic/Module/SubObjectsUpgrade.h"
  51. //-------------------------------------------------------------------------------------------------
  52. //-------------------------------------------------------------------------------------------------
  53. void SubObjectsUpgradeModuleData::buildFieldParse(MultiIniFieldParse& p)
  54. {
  55. UpgradeModuleData::buildFieldParse(p);
  56. static const FieldParse dataFieldParse[] =
  57. {
  58. { "ShowSubObjects", INI::parseAsciiStringVectorAppend, NULL, offsetof( SubObjectsUpgradeModuleData, m_showSubObjectNames ) },
  59. { "HideSubObjects", INI::parseAsciiStringVectorAppend, NULL, offsetof( SubObjectsUpgradeModuleData, m_hideSubObjectNames ) },
  60. { 0, 0, 0, 0 }
  61. };
  62. p.add(dataFieldParse);
  63. }
  64. //-------------------------------------------------------------------------------------------------
  65. //-------------------------------------------------------------------------------------------------
  66. SubObjectsUpgrade::SubObjectsUpgrade( Thing *thing, const ModuleData* moduleData ) : UpgradeModule( thing, moduleData )
  67. {
  68. }
  69. //-------------------------------------------------------------------------------------------------
  70. //-------------------------------------------------------------------------------------------------
  71. SubObjectsUpgrade::~SubObjectsUpgrade( void )
  72. {
  73. }
  74. //-------------------------------------------------------------------------------------------------
  75. //-------------------------------------------------------------------------------------------------
  76. void SubObjectsUpgrade::upgradeImplementation( )
  77. {
  78. const SubObjectsUpgradeModuleData *data = getSubObjectsUpgradeModuleData();
  79. Int64 activation, conflicting;
  80. getUpgradeActivationMasks( activation, conflicting );
  81. //First make sure we have the right combination of upgrades
  82. if( getObject()->getObjectCompletedUpgradeMask() & conflicting )
  83. {
  84. //If it has ANY of the conflicting OBJECT upgrades, then don't do it!
  85. return;
  86. }
  87. if( getObject()->getControllingPlayer()->getCompletedUpgradeMask() & conflicting )
  88. {
  89. //If it has ANY of the conflicting PLAYER upgrades, then don't do it!
  90. return;
  91. }
  92. Object *obj = getObject();
  93. Drawable *draw = obj->getDrawable();
  94. if( draw )
  95. {
  96. std::vector<AsciiString>::const_iterator subObjectName;
  97. Bool updateSubObjects = false;
  98. //Show these subobjects
  99. for( subObjectName = data->m_showSubObjectNames.begin(); subObjectName != data->m_showSubObjectNames.end(); ++subObjectName )
  100. {
  101. draw->showSubObject( *subObjectName, true );
  102. updateSubObjects = true;
  103. }
  104. //Hide these subobjects
  105. for( subObjectName = data->m_hideSubObjectNames.begin(); subObjectName != data->m_hideSubObjectNames.end(); ++subObjectName )
  106. {
  107. draw->showSubObject( *subObjectName, false );
  108. updateSubObjects = true;
  109. }
  110. if( updateSubObjects )
  111. {
  112. draw->updateSubObjects();
  113. }
  114. }
  115. }
  116. //------------------------------------------------------------------------------------------------
  117. void SubObjectsUpgrade::crc( Xfer *xfer )
  118. {
  119. // extend base class
  120. UpgradeModule::crc( xfer );
  121. } // end crc
  122. //------------------------------------------------------------------------------------------------
  123. // Xfer method
  124. // Version Info:
  125. // 1: Initial version
  126. //------------------------------------------------------------------------------------------------
  127. void SubObjectsUpgrade::xfer( Xfer *xfer )
  128. {
  129. // version
  130. XferVersion currentVersion = 1;
  131. XferVersion version = currentVersion;
  132. xfer->xferVersion( &version, currentVersion );
  133. // extend base class
  134. UpgradeModule::xfer( xfer );
  135. } // end xfer
  136. //------------------------------------------------------------------------------------------------
  137. void SubObjectsUpgrade::loadPostProcess( void )
  138. {
  139. // extend base class
  140. UpgradeModule::loadPostProcess();
  141. } // end loadPostProcess