SpecialPowerModule.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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: SpecialPowerModule.h /////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, April 2002
  25. // Desc: Special power module interface
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __SPECIALPOWERMODULE_H_
  29. #define __SPECIALPOWERMODULE_H_
  30. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/AudioEventRTS.h"
  32. #include "Common/Module.h"
  33. #include "Common/Science.h"
  34. #include "GameLogic/Module/BehaviorModule.h"
  35. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  36. class Object;
  37. class SpecialPowerTemplate;
  38. struct FieldParse;
  39. //-------------------------------------------------------------------------------------------------
  40. //-------------------------------------------------------------------------------------------------
  41. class SpecialPowerModuleInterface
  42. {
  43. public:
  44. virtual Bool isModuleForPower( const SpecialPowerTemplate *specialPowerTemplate ) const = 0;
  45. virtual Bool isReady( void ) const = 0;
  46. // This is the althernate way to one-at-a-time BlackLotus' specials; we'll keep it commented her until Dustin decides, or until 12/10/02
  47. // virtual Bool isBusy( void ) const = 0;
  48. virtual Real getPercentReady( void ) const = 0;
  49. virtual UnsignedInt getReadyFrame( void ) const = 0;
  50. virtual AsciiString getPowerName( void ) const = 0;
  51. virtual const SpecialPowerTemplate* getSpecialPowerTemplate( void ) const = 0;
  52. virtual ScienceType getRequiredScience( void ) const = 0;
  53. virtual void onSpecialPowerCreation( void ) = 0;
  54. virtual void setReadyFrame( UnsignedInt frame ) = 0;
  55. virtual void pauseCountdown( Bool pause ) = 0;
  56. virtual void doSpecialPower( UnsignedInt commandOptions ) = 0;
  57. virtual void doSpecialPowerAtObject( Object *obj, UnsignedInt commandOptions ) = 0;
  58. virtual void doSpecialPowerAtLocation( const Coord3D *loc, Real angle, UnsignedInt commandOptions ) = 0;
  59. virtual void doSpecialPowerUsingWaypoints( const Waypoint *way, UnsignedInt commandOptions ) = 0;
  60. virtual void markSpecialPowerTriggered( const Coord3D *location ) = 0;
  61. virtual void startPowerRecharge() = 0;
  62. virtual const AudioEventRTS& getInitiateSound() const = 0;
  63. virtual Bool isScriptOnly() const = 0;
  64. //If the special power launches a construction site, we need to know the final product for placement purposes.
  65. virtual const ThingTemplate* getReferenceThingTemplate() const = 0;
  66. };
  67. //-------------------------------------------------------------------------------------------------
  68. //-------------------------------------------------------------------------------------------------
  69. class SpecialPowerModuleData : public BehaviorModuleData
  70. {
  71. public:
  72. SpecialPowerModuleData();
  73. static void buildFieldParse(MultiIniFieldParse& p);
  74. const SpecialPowerTemplate *m_specialPowerTemplate; ///< pointer to the special power template
  75. AudioEventRTS m_initiateSound;
  76. Bool m_updateModuleStartsAttack; ///< update module determines when the special power actually starts! If true, update module is required.
  77. Bool m_startsPaused; ///< Paused on creation, someone else will have to unpause (like upgrade module, or script)
  78. Bool m_scriptedSpecialPowerOnly;
  79. };
  80. //-------------------------------------------------------------------------------------------------
  81. //-------------------------------------------------------------------------------------------------
  82. class SpecialPowerModule : public BehaviorModule,
  83. public SpecialPowerModuleInterface
  84. {
  85. MEMORY_POOL_GLUE_ABC( SpecialPowerModule )
  86. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( SpecialPowerModule, SpecialPowerModuleData )
  87. public:
  88. SpecialPowerModule( Thing* thing, const ModuleData* moduleData );
  89. static Int getInterfaceMask() { return MODULEINTERFACE_SPECIAL_POWER; }
  90. // BehaviorModule
  91. virtual SpecialPowerModuleInterface* getSpecialPower() { return this; }
  92. Bool isModuleForPower( const SpecialPowerTemplate *specialPowerTemplate ) const; ///< is this module for the specified special power
  93. Bool isReady( void ) const; ///< is this special power available now
  94. // This is the althernate way to one-at-a-time BlackLotus' specials; we'll keep it commented her until Dustin decides, or until 12/10/02
  95. // Bool isBusy( void ) const { return FALSE; }
  96. Real getPercentReady( void ) const; ///< get the percent ready (1.0 = ready now, 0.5 = half charged up etc.)
  97. UnsignedInt getReadyFrame( void ) const; ///< get the frame at which we are ready
  98. AsciiString getPowerName( void ) const;
  99. void syncReadyFrameToStatusQuo( void );
  100. const SpecialPowerTemplate* getSpecialPowerTemplate( void ) const;
  101. ScienceType getRequiredScience( void ) const;
  102. void onSpecialPowerCreation( void ); // called by a create module to start our countdown
  103. //
  104. // The following methods are for use by the scripting engine ONLY
  105. //
  106. void setReadyFrame( UnsignedInt frame );
  107. UnsignedInt getReadyFrame( void ) { return m_availableOnFrame; }// USED BY PLAYER TO KEEP RECHARGE TIMERS IN SYNC
  108. void pauseCountdown( Bool pause );
  109. //
  110. // the following methods should be *EXTENDED* for any special power module implementations
  111. // and carry out the special power executions
  112. //
  113. virtual void doSpecialPower( UnsignedInt commandOptions );
  114. virtual void doSpecialPowerAtObject( Object *obj, UnsignedInt commandOptions );
  115. virtual void doSpecialPowerAtLocation( const Coord3D *loc, Real angle, UnsignedInt commandOptions );
  116. virtual void doSpecialPowerUsingWaypoints( const Waypoint *way, UnsignedInt commandOptions );
  117. /**
  118. Now, there are special powers that require some preliminary processing before the actual
  119. special power triggers. When the ini setting "UpdateModuleStartsAttack" is true, then
  120. the update module will call the doSpecialPower a second time. This function then resets
  121. the power recharge, and tells the scriptengine that the attack has started.
  122. A good example of something that uses this is the Black Lotus - capture building hack attack.
  123. When the user initiates the attack, the doSpecialPower is called, which triggers the update
  124. module. The update module then orders the unit to move within range, and it isn't until the
  125. hacker start the physical attack, that the timer is reset and the attack technically begins.
  126. */
  127. virtual void markSpecialPowerTriggered( const Coord3D *location );
  128. /** start the recharge process for this special power. public because some powers call it repeatedly.
  129. */
  130. virtual void startPowerRecharge();
  131. virtual const AudioEventRTS& getInitiateSound() const;
  132. virtual Bool isScriptOnly() const;
  133. //If the special power launches a construction site, we need to know the final product for placement purposes.
  134. virtual const ThingTemplate* getReferenceThingTemplate() const { return NULL; }
  135. protected:
  136. Bool initiateIntentToDoSpecialPower( const Object *targetObj, const Coord3D *targetPos, const Waypoint *way, UnsignedInt commandOptions );
  137. void triggerSpecialPower( const Coord3D *location );
  138. void createViewObject( const Coord3D *location );
  139. void resolveSpecialPower( void );
  140. void aboutToDoSpecialPower( const Coord3D *location );
  141. UnsignedInt m_availableOnFrame; ///< on this frame, this special power is available
  142. Int m_pausedCount; ///< Reference count of sources pausing me
  143. UnsignedInt m_pausedOnFrame;
  144. Real m_pausedPercent;
  145. };
  146. #endif // end __SPECIALPOWERMODULE_H_