FiringTracker.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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: FiringTracker.h //////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, February 2002
  25. // Desc: Keeps track of shots fired and people targeted for weapons that want a history of such a thing
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef FIRING_TRACKER_H
  29. #define FIRING_TRACKER_H
  30. #include "Common/GameType.h"
  31. #include "Common/GameMemory.h"
  32. #include "Common/AudioEventRTS.h"
  33. #include "GameLogic/Module/UpdateModule.h"
  34. class Object;
  35. class Weapon;
  36. // ------------------------------------------------------------------------------------------------
  37. // ------------------------------------------------------------------------------------------------
  38. class FiringTrackerModuleData : public ModuleData
  39. {
  40. };
  41. // ------------------------------------------------------------------------------------------------
  42. // ------------------------------------------------------------------------------------------------
  43. class FiringTracker : public UpdateModule
  44. {
  45. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( FiringTracker, FiringTrackerModuleData )
  46. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(FiringTracker, "FiringTrackerPool" )
  47. public:
  48. FiringTracker(Thing *thing, const ModuleData *modData);
  49. void shotFired(const Weapon* weaponFired, ObjectID victimID ); ///< Owner just fired this weapon at this Object
  50. ObjectID getLastShotVictim() const { return m_victimID; } ///< get the last victim ID that was shot at
  51. Int getNumConsecutiveShotsAtVictim( const Object *victim ) const;
  52. /// this is never disabled, since we want disabled things to continue to slowly "spin down"... (srj)
  53. virtual DisabledMaskType getDisabledTypesToProcess() const { return DISABLEDMASK_ALL; }
  54. virtual UpdateSleepTime update(); ///< See if spin down is needed because we haven't shot in a while
  55. protected:
  56. /*
  57. The firingtracker needs to have its update run after all "normal"
  58. user update modules, so it redefines this. Please don't redefine this
  59. for other modules without very careful deliberation. (srj)
  60. */
  61. virtual SleepyUpdatePhase getUpdatePhase() const
  62. {
  63. return PHASE_FINAL;
  64. }
  65. private:
  66. void speedUp(); ///< I've qualified for an increase in my Object flag status
  67. void coolDown(); ///< I need to slow down because it has been too long since I fired.
  68. UpdateSleepTime calcTimeToSleep();
  69. private:
  70. Int m_consecutiveShots; ///< How many times I have shot at the same thing
  71. ObjectID m_victimID; ///< The thing I have shot so many times
  72. UnsignedInt m_frameToStartCooldown; ///< This is the frame I should cool down at, and is pushed back every time a shot is fired
  73. UnsignedInt m_frameToForceReload; ///< Even more than AutoReload, this means it will pre-emptively reload instead of event triggering a delay after the last shot
  74. UnsignedInt m_frameToStopLoopingSound; ///< if sound is looping, frame to stop looping it (or zero if not looping)
  75. AudioHandle m_audioHandle;
  76. };
  77. #endif