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.

236 lines
6.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef AI_BEHAVIOR_LEAD_H
  7. #define AI_BEHAVIOR_LEAD_H
  8. #include "simtimer.h"
  9. #include "ai_behavior.h"
  10. #include "ai_speech.h"
  11. #if defined( _WIN32 )
  12. #pragma once
  13. #endif
  14. // Speak concepts
  15. #define TLK_LEAD_START "TLK_LEAD_START"
  16. #define TLK_LEAD_ARRIVAL "TLK_LEAD_ARRIVAL"
  17. #define TLK_LEAD_SUCCESS "TLK_LEAD_SUCCESS"
  18. #define TLK_LEAD_FAILURE "lead_fail"
  19. #define TLK_LEAD_COMINGBACK "TLK_LEAD_COMINGBACK"
  20. #define TLK_LEAD_CATCHUP "TLK_LEAD_CATCHUP"
  21. #define TLK_LEAD_RETRIEVE "TLK_LEAD_RETRIEVE"
  22. #define TLK_LEAD_ATTRACTPLAYER "TLK_LEAD_ATTRACTPLAYER"
  23. #define TLK_LEAD_WAITOVER "TLK_LEAD_WAITOVER"
  24. #define TLK_LEAD_MISSINGWEAPON "TLK_LEAD_MISSING_WEAPON"
  25. #define TLK_LEAD_IDLE "TLK_LEAD_IDLE"
  26. //-----------------------------------------------------------------------------
  27. // class CAI_LeadBehavior
  28. //
  29. // Purpose:
  30. //
  31. //-----------------------------------------------------------------------------
  32. enum LeadBehaviorEvents_t
  33. {
  34. LBE_ARRIVAL,
  35. LBE_ARRIVAL_DONE,
  36. LBE_SUCCESS,
  37. LBE_FAILURE,
  38. LBE_DONE,
  39. };
  40. //-------------------------------------
  41. //
  42. // Handler class interface to listen to and modify actions of the lead behavior.
  43. // Could be an NPC, or another entity (like a goal entity)
  44. //
  45. class CAI_LeadBehaviorHandler
  46. {
  47. public:
  48. virtual void OnEvent( int event ) {}
  49. virtual const char *GetConceptModifiers( const char *pszConcept ) { return NULL; }
  50. };
  51. //-------------------------------------
  52. enum AI_LeadFlags_t
  53. {
  54. AILF_NO_DEF_SUCCESS = 0x01,
  55. AILF_NO_DEF_FAILURE = 0x02,
  56. AILF_USE_GOAL_FACING = 0x04,
  57. };
  58. struct AI_LeadArgs_t
  59. {
  60. const char *pszGoal;
  61. const char *pszWaitPoint;
  62. unsigned flags;
  63. float flWaitDistance;
  64. float flLeadDistance;
  65. float flRetrieveDistance;
  66. float flSuccessDistance;
  67. bool bRun;
  68. int iRetrievePlayer;
  69. int iRetrieveWaitForSpeak;
  70. int iComingBackWaitForSpeak;
  71. bool bStopScenesWhenPlayerLost;
  72. bool bDontSpeakStart;
  73. bool bLeadDuringCombat;
  74. bool bGagLeader;
  75. DECLARE_SIMPLE_DATADESC();
  76. };
  77. class CAI_LeadBehavior : public CAI_SimpleBehavior
  78. {
  79. DECLARE_CLASS( CAI_LeadBehavior, CAI_SimpleBehavior );
  80. public:
  81. CAI_LeadBehavior()
  82. : m_pSink(NULL),
  83. m_LostTimer( 3.0, 4.0 ),
  84. m_LostLOSTimer( 2.0, 3.0 )
  85. {
  86. memset( &m_args, 0, sizeof(m_args) );
  87. ClearGoal();
  88. }
  89. virtual void OnRestore();
  90. virtual const char *GetName() { return "Lead"; }
  91. virtual int DrawDebugTextOverlays( int text_offset );
  92. virtual bool IsNavigationUrgent();
  93. void LeadPlayer( const AI_LeadArgs_t &leadArgs, CAI_LeadBehaviorHandler *pSink = NULL );
  94. void StopLeading( void );
  95. virtual bool CanSelectSchedule();
  96. void BeginScheduleSelection();
  97. virtual bool IsCurTaskContinuousMove();
  98. bool SetGoal( const AI_LeadArgs_t &args );
  99. void ClearGoal() { m_goal = vec3_origin; m_waitpoint = vec3_origin; m_pSink = NULL; m_weaponname = NULL_STRING; }
  100. bool HasGoal() const { return (m_goal != vec3_origin); }
  101. bool HasWaitPoint() const { return (m_waitpoint != vec3_origin); }
  102. bool Connect( CAI_LeadBehaviorHandler *);
  103. bool Disconnect( CAI_LeadBehaviorHandler *);
  104. void SetWaitForWeapon( string_t iszWeaponName ) { m_weaponname = iszWeaponName; m_flWeaponSafetyTimeOut = gpGlobals->curtime + 60; }
  105. enum
  106. {
  107. // Schedules
  108. SCHED_LEAD_PLAYER = BaseClass::NEXT_SCHEDULE,
  109. SCHED_LEAD_PAUSE,
  110. SCHED_LEAD_PAUSE_COMBAT,
  111. SCHED_LEAD_RETRIEVE,
  112. SCHED_LEAD_RETRIEVE_WAIT,
  113. SCHED_LEAD_SUCCEED,
  114. SCHED_LEAD_AWAIT_SUCCESS,
  115. SCHED_LEAD_WAITFORPLAYER,
  116. SCHED_LEAD_WAITFORPLAYERIDLE,
  117. SCHED_LEAD_PLAYERNEEDSWEAPON,
  118. SCHED_LEAD_SPEAK_START,
  119. SCHED_LEAD_SPEAK_THEN_RETRIEVE_PLAYER,
  120. SCHED_LEAD_SPEAK_THEN_LEAD_PLAYER,
  121. NEXT_SCHEDULE,
  122. // Tasks
  123. TASK_GET_PATH_TO_LEAD_GOAL = BaseClass::NEXT_TASK,
  124. TASK_STOP_LEADING,
  125. TASK_LEAD_FACE_GOAL,
  126. TASK_LEAD_ARRIVE,
  127. TASK_LEAD_SUCCEED,
  128. TASK_LEAD_GET_PATH_TO_WAITPOINT,
  129. TASK_LEAD_WAVE_TO_PLAYER,
  130. TASK_LEAD_PLAYER_NEEDS_WEAPON,
  131. TASK_LEAD_SPEAK_START,
  132. TASK_LEAD_MOVE_TO_RANGE,
  133. TASK_LEAD_RETRIEVE_WAIT,
  134. TASK_LEAD_WALK_PATH,
  135. NEXT_TASK,
  136. // Conditions
  137. COND_LEAD_FOLLOWER_LOST = BaseClass::NEXT_CONDITION,
  138. COND_LEAD_FOLLOWER_LAGGING,
  139. COND_LEAD_FOLLOWER_NOT_LAGGING,
  140. COND_LEAD_FOLLOWER_VERY_CLOSE,
  141. COND_LEAD_SUCCESS,
  142. COND_LEAD_HAVE_FOLLOWER_LOS,
  143. COND_LEAD_FOLLOWER_MOVED_FROM_MARK,
  144. COND_LEAD_FOLLOWER_MOVING_TOWARDS_ME,
  145. NEXT_CONDITION
  146. };
  147. private:
  148. void GatherConditions();
  149. virtual int SelectSchedule();
  150. virtual int TranslateSchedule( int scheduleType );
  151. virtual void StartTask( const Task_t *pTask );
  152. virtual void RunTask( const Task_t *pTask );
  153. bool GetClosestPointOnRoute( const Vector &targetPos, Vector *pVecClosestPoint );
  154. bool PlayerIsAheadOfMe( bool bForce = false );
  155. bool Speak( AIConcept_t concept );
  156. bool IsSpeaking();
  157. // --------------------------------
  158. //
  159. // Sink notifiers. Isolated to limit exposure to actual sink storage,
  160. // provide debugging pinch pount, and allow for class-local logic
  161. // in addition to sink logic
  162. //
  163. void NotifyEvent( int event ) { if ( m_pSink ) m_pSink->OnEvent( event ) ; }
  164. const char * GetConceptModifiers( const char *pszConcept ) { return ( m_pSink ) ? m_pSink->GetConceptModifiers( pszConcept ) : NULL; }
  165. // --------------------------------
  166. AI_LeadArgs_t m_args;
  167. CAI_LeadBehaviorHandler *m_pSink;
  168. EHANDLE m_hSinkImplementor;
  169. // --------------------------------
  170. Vector m_goal;
  171. float m_goalyaw;
  172. Vector m_waitpoint;
  173. float m_waitdistance;
  174. float m_leaddistance;
  175. float m_retrievedistance;
  176. float m_successdistance;
  177. string_t m_weaponname;
  178. bool m_run;
  179. bool m_gagleader;
  180. bool m_hasspokenstart;
  181. bool m_hasspokenarrival;
  182. bool m_hasPausedScenes;
  183. float m_flSpeakNextNagTime;
  184. float m_flWeaponSafetyTimeOut;
  185. float m_flNextLeadIdle;
  186. bool m_bInitialAheadTest;
  187. CAI_MoveMonitor m_MoveMonitor;
  188. CRandStopwatch m_LostTimer;
  189. CRandStopwatch m_LostLOSTimer;
  190. DEFINE_CUSTOM_SCHEDULE_PROVIDER;
  191. DECLARE_DATADESC();
  192. };
  193. //-----------------------------------------------------------------------------
  194. #endif // AI_BEHAVIOR_LEAD_H