UpgradeModule.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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: UpgradeModule.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Johnson, Day, Smallwood September 2002
  25. // Desc: Upgrade module basic implementations
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h"
  29. #include "Common/Xfer.h"
  30. #include "GameLogic/Module/UpgradeModule.h"
  31. #ifdef _INTERNAL
  32. // for occasional debugging...
  33. //#pragma optimize("", off)
  34. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  35. #endif
  36. // ------------------------------------------------------------------------------------------------
  37. /** CRC */
  38. // ------------------------------------------------------------------------------------------------
  39. void UpgradeModule::crc( Xfer *xfer )
  40. {
  41. // extend base class
  42. BehaviorModule::crc( xfer );
  43. // extned base class
  44. UpgradeMux::upgradeMuxCRC( xfer );
  45. } // end crc
  46. // ------------------------------------------------------------------------------------------------
  47. /** Xfer Method */
  48. // ------------------------------------------------------------------------------------------------
  49. void UpgradeModule::xfer( Xfer *xfer )
  50. {
  51. // version
  52. XferVersion currentVersion = 1;
  53. XferVersion version = currentVersion;
  54. xfer->xferVersion( &version, currentVersion );
  55. // call base class
  56. BehaviorModule::xfer( xfer );
  57. // extend base class
  58. UpgradeMux::upgradeMuxXfer( xfer );
  59. } // end xfer
  60. // ------------------------------------------------------------------------------------------------
  61. /** Load post process */
  62. // ------------------------------------------------------------------------------------------------
  63. void UpgradeModule::loadPostProcess( void )
  64. {
  65. // call base class
  66. BehaviorModule::loadPostProcess();
  67. // extend base class
  68. UpgradeMux::upgradeMuxLoadPostProcess();
  69. } // end loadPostProcess
  70. // ------------------------------------------------------------------------------------------------
  71. // ------------------------------------------------------------------------------------------------
  72. UpgradeMux::UpgradeMux() : m_upgradeExecuted(false)
  73. {
  74. }
  75. // ------------------------------------------------------------------------------------------------
  76. // ------------------------------------------------------------------------------------------------
  77. Bool UpgradeMux::isAlreadyUpgraded() const
  78. {
  79. return m_upgradeExecuted;
  80. }
  81. // ------------------------------------------------------------------------------------------------
  82. // ***DANGER! DANGER! Don't use this, unless you are forcing an already made upgrade to refresh!!
  83. // ------------------------------------------------------------------------------------------------
  84. void UpgradeMux::forceRefreshUpgrade()
  85. {
  86. if( m_upgradeExecuted )
  87. {
  88. //Only do this if we've already made the upgrade!
  89. upgradeImplementation();
  90. }
  91. }
  92. // ------------------------------------------------------------------------------------------------
  93. // ------------------------------------------------------------------------------------------------
  94. Bool UpgradeMux::attemptUpgrade( UpgradeMaskType keyMask )
  95. {
  96. if (wouldUpgrade(keyMask))
  97. {
  98. // If I have an activation condition, and I haven't activated, and this key matches my condition.
  99. giveSelfUpgrade();
  100. return true;
  101. }
  102. return false;
  103. }
  104. // ------------------------------------------------------------------------------------------------
  105. // ------------------------------------------------------------------------------------------------
  106. Bool UpgradeMux::wouldUpgrade( UpgradeMaskType keyMask ) const
  107. {
  108. UpgradeMaskType activation, conflicting;
  109. getUpgradeActivationMasks(activation, conflicting);
  110. //Make sure we have activation conditions and we haven't performed the upgrade already.
  111. if( activation.any() && keyMask.any() && !m_upgradeExecuted )
  112. {
  113. //Okay, make sure we don't have any conflicting upgrades
  114. if( !keyMask.testForAny( conflicting) )
  115. {
  116. //Finally check to see if our upgrade conditions match.
  117. if( requiresAllActivationUpgrades() )
  118. {
  119. //Make sure ALL triggers requirements are upgraded
  120. if( keyMask.testForAll( activation ) )
  121. {
  122. return TRUE;
  123. }
  124. }
  125. else
  126. {
  127. //Check if ANY trigger requirements are met.
  128. if( keyMask.testForAny( activation ) )
  129. {
  130. return TRUE;
  131. }
  132. }
  133. }
  134. }
  135. //We can't upgrade!
  136. return FALSE;
  137. }
  138. //-------------------------------------------------------------------------------------------------
  139. void UpgradeMux::giveSelfUpgrade()
  140. {
  141. // If I have an activation condition, and I haven't activated, and this key matches my condition.
  142. performUpgradeFX();
  143. processUpgradeRemoval();// Need to execute removals first, to prevent both being on for a moment.
  144. upgradeImplementation();
  145. setUpgradeExecuted(true);
  146. }
  147. //-------------------------------------------------------------------------------------------------
  148. Bool UpgradeMux::testUpgradeConditions( UpgradeMaskType keyMask ) const
  149. {
  150. UpgradeMaskType activation, conflicting;
  151. getUpgradeActivationMasks(activation, conflicting);
  152. //Okay, make sure we don't have any conflicting upgrades
  153. if( !keyMask.any() || !keyMask.testForAny( conflicting ) )
  154. {
  155. //Make sure we have activation conditions
  156. if( activation.any() )
  157. {
  158. //Finally check to see if our upgrade conditions match.
  159. if( requiresAllActivationUpgrades() )
  160. {
  161. //Make sure ALL triggers requirements are upgraded
  162. if( keyMask.testForAll( activation ) )
  163. {
  164. return TRUE;
  165. }
  166. }
  167. else
  168. {
  169. //Check if ANY trigger requirements are met.
  170. if( keyMask.testForAny( activation ) )
  171. {
  172. return TRUE;
  173. }
  174. }
  175. }
  176. else
  177. {
  178. //This *upgrade* is relying only on not having conflicts.
  179. return true;
  180. }
  181. }
  182. //We can't upgrade!
  183. return false;
  184. }
  185. // ------------------------------------------------------------------------------------------------
  186. // ------------------------------------------------------------------------------------------------
  187. Bool UpgradeMux::resetUpgrade( UpgradeMaskType keyMask )
  188. {
  189. UpgradeMaskType activation, conflicting;
  190. getUpgradeActivationMasks(activation, conflicting);
  191. if( keyMask.testForAny( activation ) && m_upgradeExecuted )
  192. {
  193. m_upgradeExecuted = false;
  194. return true;
  195. }
  196. return false;
  197. }
  198. // ------------------------------------------------------------------------------------------------
  199. // ------------------------------------------------------------------------------------------------
  200. void UpgradeMux::upgradeMuxCRC( Xfer *xfer )
  201. {
  202. // just call the regular xfer, it's simple
  203. upgradeMuxXfer( xfer );
  204. }
  205. // ------------------------------------------------------------------------------------------------
  206. /** Xfer
  207. * Version Info
  208. * 1: Initial version */
  209. // ------------------------------------------------------------------------------------------------
  210. void UpgradeMux::upgradeMuxXfer( Xfer *xfer )
  211. {
  212. XferVersion currentVersion = 1;
  213. XferVersion version = currentVersion;
  214. xfer->xferVersion( &version, currentVersion );
  215. // upgrade executed
  216. xfer->xferBool( &m_upgradeExecuted );
  217. }
  218. // ------------------------------------------------------------------------------------------------
  219. // ------------------------------------------------------------------------------------------------
  220. void UpgradeMux::upgradeMuxLoadPostProcess( void )
  221. {
  222. }