Upgrade.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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: 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. //-------------------------------------------------------------------------------------------------
  40. //-------------------------------------------------------------------------------------------------
  41. enum UpgradeStatusType
  42. {
  43. UPGRADE_STATUS_INVALID = 0,
  44. UPGRADE_STATUS_IN_PRODUCTION,
  45. UPGRADE_STATUS_COMPLETE
  46. };
  47. //-------------------------------------------------------------------------------------------------
  48. /** A single upgrade *INSTANCE* */
  49. //-------------------------------------------------------------------------------------------------
  50. class Upgrade : public MemoryPoolObject,
  51. public Snapshot
  52. {
  53. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( Upgrade, "Upgrade" )
  54. public:
  55. Upgrade( const UpgradeTemplate *upgradeTemplate );
  56. // virtual destructor prototypes provided by memory pool object
  57. /// get the upgrade template for this instance
  58. const UpgradeTemplate *getTemplate( void ) const { return m_template; }
  59. // status access
  60. UpgradeStatusType getStatus( void ) const { return m_status; } ///< get status
  61. void setStatus( UpgradeStatusType status ) { m_status = status; } ///< set the status
  62. // friend access methods
  63. void friend_setNext( Upgrade *next ) { m_next = next; }
  64. void friend_setPrev( Upgrade *prev ) { m_prev = prev; }
  65. Upgrade *friend_getNext( void ) { return m_next; }
  66. Upgrade *friend_getPrev( void ) { return m_prev; }
  67. protected:
  68. // snapshot methods
  69. virtual void crc( Xfer *xfer );
  70. virtual void xfer( Xfer *xfer );
  71. virtual void loadPostProcess( void );
  72. const UpgradeTemplate *m_template; ///< template this upgrade instance is based on
  73. UpgradeStatusType m_status; ///< status of upgrade
  74. Upgrade *m_next; ///< next
  75. Upgrade *m_prev; ///< prev
  76. };
  77. //-------------------------------------------------------------------------------------------------
  78. //-------------------------------------------------------------------------------------------------
  79. enum UpgradeType
  80. {
  81. UPGRADE_TYPE_PLAYER = 0, // upgrade applies to a player as a whole
  82. UPGRADE_TYPE_OBJECT, // upgrade applies to an object instance only
  83. NUM_UPGRADE_TYPES, // keep this last
  84. };
  85. #ifdef DEFINE_UPGRADE_TYPE_NAMES
  86. static Char *UpgradeTypeNames[] =
  87. {
  88. "PLAYER",
  89. "OBJECT",
  90. NULL
  91. };
  92. #endif // end DEFINE_UPGRADE_TYPE_NAMES
  93. //-------------------------------------------------------------------------------------------------
  94. /** A single upgrade template definition */
  95. //-------------------------------------------------------------------------------------------------
  96. class UpgradeTemplate : public MemoryPoolObject
  97. {
  98. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( UpgradeTemplate, "UpgradeTemplate" )
  99. public:
  100. UpgradeTemplate( void );
  101. // virtual destructor defined by memory pool object
  102. Int calcTimeToBuild( Player *player ) const; ///< time in logic frames it will take this player to "build" this UpgradeTemplate
  103. Int calcCostToBuild( Player *player ) const; ///< calc the cost to build this upgrade
  104. // field access
  105. void setUpgradeName( const AsciiString& name ) { m_name = name; }
  106. const AsciiString& getUpgradeName( void ) const { return m_name; }
  107. void setUpgradeNameKey( NameKeyType key ) { m_nameKey = key; }
  108. NameKeyType getUpgradeNameKey( void ) const { return m_nameKey; }
  109. const AsciiString& getDisplayNameLabel( void ) const { return m_displayNameLabel; }
  110. Int64 getUpgradeMask() const { return m_upgradeMask; }
  111. UpgradeType getUpgradeType( void ) const { return m_type; }
  112. const AudioEventRTS* getResearchCompleteSound() const { return &m_researchSound; }
  113. const AudioEventRTS* getUnitSpecificSound() const { return &m_unitSpecificSound; }
  114. /// inventory pictures
  115. void cacheButtonImage();
  116. const Image* getButtonImage() const { return m_buttonImage; }
  117. /// INI parsing
  118. const FieldParse *getFieldParse() const { return m_upgradeFieldParseTable; }
  119. // friend access methods for the UpgradeCenter ONLY
  120. void friend_setNext( UpgradeTemplate *next ) { m_next = next; }
  121. void friend_setPrev( UpgradeTemplate *prev ) { m_prev = prev; }
  122. UpgradeTemplate *friend_getNext( void ) { return m_next; }
  123. UpgradeTemplate *friend_getPrev( void ) { return m_prev; }
  124. const UpgradeTemplate *friend_getNext( void ) const { return m_next; }
  125. const UpgradeTemplate *friend_getPrev( void ) const { return m_prev; }
  126. void friend_setUpgradeMask( Int64 mask ) { m_upgradeMask = mask; }
  127. void friend_makeVeterancyUpgrade(VeterancyLevel v);
  128. protected:
  129. UpgradeType m_type; ///< upgrade type (PLAYER or OBJECT)
  130. AsciiString m_name; ///< upgrade name
  131. NameKeyType m_nameKey; ///< name key
  132. AsciiString m_displayNameLabel; ///< String manager label for UI display name
  133. Real m_buildTime; ///< database # for how long it takes to "build" this
  134. Int m_cost; ///< cost for production
  135. Int64 m_upgradeMask; ///< Unique bitmask for this upgrade template
  136. AudioEventRTS m_researchSound; ///< Sound played when upgrade researched.
  137. AudioEventRTS m_unitSpecificSound; ///< Secondary sound played when upgrade researched.
  138. UpgradeTemplate *m_next; ///< next
  139. UpgradeTemplate *m_prev; ///< prev
  140. AsciiString m_buttonImageName; ///< "Queue" images to show in the build queue
  141. const Image *m_buttonImage;
  142. /// INI field table
  143. static const FieldParse m_upgradeFieldParseTable[]; ///< the parse table
  144. };
  145. //-------------------------------------------------------------------------------------------------
  146. /** The upgrade center keeps some basic information about the possible upgrades */
  147. //-------------------------------------------------------------------------------------------------
  148. class UpgradeCenter : public SubsystemInterface
  149. {
  150. public:
  151. UpgradeCenter( void );
  152. virtual ~UpgradeCenter( void );
  153. void init( void ); ///< subsystem interface
  154. void reset( void ); ///< subsystem interface
  155. void update( void ) { } ///< subsystem interface
  156. UpgradeTemplate *firstUpgradeTemplate( void ); ///< return the first upgrade template
  157. const UpgradeTemplate *findUpgradeByKey( NameKeyType key ) const; ///< find upgrade by name key
  158. const UpgradeTemplate *findUpgrade( const AsciiString& name ) const; ///< find and return upgrade by name
  159. const UpgradeTemplate *findVeterancyUpgrade(VeterancyLevel level) const; ///< find and return upgrade by name
  160. UpgradeTemplate *newUpgrade( const AsciiString& name ); ///< allocate, link, and return new upgrade
  161. /// does this player have all the necessary things to make this upgrade
  162. Bool canAffordUpgrade( Player *player, const UpgradeTemplate *upgradeTemplate, Bool displayReason = FALSE ) const;
  163. std::vector<AsciiString> getUpgradeNames( void ) const; // For WorldBuilder only!!!
  164. static void parseUpgradeDefinition( INI *ini );
  165. protected:
  166. UpgradeTemplate *findNonConstUpgradeByKey( NameKeyType key ); ///< find upgrade by name key
  167. void linkUpgrade( UpgradeTemplate *upgrade ); ///< link upgrade to list
  168. void unlinkUpgrade( UpgradeTemplate *upgrade ); ///< remove upgrade from list
  169. UpgradeTemplate *m_upgradeList; ///< list of all upgrades we can have
  170. Int m_nextTemplateMaskBit; ///< Each instantiated UpgradeTemplate will be given a Int64 bit as an identifier
  171. Bool buttonImagesCached;
  172. };
  173. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  174. extern UpgradeCenter *TheUpgradeCenter;
  175. #endif // end __UPGRADE_H_