SpecialPower.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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: SpecialPower.h ///////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, April 2002
  25. // Desc: Special power templates and the system that holds them
  26. // Edited: Kris Morness -- July 2002 (added BitFlag system)
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. #pragma once
  29. #ifndef __SPECIALPOWER_H_
  30. #define __SPECIALPOWER_H_
  31. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  32. #include "Common/AudioEventRTS.h"
  33. #include "Common/GameMemory.h"
  34. #include "Common/SubsystemInterface.h"
  35. #include "Lib/BaseType.h"
  36. #include "Common/BitFlags.h"
  37. #include "Common/Overridable.h"
  38. #include "Common/Override.h"
  39. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  40. class ObjectCreationList;
  41. class Object;
  42. enum ScienceType;
  43. struct FieldParse;
  44. enum AcademyClassificationType;
  45. // For SpecialPowerType and SpecialPowerMaskType::s_bitNameList. Part of detangling.
  46. #include "Common/SpecialPowerType.h"
  47. // For SpecialPowerMaskType. Part of detangling.
  48. #include "Common/SpecialPowerMaskType.h"
  49. #define MAKE_SPECIALPOWER_MASK(k) SpecialPowerMaskType(SpecialPowerMaskType::kInit, (k))
  50. inline Bool TEST_SPECIALPOWERMASK(const SpecialPowerMaskType& m, SpecialPowerType t)
  51. {
  52. return m.test(t);
  53. }
  54. inline Bool TEST_SPECIALPOWERMASK_ANY(const SpecialPowerMaskType& m, const SpecialPowerMaskType& mask)
  55. {
  56. return m.anyIntersectionWith(mask);
  57. }
  58. inline Bool TEST_SPECIALPOWERMASK_MULTI(const SpecialPowerMaskType& m, const SpecialPowerMaskType& mustBeSet, const SpecialPowerMaskType& mustBeClear)
  59. {
  60. return m.testSetAndClear(mustBeSet, mustBeClear);
  61. }
  62. inline Bool SPECIALPOWERMASK_ANY_SET(const SpecialPowerMaskType& m)
  63. {
  64. return m.any();
  65. }
  66. inline void CLEAR_SPECIALPOWERMASK(SpecialPowerMaskType& m)
  67. {
  68. m.clear();
  69. }
  70. inline void SET_SPECIALPOWERMASK( SpecialPowerMaskType& m, SpecialPowerType t, Int val = 1 )
  71. {
  72. m.set( t, val );
  73. }
  74. inline void SET_ALL_SPECIALPOWERMASK_BITS(SpecialPowerMaskType& m)
  75. {
  76. m.clear();
  77. m.flip();
  78. }
  79. inline void FLIP_SPECIALPOWERMASK(SpecialPowerMaskType& m)
  80. {
  81. m.flip();
  82. }
  83. //-------------------------------------------------------------------------------------------------
  84. //-------------------------------------------------------------------------------------------------
  85. class SpecialPowerTemplate : public Overridable
  86. {
  87. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( SpecialPowerTemplate, "SpecialPowerTemplate" )
  88. public:
  89. SpecialPowerTemplate();
  90. // virtual destructor prototype provided by MemoryPoolObject
  91. static const FieldParse* getFieldParse( void ) { return m_specialPowerFieldParse; }
  92. void friend_setNameAndID(const AsciiString& name, UnsignedInt id)
  93. {
  94. m_name = name;
  95. m_id = id;
  96. }
  97. AsciiString getName( void ) const { return getFO()->m_name; }
  98. UnsignedInt getID( void ) const { return getFO()->m_id; }
  99. SpecialPowerType getSpecialPowerType( void ) const { return getFO()->m_type; }
  100. UnsignedInt getReloadTime( void ) const { return getFO()->m_reloadTime; }
  101. ScienceType getRequiredScience( void ) const { return getFO()->m_requiredScience; }
  102. const AudioEventRTS *getInitiateSound( void ) const { return &getFO()->m_initiateSound; }
  103. const AudioEventRTS *getInitiateAtTargetSound( void ) const { return &getFO()->m_initiateAtLocationSound; }
  104. Bool hasPublicTimer( void ) const { return getFO()->m_publicTimer; }
  105. Bool isSharedNSync( void ) const { return getFO()->m_sharedNSync; }
  106. UnsignedInt getDetectionTime( void ) const { return getFO()->m_detectionTime; }
  107. UnsignedInt getViewObjectDuration( void ) const { return getFO()->m_viewObjectDuration; }
  108. Real getViewObjectRange( void ) const { return getFO()->m_viewObjectRange; }
  109. Real getRadiusCursorRadius() const { return getFO()->m_radiusCursorRadius; }
  110. Bool isShortcutPower() const { return getFO()->m_shortcutPower; }
  111. AcademyClassificationType getAcademyClassificationType() const { return m_academyClassificationType; }
  112. private:
  113. const SpecialPowerTemplate* getFO() const { return (const SpecialPowerTemplate*)friend_getFinalOverride(); }
  114. AsciiString m_name; ///< name
  115. UnsignedInt m_id; ///< unique identifier
  116. SpecialPowerType m_type; ///< enum allowing for fast type checking for ability processing.
  117. UnsignedInt m_reloadTime; ///< (frames) after using special power, how long it takes to use again
  118. ScienceType m_requiredScience; ///< science required (if any) to actually execute this power
  119. AudioEventRTS m_initiateSound; ///< sound to play when initiated
  120. AudioEventRTS m_initiateAtLocationSound; ///< sound to play at target location (if any)
  121. AcademyClassificationType m_academyClassificationType; ///< A value used by the academy to evaluate advice based on what players do.
  122. UnsignedInt m_detectionTime; ///< (frames) after using infiltration power (defection, etc.),
  123. ///< how long it takes for ex comrades to realize it on their own
  124. UnsignedInt m_viewObjectDuration; ///< Lifetime of a looking object we slap down so you can watch the effect
  125. Real m_viewObjectRange; ///< And how far that object can see.
  126. Real m_radiusCursorRadius; ///< size of radius cursor, if any
  127. Bool m_publicTimer; ///< display a countdown timer for this special power for all to see
  128. Bool m_sharedNSync; ///< If true, this is a special that is shared between all of a player's command centers
  129. Bool m_shortcutPower; ///< Is this shortcut power capable of being fired by the side panel?
  130. static const FieldParse m_specialPowerFieldParse[]; ///< the parse table
  131. };
  132. //-------------------------------------------------------------------------------------------------
  133. //-------------------------------------------------------------------------------------------------
  134. class SpecialPowerStore : public SubsystemInterface
  135. {
  136. public:
  137. SpecialPowerStore( void );
  138. ~SpecialPowerStore( void );
  139. virtual void init( void ) { };
  140. virtual void update( void ) { };
  141. virtual void reset( void );
  142. const SpecialPowerTemplate *findSpecialPowerTemplate( AsciiString name ) { return findSpecialPowerTemplatePrivate(name); }
  143. const SpecialPowerTemplate *findSpecialPowerTemplateByID( UnsignedInt id );
  144. const SpecialPowerTemplate *getSpecialPowerTemplateByIndex( UnsignedInt index ); // for WorldBuilder
  145. /// does the object (and therefore the player) meet all the requirements to use this power
  146. Bool canUseSpecialPower( Object *obj, const SpecialPowerTemplate *specialPowerTemplate );
  147. Int getNumSpecialPowers( void ); // for WorldBuilder
  148. static void parseSpecialPowerDefinition( INI *ini );
  149. private:
  150. protected:
  151. SpecialPowerTemplate *findSpecialPowerTemplatePrivate( AsciiString name );
  152. typedef std::vector<SpecialPowerTemplate *> SpecialPowerTemplatePtrVector;
  153. SpecialPowerTemplatePtrVector m_specialPowerTemplates; ///< the special power templates
  154. UnsignedInt m_nextSpecialPowerID;
  155. };
  156. // EXTERNAL ///////////////////////////////////////////////////////////////////////////////////////
  157. extern SpecialPowerStore *TheSpecialPowerStore;
  158. #endif // end __SPECIALPOWER_H_