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.

291 lines
9.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef NPC_BASEZOMBIE_H
  8. #define NPC_BASEZOMBIE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "ai_basenpc.h"
  13. #include "ai_blended_movement.h"
  14. #include "soundenvelope.h"
  15. #include "ai_behavior_actbusy.h"
  16. #define ZOM_ATTN_FOOTSTEP ATTN_IDLE
  17. #define ENVELOPE_CONTROLLER (CSoundEnvelopeController::GetController())
  18. #define ZOMBIE_MELEE_REACH 55
  19. extern int AE_ZOMBIE_ATTACK_RIGHT;
  20. extern int AE_ZOMBIE_ATTACK_LEFT;
  21. extern int AE_ZOMBIE_ATTACK_BOTH;
  22. extern int AE_ZOMBIE_SWATITEM;
  23. extern int AE_ZOMBIE_STARTSWAT;
  24. extern int AE_ZOMBIE_STEP_LEFT;
  25. extern int AE_ZOMBIE_STEP_RIGHT;
  26. extern int AE_ZOMBIE_SCUFF_LEFT;
  27. extern int AE_ZOMBIE_SCUFF_RIGHT;
  28. extern int AE_ZOMBIE_ATTACK_SCREAM;
  29. extern int AE_ZOMBIE_GET_UP;
  30. extern int AE_ZOMBIE_POUND;
  31. #define ZOMBIE_BODYGROUP_HEADCRAB 1 // The crab on our head
  32. // Pass these to claw attack so we know where to draw the blood.
  33. #define ZOMBIE_BLOOD_LEFT_HAND 0
  34. #define ZOMBIE_BLOOD_RIGHT_HAND 1
  35. #define ZOMBIE_BLOOD_BOTH_HANDS 2
  36. #define ZOMBIE_BLOOD_BITE 3
  37. enum HeadcrabRelease_t
  38. {
  39. RELEASE_NO,
  40. RELEASE_IMMEDIATE, // release the headcrab right now!
  41. RELEASE_SCHEDULED, // release the headcrab through the AI schedule.
  42. RELEASE_VAPORIZE, // just destroy the crab.
  43. RELEASE_RAGDOLL, // release a dead crab
  44. RELEASE_RAGDOLL_SLICED_OFF // toss the crab up a bit
  45. };
  46. //=========================================================
  47. // schedules
  48. //=========================================================
  49. enum
  50. {
  51. SCHED_ZOMBIE_CHASE_ENEMY = LAST_SHARED_SCHEDULE,
  52. SCHED_ZOMBIE_MOVE_SWATITEM,
  53. SCHED_ZOMBIE_SWATITEM,
  54. SCHED_ZOMBIE_ATTACKITEM,
  55. SCHED_ZOMBIE_RELEASECRAB,
  56. SCHED_ZOMBIE_MOVE_TO_AMBUSH,
  57. SCHED_ZOMBIE_WAIT_AMBUSH,
  58. SCHED_ZOMBIE_WANDER_MEDIUM, // medium range wandering behavior.
  59. SCHED_ZOMBIE_WANDER_FAIL,
  60. SCHED_ZOMBIE_WANDER_STANDOFF,
  61. SCHED_ZOMBIE_MELEE_ATTACK1,
  62. SCHED_ZOMBIE_POST_MELEE_WAIT,
  63. LAST_BASE_ZOMBIE_SCHEDULE,
  64. };
  65. //=========================================================
  66. // tasks
  67. //=========================================================
  68. enum
  69. {
  70. TASK_ZOMBIE_DELAY_SWAT = LAST_SHARED_TASK,
  71. TASK_ZOMBIE_GET_PATH_TO_PHYSOBJ,
  72. TASK_ZOMBIE_SWAT_ITEM,
  73. TASK_ZOMBIE_DIE,
  74. TASK_ZOMBIE_RELEASE_HEADCRAB,
  75. TASK_ZOMBIE_WAIT_POST_MELEE,
  76. LAST_BASE_ZOMBIE_TASK,
  77. };
  78. //=========================================================
  79. // Zombie conditions
  80. //=========================================================
  81. enum Zombie_Conds
  82. {
  83. COND_ZOMBIE_CAN_SWAT_ATTACK = LAST_SHARED_CONDITION,
  84. COND_ZOMBIE_RELEASECRAB,
  85. COND_ZOMBIE_LOCAL_MELEE_OBSTRUCTION,
  86. LAST_BASE_ZOMBIE_CONDITION,
  87. };
  88. typedef CAI_BlendingHost< CAI_BehaviorHost<CAI_BaseNPC> > CAI_BaseZombieBase;
  89. //=========================================================
  90. //=========================================================
  91. abstract_class CNPC_BaseZombie : public CAI_BaseZombieBase
  92. {
  93. DECLARE_CLASS( CNPC_BaseZombie, CAI_BaseZombieBase );
  94. public:
  95. CNPC_BaseZombie( void );
  96. ~CNPC_BaseZombie( void );
  97. void Spawn( void );
  98. void Precache( void );
  99. void StartTouch( CBaseEntity *pOther );
  100. bool CreateBehaviors();
  101. float MaxYawSpeed( void );
  102. bool OverrideMoveFacing( const AILocalMoveGoal_t &move, float flInterval );
  103. Class_T Classify( void );
  104. Disposition_t IRelationType( CBaseEntity *pTarget );
  105. void HandleAnimEvent( animevent_t *pEvent );
  106. void OnStateChange( NPC_STATE OldState, NPC_STATE NewState );
  107. void KillMe( void )
  108. {
  109. m_iHealth = 5;
  110. OnTakeDamage( CTakeDamageInfo( this, this, m_iHealth * 2, DMG_GENERIC ) );
  111. }
  112. int MeleeAttack1Conditions ( float flDot, float flDist );
  113. virtual float GetClawAttackRange() const { return ZOMBIE_MELEE_REACH; }
  114. // No range attacks
  115. int RangeAttack1Conditions ( float flDot, float flDist ) { return( 0 ); }
  116. virtual float GetHitgroupDamageMultiplier( int iHitGroup, const CTakeDamageInfo &info );
  117. void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  118. int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  119. virtual float GetReactionDelay( CBaseEntity *pEnemy ) { return 0.0; }
  120. virtual int SelectSchedule ( void );
  121. virtual int SelectFailSchedule( int failedSchedule, int failedTask, AI_TaskFailureCode_t taskFailCode );
  122. virtual void BuildScheduleTestBits( void );
  123. virtual int TranslateSchedule( int scheduleType );
  124. virtual Activity NPC_TranslateActivity( Activity baseAct );
  125. void StartTask( const Task_t *pTask );
  126. void RunTask( const Task_t *pTask );
  127. void GatherConditions( void );
  128. void PrescheduleThink( void );
  129. virtual void Event_Killed( const CTakeDamageInfo &info );
  130. virtual bool BecomeRagdoll( const CTakeDamageInfo &info, const Vector &forceVector );
  131. void StopLoopingSounds();
  132. virtual void OnScheduleChange( void );
  133. virtual void PoundSound();
  134. // Custom damage/death
  135. bool ShouldIgnite( const CTakeDamageInfo &info );
  136. bool ShouldIgniteZombieGib( void );
  137. virtual bool IsChopped( const CTakeDamageInfo &info );
  138. virtual bool IsSquashed( const CTakeDamageInfo &info ) { return false; }
  139. virtual void DieChopped( const CTakeDamageInfo &info );
  140. virtual void Ignite( float flFlameLifetime, bool bNPCOnly = true, float flSize = 0.0f, bool bCalledByLevelDesigner = false );
  141. void CopyRenderColorTo( CBaseEntity *pOther );
  142. virtual bool ShouldBecomeTorso( const CTakeDamageInfo &info, float flDamageThreshold );
  143. virtual HeadcrabRelease_t ShouldReleaseHeadcrab( const CTakeDamageInfo &info, float flDamageThreshold );
  144. // Headcrab releasing/breaking apart
  145. void RemoveHead( void );
  146. virtual void SetZombieModel( void ) { };
  147. virtual void BecomeTorso( const Vector &vecTorsoForce, const Vector &vecLegsForce );
  148. virtual bool CanBecomeLiveTorso() { return false; }
  149. virtual bool HeadcrabFits( CBaseAnimating *pCrab );
  150. void ReleaseHeadcrab( const Vector &vecOrigin, const Vector &vecVelocity, bool fRemoveHead, bool fRagdollBody, bool fRagdollCrab = false );
  151. void SetHeadcrabSpawnLocation( int iCrabAttachment, CBaseAnimating *pCrab );
  152. // Slumping/sleeping
  153. bool IsSlumped( void );
  154. bool IsGettingUp( void );
  155. // Swatting physics objects
  156. int GetSwatActivity( void );
  157. bool FindNearestPhysicsObject( int iMaxMass );
  158. float DistToPhysicsEnt( void );
  159. virtual bool CanSwatPhysicsObjects( void ) { return true; }
  160. // Returns whether we must be very near our enemy to attack them.
  161. virtual bool MustCloseToAttack(void) { return true; }
  162. virtual CBaseEntity *ClawAttack( float flDist, int iDamage, QAngle &qaViewPunch, Vector &vecVelocityPunch, int BloodOrigin );
  163. // Sounds & sound envelope
  164. virtual bool ShouldPlayFootstepMoan( void );
  165. virtual void PainSound( const CTakeDamageInfo &info ) = 0;
  166. virtual void AlertSound( void ) = 0;
  167. virtual void IdleSound( void ) = 0;
  168. virtual void AttackSound( void ) = 0;
  169. virtual void AttackHitSound( void ) = 0;
  170. virtual void AttackMissSound( void ) = 0;
  171. virtual void FootstepSound( bool fRightFoot ) = 0;
  172. virtual void FootscuffSound( bool fRightFoot ) = 0;
  173. // make a sound Alyx can hear when in darkness mode
  174. void MakeAISpookySound( float volume, float duration = 0.5 );
  175. virtual bool CanPlayMoanSound();
  176. virtual void MoanSound( envelopePoint_t *pEnvelope, int iEnvelopeSize );
  177. bool ShouldPlayIdleSound( void ) { return false; }
  178. virtual const char *GetMoanSound( int nSound ) = 0;
  179. virtual const char *GetHeadcrabClassname( void ) = 0;
  180. virtual const char *GetLegsModel( void ) = 0;
  181. virtual const char *GetTorsoModel( void ) = 0;
  182. virtual const char *GetHeadcrabModel( void ) = 0;
  183. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy );
  184. virtual Vector HeadTarget( const Vector &posSrc );
  185. virtual float GetAutoAimRadius();
  186. virtual void TranslateNavGoal( CBaseEntity *pEnemy, Vector &chasePosition );
  187. bool OnInsufficientStopDist( AILocalMoveGoal_t *pMoveGoal, float distClear, AIMoveResult_t *pResult );
  188. virtual bool AllowedToIgnite( void ) { return true; }
  189. public:
  190. CAI_ActBusyBehavior m_ActBusyBehavior;
  191. protected:
  192. CSoundPatch *m_pMoanSound;
  193. bool m_fIsTorso; // is this is a half-zombie?
  194. bool m_fIsHeadless; // is this zombie headless
  195. float m_flNextFlinch;
  196. bool m_bHeadShot; // Used to determine the survival of our crab beyond our death.
  197. //
  198. // Zombies catch on fire if they take too much burn damage in a given time period.
  199. //
  200. float m_flBurnDamage; // Keeps track of how much burn damage we've incurred in the last few seconds.
  201. float m_flBurnDamageResetTime; // Time at which we reset the burn damage.
  202. EHANDLE m_hPhysicsEnt;
  203. float m_flNextMoanSound;
  204. float m_flNextSwat;
  205. float m_flNextSwatScan;
  206. float m_crabHealth;
  207. float m_flMoanPitch;
  208. EHANDLE m_hObstructor;
  209. static int g_numZombies; // counts total number of existing zombies.
  210. int m_iMoanSound; // each zombie picks one of the 4 and keeps it.
  211. static int ACT_ZOM_SWATLEFTMID;
  212. static int ACT_ZOM_SWATRIGHTMID;
  213. static int ACT_ZOM_SWATLEFTLOW;
  214. static int ACT_ZOM_SWATRIGHTLOW;
  215. static int ACT_ZOM_RELEASECRAB;
  216. static int ACT_ZOM_FALL;
  217. DECLARE_DATADESC();
  218. DEFINE_CUSTOM_AI;
  219. private:
  220. bool m_bIsSlumped;
  221. };
  222. #endif // NPC_BASEZOMBIE_H