Team Fortress 2 Source Code as on 22/4/2020
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.

299 lines
7.2 KiB

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