ParkingPlaceBehavior.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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: ParkingPlaceBehavior.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, June 2002
  25. // Desc:
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __ParkingPlaceBehavior_H_
  29. #define __ParkingPlaceBehavior_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/DieModule.h"
  33. #include "GameLogic/Module/UpdateModule.h"
  34. //-------------------------------------------------------------------------------------------------
  35. class ParkingPlaceBehaviorModuleData : public UpdateModuleData
  36. {
  37. public:
  38. //UnsignedInt m_framesForFullHeal;
  39. Real m_healAmount;
  40. // Real m_extraHealAmount4Helicopters;
  41. Int m_numRows;
  42. Int m_numCols;
  43. Real m_approachHeight;
  44. Real m_landingDeckHeightOffset;
  45. Bool m_hasRunways; // if true, each col has a runway in front of it
  46. Bool m_parkInHangars; // if true, park at the hangar production spot, not the "real" parking place
  47. ParkingPlaceBehaviorModuleData()
  48. {
  49. //m_framesForFullHeal = 0;
  50. m_healAmount = 0;
  51. // m_extraHealAmount4Helicopters = 0;
  52. m_numRows = 0;
  53. m_numCols = 0;
  54. m_approachHeight = 0.0f;
  55. m_landingDeckHeightOffset = 0.0f;
  56. m_hasRunways = false;
  57. m_parkInHangars = false;
  58. }
  59. static void buildFieldParse(MultiIniFieldParse& p)
  60. {
  61. UpdateModuleData::buildFieldParse(p);
  62. static const FieldParse dataFieldParse[] =
  63. {
  64. { "NumRows", INI::parseInt, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_numRows ) },
  65. { "NumCols", INI::parseInt, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_numCols ) },
  66. { "ApproachHeight", INI::parseReal, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_approachHeight ) },
  67. { "LandingDeckHeightOffset", INI::parseReal, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_landingDeckHeightOffset ) },
  68. { "HasRunways", INI::parseBool, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_hasRunways ) },
  69. { "ParkInHangars", INI::parseBool, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_parkInHangars ) },
  70. { "HealAmountPerSecond", INI::parseReal, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_healAmount ) },
  71. // { "ExtraHealAmount4Helicopters", INI::parseReal, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_extraHealAmount4Helicopters ) },
  72. //{ "TimeForFullHeal", INI::parseDurationUnsignedInt, NULL, offsetof( ParkingPlaceBehaviorModuleData, m_framesForFullHeal ) },
  73. { 0, 0, 0, 0 }
  74. };
  75. p.add(dataFieldParse);
  76. }
  77. private:
  78. };
  79. //-------------------------------------------------------------------------------------------------
  80. //-------------------------------------------------------------------------------------------------
  81. class ParkingPlaceBehavior : public UpdateModule,
  82. public DieModuleInterface,
  83. public ParkingPlaceBehaviorInterface,
  84. public ExitInterface
  85. {
  86. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( ParkingPlaceBehavior, "ParkingPlaceBehavior" )
  87. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( ParkingPlaceBehavior, ParkingPlaceBehaviorModuleData )
  88. public:
  89. ParkingPlaceBehavior( Thing *thing, const ModuleData* moduleData );
  90. // virtual destructor prototype provided by memory pool declaration
  91. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_DIE); }
  92. // BehaviorModule
  93. virtual DieModuleInterface *getDie( void ) { return this; }
  94. virtual ParkingPlaceBehaviorInterface* getParkingPlaceBehaviorInterface() { return this; }
  95. virtual ExitInterface* getUpdateExitInterface() { return this; }
  96. // ExitInterface
  97. 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.
  98. virtual ExitDoorType reserveDoorForExit( const ThingTemplate* objType, Object *specificObject );
  99. virtual void exitObjectViaDoor( Object *newObj, ExitDoorType exitDoor );
  100. virtual void unreserveDoorForExit( ExitDoorType exitDoor );
  101. virtual void exitObjectByBudding( Object *newObj, Object *budHost ) { return; }
  102. virtual Bool getExitPosition( Coord3D& rallyPoint ) const;
  103. virtual Bool getNaturalRallyPoint( Coord3D& rallyPoint, Bool offset = TRUE ) const;
  104. virtual void setRallyPoint( const Coord3D *pos ); ///< define a "rally point" for units to move towards
  105. virtual const Coord3D *getRallyPoint( void ) const; ///< define a "rally point" for units to move towards
  106. // UpdateModule
  107. virtual UpdateSleepTime update();
  108. // DieModule
  109. virtual void onDie( const DamageInfo *damageInfo );
  110. // ParkingPlaceBehaviorInterface
  111. virtual Bool shouldReserveDoorWhenQueued(const ThingTemplate* thing) const;
  112. virtual Bool hasAvailableSpaceFor(const ThingTemplate* thing) const;
  113. virtual Bool hasReservedSpace(ObjectID id) const;
  114. virtual Int getSpaceIndex( ObjectID id ) const;
  115. virtual Bool reserveSpace(ObjectID id, Real parkingOffset, PPInfo* info);
  116. virtual void releaseSpace(ObjectID id);
  117. virtual Bool reserveRunway(ObjectID id, Bool forLanding);
  118. virtual void releaseRunway(ObjectID id);
  119. virtual void calcPPInfo( ObjectID id, PPInfo *info );
  120. virtual Int getRunwayCount() const { return m_runways.size(); }
  121. virtual ObjectID getRunwayReservation( Int r, RunwayReservationType type );
  122. virtual void transferRunwayReservationToNextInLineForTakeoff(ObjectID id);
  123. virtual Real getApproachHeight() const { return getParkingPlaceBehaviorModuleData()->m_approachHeight; }
  124. virtual Real getLandingDeckHeightOffset() const { return getParkingPlaceBehaviorModuleData()->m_landingDeckHeightOffset; }
  125. virtual void setHealee(Object* healee, Bool add);
  126. virtual void killAllParkedUnits();
  127. virtual void defectAllParkedUnits(Team* newTeam, UnsignedInt detectionTime);
  128. virtual Bool calcBestParkingAssignment( ObjectID id, Coord3D *pos, Int *oldIndex = NULL, Int *newIndex = NULL ) { return FALSE; }
  129. virtual const std::vector<Coord3D>* getTaxiLocations( ObjectID id ) const { return NULL; }
  130. virtual const std::vector<Coord3D>* getCreationLocations( ObjectID id ) const { return NULL; }
  131. private:
  132. struct ParkingPlaceInfo
  133. {
  134. Coord3D m_hangarStart;
  135. Real m_hangarStartOrient;
  136. Coord3D m_location;
  137. Coord3D m_prep;
  138. Real m_orientation;
  139. Int m_runway;
  140. ExitDoorType m_door;
  141. ObjectID m_objectInSpace;
  142. Bool m_reservedForExit;
  143. ParkingPlaceInfo()
  144. {
  145. m_hangarStart.zero();
  146. m_hangarStartOrient = 0;
  147. m_location.zero();
  148. m_prep.zero();
  149. m_orientation = 0;
  150. m_runway = 0;
  151. m_door = DOOR_NONE_AVAILABLE;
  152. m_objectInSpace = INVALID_ID;
  153. m_reservedForExit = false;
  154. }
  155. };
  156. struct RunwayInfo
  157. {
  158. Coord3D m_start;
  159. Coord3D m_end;
  160. ObjectID m_inUseBy;
  161. ObjectID m_nextInLineForTakeoff;
  162. Bool m_wasInLine;
  163. };
  164. struct HealingInfo
  165. {
  166. ObjectID m_gettingHealedID;
  167. UnsignedInt m_healStartFrame;
  168. };
  169. std::vector<ParkingPlaceInfo> m_spaces;
  170. std::vector<RunwayInfo> m_runways;
  171. std::list<HealingInfo> m_healing; // note, this list can vary in size, and be larger than the parking space count
  172. UnsignedInt m_nextHealFrame;
  173. Bool m_gotInfo;
  174. void buildInfo();
  175. void purgeDead();
  176. void resetWakeFrame();
  177. ParkingPlaceInfo* findPPI(ObjectID id);
  178. ParkingPlaceInfo* findEmptyPPI();
  179. Coord3D m_heliRallyPoint;
  180. Bool m_heliRallyPointExists; ///< Only move to the rally point if this is true
  181. };
  182. #endif // __ParkingPlaceBehavior_H_