AIDock.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. // AIDock.h
  24. // Docking behavior
  25. // Author: Michael S. Booth, February 2002
  26. #pragma once
  27. #ifndef _AI_DOCK_H_
  28. #define _AI_DOCK_H_
  29. #include "Common/GameMemory.h"
  30. #include "GameLogic/AIStateMachine.h"
  31. /**
  32. * The states of the Docking state machine.
  33. */
  34. enum
  35. {
  36. AI_DOCK_APPROACH, ///< given a queue pos, move to it
  37. AI_DOCK_WAIT_FOR_CLEARANCE, ///< wait for dock to give us enter clearance
  38. AI_DOCK_ADVANCE_POSITION, ///< Advance in approach position as line moves forward
  39. AI_DOCK_MOVE_TO_ENTRY, ///< move to the dock entrance
  40. AI_DOCK_MOVE_TO_DOCK, ///< move to the actual dock position
  41. AI_DOCK_PROCESS_DOCK, ///< invoke the dock's action until it is done
  42. AI_DOCK_MOVE_TO_EXIT, ///< move to the dock exit, can exit the dock machine
  43. AI_DOCK_MOVE_TO_RALLY ///< Move to rally if desired, exit the dock machine no matter what
  44. };
  45. //-----------------------------------------------------------------------------------------------------------
  46. /**
  47. * The docking state machine.
  48. */
  49. class AIDockMachine : public StateMachine
  50. {
  51. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( AIDockMachine, "AIDockMachinePool" );
  52. public:
  53. /**
  54. * The implementation of this constructor defines the states
  55. * used by this machine.
  56. */
  57. AIDockMachine( Object *owner );
  58. static Bool ableToAdvance( State *thisState, void* userData ); // Condition for scooting forward in line while waiting
  59. virtual void halt(void); ///< Stops the state machine & disables it in preparation for deleting it.
  60. Int m_approachPosition; ///< The Approach Position I am holding, to make scoot forward checks quicker.
  61. protected:
  62. // snapshot interface
  63. virtual void crc( Xfer *xfer );
  64. virtual void xfer( Xfer *xfer );
  65. virtual void loadPostProcess();
  66. };
  67. // Please do not use these states in some other machine. I know that wouldn't even make sense, but they
  68. // cast their getMachine to an AIDock machine to store stuff across states so you'd crash.
  69. //-----------------------------------------------------------------------------------------------------------
  70. class AIDockApproachState : public AIInternalMoveToState
  71. {
  72. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIDockApproachState, "AIDockApproachState")
  73. public:
  74. AIDockApproachState( StateMachine *machine ) : AIInternalMoveToState( machine, "AIDockApproachState" ) { }
  75. virtual StateReturnType onEnter( void );
  76. virtual void onExit( StateExitType status );
  77. virtual StateReturnType update( void );
  78. protected:
  79. // snapshot interface STUBBED.
  80. virtual void crc( Xfer *xfer ){};
  81. virtual void xfer( Xfer *xfer );
  82. virtual void loadPostProcess(){};
  83. };
  84. EMPTY_DTOR(AIDockApproachState)
  85. //-----------------------------------------------------------------------------------------------------------
  86. class AIDockWaitForClearanceState : public State
  87. {
  88. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIDockWaitForClearanceState, "AIDockWaitForClearanceState")
  89. public:
  90. AIDockWaitForClearanceState( StateMachine *machine ) : State( machine, "AIDockWaitForClearanceState" ), m_enterFrame(0) { }
  91. virtual StateReturnType onEnter( void );
  92. virtual StateReturnType update( void );
  93. virtual void onExit( StateExitType status );
  94. protected:
  95. UnsignedInt m_enterFrame;
  96. protected:
  97. // snapshot interface STUBBED.
  98. virtual void crc( Xfer *xfer ){};
  99. virtual void xfer( Xfer *xfer );
  100. virtual void loadPostProcess(){};
  101. };
  102. EMPTY_DTOR(AIDockWaitForClearanceState)
  103. //-----------------------------------------------------------------------------------------------------------
  104. class AIDockAdvancePositionState : public AIInternalMoveToState
  105. {
  106. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIDockAdvancePositionState, "AIDockAdvancePositionState")
  107. public:
  108. AIDockAdvancePositionState( StateMachine *machine ) : AIInternalMoveToState( machine, "AIDockApproachState" ) { }
  109. virtual StateReturnType onEnter( void );
  110. virtual void onExit( StateExitType status );
  111. virtual StateReturnType update( void );
  112. };
  113. EMPTY_DTOR(AIDockAdvancePositionState)
  114. //-----------------------------------------------------------------------------------------------------------
  115. class AIDockMoveToEntryState : public AIInternalMoveToState
  116. {
  117. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIDockMoveToEntryState, "AIDockMoveToEntryState")
  118. public:
  119. AIDockMoveToEntryState( StateMachine *machine ) : AIInternalMoveToState( machine, "AIDockMoveToEntryState" ) { }
  120. virtual StateReturnType onEnter( void );
  121. virtual void onExit( StateExitType status );
  122. virtual StateReturnType update( void );
  123. };
  124. EMPTY_DTOR(AIDockMoveToEntryState)
  125. //-----------------------------------------------------------------------------------------------------------
  126. class AIDockMoveToDockState : public AIInternalMoveToState
  127. {
  128. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIDockMoveToDockState, "AIDockMoveToDockState")
  129. public:
  130. AIDockMoveToDockState( StateMachine *machine ) : AIInternalMoveToState( machine, "AIDockMoveToDockState" ) { }
  131. virtual StateReturnType onEnter( void );
  132. virtual void onExit( StateExitType status );
  133. virtual StateReturnType update( void );
  134. };
  135. EMPTY_DTOR(AIDockMoveToDockState)
  136. //-----------------------------------------------------------------------------------------------------------
  137. class AIDockMoveToRallyState : public AIInternalMoveToState
  138. {
  139. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIDockMoveToRallyState, "AIDockMoveToRallyState")
  140. public:
  141. AIDockMoveToRallyState( StateMachine *machine ) : AIInternalMoveToState( machine, "AIDockMoveToRallyState" ) { }
  142. virtual StateReturnType onEnter( void );
  143. virtual void onExit( StateExitType status );
  144. virtual StateReturnType update( void );
  145. };
  146. EMPTY_DTOR(AIDockMoveToRallyState)
  147. //-----------------------------------------------------------------------------------------------------------
  148. class AIDockProcessDockState : public State
  149. {
  150. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIDockProcessDockState, "AIDockProcessDockState")
  151. public:
  152. AIDockProcessDockState( StateMachine *machine );
  153. virtual StateReturnType onEnter( void );
  154. virtual void onExit( StateExitType status );
  155. virtual StateReturnType update( void );
  156. void setNextDockActionFrame();//This puts a delay between callings of Action to tweak the speed of docking.
  157. UnsignedInt m_nextDockActionFrame;// In the unlikely event of saving a game in the middle of docking, you may
  158. // complete a Action a few frames sooner than you would have: It does not need to be saved.
  159. Object* findMyDrone();
  160. protected:
  161. // snapshot interface STUBBED.
  162. virtual void crc( Xfer *xfer ){};
  163. virtual void xfer( Xfer *xfer ){XferVersion cv = 1; XferVersion v = cv; xfer->xferVersion( &v, cv );}
  164. virtual void loadPostProcess(){};
  165. private:
  166. ObjectID m_droneID; ///< If I have a drone, the drone will get repaired too.
  167. };
  168. EMPTY_DTOR(AIDockProcessDockState)
  169. //-----------------------------------------------------------------------------------------------------------
  170. class AIDockMoveToExitState : public AIInternalMoveToState
  171. {
  172. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIDockMoveToExitState, "AIDockMoveToExitState")
  173. public:
  174. AIDockMoveToExitState( StateMachine *machine ) : AIInternalMoveToState( machine, "AIDockMoveToExitState" ) { }
  175. virtual StateReturnType onEnter( void );
  176. virtual void onExit( StateExitType status );
  177. virtual StateReturnType update( void );
  178. };
  179. EMPTY_DTOR(AIDockMoveToExitState)
  180. //-----------------------------------------------------------------------------------------------------------
  181. #endif // _AI_DOCK_H_