AIGuardRetaliate.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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: AIGuardRetaliate.h
  24. /*---------------------------------------------------------------------------*/
  25. /* Electronic Arts Los Angeles */
  26. /* Confidential Information */
  27. /* Copyright (C) 2003 - All Rights Reserved */
  28. /* DO NOT DISTRIBUTE */
  29. /*---------------------------------------------------------------------------*/
  30. /* Project: RTS3 */
  31. /* File name: AIGuardRetaliate.h */
  32. /* Created: Kris Morness July 2003 */
  33. /* Desc: // Define Guard Retaliation states for AI */
  34. /*---------------------------------------------------------------------------*/
  35. #pragma once
  36. #ifndef __AI_GUARD_RETALIATION_H
  37. #define __AI_GUARD_RETALIATION_H
  38. // INCLUDES ///////////////////////////////////////////////////////////////////
  39. #include "Common/GameMemory.h"
  40. #include "GameLogic/AIStateMachine.h"
  41. #include "GameLogic/GameLogic.h"
  42. #include "GameLogic/Object.h"
  43. #include "GameLogic/AI.h"
  44. // DEFINES ////////////////////////////////////////////////////////////////////
  45. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  46. enum
  47. {
  48. // prevent collisions with other states that we might use, (namely AI_IDLE)
  49. AI_GUARD_RETALIATE_INNER = 5000, ///< Attack anything within this area till death
  50. AI_GUARD_RETALIATE_IDLE, ///< Wait till something shows up to attack.
  51. AI_GUARD_RETALIATE_OUTER, ///< Attack anything within this area that has been aggressive, until the timer expires
  52. AI_GUARD_RETALIATE_RETURN, ///< Restore to a position within the inner circle
  53. AI_GUARD_RETALIATE_GET_CRATE, ///< Pick up a crate from an enemy we killed.
  54. AI_GUARD_RETALIATE_ATTACK_AGGRESSOR, ///< Attack something that attacked me (that I can attack)
  55. };
  56. //--------------------------------------------------------------------------------------
  57. class GuardRetaliateExitConditions : public AttackExitConditionsInterface
  58. {
  59. public:
  60. enum ExitConditionsEnum
  61. {
  62. ATTACK_ExitIfOutsideRadius = 0x01,
  63. ATTACK_ExitIfExpiredDuration = 0x02,
  64. ATTACK_ExitIfNoUnitFound = 0x04
  65. };
  66. Int m_conditionsToConsider;
  67. Coord3D m_center; // can be updated at any time by owner
  68. Real m_radiusSqr; // can be updated at any time by owner
  69. UnsignedInt m_attackGiveUpFrame; // frame at which we give up (if using)
  70. GuardRetaliateExitConditions() : m_attackGiveUpFrame(0), m_conditionsToConsider(0), m_radiusSqr(0.0f)
  71. {
  72. //Added By Sadullah Nader
  73. // Initializations missing and needed
  74. m_center.zero();
  75. }
  76. virtual Bool shouldExit(const StateMachine* machine) const;
  77. };
  78. // FORWARD DECLARATIONS ///////////////////////////////////////////////////////
  79. //--------------------------------------------------------------------------------------
  80. class AIGuardRetaliateMachine : public StateMachine
  81. {
  82. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( AIGuardRetaliateMachine, "AIGuardRetaliateMachinePool" );
  83. private:
  84. Coord3D m_positionToGuard;
  85. ObjectID m_nemesisToAttack;
  86. protected:
  87. // snapshot interface
  88. virtual void crc( Xfer *xfer );
  89. virtual void xfer( Xfer *xfer );
  90. virtual void loadPostProcess();
  91. public:
  92. /**
  93. * The implementation of this constructor defines the states
  94. * used by this machine.
  95. */
  96. AIGuardRetaliateMachine( Object *owner );
  97. virtual Bool isIdle() const;
  98. const Coord3D *getPositionToGuard( void ) const { return &m_positionToGuard; }
  99. void setTargetPositionToGuard( const Coord3D *pos) { m_positionToGuard = *pos; }
  100. void setNemesisID(ObjectID id) { m_nemesisToAttack = id; }
  101. ObjectID getNemesisID() const { return m_nemesisToAttack; }
  102. Bool lookForInnerTarget(void);
  103. static Real getStdGuardRange(const Object* obj);
  104. };
  105. //--------------------------------------------------------------------------------------
  106. class AIGuardRetaliateInnerState : public State
  107. {
  108. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIGuardRetaliateInnerState, "AIGuardRetaliateInnerState")
  109. public:
  110. AIGuardRetaliateInnerState( StateMachine *machine ) : State( machine, "AIGuardRetaliateInner" )
  111. {
  112. m_attackState = 0;
  113. m_enterState = 0;
  114. }
  115. virtual StateReturnType onEnter( void );
  116. virtual StateReturnType update( void );
  117. virtual void onExit( StateExitType status );
  118. protected:
  119. // snapshot interface
  120. virtual void crc( Xfer *xfer );
  121. virtual void xfer( Xfer *xfer );
  122. virtual void loadPostProcess();
  123. private:
  124. AIGuardRetaliateMachine* getGuardMachine() { return (AIGuardRetaliateMachine*)getMachine(); }
  125. GuardRetaliateExitConditions m_exitConditions;
  126. AIAttackState *m_attackState;
  127. AIEnterState *m_enterState;
  128. };
  129. EMPTY_DTOR(AIGuardRetaliateInnerState)
  130. //--------------------------------------------------------------------------------------
  131. class AIGuardRetaliateIdleState : public State
  132. {
  133. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIGuardRetaliateIdleState, "AIGuardRetaliateIdleState")
  134. public:
  135. AIGuardRetaliateIdleState( StateMachine *machine ) : State( machine, "AIGuardRetaliateIdleState" ) { }
  136. virtual StateReturnType onEnter( void );
  137. virtual StateReturnType update( void );
  138. virtual void onExit( StateExitType status );
  139. protected:
  140. // snapshot interface
  141. virtual void crc( Xfer *xfer );
  142. virtual void xfer( Xfer *xfer );
  143. virtual void loadPostProcess();
  144. private:
  145. AIGuardRetaliateMachine* getGuardMachine() { return (AIGuardRetaliateMachine*)getMachine(); }
  146. UnsignedInt m_nextEnemyScanTime;
  147. Coord3D m_guardeePos; ///< Where the object we are guarding was last.
  148. };
  149. EMPTY_DTOR(AIGuardRetaliateIdleState)
  150. //--------------------------------------------------------------------------------------
  151. class AIGuardRetaliateOuterState : public State
  152. {
  153. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIGuardRetaliateOuterState, "AIGuardRetaliateOuterState")
  154. public:
  155. AIGuardRetaliateOuterState( StateMachine *machine ) : State( machine, "AIGuardRetaliateOuter" )
  156. {
  157. m_attackState = NULL;
  158. }
  159. virtual StateReturnType onEnter( void );
  160. virtual StateReturnType update( void );
  161. virtual void onExit( StateExitType status );
  162. protected:
  163. // snapshot interface
  164. virtual void crc( Xfer *xfer );
  165. virtual void xfer( Xfer *xfer );
  166. virtual void loadPostProcess();
  167. private:
  168. AIGuardRetaliateMachine* getGuardMachine() { return (AIGuardRetaliateMachine*)getMachine(); }
  169. GuardRetaliateExitConditions m_exitConditions;
  170. AIAttackState *m_attackState;
  171. };
  172. EMPTY_DTOR(AIGuardRetaliateOuterState)
  173. //--------------------------------------------------------------------------------------
  174. class AIGuardRetaliateReturnState : public AIInternalMoveToState
  175. {
  176. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIGuardRetaliateReturnState, "AIGuardRetaliateReturnState")
  177. private:
  178. AIGuardRetaliateMachine* getGuardMachine() { return (AIGuardRetaliateMachine*)getMachine(); }
  179. public:
  180. AIGuardRetaliateReturnState( StateMachine *machine ) : AIInternalMoveToState( machine, "AIGuardRetaliateReturn" )
  181. {
  182. m_nextReturnScanTime = 0;
  183. }
  184. virtual StateReturnType onEnter( void );
  185. virtual StateReturnType update( void );
  186. virtual void onExit( StateExitType status );
  187. protected:
  188. // snapshot interface
  189. virtual void crc( Xfer *xfer );
  190. virtual void xfer( Xfer *xfer );
  191. virtual void loadPostProcess();
  192. private:
  193. UnsignedInt m_nextReturnScanTime;
  194. };
  195. EMPTY_DTOR(AIGuardRetaliateReturnState)
  196. //--------------------------------------------------------------------------------------
  197. class AIGuardRetaliatePickUpCrateState : public AIPickUpCrateState
  198. {
  199. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIGuardRetaliatePickUpCrateState, "AIGuardRetaliatePickUpCrateState")
  200. public:
  201. AIGuardRetaliatePickUpCrateState( StateMachine *machine );
  202. virtual StateReturnType onEnter( void );
  203. virtual StateReturnType update( void );
  204. virtual void onExit( StateExitType status );
  205. };
  206. EMPTY_DTOR(AIGuardRetaliatePickUpCrateState)
  207. //--------------------------------------------------------------------------------------
  208. class AIGuardRetaliateAttackAggressorState : public State
  209. {
  210. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIGuardRetaliateAttackAggressorState, "AIGuardRetaliateAttackAggressorState")
  211. public:
  212. AIGuardRetaliateAttackAggressorState( StateMachine *machine );
  213. virtual StateReturnType onEnter( void );
  214. virtual StateReturnType update( void );
  215. virtual void onExit( StateExitType status );
  216. #ifdef STATE_MACHINE_DEBUG
  217. virtual AsciiString getName() const ;
  218. #endif
  219. protected:
  220. // snapshot interface
  221. virtual void crc( Xfer *xfer );
  222. virtual void xfer( Xfer *xfer );
  223. virtual void loadPostProcess();
  224. private:
  225. AIGuardRetaliateMachine* getGuardMachine() { return (AIGuardRetaliateMachine*)getMachine(); }
  226. GuardRetaliateExitConditions m_exitConditions;
  227. AIAttackState *m_attackState;
  228. };
  229. EMPTY_DTOR(AIGuardRetaliateAttackAggressorState)
  230. //--------------------------------------------------------------------------------------
  231. #endif