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.

344 lines
11 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: This is the base version of the vortigaunt
  4. //
  5. //=============================================================================//
  6. #ifndef NPC_VORTIGAUNT_H
  7. #define NPC_VORTIGAUNT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "ai_basenpc.h"
  12. #include "ai_behavior.h"
  13. #include "ai_behavior_lead.h"
  14. #include "ai_behavior_standoff.h"
  15. #include "ai_behavior_assault.h"
  16. #include "npc_playercompanion.h"
  17. #define VORTIGAUNT_MAX_BEAMS 8
  18. #define VORTIGAUNT_BEAM_ALL -1
  19. #define VORTIGAUNT_BEAM_ZAP 0
  20. #define VORTIGAUNT_BEAM_HEAL 1
  21. #define VORTIGAUNT_BEAM_DISPEL 2
  22. class CBeam;
  23. class CSprite;
  24. class CVortigauntChargeToken;
  25. class CVortigauntEffectDispel;
  26. extern ConVar sk_vortigaunt_zap_range;
  27. enum VortigauntHealState_t
  28. {
  29. HEAL_STATE_NONE, // Not trying to heal
  30. HEAL_STATE_WARMUP, // In the "warm-up" phase of healing
  31. HEAL_STATE_HEALING, // In the process of healing
  32. HEAL_STATE_COOLDOWN, // in the "cooldown" phase of healing
  33. };
  34. //=========================================================
  35. // >> CNPC_Vortigaunt
  36. //=========================================================
  37. class CNPC_Vortigaunt : public CNPC_PlayerCompanion
  38. {
  39. DECLARE_CLASS( CNPC_Vortigaunt, CNPC_PlayerCompanion );
  40. public:
  41. CNPC_Vortigaunt( void );
  42. virtual void Spawn( void );
  43. virtual void Precache( void );
  44. virtual float MaxYawSpeed( void );
  45. virtual Vector FacingPosition( void );
  46. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy = true );
  47. virtual void PrescheduleThink( void );
  48. virtual void BuildScheduleTestBits( void );
  49. virtual void OnScheduleChange( void );
  50. virtual int RangeAttack1Conditions( float flDot, float flDist ); // Primary zap
  51. virtual int RangeAttack2Conditions( float flDot, float flDist ); // Concussive zap (larger)
  52. virtual bool InnateWeaponLOSCondition( const Vector &ownerPos, const Vector &targetPos, bool bSetConditions );
  53. virtual int MeleeAttack1Conditions( float flDot, float flDist ); // Dispel
  54. virtual float InnateRange1MinRange( void ) { return 0.0f; }
  55. virtual float InnateRange1MaxRange( void ) { return sk_vortigaunt_zap_range.GetFloat()*12; }
  56. virtual int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  57. virtual bool FInViewCone( CBaseEntity *pEntity );
  58. virtual bool ShouldMoveAndShoot( void );
  59. // vorts have a very long head/neck swing, so debounce heavily
  60. virtual float GetHeadDebounce( void ) { return 0.7; } // how much of previous head turn to use
  61. virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  62. virtual void AlertSound( void );
  63. virtual Class_T Classify ( void ) { return IsGameEndAlly() ? CLASS_PLAYER_ALLY_VITAL : CLASS_VORTIGAUNT; }
  64. virtual void HandleAnimEvent( animevent_t *pEvent );
  65. virtual Activity NPC_TranslateActivity( Activity eNewActivity );
  66. virtual void UpdateOnRemove( void );
  67. virtual void Event_Killed( const CTakeDamageInfo &info );
  68. virtual void GatherConditions( void );
  69. virtual void RunTask( const Task_t *pTask );
  70. virtual void StartTask( const Task_t *pTask );
  71. virtual void ClearSchedule( const char *szReason );
  72. virtual void DeclineFollowing( void );
  73. virtual bool CanBeUsedAsAFriend( void );
  74. virtual bool IsPlayerAlly( void ) { return true; }
  75. // Override these to set behavior
  76. virtual int TranslateSchedule( int scheduleType );
  77. virtual int SelectSchedule( void );
  78. virtual int SelectFailSchedule( int failedSchedule, int failedTask, AI_TaskFailureCode_t taskFailCode );
  79. virtual bool IsValidEnemy( CBaseEntity *pEnemy );
  80. bool IsLeading( void ) { return ( GetRunningBehavior() == &m_LeadBehavior && m_LeadBehavior.HasGoal() ); }
  81. void DeathSound( const CTakeDamageInfo &info );
  82. void PainSound( const CTakeDamageInfo &info );
  83. virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  84. virtual void SpeakSentence( int sentType );
  85. virtual int IRelationPriority( CBaseEntity *pTarget );
  86. virtual Disposition_t IRelationType( CBaseEntity *pTarget );
  87. virtual bool IsReadinessCapable( void ) { return true; }
  88. virtual float GetReadinessDecay() { return 30.0f; }
  89. virtual bool ShouldRegenerateHealth( void ) { return m_bRegenerateHealth; }
  90. virtual bool CanRunAScriptedNPCInteraction( bool bForced = false );
  91. virtual void AimGun( void );
  92. virtual void OnUpdateShotRegulator( void );
  93. void InputEnableArmorRecharge( inputdata_t &data );
  94. void InputDisableArmorRecharge( inputdata_t &data );
  95. void InputExtractBugbait( inputdata_t &data );
  96. void InputChargeTarget( inputdata_t &data );
  97. void InputDispel( inputdata_t &data );
  98. void InputBeginCarryNPC( inputdata_t &indputdata );
  99. void InputEndCarryNPC( inputdata_t &indputdata );
  100. // Health regeneration
  101. void InputEnableHealthRegeneration( inputdata_t &data );
  102. void InputDisableHealthRegeneration( inputdata_t &data );
  103. // color
  104. void InputTurnBlue( inputdata_t &data );
  105. void InputTurnBlack( inputdata_t &data );
  106. virtual void SetScriptedScheduleIgnoreConditions( Interruptability_t interrupt );
  107. virtual void OnRestore( void );
  108. virtual bool OverrideMoveFacing( const AILocalMoveGoal_t &move, float flInterval );
  109. virtual void OnStartScene( void );
  110. virtual bool IsInterruptable( void );
  111. virtual bool CanFlinch( void );
  112. // used so a grub can notify me that I stepped on it. Says a line.
  113. void OnSquishedGrub( const CBaseEntity *pGrub );
  114. private:
  115. int NumAntlionsInRadius( float flRadius );
  116. void DispelAntlions( const Vector &vecOrigin, float flRadius, bool bDispel = true );
  117. bool HealGestureHasLOS( void );
  118. bool PlayerBelowHealthPercentage( CBasePlayer *pPlayer, float flPerc );
  119. void StartHealing( void );
  120. void StopHealing( bool bInterrupt = false );
  121. void MaintainHealSchedule( void );
  122. bool ShouldHealTarget( CBaseEntity *pTarget );
  123. int SelectHealSchedule( void );
  124. void CreateBeamBlast( const Vector &vecOrigin );
  125. private:
  126. //=========================================================
  127. // Vortigaunt schedules
  128. //=========================================================
  129. enum
  130. {
  131. SCHED_VORTIGAUNT_STAND = BaseClass::NEXT_SCHEDULE,
  132. SCHED_VORTIGAUNT_RANGE_ATTACK,
  133. SCHED_VORTIGAUNT_HEAL,
  134. SCHED_VORTIGAUNT_EXTRACT_BUGBAIT,
  135. SCHED_VORTIGAUNT_FACE_PLAYER,
  136. SCHED_VORTIGAUNT_RUN_TO_PLAYER,
  137. SCHED_VORTIGAUNT_DISPEL_ANTLIONS,
  138. SCHED_VORT_FLEE_FROM_BEST_SOUND,
  139. SCHED_VORT_ALERT_FACE_BESTSOUND,
  140. };
  141. //=========================================================
  142. // Vortigaunt Tasks
  143. //=========================================================
  144. enum
  145. {
  146. TASK_VORTIGAUNT_HEAL_WARMUP = BaseClass::NEXT_TASK,
  147. TASK_VORTIGAUNT_HEAL,
  148. TASK_VORTIGAUNT_EXTRACT_WARMUP,
  149. TASK_VORTIGAUNT_EXTRACT,
  150. TASK_VORTIGAUNT_EXTRACT_COOLDOWN,
  151. TASK_VORTIGAUNT_FIRE_EXTRACT_OUTPUT,
  152. TASK_VORTIGAUNT_WAIT_FOR_PLAYER,
  153. TASK_VORTIGAUNT_GET_HEAL_TARGET,
  154. TASK_VORTIGAUNT_DISPEL_ANTLIONS
  155. };
  156. //=========================================================
  157. // Vortigaunt Conditions
  158. //=========================================================
  159. enum
  160. {
  161. COND_VORTIGAUNT_CAN_HEAL = BaseClass::NEXT_CONDITION,
  162. COND_VORTIGAUNT_HEAL_TARGET_TOO_FAR, // Outside or heal range
  163. COND_VORTIGAUNT_HEAL_TARGET_BLOCKED, // Blocked by an obstruction
  164. COND_VORTIGAUNT_HEAL_TARGET_BEHIND_US, // Not within our "forward" range
  165. COND_VORTIGAUNT_HEAL_VALID, // All conditions satisfied
  166. COND_VORTIGAUNT_DISPEL_ANTLIONS, // Repulse all antlions around us
  167. };
  168. // ------------
  169. // Beams
  170. // ------------
  171. inline bool InAttackSequence( void );
  172. void ClearBeams( void );
  173. void ArmBeam( int beamType, int nHand );
  174. void ZapBeam( int nHand );
  175. int m_nLightningSprite;
  176. // ---------------
  177. // Glow
  178. // ----------------
  179. void ClearHandGlow( void );
  180. float m_fGlowAge;
  181. float m_fGlowChangeTime;
  182. bool m_bGlowTurningOn;
  183. int m_nCurGlowIndex;
  184. CHandle<CVortigauntEffectDispel> m_hHandEffect[2];
  185. void StartHandGlow( int beamType, int nHand );
  186. void EndHandGlow( int beamType = VORTIGAUNT_BEAM_ALL );
  187. void MaintainGlows( void );
  188. // ----------------
  189. // Healing
  190. // ----------------
  191. bool m_bRegenerateHealth;
  192. float m_flNextHealTime; // Next time allowed to heal player
  193. EHANDLE m_hHealTarget; // The person that I'm going to heal.
  194. bool m_bPlayerRequestedHeal; // This adds some priority to our heal (allows it to happen in combat, etc)
  195. float m_flNextHealTokenTime;
  196. VortigauntHealState_t m_eHealState;
  197. CBaseEntity *FindHealTarget( void );
  198. bool HealBehaviorAvailable( void );
  199. void SetHealTarget( CBaseEntity *pTarget, bool bPlayerRequested );
  200. void GatherHealConditions( void );
  201. int m_nNumTokensToSpawn;
  202. float m_flHealHinderedTime;
  203. float m_flPainTime;
  204. float m_nextLineFireTime;
  205. bool m_bArmorRechargeEnabled;
  206. bool m_bForceArmorRecharge;
  207. float m_flDispelTestTime;
  208. bool m_bExtractingBugbait;
  209. bool IsCarryingNPC( void ) const { return m_bCarryingNPC; }
  210. bool m_bCarryingNPC;
  211. COutputEvent m_OnFinishedExtractingBugbait;
  212. COutputEvent m_OnFinishedChargingTarget;
  213. COutputEvent m_OnPlayerUse;
  214. //Adrian: Let's do it the right way!
  215. int m_iLeftHandAttachment;
  216. int m_iRightHandAttachment;
  217. bool m_bStopLoopingSounds;
  218. float m_flAimDelay; // Amount of time to suppress aiming
  219. // used for fading from green vort to blue vort
  220. CNetworkVar( bool, m_bIsBlue );
  221. CNetworkVar( float, m_flBlueEndFadeTime );
  222. // used for fading to black
  223. CNetworkVar( bool, m_bIsBlack );
  224. public:
  225. DECLARE_SERVERCLASS();
  226. DECLARE_DATADESC();
  227. DEFINE_CUSTOM_AI;
  228. };
  229. //=============================================================================
  230. //
  231. // Charge Token
  232. //
  233. //=============================================================================
  234. class CVortigauntChargeToken : public CBaseEntity
  235. {
  236. DECLARE_CLASS( CVortigauntChargeToken, CBaseEntity );
  237. public:
  238. static CVortigauntChargeToken *CreateChargeToken( const Vector &vecOrigin, CBaseEntity *pOwner, CBaseEntity *pTarget );
  239. CVortigauntChargeToken( void );
  240. virtual void Spawn( void );
  241. virtual void Precache( void );
  242. virtual unsigned int PhysicsSolidMaskForEntity( void ) const;
  243. void FadeAndDie( void );
  244. void SeekThink( void );
  245. void SeekTouch( CBaseEntity *pOther );
  246. void SetTargetEntity( CBaseEntity *pTarget ) { m_hTarget = pTarget; }
  247. private:
  248. Vector GetSteerVector( const Vector &vecForward );
  249. float m_flLifetime;
  250. EHANDLE m_hTarget;
  251. CNetworkVar( bool, m_bFadeOut );
  252. DECLARE_SERVERCLASS();
  253. DECLARE_DATADESC();
  254. };
  255. //=============================================================================
  256. //
  257. // Dispel Effect
  258. //
  259. //=============================================================================
  260. class CVortigauntEffectDispel : public CBaseEntity
  261. {
  262. DECLARE_CLASS( CVortigauntEffectDispel, CBaseEntity );
  263. public:
  264. static CVortigauntEffectDispel *CreateEffectDispel( const Vector &vecOrigin, CBaseEntity *pOwner, CBaseEntity *pTarget );
  265. CVortigauntEffectDispel( void );
  266. virtual void Spawn( void );
  267. void FadeAndDie( void );
  268. private:
  269. CNetworkVar( bool, m_bFadeOut );
  270. DECLARE_SERVERCLASS();
  271. DECLARE_DATADESC();
  272. };
  273. #endif // NPC_VORTIGAUNT_H