UpgradeModule.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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: 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. // ------------------------------------------------------------------------------------------------
  32. /** CRC */
  33. // ------------------------------------------------------------------------------------------------
  34. void UpgradeModule::crc( Xfer *xfer )
  35. {
  36. // extend base class
  37. BehaviorModule::crc( xfer );
  38. // extned base class
  39. UpgradeMux::upgradeMuxCRC( xfer );
  40. } // end crc
  41. // ------------------------------------------------------------------------------------------------
  42. /** Xfer Method */
  43. // ------------------------------------------------------------------------------------------------
  44. void UpgradeModule::xfer( Xfer *xfer )
  45. {
  46. // version
  47. XferVersion currentVersion = 1;
  48. XferVersion version = currentVersion;
  49. xfer->xferVersion( &version, currentVersion );
  50. // call base class
  51. BehaviorModule::xfer( xfer );
  52. // extend base class
  53. UpgradeMux::upgradeMuxXfer( xfer );
  54. } // end xfer
  55. // ------------------------------------------------------------------------------------------------
  56. /** Load post process */
  57. // ------------------------------------------------------------------------------------------------
  58. void UpgradeModule::loadPostProcess( void )
  59. {
  60. // call base class
  61. BehaviorModule::loadPostProcess();
  62. // extend base class
  63. UpgradeMux::upgradeMuxLoadPostProcess();
  64. } // end loadPostProcess
  65. // ------------------------------------------------------------------------------------------------
  66. // ------------------------------------------------------------------------------------------------
  67. UpgradeMux::UpgradeMux() : m_upgradeExecuted(false)
  68. {
  69. }
  70. // ------------------------------------------------------------------------------------------------
  71. // ------------------------------------------------------------------------------------------------
  72. Bool UpgradeMux::isAlreadyUpgraded() const
  73. {
  74. return m_upgradeExecuted;
  75. }
  76. // ------------------------------------------------------------------------------------------------
  77. // ***DANGER! DANGER! Don't use this, unless you are forcing an already made upgrade to refresh!!
  78. // ------------------------------------------------------------------------------------------------
  79. void UpgradeMux::forceRefreshUpgrade()
  80. {
  81. if( m_upgradeExecuted )
  82. {
  83. //Only do this if we've already made the upgrade!
  84. upgradeImplementation();
  85. }
  86. }
  87. // ------------------------------------------------------------------------------------------------
  88. // ------------------------------------------------------------------------------------------------
  89. Bool UpgradeMux::attemptUpgrade( Int64 keyMask )
  90. {
  91. if (wouldUpgrade(keyMask))
  92. {
  93. // If I have an activation condition, and I haven't activated, and this key matches my condition.
  94. giveSelfUpgrade();
  95. return true;
  96. }
  97. return false;
  98. }
  99. // ------------------------------------------------------------------------------------------------
  100. // ------------------------------------------------------------------------------------------------
  101. Bool UpgradeMux::wouldUpgrade( Int64 keyMask ) const
  102. {
  103. Int64 activation, conflicting;
  104. getUpgradeActivationMasks(activation, conflicting);
  105. //Make sure we have activation conditions and we haven't performed the upgrade already.
  106. if( activation && !m_upgradeExecuted )
  107. {
  108. //Okay, make sure we don't have any conflicting upgrades
  109. if( !(conflicting & keyMask) )
  110. {
  111. //Finally check to see if our upgrade conditions match.
  112. if( requiresAllActivationUpgrades() )
  113. {
  114. //Make sure ALL triggers requirements are upgraded
  115. return (activation & keyMask) == activation;
  116. }
  117. else
  118. {
  119. //Check if ANY trigger requirements are met.
  120. return (activation & keyMask) != 0;
  121. }
  122. }
  123. }
  124. //We can't upgrade!
  125. return false;
  126. }
  127. //-------------------------------------------------------------------------------------------------
  128. Bool UpgradeMux::testUpgradeConditions( Int64 keyMask ) const
  129. {
  130. Int64 activation, conflicting;
  131. getUpgradeActivationMasks(activation, conflicting);
  132. //Okay, make sure we don't have any conflicting upgrades
  133. if( !(conflicting & keyMask) )
  134. {
  135. //Make sure we have activation conditions
  136. if( activation )
  137. {
  138. //Finally check to see if our upgrade conditions match.
  139. if( requiresAllActivationUpgrades() )
  140. {
  141. //Make sure ALL triggers requirements are upgraded
  142. return (activation & keyMask) == activation;
  143. }
  144. else
  145. {
  146. //Check if ANY trigger requirements are met.
  147. return (activation & keyMask) != 0;
  148. }
  149. }
  150. else
  151. {
  152. //This *upgrade* is relying only on not having conflicts.
  153. return true;
  154. }
  155. }
  156. //We can't upgrade!
  157. return false;
  158. }
  159. // ------------------------------------------------------------------------------------------------
  160. // ------------------------------------------------------------------------------------------------
  161. Bool UpgradeMux::resetUpgrade( Int64 keyMask )
  162. {
  163. Int64 activation, conflicting;
  164. getUpgradeActivationMasks(activation, conflicting);
  165. if( activation & keyMask && m_upgradeExecuted )
  166. {
  167. m_upgradeExecuted = false;
  168. return true;
  169. }
  170. return false;
  171. }
  172. // ------------------------------------------------------------------------------------------------
  173. // ------------------------------------------------------------------------------------------------
  174. void UpgradeMux::upgradeMuxCRC( Xfer *xfer )
  175. {
  176. // just call the regular xfer, it's simple
  177. upgradeMuxXfer( xfer );
  178. }
  179. // ------------------------------------------------------------------------------------------------
  180. /** Xfer
  181. * Version Info
  182. * 1: Initial version */
  183. // ------------------------------------------------------------------------------------------------
  184. void UpgradeMux::upgradeMuxXfer( Xfer *xfer )
  185. {
  186. XferVersion currentVersion = 1;
  187. XferVersion version = currentVersion;
  188. xfer->xferVersion( &version, currentVersion );
  189. // upgrade executed
  190. xfer->xferBool( &m_upgradeExecuted );
  191. }
  192. // ------------------------------------------------------------------------------------------------
  193. // ------------------------------------------------------------------------------------------------
  194. void UpgradeMux::upgradeMuxLoadPostProcess( void )
  195. {
  196. }