SpecialPower.h 7.6 KB

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