FlightDeckBehavior.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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: FlightDeckBehavior.h /////////////////////////////////////////////////////////////////////
  24. // Author: Kris Morness, May 2003
  25. // Desc: Handles aircraft movement and parking behavior for aircraft carriers.
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __FLIGHT_DECK_BEHAVIOR_H
  29. #define __FLIGHT_DECK_BEHAVIOR_H
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/DieModule.h"
  33. #include "GameLogic/Module/AIUpdate.h"
  34. #define MAX_RUNWAYS 2 //***NOTE: If you change this, make sure you update the parsing section!
  35. //And also do a search for MAX_RUNWAYS and evaluate any special case comments!
  36. enum
  37. {
  38. RUNWAY_START_BONE,
  39. RUNWAY_END_BONE,
  40. NUM_RUNWAY_BONES,
  41. };
  42. struct RunwayDefinition
  43. {
  44. RunwayDefinition::RunwayDefinition()
  45. {
  46. m_catapultParticleSystem = NULL;
  47. }
  48. std::vector<AsciiString> m_spacesBoneNames;
  49. std::vector<AsciiString> m_taxiBoneNames;
  50. std::vector<AsciiString> m_creationBoneNames;
  51. AsciiString m_takeoffBoneNames[ NUM_RUNWAY_BONES ];
  52. AsciiString m_landingBoneNames[ NUM_RUNWAY_BONES ];
  53. const ParticleSystemTemplate *m_catapultParticleSystem;
  54. };
  55. //-------------------------------------------------------------------------------------------------
  56. class FlightDeckBehaviorModuleData : public AIUpdateModuleData
  57. {
  58. public:
  59. RunwayDefinition m_runwayInfo[ MAX_RUNWAYS ];
  60. AsciiString m_thingTemplateName;
  61. Real m_healAmount;
  62. Real m_approachHeight;
  63. Real m_landingDeckHeightOffset;
  64. Int m_numRows;
  65. Int m_numCols;
  66. UnsignedInt m_cleanupFrames;
  67. UnsignedInt m_humanFollowFrames;
  68. UnsignedInt m_replacementFrames;
  69. UnsignedInt m_dockAnimationFrames;
  70. UnsignedInt m_launchWaveFrames;
  71. UnsignedInt m_launchRampFrames;
  72. UnsignedInt m_lowerRampFrames;
  73. UnsignedInt m_catapultFireFrames;
  74. FlightDeckBehaviorModuleData();
  75. static void buildFieldParse( MultiIniFieldParse& p );
  76. static void parseRunwayStrip( INI* ini, void *instance, void *store, const void* /*userData*/ );
  77. };
  78. //-------------------------------------------------------------------------------------------------
  79. //-------------------------------------------------------------------------------------------------
  80. class FlightDeckBehavior : public AIUpdateInterface,
  81. public ParkingPlaceBehaviorInterface,
  82. public DieModuleInterface,
  83. public ExitInterface
  84. {
  85. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( FlightDeckBehavior, "FlightDeckBehavior" )
  86. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( FlightDeckBehavior, FlightDeckBehaviorModuleData )
  87. public:
  88. FlightDeckBehavior( Thing *thing, const ModuleData* moduleData );
  89. // virtual destructor prototype provided by memory pool declaration
  90. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_DIE); }
  91. // BehaviorModule
  92. virtual ParkingPlaceBehaviorInterface* getParkingPlaceBehaviorInterface() { return this; }
  93. virtual ExitInterface* getUpdateExitInterface() { return this; }
  94. virtual DieModuleInterface* getDie() { return this; }
  95. // ExitInterface
  96. virtual Bool isExitBusy() const {return FALSE;} ///< Contain style exiters are getting the ability to space out exits, so ask this before reserveDoor as a kind of no-commitment check.
  97. virtual ExitDoorType reserveDoorForExit( const ThingTemplate* objType, Object *specificObject );
  98. virtual void exitObjectViaDoor( Object *newObj, ExitDoorType exitDoor );
  99. virtual void unreserveDoorForExit( ExitDoorType exitDoor );
  100. virtual void exitObjectByBudding( Object *newObj, Object *budHost ) { return; }
  101. virtual Bool getExitPosition( Coord3D& rallyPoint ) const { return FALSE; }
  102. virtual Bool getNaturalRallyPoint( Coord3D& rallyPoint, Bool offset = TRUE ) { return FALSE; }
  103. virtual void setRallyPoint( const Coord3D *pos ) {}
  104. virtual const Coord3D *getRallyPoint( void ) const { return NULL;}
  105. // UpdateModule
  106. virtual UpdateSleepTime update();
  107. // DieModule
  108. virtual void onDie( const DamageInfo *damageInfo );
  109. // ParkingPlaceBehaviorInterface
  110. virtual Bool shouldReserveDoorWhenQueued(const ThingTemplate* thing) const;
  111. virtual Bool hasAvailableSpaceFor(const ThingTemplate* thing) const;
  112. virtual Bool hasReservedSpace(ObjectID id) const;
  113. virtual Int getSpaceIndex( ObjectID id ) const;
  114. virtual Bool reserveSpace(ObjectID id, Real parkingOffset, PPInfo* info);
  115. virtual void releaseSpace(ObjectID id);
  116. virtual Bool reserveRunway(ObjectID id, Bool forLanding);
  117. virtual void releaseRunway(ObjectID id);
  118. virtual void calcPPInfo( ObjectID id, PPInfo *info );
  119. virtual Int getRunwayCount() const { return m_runways.size(); }
  120. virtual ObjectID getRunwayReservation( Int r, RunwayReservationType type );
  121. virtual void transferRunwayReservationToNextInLineForTakeoff(ObjectID id);
  122. virtual Real getApproachHeight() const { return getFlightDeckBehaviorModuleData()->m_approachHeight; }
  123. virtual Real getLandingDeckHeightOffset() const { return getFlightDeckBehaviorModuleData()->m_landingDeckHeightOffset; }
  124. virtual void setHealee(Object* healee, Bool add);
  125. virtual void killAllParkedUnits();
  126. virtual void defectAllParkedUnits(Team* newTeam, UnsignedInt detectionTime);
  127. virtual Bool calcBestParkingAssignment( ObjectID id, Coord3D *pos, Int *oldIndex = NULL, Int *newIndex = NULL );
  128. // AIUpdateInterface
  129. virtual void aiDoCommand(const AICommandParms* parms);
  130. virtual const std::vector<Coord3D>* getTaxiLocations( ObjectID id ) const;
  131. virtual const std::vector<Coord3D>* getCreationLocations( ObjectID id ) const;
  132. private:
  133. Bool isAbleToGiveUpParkingSpace( Object *jet );
  134. Bool isAbleToMoveForward( const Object &jet ) const;
  135. Bool isInPositionToTakeoff( const Object &jet ) const;
  136. void validateAssignments();
  137. void propagateOrdersToPlanes();
  138. void propagateOrderToSpecificPlane( Object *jet );
  139. Bool hasTakeoffOrders();
  140. struct FlightDeckInfo
  141. {
  142. Coord3D m_prep;
  143. Real m_orientation;
  144. Int m_runway;
  145. ObjectID m_objectInSpace;
  146. FlightDeckInfo()
  147. {
  148. m_prep.zero();
  149. m_orientation = 0;
  150. m_runway = 0;
  151. m_objectInSpace = INVALID_ID;
  152. }
  153. };
  154. struct RunwayInfo
  155. {
  156. Coord3D m_start;
  157. Matrix3D m_startTransform;
  158. Coord3D m_end;
  159. Coord3D m_landingStart;
  160. Coord3D m_landingEnd;
  161. std::vector<Coord3D> m_taxi;
  162. std::vector<Coord3D> m_creation;
  163. Real m_startOrient;
  164. ObjectID m_inUseByForTakeoff;
  165. ObjectID m_inUseByForLanding;
  166. };
  167. struct HealingInfo
  168. {
  169. ObjectID m_gettingHealedID;
  170. UnsignedInt m_healStartFrame;
  171. };
  172. void buildInfo( Bool createUnits = TRUE);
  173. void purgeDead();
  174. void resetWakeFrame();
  175. FlightDeckInfo* findPPI(ObjectID id);
  176. FlightDeckInfo* findEmptyPPI();
  177. const ThingTemplate *m_thingTemplate;
  178. std::vector<FlightDeckInfo> m_spaces;
  179. std::vector<RunwayInfo> m_runways;
  180. std::list<HealingInfo> m_healing; // note, this list can vary in size, and be larger than the parking space count
  181. UnsignedInt m_nextHealFrame;
  182. UnsignedInt m_nextCleanupFrame;
  183. UnsignedInt m_startedProductionFrame;
  184. UnsignedInt m_nextAllowedProductionFrame;
  185. UnsignedInt m_nextLaunchWaveFrame[ MAX_RUNWAYS ];
  186. UnsignedInt m_rampUpFrame[ MAX_RUNWAYS ]; //The frame the ramp has completed raising.
  187. UnsignedInt m_catapultSystemFrame[ MAX_RUNWAYS ]; //The frame the catapult effect created.
  188. UnsignedInt m_lowerRampFrame[ MAX_RUNWAYS ]; //The frame the ramp begins to lower.
  189. ObjectID m_designatedTarget;
  190. AICommandType m_designatedCommand;
  191. Coord3D m_designatedPosition;
  192. Bool m_gotInfo;
  193. Bool m_rampUp[ MAX_RUNWAYS ];
  194. };
  195. #endif // __FLIGHT_DECK_BEHAVIOR_H