Upgrade.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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: Upgrade.h ////////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, March 2002
  25. // Desc: Upgrade system for players
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __UPGRADE_H_
  29. #define __UPGRADE_H_
  30. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/AudioEventRTS.h"
  32. #include "Common/INI.h"
  33. #include "Common/Snapshot.h"
  34. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  35. class Player;
  36. class UpgradeTemplate;
  37. enum NameKeyType;
  38. class Image;
  39. enum AcademyClassificationType;
  40. //-------------------------------------------------------------------------------------------------
  41. //-------------------------------------------------------------------------------------------------
  42. enum UpgradeStatusType
  43. {
  44. UPGRADE_STATUS_INVALID = 0,
  45. UPGRADE_STATUS_IN_PRODUCTION,
  46. UPGRADE_STATUS_COMPLETE
  47. };
  48. //The maximum number of upgrades.
  49. #define UPGRADE_MAX_COUNT 128
  50. typedef BitFlags<UPGRADE_MAX_COUNT> UpgradeMaskType;
  51. #define MAKE_UPGRADE_MASK(k) UpgradeMaskType(UpgradeMaskType::kInit, (k))
  52. #define MAKE_UPGRADE_MASK2(k,a) UpgradeMaskType(UpgradeMaskType::kInit, (k), (a))
  53. #define MAKE_UPGRADE_MASK3(k,a,b) UpgradeMaskType(UpgradeMaskType::kInit, (k), (a), (b))
  54. #define MAKE_UPGRADE_MASK4(k,a,b,c) UpgradeMaskType(UpgradeMaskType::kInit, (k), (a), (b), (c))
  55. #define MAKE_UPGRADE_MASK5(k,a,b,c,d) UpgradeMaskType(UpgradeMaskType::kInit, (k), (a), (b), (c), (d))
  56. inline Bool TEST_UPGRADE_MASK( const UpgradeMaskType& m, Int index )
  57. {
  58. return m.test( index );
  59. }
  60. inline Bool TEST_UPGRADE_MASK_ANY( const UpgradeMaskType& m, const UpgradeMaskType& mask )
  61. {
  62. return m.anyIntersectionWith( mask );
  63. }
  64. inline Bool TEST_UPGRADE_MASK_MULTI( const UpgradeMaskType& m, const UpgradeMaskType& mustBeSet, const UpgradeMaskType& mustBeClear )
  65. {
  66. return m.testSetAndClear( mustBeSet, mustBeClear );
  67. }
  68. inline Bool UPGRADE_MASK_ANY_SET( const UpgradeMaskType& m)
  69. {
  70. return m.any();
  71. }
  72. inline void CLEAR_UPGRADE_MASK( UpgradeMaskType& m )
  73. {
  74. m.clear();
  75. }
  76. inline void SET_ALL_UPGRADE_MASK_BITS( UpgradeMaskType& m )
  77. {
  78. m.clear( );
  79. m.flip( );
  80. }
  81. inline void FLIP_UPGRADE_MASK( UpgradeMaskType& m )
  82. {
  83. m.flip();
  84. }
  85. //-------------------------------------------------------------------------------------------------
  86. /** A single upgrade *INSTANCE* */
  87. //-------------------------------------------------------------------------------------------------
  88. class Upgrade : public MemoryPoolObject,
  89. public Snapshot
  90. {
  91. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( Upgrade, "Upgrade" )
  92. public:
  93. Upgrade( const UpgradeTemplate *upgradeTemplate );
  94. // virtual destructor prototypes provided by memory pool object
  95. /// get the upgrade template for this instance
  96. const UpgradeTemplate *getTemplate( void ) const { return m_template; }
  97. // status access
  98. UpgradeStatusType getStatus( void ) const { return m_status; } ///< get status
  99. void setStatus( UpgradeStatusType status ) { m_status = status; } ///< set the status
  100. // friend access methods
  101. void friend_setNext( Upgrade *next ) { m_next = next; }
  102. void friend_setPrev( Upgrade *prev ) { m_prev = prev; }
  103. Upgrade *friend_getNext( void ) { return m_next; }
  104. Upgrade *friend_getPrev( void ) { return m_prev; }
  105. protected:
  106. // snapshot methods
  107. virtual void crc( Xfer *xfer );
  108. virtual void xfer( Xfer *xfer );
  109. virtual void loadPostProcess( void );
  110. const UpgradeTemplate *m_template; ///< template this upgrade instance is based on
  111. UpgradeStatusType m_status; ///< status of upgrade
  112. Upgrade *m_next; ///< next
  113. Upgrade *m_prev; ///< prev
  114. };
  115. //-------------------------------------------------------------------------------------------------
  116. //-------------------------------------------------------------------------------------------------
  117. enum UpgradeType
  118. {
  119. UPGRADE_TYPE_PLAYER = 0, // upgrade applies to a player as a whole
  120. UPGRADE_TYPE_OBJECT, // upgrade applies to an object instance only
  121. NUM_UPGRADE_TYPES, // keep this last
  122. };
  123. extern const char *TheUpgradeTypeNames[]; //Change above, change this!
  124. //-------------------------------------------------------------------------------------------------
  125. /** A single upgrade template definition */
  126. //-------------------------------------------------------------------------------------------------
  127. class UpgradeTemplate : public MemoryPoolObject
  128. {
  129. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( UpgradeTemplate, "UpgradeTemplate" )
  130. public:
  131. UpgradeTemplate( void );
  132. // virtual destructor defined by memory pool object
  133. Int calcTimeToBuild( Player *player ) const; ///< time in logic frames it will take this player to "build" this UpgradeTemplate
  134. Int calcCostToBuild( Player *player ) const; ///< calc the cost to build this upgrade
  135. // field access
  136. void setUpgradeName( const AsciiString& name ) { m_name = name; }
  137. const AsciiString& getUpgradeName( void ) const { return m_name; }
  138. void setUpgradeNameKey( NameKeyType key ) { m_nameKey = key; }
  139. NameKeyType getUpgradeNameKey( void ) const { return m_nameKey; }
  140. const AsciiString& getDisplayNameLabel( void ) const { return m_displayNameLabel; }
  141. UpgradeMaskType getUpgradeMask() const { return m_upgradeMask; }
  142. UpgradeType getUpgradeType( void ) const { return m_type; }
  143. const AudioEventRTS* getResearchCompleteSound() const { return &m_researchSound; }
  144. const AudioEventRTS* getUnitSpecificSound() const { return &m_unitSpecificSound; }
  145. AcademyClassificationType getAcademyClassificationType() const { return m_academyClassificationType; }
  146. /// inventory pictures
  147. void cacheButtonImage();
  148. const Image* getButtonImage() const { return m_buttonImage; }
  149. /// INI parsing
  150. const FieldParse *getFieldParse() const { return m_upgradeFieldParseTable; }
  151. // friend access methods for the UpgradeCenter ONLY
  152. void friend_setNext( UpgradeTemplate *next ) { m_next = next; }
  153. void friend_setPrev( UpgradeTemplate *prev ) { m_prev = prev; }
  154. UpgradeTemplate *friend_getNext( void ) { return m_next; }
  155. UpgradeTemplate *friend_getPrev( void ) { return m_prev; }
  156. const UpgradeTemplate *friend_getNext( void ) const { return m_next; }
  157. const UpgradeTemplate *friend_getPrev( void ) const { return m_prev; }
  158. void friend_setUpgradeMask( UpgradeMaskType mask ) { m_upgradeMask = mask; }
  159. void friend_makeVeterancyUpgrade(VeterancyLevel v);
  160. protected:
  161. UpgradeType m_type; ///< upgrade type (PLAYER or OBJECT)
  162. AsciiString m_name; ///< upgrade name
  163. NameKeyType m_nameKey; ///< name key
  164. AsciiString m_displayNameLabel; ///< String manager label for UI display name
  165. Real m_buildTime; ///< database # for how long it takes to "build" this
  166. Int m_cost; ///< cost for production
  167. UpgradeMaskType m_upgradeMask; ///< Unique bitmask for this upgrade template
  168. AudioEventRTS m_researchSound; ///< Sound played when upgrade researched.
  169. AudioEventRTS m_unitSpecificSound; ///< Secondary sound played when upgrade researched.
  170. AcademyClassificationType m_academyClassificationType; ///< A value used by the academy to evaluate advice based on what players do.
  171. UpgradeTemplate *m_next; ///< next
  172. UpgradeTemplate *m_prev; ///< prev
  173. AsciiString m_buttonImageName; ///< "Queue" images to show in the build queue
  174. const Image *m_buttonImage;
  175. /// INI field table
  176. static const FieldParse m_upgradeFieldParseTable[]; ///< the parse table
  177. };
  178. //-------------------------------------------------------------------------------------------------
  179. /** The upgrade center keeps some basic information about the possible upgrades */
  180. //-------------------------------------------------------------------------------------------------
  181. class UpgradeCenter : public SubsystemInterface
  182. {
  183. public:
  184. UpgradeCenter( void );
  185. virtual ~UpgradeCenter( void );
  186. void init( void ); ///< subsystem interface
  187. void reset( void ); ///< subsystem interface
  188. void update( void ) { } ///< subsystem interface
  189. UpgradeTemplate *firstUpgradeTemplate( void ); ///< return the first upgrade template
  190. const UpgradeTemplate *findUpgradeByKey( NameKeyType key ) const; ///< find upgrade by name key
  191. const UpgradeTemplate *findUpgrade( const AsciiString& name ) const; ///< find and return upgrade by name
  192. const UpgradeTemplate *findVeterancyUpgrade(VeterancyLevel level) const; ///< find and return upgrade by name
  193. UpgradeTemplate *newUpgrade( const AsciiString& name ); ///< allocate, link, and return new upgrade
  194. /// does this player have all the necessary things to make this upgrade
  195. Bool canAffordUpgrade( Player *player, const UpgradeTemplate *upgradeTemplate, Bool displayReason = FALSE ) const;
  196. std::vector<AsciiString> getUpgradeNames( void ) const; // For WorldBuilder only!!!
  197. static void parseUpgradeDefinition( INI *ini );
  198. protected:
  199. UpgradeTemplate *findNonConstUpgradeByKey( NameKeyType key ); ///< find upgrade by name key
  200. void linkUpgrade( UpgradeTemplate *upgrade ); ///< link upgrade to list
  201. void unlinkUpgrade( UpgradeTemplate *upgrade ); ///< remove upgrade from list
  202. UpgradeTemplate *m_upgradeList; ///< list of all upgrades we can have
  203. Int m_nextTemplateMaskBit; ///< Each instantiated UpgradeTemplate will be given a Int64 bit as an identifier
  204. Bool buttonImagesCached;
  205. };
  206. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  207. extern UpgradeCenter *TheUpgradeCenter;
  208. #endif // end __UPGRADE_H_