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.

280 lines
8.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef NPC_MANHACK_H
  7. #define NPC_MANHACK_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "ai_basenpc_physicsflyer.h"
  12. #include "Sprite.h"
  13. #include "SpriteTrail.h"
  14. #include "player_pickup.h"
  15. // Start with the engine off and folded up.
  16. #define SF_MANHACK_PACKED_UP (1 << 16)
  17. #define SF_MANHACK_NO_DAMAGE_EFFECTS (1 << 17)
  18. #define SF_MANHACK_USE_AIR_NODES (1 << 18)
  19. #define SF_MANHACK_CARRIED (1 << 19) // Being carried by a metrocop
  20. #define SF_MANHACK_NO_DANGER_SOUNDS (1 << 20)
  21. enum
  22. {
  23. MANHACK_EYE_STATE_IDLE,
  24. MANHACK_EYE_STATE_CHASE,
  25. MANHACK_EYE_STATE_CHARGE,
  26. MANHACK_EYE_STATE_STUNNED,
  27. };
  28. //-----------------------------------------------------------------------------
  29. // Attachment points.
  30. //-----------------------------------------------------------------------------
  31. #define MANHACK_GIB_HEALTH 30
  32. #define MANHACK_INACTIVE_HEALTH 25
  33. #define MANHACK_MAX_SPEED 500
  34. #define MANHACK_BURST_SPEED 650
  35. #define MANHACK_NPC_BURST_SPEED 800
  36. //-----------------------------------------------------------------------------
  37. // Movement parameters.
  38. //-----------------------------------------------------------------------------
  39. #define MANHACK_WAYPOINT_DISTANCE 25 // Distance from waypoint that counts as arrival.
  40. class CSprite;
  41. class SmokeTrail;
  42. class CSoundPatch;
  43. //-----------------------------------------------------------------------------
  44. // Manhack
  45. //-----------------------------------------------------------------------------
  46. class CNPC_Manhack : public CNPCBaseInteractive<CAI_BasePhysicsFlyingBot>, public CDefaultPlayerPickupVPhysics
  47. {
  48. DECLARE_CLASS( CNPC_Manhack, CNPCBaseInteractive<CAI_BasePhysicsFlyingBot> );
  49. DECLARE_SERVERCLASS();
  50. public:
  51. CNPC_Manhack();
  52. ~CNPC_Manhack();
  53. Class_T Classify(void);
  54. bool CorpseGib( const CTakeDamageInfo &info );
  55. void Event_Dying(void);
  56. void Event_Killed( const CTakeDamageInfo &info );
  57. int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  58. int OnTakeDamage_Dying( const CTakeDamageInfo &info );
  59. void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  60. void TranslateNavGoal( CBaseEntity *pEnemy, Vector &chasePosition );
  61. float GetDefaultNavGoalTolerance();
  62. void UpdateOnRemove( void );
  63. void KillSprites( float flDelay );
  64. void OnStateChange( NPC_STATE OldState, NPC_STATE NewState );
  65. virtual bool CreateVPhysics( void );
  66. virtual void DeathSound( const CTakeDamageInfo &info );
  67. virtual bool ShouldGib( const CTakeDamageInfo &info );
  68. Activity NPC_TranslateActivity( Activity baseAct );
  69. virtual int TranslateSchedule( int scheduleType );
  70. int MeleeAttack1Conditions ( float flDot, float flDist );
  71. void HandleAnimEvent( animevent_t *pEvent );
  72. bool OverrideMove(float flInterval);
  73. void MoveToTarget(float flInterval, const Vector &MoveTarget);
  74. void MoveExecute_Alive(float flInterval);
  75. void MoveExecute_Dead(float flInterval);
  76. int MoveCollisionMask(void);
  77. void TurnHeadRandomly( float flInterval );
  78. void CrashTouch( CBaseEntity *pOther );
  79. void StartEngine( bool fStartSound );
  80. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy = true ) { return WorldSpaceCenter(); }
  81. virtual float GetHeadTurnRate( void ) { return 45.0f; } // Degrees per second
  82. void CheckCollisions(float flInterval);
  83. virtual void GatherEnemyConditions( CBaseEntity *pEnemy );
  84. void PlayFlySound(void);
  85. virtual void StopLoopingSounds(void);
  86. void Precache(void);
  87. void RunTask( const Task_t *pTask );
  88. void Spawn(void);
  89. void Activate();
  90. void StartTask( const Task_t *pTask );
  91. void BladesInit();
  92. void SoundInit( void );
  93. void StartEye( void );
  94. bool HandleInteraction(int interactionType, void* data, CBaseCombatCharacter* sourceEnt);
  95. void PostNPCInit( void );
  96. void GatherConditions();
  97. void PrescheduleThink( void );
  98. void SpinBlades(float flInterval);
  99. void Slice( CBaseEntity *pHitEntity, float flInterval, trace_t &tr );
  100. void Bump( CBaseEntity *pHitEntity, float flInterval, trace_t &tr );
  101. void Splash( const Vector &vecSplashPos );
  102. float ManhackMaxSpeed( void );
  103. virtual void VPhysicsShadowCollision( int index, gamevcollisionevent_t *pEvent );
  104. void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  105. void HitPhysicsObject( CBaseEntity *pOther );
  106. virtual void ClampMotorForces( Vector &linear, AngularImpulse &angular );
  107. unsigned int PhysicsSolidMaskForEntity( void ) const;
  108. // Create smoke trail!
  109. void CreateSmokeTrail();
  110. void DestroySmokeTrail();
  111. void Ignite( float flFlameLifetime, bool bNPCOnly, float flSize, bool bCalledByLevelDesigner ) { return; }
  112. void InputDisableSwarm( inputdata_t &inputdata );
  113. void InputUnpack( inputdata_t &inputdata );
  114. // CDefaultPlayerPickupVPhysics
  115. virtual void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  116. virtual void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t Reason );
  117. CBasePlayer *HasPhysicsAttacker( float dt );
  118. float GetMaxEnginePower();
  119. // INPCInteractive Functions
  120. virtual bool CanInteractWith( CAI_BaseNPC *pUser ) { return false; } // Disabled for now (sjb)
  121. virtual bool HasBeenInteractedWith() { return m_bHackedByAlyx; }
  122. virtual void NotifyInteraction( CAI_BaseNPC *pUser )
  123. {
  124. // Turn the sprites off and on again so their colors will change.
  125. KillSprites(0.0f);
  126. m_bHackedByAlyx = true;
  127. StartEye();
  128. }
  129. virtual void InputPowerdown( inputdata_t &inputdata )
  130. {
  131. m_iHealth = 0;
  132. }
  133. DEFINE_CUSTOM_AI;
  134. DECLARE_DATADESC();
  135. private:
  136. bool IsInEffectiveTargetZone( CBaseEntity *pTarget );
  137. void MaintainGroundHeight( void );
  138. void StartBurst( const Vector &vecDirection );
  139. void StopBurst( bool bInterruptSchedule = false );
  140. void UpdatePanels( void );
  141. void SetEyeState( int state );
  142. void ShowHostile( bool hostile = true );
  143. bool IsFlyingActivity( Activity baseAct );
  144. // Computes the slice bounce velocity
  145. void ComputeSliceBounceVelocity( CBaseEntity *pHitEntity, trace_t &tr );
  146. // Take damage from being thrown by a physcannon
  147. void TakeDamageFromPhyscannon( CBasePlayer *pPlayer );
  148. // Take damage from a vehicle:
  149. void TakeDamageFromVehicle( int index, gamevcollisionevent_t *pEvent );
  150. // Take damage from physics impacts
  151. void TakeDamageFromPhysicsImpact( int index, gamevcollisionevent_t *pEvent );
  152. // Are we being held by the physcannon?
  153. bool IsHeldByPhyscannon( );
  154. void StartLoitering( const Vector &vecLoiterPosition );
  155. void StopLoitering() { m_vecLoiterPosition = vec3_invalid; m_fTimeNextLoiterPulse = gpGlobals->curtime; }
  156. bool IsLoitering() { return m_vecLoiterPosition != vec3_invalid; }
  157. void Loiter();
  158. //
  159. // Movement variables.
  160. //
  161. Vector m_vForceVelocity; // Someone forced me to move
  162. Vector m_vTargetBanking;
  163. Vector m_vForceMoveTarget; // Will fly here
  164. float m_fForceMoveTime; // If time is less than this
  165. Vector m_vSwarmMoveTarget; // Will fly here
  166. float m_fSwarmMoveTime; // If time is less than this
  167. float m_fEnginePowerScale; // scale all thrust by this amount (usually 1.0!)
  168. float m_flNextEngineSoundTime;
  169. float m_flEngineStallTime;
  170. float m_flNextBurstTime;
  171. float m_flBurstDuration;
  172. Vector m_vecBurstDirection;
  173. float m_flWaterSuspendTime;
  174. int m_nLastSpinSound;
  175. // physics influence
  176. CHandle<CBasePlayer> m_hPhysicsAttacker;
  177. float m_flLastPhysicsInfluenceTime;
  178. // Death
  179. float m_fSparkTime;
  180. float m_fSmokeTime;
  181. bool m_bDirtyPitch; // indicates whether we want the sound pitch updated.(sjb)
  182. bool m_bShowingHostile;
  183. bool m_bBladesActive;
  184. bool m_bIgnoreClipbrushes;
  185. float m_flBladeSpeed;
  186. CSprite *m_pEyeGlow;
  187. CSprite *m_pLightGlow;
  188. CHandle<SmokeTrail> m_hSmokeTrail;
  189. int m_iPanel1;
  190. int m_iPanel2;
  191. int m_iPanel3;
  192. int m_iPanel4;
  193. int m_nLastWaterLevel;
  194. bool m_bDoSwarmBehavior;
  195. bool m_bGib;
  196. bool m_bHeld;
  197. bool m_bHackedByAlyx;
  198. Vector m_vecLoiterPosition;
  199. float m_fTimeNextLoiterPulse;
  200. float m_flBumpSuppressTime;
  201. CNetworkVar( int, m_nEnginePitch1 );
  202. CNetworkVar( int, m_nEnginePitch2 );
  203. CNetworkVar( float, m_flEnginePitch1Time );
  204. CNetworkVar( float, m_flEnginePitch2Time );
  205. };
  206. #endif //NPC_MANHACK_H