OverchargeBehavior.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: OverchargeBehavior.h /////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, June 2002
  25. // Desc: Objects with this behavior module will get the ability to produce more power
  26. // for a short amount of time, during this "overcharge" state object health is
  27. // slowly reduced
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. #pragma once
  30. #ifndef __OVERCHARGE_BEHAVIOR_H_
  31. #define __OVERCHARGE_BEHAVIOR_H_
  32. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  33. #include "GameLogic/Module/BehaviorModule.h"
  34. #include "GameLogic/Module/DamageModule.h"
  35. #include "GameLogic/Module/UpdateModule.h"
  36. //-------------------------------------------------------------------------------------------------
  37. // ------------------------------------------------------------------------------------------------
  38. class OverchargeBehaviorModuleData : public UpdateModuleData
  39. {
  40. public:
  41. OverchargeBehaviorModuleData( void );
  42. static void buildFieldParse( MultiIniFieldParse &p );
  43. Real m_healthPercentToDrainPerSecond; ///< when active, this much health is drained
  44. Real m_notAllowedWhenHealthBelowPercent; ///< you cannot overcharge when object is below this health %
  45. };
  46. // ------------------------------------------------------------------------------------------------
  47. // ------------------------------------------------------------------------------------------------
  48. class OverchargeBehaviorInterface
  49. {
  50. public:
  51. virtual void toggle( void ) = 0;
  52. virtual void enable( Bool enable ) = 0;
  53. virtual Bool isOverchargeActive( void ) = 0;
  54. };
  55. //-------------------------------------------------------------------------------------------------
  56. //-------------------------------------------------------------------------------------------------
  57. class OverchargeBehavior : public UpdateModule,
  58. public DamageModuleInterface,
  59. public OverchargeBehaviorInterface
  60. {
  61. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( OverchargeBehavior, "OverchargeBehavior" )
  62. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( OverchargeBehavior, OverchargeBehaviorModuleData )
  63. public:
  64. OverchargeBehavior( Thing *thing, const ModuleData *moduleData );
  65. // virtual destructor prototype provided by memory pool declaration
  66. // interface housekeeping
  67. virtual OverchargeBehaviorInterface* getOverchargeBehaviorInterface() { return this; }
  68. static Int getInterfaceMask( void ) { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_DAMAGE); }
  69. // BehaviorModule
  70. virtual DamageModuleInterface* getDamage( void ) { return this; }
  71. // UpdateModuleInterface
  72. virtual UpdateSleepTime update( void );
  73. // DamageModuleInterface
  74. virtual void onDamage( DamageInfo *damageInfo );
  75. virtual void onHealing( DamageInfo *damageInfo ) { }
  76. virtual void onBodyDamageStateChange( const DamageInfo *damageInfo,
  77. BodyDamageType oldState,
  78. BodyDamageType newState ) { }
  79. // specific methods
  80. virtual void toggle( void ); ///< toggle overcharge on/off
  81. virtual void enable( Bool enable ); ///< turn overcharge on/off
  82. virtual Bool isOverchargeActive( void ) { return m_overchargeActive; }
  83. void onDelete( void ); ///< we have some work to do when this module goes away
  84. void onCapture( Player *oldOwner, Player *newOwner ); ///< object containing upgrade has changed teams
  85. protected:
  86. Bool m_overchargeActive; ///< Overcharge is currently on/off for this object
  87. };
  88. #endif // end __OVERCHARGE_BEHAVIOR_H_