DumbProjectileBehavior.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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: DumbProjectileBehavior.h
  24. // Author: Steven Johnson, July 2002
  25. // Desc:
  26. #pragma once
  27. #ifndef _DumbProjectileBehavior_H_
  28. #define _DumbProjectileBehavior_H_
  29. #include "Common/GameType.h"
  30. #include "Common/GlobalData.h"
  31. #include "Common/STLTypeDefs.h"
  32. #include "GameLogic/Module/BehaviorModule.h"
  33. #include "GameLogic/Module/CollideModule.h"
  34. #include "GameLogic/Module/UpdateModule.h"
  35. #include "GameLogic/WeaponBonusConditionFlags.h"
  36. #include "Common/INI.h"
  37. #include "WWMath/Matrix3D.h"
  38. class ParticleSystem;
  39. class FXList;
  40. //-------------------------------------------------------------------------------------------------
  41. class DumbProjectileBehaviorModuleData : public UpdateModuleData
  42. {
  43. public:
  44. /**
  45. These four data define a Bezier curve. The first and last control points are the firer and victim.
  46. */
  47. Real m_firstHeight; ///< The first airborne control point will be this high above the highest intervening terrain
  48. Real m_secondHeight; ///< And the second, this.
  49. Real m_firstPercentIndent; ///< The first point will be this percent along the target line
  50. Real m_secondPercentIndent; ///< And the second, this.
  51. UnsignedInt m_maxLifespan;
  52. Bool m_tumbleRandomly;
  53. Bool m_orientToFlightPath;
  54. Bool m_detonateCallsKill;
  55. Int m_garrisonHitKillCount;
  56. KindOfMaskType m_garrisonHitKillKindof; ///< the kind(s) of units that can be collided with
  57. KindOfMaskType m_garrisonHitKillKindofNot; ///< the kind(s) of units that CANNOT be collided with
  58. const FXList* m_garrisonHitKillFX;
  59. Real m_flightPathAdjustDistPerFrame;
  60. DumbProjectileBehaviorModuleData();
  61. static void buildFieldParse(MultiIniFieldParse& p);
  62. };
  63. //-------------------------------------------------------------------------------------------------
  64. class DumbProjectileBehavior : public UpdateModule, public ProjectileUpdateInterface
  65. {
  66. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( DumbProjectileBehavior, "DumbProjectileBehavior" )
  67. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( DumbProjectileBehavior, DumbProjectileBehaviorModuleData );
  68. public:
  69. DumbProjectileBehavior( Thing *thing, const ModuleData* moduleData );
  70. // virtual destructor provided by memory pool object
  71. // UpdateModuleInterface
  72. virtual UpdateSleepTime update();
  73. virtual ProjectileUpdateInterface* getProjectileUpdateInterface() { return this; }
  74. // ProjectileUpdateInterface
  75. virtual void projectileLaunchAtObjectOrPosition(const Object *victim, const Coord3D* victimPos, const Object *launcher, WeaponSlotType wslot, Int specificBarrelToUse, const WeaponTemplate* detWeap, const ParticleSystemTemplate* exhaustSysOverride);
  76. virtual void projectileFireAtObjectOrPosition( const Object *victim, const Coord3D *victimPos, const WeaponTemplate *detWeap, const ParticleSystemTemplate* exhaustSysOverride );
  77. virtual Bool projectileHandleCollision( Object *other );
  78. virtual Bool projectileIsArmed() const { return true; }
  79. virtual ObjectID projectileGetLauncherID() const { return m_launcherID; }
  80. virtual void setFramesTillCountermeasureDiversionOccurs( UnsignedInt frames ) {}
  81. virtual void projectileNowJammed() {}
  82. protected:
  83. void positionForLaunch(const Object *launcher, WeaponSlotType wslot, Int specificBarrelToUse);
  84. void detonate();
  85. private:
  86. ObjectID m_launcherID; ///< ID of object that launched us (zero if not yet launched)
  87. ObjectID m_victimID; ///< ID of object we are targeting (zero if not yet launched)
  88. const WeaponTemplate* m_detonationWeaponTmpl; ///< weapon to fire at end (or null)
  89. UnsignedInt m_lifespanFrame; ///< if we haven't collided by this frame, blow up anyway
  90. VecCoord3D m_flightPath; ///< The frame by frame flight path in a Bezier curve
  91. Coord3D m_flightPathStart; ///< where flight path started (in case we must regen it)
  92. Coord3D m_flightPathEnd; ///< where flight path ends (in case we must regen it)
  93. Real m_flightPathSpeed; ///< flight path speed (in case we must regen it)
  94. Int m_flightPathSegments; ///< number of segments in the flightpath (in case we must regen it)
  95. Int m_currentFlightPathStep; ///< Our current index in the flight path vector. Quicker than popping off.
  96. WeaponBonusConditionFlags m_extraBonusFlags;
  97. Bool m_hasDetonated; ///<
  98. Bool calcFlightPath(Bool recalcNumSegments);
  99. #if defined(_DEBUG) || defined(_INTERNAL)
  100. void displayFlightPath(); ///< Uses little debug icons in worldspace to show the path chosen when it is decided upon
  101. #endif
  102. };
  103. #endif // _DumbProjectileBehavior_H_