Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

335 lines
8.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef AI_BEHAVIOR_ASSAULT_H
  7. #define AI_BEHAVIOR_ASSAULT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "simtimer.h"
  12. #include "ai_behavior.h"
  13. #include "ai_goalentity.h"
  14. #include "ai_moveshoot.h"
  15. #include "ai_utils.h"
  16. #define CUE_POINT_TOLERANCE (3.0*12.0)
  17. enum RallySelectMethod_t
  18. {
  19. RALLY_POINT_SELECT_CLOSEST = 0,
  20. RALLY_POINT_SELECT_RANDOM,
  21. RALLY_POINT_SELECT_FURTHEST
  22. };
  23. enum BranchingMethod_t
  24. {
  25. BRANCH_RANDOM,
  26. BRANCH_CLOSEST,
  27. BRANCH_FURTHEST
  28. };
  29. enum AssaultCue_t
  30. {
  31. CUE_NO_ASSAULT = 0, // used to indicate that no assault is being conducted presently
  32. CUE_ENTITY_INPUT = 1,
  33. CUE_PLAYER_GUNFIRE,
  34. CUE_DONT_WAIT,
  35. CUE_COMMANDER,
  36. CUE_NONE,
  37. };
  38. enum
  39. {
  40. ASSAULT_SENTENCE_HIT_RALLY_POINT = SENTENCE_BASE_BEHAVIOR_INDEX,
  41. ASSAULT_SENTENCE_HIT_ASSAULT_POINT,
  42. ASSAULT_SENTENCE_SQUAD_ADVANCE_TO_RALLY,
  43. ASSAULT_SENTENCE_SQUAD_ADVANCE_TO_ASSAULT,
  44. ASSAULT_SENTENCE_COVER_NO_AMMO,
  45. ASSAULT_SENTENCE_UNDER_ATTACK,
  46. };
  47. // Allow diversion from the assault up to this amount of time after last having an enemy
  48. #define ASSAULT_DIVERSION_TIME 4
  49. #define SF_ASSAULTPOINT_CLEARONARRIVAL 0x00000001
  50. //=============================================================================
  51. //=============================================================================
  52. class CAI_AssaultGoal : public CAI_GoalEntity
  53. {
  54. typedef CAI_GoalEntity BaseClass;
  55. virtual void EnableGoal( CAI_BaseNPC *pAI );
  56. virtual void DisableGoal( CAI_BaseNPC *pAI );
  57. string_t m_RallyPoint;
  58. int m_AssaultCue;
  59. int m_RallySelectMethod;
  60. int m_BranchMethod;
  61. void InputBeginAssault( inputdata_t &inputdata );
  62. DECLARE_DATADESC();
  63. friend class CAI_AssaultBehavior;
  64. };
  65. //=============================================================================
  66. //=============================================================================
  67. class CRallyPoint : public CPointEntity
  68. {
  69. DECLARE_CLASS( CRallyPoint, CPointEntity );
  70. public:
  71. CRallyPoint()
  72. {
  73. m_hLockedBy.Set(NULL);
  74. m_sExclusivity = RALLY_EXCLUSIVE_NOT_EVALUATED;
  75. }
  76. bool Lock( CBaseEntity *pLocker )
  77. {
  78. if( IsLocked() )
  79. {
  80. // Already locked.
  81. return false;
  82. }
  83. m_hLockedBy.Set( pLocker );
  84. return true;
  85. }
  86. bool Unlock( CBaseEntity *pUnlocker )
  87. {
  88. if( IsLocked() )
  89. {
  90. if( m_hLockedBy.Get() != pUnlocker )
  91. {
  92. // Refuse! Only the locker may unlock.
  93. return false;
  94. }
  95. }
  96. m_hLockedBy.Set( NULL );
  97. return true;
  98. }
  99. bool IsLocked( void ) { return (m_hLockedBy.Get() != NULL); }
  100. bool ShouldBeLocked( void ) { return m_bShouldLock; }
  101. int DrawDebugTextOverlays();
  102. bool IsExclusive();
  103. enum
  104. {
  105. RALLY_EXCLUSIVE_NOT_EVALUATED = -1,
  106. RALLY_EXCLUSIVE_NO,
  107. RALLY_EXCLUSIVE_YES,
  108. };
  109. string_t m_AssaultPointName;
  110. string_t m_RallySequenceName;
  111. float m_flAssaultDelay;
  112. int m_iPriority;
  113. int m_iStrictness;
  114. bool m_bForceCrouch;
  115. bool m_bIsUrgent;
  116. short m_sExclusivity;
  117. bool m_bShouldLock;
  118. COutputEvent m_OnArrival;
  119. DECLARE_DATADESC();
  120. private:
  121. EHANDLE m_hLockedBy;
  122. };
  123. //=============================================================================
  124. //=============================================================================
  125. class CAssaultPoint : public CPointEntity
  126. {
  127. DECLARE_CLASS( CAssaultPoint, CPointEntity );
  128. public:
  129. CAssaultPoint()
  130. {
  131. // This used to be a constant in code. Now it's a keyfield in hammer.
  132. // So in the constructor, we set this value to the former constant
  133. // default value, for legacy maps. (sjb)
  134. m_flAssaultPointTolerance = CUE_POINT_TOLERANCE;
  135. }
  136. void InputSetClearOnContact( inputdata_t &inputdata )
  137. {
  138. m_bClearOnContact = inputdata.value.Bool();
  139. }
  140. void InputSetAllowDiversion( inputdata_t &inputdata )
  141. {
  142. m_bAllowDiversion = inputdata.value.Bool();
  143. }
  144. void InputSetForceClear( inputdata_t &inputdata )
  145. {
  146. m_bInputForcedClear = inputdata.value.Bool();
  147. }
  148. public:
  149. string_t m_AssaultHintGroup;
  150. string_t m_NextAssaultPointName;
  151. COutputEvent m_OnAssaultClear;
  152. float m_flAssaultTimeout;
  153. bool m_bClearOnContact;
  154. bool m_bAllowDiversion;
  155. float m_flAllowDiversionRadius;
  156. bool m_bNeverTimeout;
  157. int m_iStrictness;
  158. bool m_bForceCrouch;
  159. bool m_bIsUrgent;
  160. bool m_bInputForcedClear;
  161. float m_flAssaultPointTolerance;
  162. float m_flTimeLastUsed;
  163. COutputEvent m_OnArrival;
  164. DECLARE_DATADESC();
  165. };
  166. //=============================================================================
  167. //=============================================================================
  168. class CAI_AssaultBehavior : public CAI_SimpleBehavior
  169. {
  170. DECLARE_CLASS( CAI_AssaultBehavior, CAI_SimpleBehavior );
  171. public:
  172. CAI_AssaultBehavior();
  173. virtual const char *GetName() { return "Assault"; }
  174. virtual int DrawDebugTextOverlays( int text_offset );
  175. virtual void OnRestore();
  176. void SetGoal( CAI_AssaultGoal *pGoal ) { m_hGoal = pGoal; }
  177. bool CanRunAScriptedNPCInteraction( bool bForced );
  178. virtual bool CanSelectSchedule();
  179. virtual void BeginScheduleSelection();
  180. virtual void EndScheduleSelection();
  181. bool HasHitRallyPoint() { return m_bHitRallyPoint; }
  182. bool HasHitAssaultPoint() { return m_bHitAssaultPoint; }
  183. void ClearAssaultPoint( void );
  184. void OnHitAssaultPoint( void );
  185. bool PollAssaultCue( void );
  186. void ReceiveAssaultCue( AssaultCue_t cue );
  187. bool HasAssaultCue( void ) { return m_AssaultCue != CUE_NO_ASSAULT; }
  188. bool AssaultHasBegun();
  189. CAssaultPoint *FindAssaultPoint( string_t iszAssaultPointName );
  190. void SetAssaultPoint( CAssaultPoint *pAssaultPoint );
  191. void GatherConditions( void );
  192. void StartTask( const Task_t *pTask );
  193. void RunTask( const Task_t *pTask );
  194. void BuildScheduleTestBits();
  195. int TranslateSchedule( int scheduleType );
  196. void OnStartSchedule( int scheduleType );
  197. void ClearSchedule( const char *szReason );
  198. void InitializeBehavior();
  199. void SetParameters( string_t rallypointname, AssaultCue_t assaultcue, int rallySelectMethod );
  200. void SetParameters( CBaseEntity *pRallyEnt, AssaultCue_t assaultcue );
  201. bool IsAllowedToDivert( void );
  202. bool IsValidShootPosition( const Vector &vLocation, CAI_Node *pNode, CAI_Hint const *pHint );
  203. float GetMaxTacticalLateralMovement( void );
  204. void UpdateOnRemove();
  205. bool OnStrictAssault( void );
  206. bool UpdateForceCrouch( void );
  207. bool IsForcingCrouch( void );
  208. bool IsUrgent( void );
  209. CRallyPoint *FindBestRallyPointInRadius( const Vector &vecCenter, float flRadius );;
  210. void Disable( void ) { m_AssaultCue = CUE_NO_ASSAULT; m_bHitRallyPoint = false; m_bHitAssaultPoint = false; }
  211. enum
  212. {
  213. SCHED_MOVE_TO_RALLY_POINT = BaseClass::NEXT_SCHEDULE, // Try to get out of the player's way
  214. SCHED_ASSAULT_FAILED_TO_MOVE,
  215. SCHED_FAIL_MOVE_TO_RALLY_POINT,
  216. SCHED_MOVE_TO_ASSAULT_POINT,
  217. SCHED_AT_ASSAULT_POINT,
  218. SCHED_HOLD_RALLY_POINT,
  219. SCHED_HOLD_ASSAULT_POINT,
  220. SCHED_WAIT_AND_CLEAR,
  221. SCHED_ASSAULT_MOVE_AWAY,
  222. SCHED_CLEAR_ASSAULT_POINT,
  223. NEXT_SCHEDULE,
  224. TASK_GET_PATH_TO_RALLY_POINT = BaseClass::NEXT_TASK,
  225. TASK_FACE_RALLY_POINT,
  226. TASK_GET_PATH_TO_ASSAULT_POINT,
  227. TASK_FACE_ASSAULT_POINT,
  228. TASK_HIT_ASSAULT_POINT,
  229. TASK_HIT_RALLY_POINT,
  230. TASK_AWAIT_CUE,
  231. TASK_AWAIT_ASSAULT_TIMEOUT,
  232. TASK_ANNOUNCE_CLEAR,
  233. TASK_WAIT_ASSAULT_DELAY,
  234. TASK_ASSAULT_MOVE_AWAY_PATH,
  235. TASK_ASSAULT_DEFER_SCHEDULE_SELECTION,
  236. NEXT_TASK,
  237. /*
  238. COND_PUT_CONDITIONS_HERE = BaseClass::NEXT_CONDITION,
  239. NEXT_CONDITION,
  240. */
  241. };
  242. DEFINE_CUSTOM_SCHEDULE_PROVIDER;
  243. public:
  244. CHandle<CAssaultPoint> m_hAssaultPoint;
  245. CHandle<CRallyPoint> m_hRallyPoint;
  246. public:
  247. void UnlockRallyPoint( void );
  248. private:
  249. void OnScheduleChange();
  250. virtual int SelectSchedule();
  251. AssaultCue_t m_AssaultCue; // the cue we're waiting for to begin the assault
  252. AssaultCue_t m_ReceivedAssaultCue; // the last assault cue we received from someone/thing external.
  253. bool m_bHitRallyPoint;
  254. bool m_bHitAssaultPoint;
  255. // Diversion
  256. bool m_bDiverting;
  257. float m_flLastSawAnEnemyAt;
  258. float m_flTimeDeferScheduleSelection;
  259. string_t m_AssaultPointName;
  260. CHandle<CAI_AssaultGoal> m_hGoal;
  261. //---------------------------------
  262. DECLARE_DATADESC();
  263. };
  264. #endif // AI_BEHAVIOR_ASSAULT_H