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.

232 lines
5.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Combat behaviors for AIs in a relatively self-preservationist mode.
  4. // Lots of cover taking and attempted shots out of cover.
  5. //
  6. //=============================================================================//
  7. #ifndef AI_BEHAVIOR_STANDOFF_H
  8. #define AI_BEHAVIOR_STANDOFF_H
  9. #include "utlvector.h"
  10. #include "utlmap.h"
  11. #include "ai_behavior.h"
  12. #include "ai_utils.h"
  13. #include "ai_hint.h"
  14. #if defined( _WIN32 )
  15. #pragma once
  16. #endif
  17. //-----------------------------------------------------------------------------
  18. enum AI_HintChangeReaction_t
  19. {
  20. AIHCR_DEFAULT_AI,
  21. AIHCR_MOVE_ON_COVER,
  22. AIHCR_MOVE_IMMEDIATE,
  23. };
  24. struct AI_StandoffParams_t
  25. {
  26. AI_HintChangeReaction_t hintChangeReaction;
  27. bool fCoverOnReload;
  28. bool fPlayerIsBattleline;
  29. float minTimeShots;
  30. float maxTimeShots;
  31. int minShots;
  32. int maxShots;
  33. int oddsCover;
  34. bool fStayAtCover;
  35. float flAbandonTimeLimit;
  36. DECLARE_SIMPLE_DATADESC();
  37. };
  38. //-------------------------------------
  39. enum AI_Posture_t
  40. {
  41. AIP_INDIFFERENT,
  42. AIP_STANDING,
  43. AIP_CROUCHING,
  44. AIP_PEEKING,
  45. };
  46. enum
  47. {
  48. STANDOFF_SENTENCE_BEGIN_STANDOFF = SENTENCE_BASE_BEHAVIOR_INDEX,
  49. STANDOFF_SENTENCE_END_STANDOFF,
  50. STANDOFF_SENTENCE_OUT_OF_AMMO,
  51. STANDOFF_SENTENCE_FORCED_TAKE_COVER,
  52. STANDOFF_SENTENCE_STAND_CHECK_TARGET,
  53. };
  54. class CAI_MappedActivityBehavior_Temporary : public CAI_SimpleBehavior
  55. {
  56. DECLARE_CLASS( CAI_MappedActivityBehavior_Temporary, CAI_SimpleBehavior );
  57. public:
  58. CAI_MappedActivityBehavior_Temporary( CAI_BaseNPC *pOuter = NULL )
  59. : CAI_SimpleBehavior(pOuter)
  60. {
  61. SetDefLessFunc( m_ActivityMap );
  62. }
  63. protected:
  64. Activity GetMappedActivity( AI_Posture_t posture, Activity activity );
  65. void OnChangeActiveWeapon( CBaseCombatWeapon *pOldWeapon, CBaseCombatWeapon *pNewWeapon );
  66. virtual void UpdateTranslateActivityMap();
  67. private:
  68. CUtlMap<unsigned, Activity> m_ActivityMap;
  69. };
  70. class CAI_StandoffBehavior : public CAI_MappedActivityBehavior_Temporary
  71. {
  72. DECLARE_CLASS( CAI_StandoffBehavior, CAI_MappedActivityBehavior_Temporary );
  73. public:
  74. CAI_StandoffBehavior( CAI_BaseNPC *pOuter = NULL );
  75. virtual const char *GetName() { return "Standoff"; }
  76. void SetActive( bool fActive );
  77. void SetParameters( const AI_StandoffParams_t &params, CAI_GoalEntity *pGoalEntity = NULL );
  78. Vector GetStandoffGoalPosition();
  79. void SetStandoffGoalPosition( const Vector &vecPos );
  80. void ClearStandoffGoalPosition();
  81. AI_Posture_t GetPosture();
  82. bool IsActive( void ) { return m_fActive; }
  83. void OnChangeTacticalConstraints();
  84. bool CanSelectSchedule();
  85. bool IsBehindBattleLines( const Vector &point );
  86. protected:
  87. void Spawn();
  88. void BeginScheduleSelection();
  89. void EndScheduleSelection();
  90. void PrescheduleThink();
  91. void GatherConditions();
  92. int SelectSchedule();
  93. int TranslateSchedule( int scheduleType );
  94. void StartTask( const Task_t *pTask );
  95. void BuildScheduleTestBits();
  96. virtual void OnUpdateShotRegulator();
  97. Activity NPC_TranslateActivity( Activity eNewActivity );
  98. bool IsValidCover( const Vector &vecCoverLocation, CAI_Hint const *pHint );
  99. bool IsValidShootPosition( const Vector &vecCoverLocation, CAI_Node *pNode, CAI_Hint const *pHint );
  100. void SetPosture( AI_Posture_t posture );
  101. void OnChangeHintGroup( string_t oldGroup, string_t newGroup );
  102. virtual int SelectScheduleUpdateWeapon();
  103. virtual int SelectScheduleCheckCover();
  104. virtual int SelectScheduleEstablishAim();
  105. virtual int SelectScheduleAttack();
  106. bool PlayerIsLeading();
  107. CBaseEntity *GetPlayerLeader();
  108. bool GetDirectionOfStandoff( Vector *pDir );
  109. void UpdateBattleLines();
  110. Hint_e GetHintType();
  111. void SetReuseCurrentCover();
  112. void UnlockHintNode();
  113. Activity GetCoverActivity();
  114. void OnRestore();
  115. void UpdateTranslateActivityMap();
  116. // Standoff overrides base AI crouch handling
  117. bool IsCrouching( void ) { return false; }
  118. private:
  119. //----------------------------
  120. enum
  121. {
  122. NEXT_SCHEDULE = BaseClass::NEXT_SCHEDULE,
  123. NEXT_TASK = BaseClass::NEXT_TASK,
  124. COND_ABANDON_TIME_EXPIRED = BaseClass::NEXT_CONDITION,
  125. NEXT_CONDITION
  126. };
  127. DEFINE_CUSTOM_SCHEDULE_PROVIDER;
  128. //---------------------------------
  129. // @TODO (toml 07-30-03): replace all these booleans with a singe 32 bit unsigned & bit flags
  130. bool m_fActive;
  131. bool m_fTestNoDamage;
  132. Vector m_vecStandoffGoalPosition;
  133. AI_Posture_t m_posture;
  134. AI_StandoffParams_t m_params;
  135. EHANDLE m_hStandoffGoal;
  136. bool m_fTakeCover;
  137. float m_SavedDistTooFar;
  138. bool m_fForceNewEnemy;
  139. CAI_MoveMonitor m_PlayerMoveMonitor;
  140. CSimTimer m_TimeForceCoverHint;
  141. CSimTimer m_TimePreventForceNewEnemy;
  142. CRandSimTimer m_RandomCoverChangeTimer;
  143. // FIXME: TEMPORARY! REMOVE
  144. int m_nSavedMinShots, m_nSavedMaxShots;
  145. float m_flSavedMinRest, m_flSavedMaxRest;
  146. //---------------------------------
  147. struct BattleLine_t
  148. {
  149. Vector point;
  150. Vector normal;
  151. };
  152. CThinkOnceSemaphore m_UpdateBattleLinesSemaphore;
  153. CUtlVector<BattleLine_t> m_BattleLines;
  154. bool m_fIgnoreFronts;
  155. //---------------------------------
  156. bool m_bHasLowCoverActivity;
  157. //---------------------------------
  158. DECLARE_DATADESC();
  159. };
  160. //-------------------------------------
  161. inline void CAI_StandoffBehavior::SetPosture( AI_Posture_t posture )
  162. {
  163. m_posture = posture;
  164. }
  165. //-------------------------------------
  166. inline AI_Posture_t CAI_StandoffBehavior::GetPosture()
  167. {
  168. return m_posture;
  169. }
  170. //-----------------------------------------------------------------------------
  171. #endif // AI_BEHAVIOR_STANDOFF_H