JetAIUpdate.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. // JetAIUpdate.h //////////
  24. // Author: Steven Johnson, June 2002
  25. #pragma once
  26. #ifndef _JET_AI_UPDATE_H_
  27. #define _JET_AI_UPDATE_H_
  28. #include "Common/STLTypedefs.h"
  29. #include "Common/GameMemory.h"
  30. #include "GameLogic/AIStateMachine.h"
  31. #include "GameLogic/Module/AIUpdate.h"
  32. #ifdef _INTERNAL
  33. // for occasional debugging...
  34. //#pragma optimize("", off)
  35. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  36. #endif
  37. //-------------------------------------------------------------------------------------------------
  38. //-------------------------------------------------------------------------------------------------
  39. //-------------------------------------------------------------------------------------------------
  40. //-------------------------------------------------------------------------------------------------
  41. class JetAIUpdateModuleData : public AIUpdateModuleData
  42. {
  43. public:
  44. Real m_outOfAmmoDamagePerSecond; /**< amount of damage to take per SEC (not per frame) when out of ammo
  45. note that it's expressed as a percent of max health, not an absolute */
  46. Real m_takeoffDistForMaxLift; ///< percent of distance from start (100%) to end (0%) that gives us max lift. Higher value lifts off sooner.
  47. Real m_minHeight; ///< how far off the ground to lift the drawable when taxiing
  48. Real m_parkingOffset; ///< tweaking the park loc
  49. Real m_sneakyOffsetWhenAttacking; ///< our sneaky offset when attacking (or zero)
  50. Bool m_keepsParkingSpaceWhenAirborne; ///< if t, keeps its parking space reservation even when airborne
  51. Bool m_needsRunway; ///< if t, needs runways to takeoff/land
  52. UnsignedInt m_takeoffPause; ///< pre-takeoff pause
  53. LocomotorSetType m_attackingLoco; ///< custom attacking loco
  54. LocomotorSetType m_returningLoco; ///< custom return-for-ammo loco
  55. UnsignedInt m_attackLocoPersistTime; ///< if we have a custom attack loco, it persists for this long after attack is done
  56. UnsignedInt m_attackersMissPersistTime; ///< how long after our attack we continue immunity
  57. UnsignedInt m_lockonTime; ///< time it takes for someone to lock-on to us.
  58. AsciiString m_lockonCursor; ///< template used for lockon.
  59. Real m_lockonInitialDist; ///< how far away the lockon cursor starts.
  60. Real m_lockonFreq;
  61. Real m_lockonAngleSpin; ///< how many times to spin around it
  62. Real m_lockonBlinky;
  63. UnsignedInt m_returnToBaseIdleTime; ///< if we're idle for this long, return to base
  64. JetAIUpdateModuleData();
  65. static void buildFieldParse(MultiIniFieldParse& p);
  66. };
  67. //-------------------------------------------------------------------------------------------------
  68. class JetAIUpdate : public AIUpdateInterface
  69. {
  70. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( JetAIUpdate, "JetAIUpdate" )
  71. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( JetAIUpdate, JetAIUpdateModuleData )
  72. virtual UpdateSleepTime update();
  73. public:
  74. JetAIUpdate( Thing *thing, const ModuleData* moduleData );
  75. // virtual destructor prototype provided by memory pool declaration
  76. virtual void onObjectCreated();
  77. virtual void onDelete();
  78. virtual JetAIUpdate* getJetAIUpdate() { return this; }
  79. virtual const JetAIUpdate* getJetAIUpdate() const { return this; }
  80. virtual void aiDoCommand(const AICommandParms* parms);
  81. virtual Bool chooseLocomotorSet(LocomotorSetType wst);
  82. virtual void setLocomotorGoalNone();
  83. virtual Bool isIdle() const;
  84. virtual Bool isTaxiingToParking() const; //only applies to jets interacting with runways.
  85. virtual Bool isReloading() const;
  86. virtual Bool isAllowedToMoveAwayFromUnit() const;
  87. virtual Bool getSneakyTargetingOffset(Coord3D* offset) const;
  88. virtual void addTargeter(ObjectID id, Bool add);
  89. virtual Bool isTemporarilyPreventingAimSuccess() const;
  90. virtual Bool isDoingGroundMovement() const;
  91. virtual void notifyVictimIsDead();
  92. virtual Bool isOutOfSpecialReloadAmmo() const;
  93. const Coord3D* friend_getProducerLocation() const { return &m_producerLocation; }
  94. Real friend_getOutOfAmmoDamagePerSecond() const { return getJetAIUpdateModuleData()->m_outOfAmmoDamagePerSecond; }
  95. Bool friend_keepsParkingSpaceWhenAirborne() const { return getJetAIUpdateModuleData()->m_keepsParkingSpaceWhenAirborne; }
  96. Bool friend_needsRunway() const { return getJetAIUpdateModuleData()->m_needsRunway; }
  97. Real friend_getTakeoffDistForMaxLift() const { return getJetAIUpdateModuleData()->m_takeoffDistForMaxLift; }
  98. Real friend_getMinHeight() const { return getJetAIUpdateModuleData()->m_minHeight; }
  99. Real friend_getParkingOffset() const { return getJetAIUpdateModuleData()->m_parkingOffset; }
  100. UnsignedInt friend_getTakeoffPause() const { return getJetAIUpdateModuleData()->m_takeoffPause; }
  101. void friend_setGoalPath( const std::vector<Coord3D>* path ) { getStateMachine()->setGoalPath(path); }
  102. void friend_setTakeoffInProgress(Bool v) { setFlag(TAKEOFF_IN_PROGRESS, v); }
  103. void friend_setLandingInProgress(Bool v) { setFlag(LANDING_IN_PROGRESS, v); }
  104. void friend_setTaxiInProgress(Bool v) { setFlag(TAXI_IN_PROGRESS, v); }
  105. void friend_setUseSpecialReturnLoco(Bool v) { setFlag(USE_SPECIAL_RETURN_LOCO, v); }
  106. void friend_setAllowCircling(Bool v) { setFlag(ALLOW_CIRCLING, v); }
  107. const Coord3D& friend_getLandingPosForHelipadStuff() const { return m_landingPosForHelipadStuff; }
  108. void friend_enableAfterburners(Bool v);
  109. void friend_setAllowAirLoco(Bool a);
  110. Bool friend_isTakeoffOrLandingInProgress() const
  111. {
  112. return (getFlag(TAKEOFF_IN_PROGRESS) || getFlag(LANDING_IN_PROGRESS));
  113. }
  114. void friend_addWaypointToGoalPath( const Coord3D &pos );
  115. AICommandType friend_getPendingCommandType() const;
  116. void friend_purgePendingCommand();
  117. protected:
  118. virtual AIStateMachine* makeStateMachine();
  119. virtual void privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
  120. virtual void privateFollowPathAppend( const Coord3D *pos, CommandSourceType cmdSource );
  121. virtual void privateEnter( Object *obj, CommandSourceType cmdSource ); ///< enter the given object
  122. virtual void privateGetRepaired( Object *repairDepot, CommandSourceType cmdSource );///< get repaired at repair depot
  123. void pruneDeadTargeters();
  124. void positionLockon();
  125. virtual Bool getTreatAsAircraftForLocoDistToGoal() const;
  126. Bool isParkedAt(const Object* obj) const;
  127. private:
  128. enum FlagType
  129. {
  130. HAS_PENDING_COMMAND,
  131. ALLOW_AIR_LOCO,
  132. HAS_PRODUCER_LOCATION,
  133. TAKEOFF_IN_PROGRESS,
  134. LANDING_IN_PROGRESS,
  135. USE_SPECIAL_RETURN_LOCO,
  136. ALLOW_CIRCLING,
  137. ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD,
  138. TAXI_IN_PROGRESS
  139. };
  140. Coord3D m_producerLocation; ///< remember this, so that if our producer dies, we have a place to circle aimlessly
  141. AICommandParmsStorage m_mostRecentCommand;
  142. AudioEventRTS m_afterburnerSound; ///< Sound when afterburners on
  143. UnsignedInt m_attackLocoExpireFrame;
  144. UnsignedInt m_attackersMissExpireFrame;
  145. UnsignedInt m_returnToBaseFrame; ///< if nonzero, return to base at this frame when we are idle, even if not out of ammo
  146. std::list<ObjectID> m_targetedBy; ///< object(s) currently targeting us, if any
  147. UnsignedInt m_untargetableExpireFrame;
  148. Drawable* m_lockonDrawable;
  149. Int m_flags;
  150. Coord3D m_landingPosForHelipadStuff;
  151. Bool m_enginesOn; ///<
  152. void getProducerLocation();
  153. void buildLockonDrawableIfNecessary();
  154. void doLandingCommand(Object *airfield, CommandSourceType cmdSource);
  155. Bool getFlag(FlagType f) const;
  156. void setFlag(FlagType f, Bool v);
  157. };
  158. #endif