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.

296 lines
8.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines the headcrab, a tiny, jumpy alien parasite.
  4. //
  5. //=============================================================================//
  6. #ifndef NPC_HEADCRAB_H
  7. #define NPC_HEADCRAB_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "ai_squadslot.h"
  12. #include "ai_basenpc.h"
  13. #include "soundent.h"
  14. abstract_class CBaseHeadcrab : public CAI_BaseNPC
  15. {
  16. DECLARE_CLASS( CBaseHeadcrab, CAI_BaseNPC );
  17. public:
  18. void Spawn( void );
  19. void Precache( void );
  20. void RunTask( const Task_t *pTask );
  21. void StartTask( const Task_t *pTask );
  22. void OnChangeActivity( Activity NewActivity );
  23. bool IsFirmlyOnGround();
  24. void MoveOrigin( const Vector &vecDelta );
  25. void ThrowAt( const Vector &vecPos );
  26. void ThrowThink( void );
  27. virtual void JumpAttack( bool bRandomJump, const Vector &vecPos = vec3_origin, bool bThrown = false );
  28. void JumpToBurrowHint( CAI_Hint *pHint );
  29. bool HasHeadroom();
  30. void LeapTouch ( CBaseEntity *pOther );
  31. virtual void TouchDamage( CBaseEntity *pOther );
  32. bool CorpseGib( const CTakeDamageInfo &info );
  33. void Touch( CBaseEntity *pOther );
  34. Vector BodyTarget( const Vector &posSrc, bool bNoisy = true );
  35. float GetAutoAimRadius();
  36. void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  37. void Ignite( float flFlameLifetime, bool bNPCOnly = true, float flSize = 0.0f, bool bCalledByLevelDesigner = false );
  38. float MaxYawSpeed( void );
  39. void GatherConditions( void );
  40. void PrescheduleThink( void );
  41. Class_T Classify( void );
  42. void HandleAnimEvent( animevent_t *pEvent );
  43. int RangeAttack1Conditions ( float flDot, float flDist );
  44. int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  45. void ClampRagdollForce( const Vector &vecForceIn, Vector *vecForceOut );
  46. void Event_Killed( const CTakeDamageInfo &info );
  47. void BuildScheduleTestBits( void );
  48. bool FValidateHintType( CAI_Hint *pHint );
  49. bool IsJumping( void ) { return m_bMidJump; }
  50. virtual void BiteSound( void ) = 0;
  51. virtual void AttackSound( void ) {};
  52. virtual void ImpactSound( void ) {};
  53. virtual void TelegraphSound( void ) {};
  54. virtual int SelectSchedule( void );
  55. virtual int SelectFailSchedule( int failedSchedule, int failedTask, AI_TaskFailureCode_t taskFailCode );
  56. virtual int TranslateSchedule( int scheduleType );
  57. virtual float GetReactionDelay( CBaseEntity *pEnemy ) { return 0.0; }
  58. bool HandleInteraction(int interactionType, void *data, CBaseCombatCharacter* sourceEnt);
  59. void CrawlFromCanister();
  60. virtual bool AllowedToIgnite( void ) { return true; }
  61. virtual bool CanBeAnEnemyOf( CBaseEntity *pEnemy );
  62. bool IsHangingFromCeiling( void )
  63. {
  64. #ifdef HL2_EPISODIC
  65. return m_bHangingFromCeiling;
  66. #else
  67. return false;
  68. #endif
  69. }
  70. virtual void PlayerHasIlluminatedNPC( CBasePlayer *pPlayer, float flDot );
  71. void DropFromCeiling( void );
  72. DEFINE_CUSTOM_AI;
  73. DECLARE_DATADESC();
  74. protected:
  75. void HeadcrabInit();
  76. void Leap( const Vector &vecVel );
  77. void GrabHintNode( CAI_Hint *pHint );
  78. bool FindBurrow( const Vector &origin, float distance, bool excludeNear );
  79. bool ValidBurrowPoint( const Vector &point );
  80. void ClearBurrowPoint( const Vector &origin );
  81. void Burrow( void );
  82. void Unburrow( void );
  83. void SetBurrowed( bool bBurrowed );
  84. void JumpFromCanister();
  85. // Begins the climb from the canister
  86. void BeginClimbFromCanister();
  87. void InputBurrow( inputdata_t &inputdata );
  88. void InputBurrowImmediate( inputdata_t &inputdata );
  89. void InputUnburrow( inputdata_t &inputdata );
  90. void InputStartHangingFromCeiling( inputdata_t &inputdata );
  91. void InputDropFromCeiling( inputdata_t &inputdata );
  92. int CalcDamageInfo( CTakeDamageInfo *pInfo );
  93. void CreateDust( bool placeDecal = true );
  94. // Eliminates roll + pitch potentially in the headcrab at canister jump time
  95. void EliminateRollAndPitch();
  96. float InnateRange1MinRange( void );
  97. float InnateRange1MaxRange( void );
  98. protected:
  99. int m_nGibCount;
  100. float m_flTimeDrown;
  101. Vector m_vecCommittedJumpPos; // The position of our enemy when we locked in our jump attack.
  102. float m_flNextNPCThink;
  103. float m_flIgnoreWorldCollisionTime;
  104. bool m_bCommittedToJump; // Whether we have 'locked in' to jump at our enemy.
  105. bool m_bCrawlFromCanister;
  106. bool m_bStartBurrowed;
  107. bool m_bBurrowed;
  108. bool m_bHidden;
  109. bool m_bMidJump;
  110. bool m_bAttackFailed; // whether we ran into a wall during a jump.
  111. float m_flBurrowTime;
  112. int m_nContext; // for FValidateHintType context
  113. int m_nJumpFromCanisterDir;
  114. bool m_bHangingFromCeiling;
  115. float m_flIlluminatedTime;
  116. };
  117. //=========================================================
  118. //=========================================================
  119. // The ever popular chubby classic headcrab
  120. //=========================================================
  121. //=========================================================
  122. class CHeadcrab : public CBaseHeadcrab
  123. {
  124. DECLARE_CLASS( CHeadcrab, CBaseHeadcrab );
  125. public:
  126. void Precache( void );
  127. void Spawn( void );
  128. float MaxYawSpeed( void );
  129. Activity NPC_TranslateActivity( Activity eNewActivity );
  130. void BiteSound( void );
  131. void PainSound( const CTakeDamageInfo &info );
  132. void DeathSound( const CTakeDamageInfo &info );
  133. void IdleSound( void );
  134. void AlertSound( void );
  135. void AttackSound( void );
  136. void TelegraphSound( void );
  137. };
  138. //=========================================================
  139. //=========================================================
  140. // The spindly, fast headcrab
  141. //=========================================================
  142. //=========================================================
  143. class CFastHeadcrab : public CBaseHeadcrab
  144. {
  145. DECLARE_DATADESC();
  146. public:
  147. DECLARE_CLASS( CFastHeadcrab, CBaseHeadcrab );
  148. void Precache( void );
  149. void Spawn( void );
  150. bool QuerySeeEntity(CBaseEntity *pSightEnt, bool bOnlyHateOrFearIfNPC = false);
  151. float MaxYawSpeed( void );
  152. void PrescheduleThink( void );
  153. void RunTask( const Task_t *pTask );
  154. void StartTask( const Task_t *pTask );
  155. int SelectSchedule( void );
  156. int TranslateSchedule( int scheduleType );
  157. int m_iRunMode;
  158. float m_flRealGroundSpeed;
  159. float m_flSlowRunTime;
  160. float m_flPauseTime;
  161. Vector m_vecJumpVel;
  162. void BiteSound( void );
  163. void PainSound( const CTakeDamageInfo &info );
  164. void DeathSound( const CTakeDamageInfo &info );
  165. void IdleSound( void );
  166. void AlertSound( void );
  167. void AttackSound( void );
  168. enum SquadSlot_t
  169. {
  170. SQUAD_SLOT_ENGAGE1 = LAST_SHARED_SQUADSLOT,
  171. SQUAD_SLOT_ENGAGE2,
  172. SQUAD_SLOT_ENGAGE3,
  173. SQUAD_SLOT_ENGAGE4,
  174. };
  175. DEFINE_CUSTOM_AI;
  176. };
  177. //=========================================================
  178. //=========================================================
  179. // Treacherous black headcrab
  180. //=========================================================
  181. //=========================================================
  182. class CBlackHeadcrab : public CBaseHeadcrab
  183. {
  184. DECLARE_CLASS( CBlackHeadcrab, CBaseHeadcrab );
  185. public:
  186. void Eject( const QAngle &vecAngles, float flVelocityScale, CBaseEntity *pEnemy );
  187. void EjectTouch( CBaseEntity *pOther );
  188. //
  189. // CBaseHeadcrab implementation.
  190. //
  191. void TouchDamage( CBaseEntity *pOther );
  192. void BiteSound( void );
  193. void AttackSound( void );
  194. //
  195. // CAI_BaseNPC implementation.
  196. //
  197. virtual void PrescheduleThink( void );
  198. virtual void BuildScheduleTestBits( void );
  199. virtual int SelectSchedule( void );
  200. virtual int TranslateSchedule( int scheduleType );
  201. virtual Activity NPC_TranslateActivity( Activity eNewActivity );
  202. virtual void HandleAnimEvent( animevent_t *pEvent );
  203. virtual float MaxYawSpeed( void );
  204. virtual int GetSoundInterests( void ) { return (BaseClass::GetSoundInterests() | SOUND_DANGER | SOUND_BULLET_IMPACT); }
  205. bool IsHeavyDamage( const CTakeDamageInfo &info );
  206. virtual void PainSound( const CTakeDamageInfo &info );
  207. virtual void DeathSound( const CTakeDamageInfo &info );
  208. virtual void IdleSound( void );
  209. virtual void AlertSound( void );
  210. virtual void ImpactSound( void );
  211. virtual void TelegraphSound( void );
  212. #if HL2_EPISODIC
  213. virtual bool FInViewCone( CBaseEntity *pEntity );
  214. #endif
  215. //
  216. // CBaseEntity implementation.
  217. //
  218. virtual void Precache( void );
  219. virtual void Spawn( void );
  220. DEFINE_CUSTOM_AI;
  221. DECLARE_DATADESC();
  222. private:
  223. void JumpFlinch( const Vector *pvecAwayFromPos );
  224. void Panic( float flDuration );
  225. bool m_bPanicState;
  226. float m_flPanicStopTime;
  227. float m_flNextHopTime; // Keeps us from hopping too often due to damage.
  228. };
  229. #endif // NPC_HEADCRAB_H