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.

418 lines
12 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef NPC_ANTLION_H
  8. #define NPC_ANTLION_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "ai_blended_movement.h"
  13. #include "soundent.h"
  14. #include "ai_behavior_follow.h"
  15. #include "ai_behavior_assault.h"
  16. class CAntlionTemplateMaker;
  17. #define ANTLION_FOLLOW_DISTANCE 350
  18. #define ANTLION_FOLLOW_DISTANCE_SQR (ANTLION_FOLLOW_DISTANCE*ANTLION_FOLLOW_DISTANCE)
  19. #define ANTLION_SKIN_COUNT 4
  20. class CNPC_Antlion;
  21. // Antlion follow behavior
  22. class CAI_AntlionFollowBehavior : public CAI_FollowBehavior
  23. {
  24. typedef CAI_FollowBehavior BaseClass;
  25. public:
  26. CAI_AntlionFollowBehavior()
  27. : BaseClass( AIF_ANTLION )
  28. {
  29. }
  30. bool FarFromFollowTarget( void )
  31. {
  32. return ( GetFollowTarget() && (GetAbsOrigin() - GetFollowTarget()->GetAbsOrigin()).LengthSqr() > ANTLION_FOLLOW_DISTANCE_SQR );
  33. }
  34. bool ShouldFollow( void )
  35. {
  36. if ( GetFollowTarget() == NULL )
  37. return false;
  38. if ( GetEnemy() != NULL )
  39. return false;
  40. return true;
  41. }
  42. };
  43. //
  44. // Antlion class
  45. //
  46. enum AntlionMoveState_e
  47. {
  48. ANTLION_MOVE_FREE,
  49. ANTLION_MOVE_FOLLOW,
  50. ANTLION_MOVE_FIGHT_TO_GOAL,
  51. };
  52. #define SF_ANTLION_BURROW_ON_ELUDED ( 1 << 16 )
  53. #define SF_ANTLION_USE_GROUNDCHECKS ( 1 << 17 )
  54. #define SF_ANTLION_WORKER ( 1 << 18 ) // Use the "worker" model
  55. typedef CAI_BlendingHost< CAI_BehaviorHost<CAI_BlendedNPC> > CAI_BaseAntlionBase;
  56. class CNPC_Antlion : public CAI_BaseAntlionBase
  57. {
  58. public:
  59. DECLARE_CLASS( CNPC_Antlion, CAI_BaseAntlionBase );
  60. CNPC_Antlion( void );
  61. virtual float InnateRange1MinRange( void ) { return 50*12; }
  62. virtual float InnateRange1MaxRange( void ) { return 250*12; }
  63. bool IsWorker( void ) const { return HasSpawnFlags( SF_ANTLION_WORKER ); } // NOTE: IsAntlionWorker function must agree!
  64. float GetIdealAccel( void ) const;
  65. float MaxYawSpeed( void );
  66. bool FInViewCone( CBaseEntity *pEntity );
  67. bool FInViewCone( const Vector &vecSpot );
  68. void Activate( void );
  69. void HandleAnimEvent( animevent_t *pEvent );
  70. void StartTask( const Task_t *pTask );
  71. void RunTask( const Task_t *pTask );
  72. void IdleSound( void );
  73. void PainSound( const CTakeDamageInfo &info );
  74. void Precache( void );
  75. void Spawn( void );
  76. int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  77. void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  78. void BuildScheduleTestBits( void );
  79. void GatherConditions( void );
  80. void PrescheduleThink( void );
  81. void ZapThink( void );
  82. void BurrowUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  83. bool CreateVPhysics();
  84. bool IsJumpLegal( const Vector &startPos, const Vector &apex, const Vector &endPos ) const;
  85. bool HandleInteraction( int interactionType, void *data, CBaseCombatCharacter *sender = NULL );
  86. bool QuerySeeEntity( CBaseEntity *pEntity, bool bOnlyHateOrFearIfNPC = false );
  87. bool ShouldPlayIdleSound( void );
  88. bool OverrideMoveFacing( const AILocalMoveGoal_t &move, float flInterval );
  89. bool IsValidEnemy(CBaseEntity *pEnemy);
  90. bool QueryHearSound( CSound *pSound );
  91. bool IsLightDamage( const CTakeDamageInfo &info );
  92. bool CreateBehaviors( void );
  93. bool ShouldHearBugbait( void ) { return ( m_bIgnoreBugbait == false ); }
  94. int SelectSchedule( void );
  95. void Touch( CBaseEntity *pOther );
  96. virtual int RangeAttack1Conditions( float flDot, float flDist );
  97. virtual int MeleeAttack1Conditions( float flDot, float flDist );
  98. virtual int MeleeAttack2Conditions( float flDot, float flDist );
  99. virtual int GetSoundInterests( void ) { return (BaseClass::GetSoundInterests())|(SOUND_DANGER|SOUND_PHYSICS_DANGER|SOUND_THUMPER|SOUND_BUGBAIT); }
  100. virtual bool IsHeavyDamage( const CTakeDamageInfo &info );
  101. Class_T Classify( void ) { return CLASS_ANTLION; }
  102. void Event_Killed( const CTakeDamageInfo &info );
  103. bool FValidateHintType ( CAI_Hint *pHint );
  104. void GatherEnemyConditions( CBaseEntity *pEnemy );
  105. bool IsAllied( void );
  106. bool ShouldGib( const CTakeDamageInfo &info );
  107. bool CorpseGib( const CTakeDamageInfo &info );
  108. float GetMaxJumpSpeed() const { return 1024.0f; }
  109. void SetFightTarget( CBaseEntity *pTarget );
  110. void InputFightToPosition( inputdata_t &inputdata );
  111. void InputStopFightToPosition( inputdata_t &inputdata );
  112. void InputJumpAtTarget( inputdata_t &inputdata );
  113. void SetFollowTarget( CBaseEntity *pTarget );
  114. int TranslateSchedule( int scheduleType );
  115. virtual Activity NPC_TranslateActivity( Activity baseAct );
  116. bool ShouldResumeFollow( void );
  117. bool ShouldAbandonFollow( void );
  118. void SetMoveState( AntlionMoveState_e state );
  119. int ChooseMoveSchedule( void );
  120. DECLARE_DATADESC();
  121. bool m_bStartBurrowed;
  122. float m_flNextJumpPushTime;
  123. void SetParentSpawnerName( const char *szName ) { m_strParentSpawner = MAKE_STRING( szName ); }
  124. const char *GetParentSpawnerName( void ) { return STRING( m_strParentSpawner ); }
  125. virtual void StopLoopingSounds( void );
  126. bool AllowedToBePushed( void );
  127. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy = true );
  128. virtual float GetAutoAimRadius() { return 36.0f; }
  129. void ClearBurrowPoint( const Vector &origin );
  130. void Flip( bool bZapped = false );
  131. bool CanBecomeRagdoll();
  132. virtual void NotifyDeadFriend( CBaseEntity *pFriend );
  133. private:
  134. inline CBaseEntity *EntityToWatch( void );
  135. void UpdateHead( void );
  136. bool FindChasePosition( const Vector &targetPos, Vector &result );
  137. bool GetGroundPosition( const Vector &testPos, Vector &result );
  138. bool GetPathToSoundFleePoint( int soundType );
  139. inline bool IsFlipped( void );
  140. void Burrow( void );
  141. void Unburrow( void );
  142. void InputUnburrow( inputdata_t &inputdata );
  143. void InputBurrow( inputdata_t &inputdata );
  144. void InputBurrowAway( inputdata_t &inputdata );
  145. void InputDisableJump( inputdata_t &inputdata );
  146. void InputEnableJump( inputdata_t &inputdata );
  147. void InputIgnoreBugbait( inputdata_t &inputdata );
  148. void InputHearBugbait( inputdata_t &inputdata );
  149. bool FindBurrow( const Vector &origin, float distance, int type, bool excludeNear = true );
  150. void CreateDust( bool placeDecal = true );
  151. bool ValidBurrowPoint( const Vector &point );
  152. bool CheckLanding( void );
  153. bool Alone( void );
  154. bool CheckAlertRadius( void );
  155. bool ShouldJump( void );
  156. void MeleeAttack( float distance, float damage, QAngle& viewPunch, Vector& shove );
  157. void SetWings( bool state );
  158. void StartJump( void );
  159. void LockJumpNode( void );
  160. bool IsUnusableNode(int iNodeID, CAI_Hint *pHint);
  161. bool OnObstructionPreSteer( AILocalMoveGoal_t *pMoveGoal, float distClear, AIMoveResult_t *pResult );
  162. void ManageFleeCapabilities( bool bEnable );
  163. int SelectFailSchedule( int failedSchedule, int failedTask, AI_TaskFailureCode_t taskFailCode );
  164. bool IsFirmlyOnGround( void );
  165. void CascadePush( const Vector &vecForce );
  166. virtual bool CanRunAScriptedNPCInteraction( bool bForced = false );
  167. virtual void Ignite ( float flFlameLifetime, bool bNPCOnly, float flSize, bool bCalledByLevelDesigner );
  168. virtual bool GetSpitVector( const Vector &vecStartPos, const Vector &vecTarget, Vector *vecOut );
  169. virtual bool InnateWeaponLOSCondition( const Vector &ownerPos, const Vector &targetPos, bool bSetConditions );
  170. virtual bool FCanCheckAttacks( void );
  171. bool SeenEnemyWithinTime( float flTime );
  172. void DelaySquadAttack( float flDuration );
  173. #if HL2_EPISODIC
  174. void DoPoisonBurst();
  175. #endif
  176. float m_flIdleDelay;
  177. float m_flBurrowTime;
  178. float m_flJumpTime;
  179. float m_flAlertRadius;
  180. float m_flPounceTime;
  181. int m_iUnBurrowAttempts;
  182. int m_iContext; //for FValidateHintType context
  183. Vector m_vecSaveSpitVelocity; // Saved when we start to attack and used if we failed to get a clear shot once we release
  184. CAI_AntlionFollowBehavior m_FollowBehavior;
  185. CAI_AssaultBehavior m_AssaultBehavior;
  186. AntlionMoveState_e m_MoveState;
  187. COutputEvent m_OnReachFightGoal; //Reached our scripted destination to fight to
  188. COutputEvent m_OnUnBurrowed; //Unburrowed
  189. Vector m_vecSavedJump;
  190. Vector m_vecLastJumpAttempt;
  191. float m_flIgnoreSoundTime; // Sound time to ignore if earlier than
  192. float m_flNextAcknowledgeTime; // Next time an antlion can make an acknowledgement noise
  193. float m_flSuppressFollowTime; // Amount of time to suppress our follow time
  194. float m_flObeyFollowTime; // A range of time the antlions must be obedient
  195. Vector m_vecHeardSound;
  196. bool m_bHasHeardSound;
  197. bool m_bAgitatedSound; //Playing agitated sound?
  198. bool m_bWingsOpen; //Are the wings open?
  199. bool m_bIgnoreBugbait; //If the antlion should ignore bugbait sounds
  200. string_t m_strParentSpawner; //Name of our spawner
  201. EHANDLE m_hFollowTarget;
  202. EHANDLE m_hFightGoalTarget;
  203. float m_flEludeDistance; //Distance until the antlion will consider himself "eluded" if so flagged
  204. bool m_bLeapAttack;
  205. bool m_bDisableJump;
  206. float m_flTimeDrown;
  207. float m_flTimeDrownSplash;
  208. bool m_bDontExplode; // Suppresses worker poison burst when drowning, failing to unburrow, etc.
  209. bool m_bLoopingStarted;
  210. bool m_bSuppressUnburrowEffects; // Don't kick up dust when spawning
  211. #if HL2_EPISODIC
  212. bool m_bHasDoneAirAttack; ///< only allowed to apply this damage once per glide
  213. #endif
  214. bool m_bForcedStuckJump;
  215. int m_nBodyBone;
  216. // Used to trigger a heavy damage interrupt if sustained damage is taken
  217. int m_nSustainedDamage;
  218. float m_flLastDamageTime;
  219. float m_flZapDuration;
  220. protected:
  221. int m_poseHead_Yaw, m_poseHead_Pitch;
  222. virtual void PopulatePoseParameters( void );
  223. private:
  224. HSOUNDSCRIPTHANDLE m_hFootstep;
  225. DEFINE_CUSTOM_AI;
  226. //==================================================
  227. // AntlionConditions
  228. //==================================================
  229. enum
  230. {
  231. COND_ANTLION_FLIPPED = LAST_SHARED_CONDITION,
  232. COND_ANTLION_ON_NPC,
  233. COND_ANTLION_CAN_JUMP,
  234. COND_ANTLION_FOLLOW_TARGET_TOO_FAR,
  235. COND_ANTLION_RECEIVED_ORDERS,
  236. COND_ANTLION_IN_WATER,
  237. COND_ANTLION_CAN_JUMP_AT_TARGET,
  238. COND_ANTLION_SQUADMATE_KILLED
  239. };
  240. //==================================================
  241. // AntlionSchedules
  242. //==================================================
  243. enum
  244. {
  245. SCHED_ANTLION_CHASE_ENEMY_BURROW = LAST_SHARED_SCHEDULE,
  246. SCHED_ANTLION_JUMP,
  247. SCHED_ANTLION_RUN_TO_BURROW_IN,
  248. SCHED_ANTLION_BURROW_IN,
  249. SCHED_ANTLION_BURROW_WAIT,
  250. SCHED_ANTLION_BURROW_OUT,
  251. SCHED_ANTLION_WAIT_FOR_UNBORROW_TRIGGER,
  252. SCHED_ANTLION_WAIT_FOR_CLEAR_UNBORROW,
  253. SCHED_ANTLION_WAIT_UNBORROW,
  254. SCHED_ANTLION_FLEE_THUMPER,
  255. SCHED_ANTLION_CHASE_BUGBAIT,
  256. SCHED_ANTLION_FLIP,
  257. SCHED_ANTLION_DISMOUNT_NPC,
  258. SCHED_ANTLION_RUN_TO_FIGHT_GOAL,
  259. SCHED_ANTLION_RUN_TO_FOLLOW_GOAL,
  260. SCHED_ANTLION_BUGBAIT_IDLE_STAND,
  261. SCHED_ANTLION_BURROW_AWAY,
  262. SCHED_ANTLION_FLEE_PHYSICS_DANGER,
  263. SCHED_ANTLION_POUNCE,
  264. SCHED_ANTLION_POUNCE_MOVING,
  265. SCHED_ANTLION_DROWN,
  266. SCHED_ANTLION_WORKER_RANGE_ATTACK1,
  267. SCHED_ANTLION_WORKER_RUN_RANDOM,
  268. SCHED_ANTLION_TAKE_COVER_FROM_ENEMY,
  269. SCHED_ANTLION_ZAP_FLIP,
  270. SCHED_ANTLION_WORKER_FLANK_RANDOM,
  271. SCHED_ANTLION_TAKE_COVER_FROM_SAVEPOSITION
  272. };
  273. //==================================================
  274. // AntlionTasks
  275. //==================================================
  276. enum
  277. {
  278. TASK_ANTLION_SET_CHARGE_GOAL = LAST_SHARED_TASK,
  279. TASK_ANTLION_FIND_BURROW_IN_POINT,
  280. TASK_ANTLION_FIND_BURROW_OUT_POINT,
  281. TASK_ANTLION_BURROW,
  282. TASK_ANTLION_UNBURROW,
  283. TASK_ANTLION_VANISH,
  284. TASK_ANTLION_BURROW_WAIT,
  285. TASK_ANTLION_CHECK_FOR_UNBORROW,
  286. TASK_ANTLION_JUMP,
  287. TASK_ANTLION_WAIT_FOR_TRIGGER,
  288. TASK_ANTLION_GET_THUMPER_ESCAPE_PATH,
  289. TASK_ANTLION_GET_PATH_TO_BUGBAIT,
  290. TASK_ANTLION_FACE_BUGBAIT,
  291. TASK_ANTLION_DISMOUNT_NPC,
  292. TASK_ANTLION_REACH_FIGHT_GOAL,
  293. TASK_ANTLION_GET_PHYSICS_DANGER_ESCAPE_PATH,
  294. TASK_ANTLION_FACE_JUMP,
  295. TASK_ANTLION_DROWN,
  296. TASK_ANTLION_GET_PATH_TO_RANDOM_NODE,
  297. TASK_ANTLION_FIND_COVER_FROM_SAVEPOSITION,
  298. };
  299. };
  300. //-----------------------------------------------------------------------------
  301. // Purpose: Shield
  302. //-----------------------------------------------------------------------------
  303. class CAntlionRepellant : public CPointEntity
  304. {
  305. DECLARE_DATADESC();
  306. public:
  307. DECLARE_CLASS( CAntlionRepellant, CPointEntity );
  308. ~CAntlionRepellant();
  309. public:
  310. void Spawn( void );
  311. void InputEnable( inputdata_t &inputdata );
  312. void InputDisable( inputdata_t &inputdata );
  313. float GetRadius( void );
  314. void SetRadius( float flRadius ) { m_flRepelRadius = flRadius; }
  315. static bool IsPositionRepellantFree( Vector vDesiredPos );
  316. void OnRestore( void );
  317. private:
  318. float m_flRepelRadius;
  319. bool m_bEnabled;
  320. };
  321. extern bool IsAntlion( CBaseEntity *pEntity );
  322. extern bool IsAntlionWorker( CBaseEntity *pEntity );
  323. #ifdef HL2_EPISODIC
  324. extern float AntlionWorkerBurstRadius( void );
  325. #endif // HL2_EPISODIC
  326. #endif // NPC_ANTLION_H