AITNGuard.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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: AITNGuard.h
  24. /*---------------------------------------------------------------------------*/
  25. /* EA Pacific */
  26. /* Confidential Information */
  27. /* Copyright (C) 2001 - All Rights Reserved */
  28. /* DO NOT DISTRIBUTE */
  29. /*---------------------------------------------------------------------------*/
  30. /* Project: RTS3 */
  31. /* File name: AITNGuard.h */
  32. /* Created: John K. McDonald, Jr., 3/29/2002 */
  33. /* Desc: // Define Guard states for AI */
  34. /* Revision History: */
  35. /* 3/29/2002 : Initial creation */
  36. /*---------------------------------------------------------------------------*/
  37. #pragma once
  38. #ifndef _H_AITNGUARD_
  39. #define _H_AITNGUARD_
  40. // INCLUDES ///////////////////////////////////////////////////////////////////
  41. #include "Common/GameMemory.h"
  42. #include "GameLogic/AIStateMachine.h"
  43. #include "GameLogic/GameLogic.h"
  44. #include "GameLogic/Object.h"
  45. #include "GameLogic/AI.h"
  46. // DEFINES ////////////////////////////////////////////////////////////////////
  47. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  48. enum
  49. {
  50. // prevent collisions with other states that we might use, (namely AI_IDLE)
  51. AI_TN_GUARD_INNER = 5000, ///< Attack anything within this area till death
  52. AI_TN_GUARD_IDLE, ///< Wait till something shows up to attack.
  53. AI_TN_GUARD_OUTER, ///< Attack anything within this area that has been aggressive, until the timer expires
  54. AI_TN_GUARD_RETURN, ///< Restore to a position within the inner circle
  55. AI_TN_GUARD_GET_CRATE, ///< Pick up a crate from an enemy we killed.
  56. AI_TN_GUARD_ATTACK_AGGRESSOR, ///< Attack something that attacked me (that I can attack)
  57. };
  58. //--------------------------------------------------------------------------------------
  59. class TunnelNetworkExitConditions : public AttackExitConditionsInterface
  60. {
  61. public:
  62. UnsignedInt m_attackGiveUpFrame; // frame at which we give up (if using)
  63. TunnelNetworkExitConditions() : m_attackGiveUpFrame(0)
  64. {
  65. }
  66. virtual Bool shouldExit(const StateMachine* machine) const;
  67. };
  68. // FORWARD DECLARATIONS ///////////////////////////////////////////////////////
  69. //--------------------------------------------------------------------------------------
  70. class AITNGuardMachine : public StateMachine
  71. {
  72. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( AITNGuardMachine, "AITNGuardMachinePool" );
  73. private:
  74. Coord3D m_positionToGuard;
  75. ObjectID m_nemesisToAttack;
  76. GuardMode m_guardMode;
  77. protected:
  78. // snapshot interface
  79. virtual void crc( Xfer *xfer );
  80. virtual void xfer( Xfer *xfer );
  81. virtual void loadPostProcess();
  82. public:
  83. /**
  84. * The implementation of this constructor defines the states
  85. * used by this machine.
  86. */
  87. AITNGuardMachine( Object *owner );
  88. const Coord3D *getPositionToGuard( void ) const { return &m_positionToGuard; }
  89. void setTargetPositionToGuard( const Coord3D *pos) { m_positionToGuard = *pos; }
  90. void setNemesisID(ObjectID id) { m_nemesisToAttack = id; }
  91. ObjectID getNemesisID() const { return m_nemesisToAttack; }
  92. GuardMode getGuardMode() const { return m_guardMode; }
  93. void setGuardMode(GuardMode guardMode) { m_guardMode = guardMode; }
  94. Bool lookForInnerTarget(void);
  95. static Real getStdGuardRange(const Object* obj);
  96. };
  97. //--------------------------------------------------------------------------------------
  98. class AITNGuardInnerState : public State
  99. {
  100. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AITNGuardInnerState, "AITNGuardInnerState")
  101. public:
  102. AITNGuardInnerState( StateMachine *machine ) : State( machine, "AITNGuardInner" ) { }
  103. virtual StateReturnType onEnter( void );
  104. virtual StateReturnType update( void );
  105. virtual void onExit( StateExitType status );
  106. protected:
  107. // snapshot interface
  108. virtual void crc( Xfer *xfer );
  109. virtual void xfer( Xfer *xfer );
  110. virtual void loadPostProcess();
  111. private:
  112. AITNGuardMachine* getGuardMachine() { return (AITNGuardMachine*)getMachine(); }
  113. TunnelNetworkExitConditions m_exitConditions;
  114. Bool m_scanForEnemy;
  115. AIAttackState *m_attackState;
  116. };
  117. EMPTY_DTOR(AITNGuardInnerState)
  118. //--------------------------------------------------------------------------------------
  119. class AITNGuardIdleState : public State
  120. {
  121. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AITNGuardIdleState, "AITNGuardIdleState")
  122. public:
  123. AITNGuardIdleState( StateMachine *machine ) : State( machine, "AITNGuardIdleState" ) { }
  124. virtual StateReturnType onEnter( void );
  125. virtual StateReturnType update( void );
  126. virtual void onExit( StateExitType status );
  127. protected:
  128. // snapshot interface
  129. virtual void crc( Xfer *xfer );
  130. virtual void xfer( Xfer *xfer );
  131. virtual void loadPostProcess();
  132. private:
  133. AITNGuardMachine* getGuardMachine() { return (AITNGuardMachine*)getMachine(); }
  134. UnsignedInt m_nextEnemyScanTime;
  135. Coord3D m_guardeePos; ///< Where the object we are guarding was last.
  136. };
  137. EMPTY_DTOR(AITNGuardIdleState)
  138. //--------------------------------------------------------------------------------------
  139. class AITNGuardOuterState : public State
  140. {
  141. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AITNGuardOuterState, "AITNGuardOuterState")
  142. public:
  143. AITNGuardOuterState( StateMachine *machine ) : State( machine, "AITNGuardOuter" )
  144. {
  145. m_attackState = NULL;
  146. }
  147. virtual StateReturnType onEnter( void );
  148. virtual StateReturnType update( void );
  149. virtual void onExit( StateExitType status );
  150. protected:
  151. // snapshot interface
  152. virtual void crc( Xfer *xfer );
  153. virtual void xfer( Xfer *xfer );
  154. virtual void loadPostProcess();
  155. private:
  156. AITNGuardMachine* getGuardMachine() { return (AITNGuardMachine*)getMachine(); }
  157. TunnelNetworkExitConditions m_exitConditions;
  158. AIAttackState *m_attackState;
  159. };
  160. EMPTY_DTOR(AITNGuardOuterState)
  161. //--------------------------------------------------------------------------------------
  162. class AITNGuardReturnState : public AIEnterState
  163. {
  164. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AITNGuardReturnState, "AITNGuardReturnState")
  165. private:
  166. AITNGuardMachine* getGuardMachine() { return (AITNGuardMachine*)getMachine(); }
  167. public:
  168. AITNGuardReturnState( StateMachine *machine ) : AIEnterState(machine )
  169. {
  170. m_nextReturnScanTime = 0;
  171. }
  172. virtual StateReturnType onEnter( void );
  173. virtual StateReturnType update( void );
  174. virtual void onExit( StateExitType status );
  175. protected:
  176. UnsignedInt m_nextReturnScanTime;
  177. protected:
  178. // snapshot interface
  179. virtual void crc( Xfer *xfer );
  180. virtual void xfer( Xfer *xfer );
  181. virtual void loadPostProcess();
  182. };
  183. EMPTY_DTOR(AITNGuardReturnState)
  184. //--------------------------------------------------------------------------------------
  185. class AITNGuardPickUpCrateState : public AIPickUpCrateState
  186. {
  187. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AITNGuardPickUpCrateState, "AITNGuardPickUpCrateState")
  188. public:
  189. AITNGuardPickUpCrateState( StateMachine *machine );
  190. virtual StateReturnType onEnter( void );
  191. virtual StateReturnType update( void );
  192. virtual void onExit( StateExitType status );
  193. };
  194. EMPTY_DTOR(AITNGuardPickUpCrateState)
  195. //--------------------------------------------------------------------------------------
  196. class AITNGuardAttackAggressorState : public State
  197. {
  198. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AITNGuardAttackAggressorState, "AITNGuardAttackAggressorState")
  199. public:
  200. AITNGuardAttackAggressorState( StateMachine *machine );
  201. virtual StateReturnType onEnter( void );
  202. virtual StateReturnType update( void );
  203. virtual void onExit( StateExitType status );
  204. protected:
  205. // snapshot interface
  206. virtual void crc( Xfer *xfer );
  207. virtual void xfer( Xfer *xfer );
  208. virtual void loadPostProcess();
  209. private:
  210. AITNGuardMachine* getGuardMachine() { return (AITNGuardMachine*)getMachine(); }
  211. TunnelNetworkExitConditions m_exitConditions;
  212. AIAttackState *m_attackState;
  213. };
  214. EMPTY_DTOR(AITNGuardAttackAggressorState)
  215. //--------------------------------------------------------------------------------------
  216. #endif /* _H_AIGUARD_ */