MissileAIUpdate.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: MissileAIUpdate.h
  24. // Author: Michael S. Booth, December 2001
  25. // Desc: Missile behavior
  26. #pragma once
  27. #ifndef _MISSILE_AI_UPDATE_H_
  28. #define _MISSILE_AI_UPDATE_H_
  29. #include "Common/GameType.h"
  30. #include "Common/GlobalData.h"
  31. #include "GameLogic/Module/AIUpdate.h"
  32. #include "GameLogic/WeaponBonusConditionFlags.h"
  33. #include "Common/INI.h"
  34. #include "WWMath/Matrix3D.h"
  35. enum ParticleSystemID;
  36. class FXList;
  37. //-------------------------------------------------------------------------------------------------
  38. class MissileAIUpdateModuleData : public AIUpdateModuleData
  39. {
  40. public:
  41. Bool m_tryToFollowTarget; ///< if true, attack object, not pos
  42. UnsignedInt m_fuelLifetime; ///< num frames till missile runs out of motive power (0 == inf)
  43. UnsignedInt m_ignitionDelay; ///< delay in frames from when missile is 'fired', to when it starts moving 15
  44. Real m_initialVel;
  45. Real m_initialDist;
  46. Real m_diveDistance; ///< If I get this close to my target, start ignoring my preferred height
  47. const FXList* m_ignitionFX; ///< FXList to do when missile 'ignites'
  48. Bool m_useWeaponSpeed; ///< if true, limit speed of projectile to the Weapon's info
  49. Bool m_detonateOnNoFuel; ///< If true, don't just stop thrusting, blow up when out of gas
  50. Int m_garrisonHitKillCount;
  51. KindOfMaskType m_garrisonHitKillKindof; ///< the kind(s) of units that can be collided with
  52. KindOfMaskType m_garrisonHitKillKindofNot; ///< the kind(s) of units that CANNOT be collided with
  53. const FXList* m_garrisonHitKillFX;
  54. Real m_distanceScatterWhenJammed; ///< How far I scatter when Jammed
  55. Real m_lockDistance; ///< If I get this close to my target, guaranteed hit.
  56. Bool m_detonateCallsKill; ///< if true, kill() will be called, instead of KILL_SELF state, which calls destroy.
  57. Int m_killSelfDelay; ///< If I have detonated and entered the KILL-SELF state, how ling do I wait before I Kill/destroy self?
  58. MissileAIUpdateModuleData();
  59. static void buildFieldParse(MultiIniFieldParse& p);
  60. };
  61. //-------------------------------------------------------------------------------------------------
  62. class MissileAIUpdate : public AIUpdateInterface, public ProjectileUpdateInterface
  63. {
  64. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( MissileAIUpdate, "MissileAIUpdate" )
  65. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( MissileAIUpdate, MissileAIUpdateModuleData );
  66. public:
  67. MissileAIUpdate( Thing *thing, const ModuleData* moduleData );
  68. enum MissileStateType // Stored in save file, don't renumber.
  69. {
  70. PRELAUNCH = 0,
  71. LAUNCH = 1, ///< released from launcher, falling
  72. IGNITION = 2, ///< engines ignite
  73. ATTACK_NOTURN = 3, ///< fly toward victim
  74. ATTACK = 4, ///< fly toward victim
  75. DEAD = 5,
  76. KILL = 6, ///< Hit victim (cheat).
  77. KILL_SELF = 7, ///< Destroy self.
  78. };
  79. virtual ProjectileUpdateInterface* getProjectileUpdateInterface() { return this; }
  80. virtual void projectileFireAtObjectOrPosition( const Object *victim, const Coord3D *victimPos, const WeaponTemplate *detWeap, const ParticleSystemTemplate* exhaustSysOverride );
  81. virtual void projectileLaunchAtObjectOrPosition(const Object *victim, const Coord3D* victimPos, const Object *launcher, WeaponSlotType wslot, Int specificBarrelToUse, const WeaponTemplate* detWeap, const ParticleSystemTemplate* exhaustSysOverride);
  82. virtual Bool projectileHandleCollision( Object *other );
  83. virtual Bool projectileIsArmed() const { return m_isArmed; }
  84. virtual ObjectID projectileGetLauncherID() const { return m_launcherID; }
  85. virtual void setFramesTillCountermeasureDiversionOccurs( UnsignedInt frames ); ///< Number of frames till missile diverts to countermeasures.
  86. virtual void projectileNowJammed();///< We lose our Object target and scatter to the ground
  87. virtual Bool processCollision(PhysicsBehavior *physics, Object *other); ///< Returns true if the physics collide should apply the force. Normally not. jba.
  88. virtual UpdateSleepTime update();
  89. virtual void onDelete( void );
  90. protected:
  91. void detonate();
  92. private:
  93. MissileStateType m_state; ///< the behavior state of the missile
  94. UnsignedInt m_stateTimestamp; ///< time of state change
  95. UnsignedInt m_nextTargetTrackTime; ///< if nonzero, how often we update our target pos
  96. ObjectID m_launcherID; ///< ID of object that launched us (INVALID_ID if not yet launched)
  97. ObjectID m_victimID; ///< ID of object that I am rocketing towards (INVALID_ID if not yet launched)
  98. UnsignedInt m_fuelExpirationDate; ///< how long 'til we run out of fuel
  99. Real m_noTurnDistLeft; ///< when zero, ok to start turning
  100. Real m_maxAccel;
  101. Coord3D m_originalTargetPos; ///< When firing uphill, we aim high to clear the brow of the hill. jba.
  102. Coord3D m_prevPos;
  103. WeaponBonusConditionFlags m_extraBonusFlags;
  104. const WeaponTemplate* m_detonationWeaponTmpl; ///< weapon to fire at end (or null)
  105. const ParticleSystemTemplate* m_exhaustSysTmpl;
  106. ParticleSystemID m_exhaustID; ///< our exhaust particle system (if any)
  107. UnsignedInt m_framesTillDecoyed; ///< Number of frames before missile will get distracted by decoy countermeasures.
  108. Bool m_isTrackingTarget; ///< Was I originally shot at a moving object?
  109. Bool m_isArmed; ///< if true, missile will explode on contact
  110. Bool m_noDamage; ///< if true, missile will not cause damage when it detonates. (Used for flares).
  111. Bool m_isJammed; ///< No target, just shooting at a scattered position
  112. void doPrelaunchState();
  113. void doLaunchState();
  114. void doIgnitionState();
  115. void doAttackState(Bool turnOK);
  116. void doKillState();
  117. void doKillSelfState();
  118. void doDeadState();
  119. void airborneTargetGone(); ///< My airborne target has died, so I have to do something cool to make up for that
  120. void tossExhaust();
  121. void switchToState(MissileStateType s);
  122. };
  123. #endif // _MISSILE_AI_UPDATE_H_