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.

294 lines
8.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Base class for helicopters & helicopter-type vehicles
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CBASEHELICOPTER_H
  8. #define CBASEHELICOPTER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "ai_basenpc.h"
  13. #include "ai_trackpather.h"
  14. //---------------------------------------------------------
  15. // Helicopter flags
  16. //---------------------------------------------------------
  17. enum HelicopterFlags_t
  18. {
  19. BITS_HELICOPTER_GUN_ON = 0x00000001, // Gun is on and aiming
  20. BITS_HELICOPTER_MISSILE_ON = 0x00000002, // Missile turrets are on and aiming
  21. };
  22. //---------------------------------------------------------
  23. //---------------------------------------------------------
  24. #define SF_NOWRECKAGE 0x08
  25. #define SF_NOROTORWASH 0x20
  26. #define SF_AWAITINPUT 0x40
  27. //---------------------------------------------------------
  28. //---------------------------------------------------------
  29. // Pathing data
  30. #define BASECHOPPER_LEAD_DISTANCE 800.0f
  31. #define BASECHOPPER_MIN_CHASE_DIST_DIFF 128.0f // Distance threshold used to determine when a target has moved enough to update our navigation to it
  32. #define BASECHOPPER_AVOID_DIST 256.0f
  33. #define BASECHOPPER_MAX_SPEED 400.0f
  34. #define BASECHOPPER_MAX_FIRING_SPEED 250.0f
  35. #define BASECHOPPER_MIN_ROCKET_DIST 1000.0f
  36. #define BASECHOPPER_MAX_GUN_DIST 2000.0f
  37. //---------------------------------------------------------
  38. // Physics rotor pushing
  39. #define BASECHOPPER_WASH_RADIUS 256
  40. #define BASECHOPPER_WASH_PUSH_MIN 30 // Initial force * their mass applied to objects in the wash
  41. #define BASECHOPPER_WASH_PUSH_MAX 40 // Maximum force * their mass applied to objects in the wash
  42. #define BASECHOPPER_WASH_RAMP_TIME 1.0 // Time it takes to ramp from the initial to the max force on an object in the wash (at the center of the wash)
  43. #define BASECHOPPER_WASH_MAX_MASS 300 // Don't attempt to push anything over this mass
  44. #define BASECHOPPER_WASH_MAX_OBJECTS 6 // Maximum number of objects the wash will push at once
  45. // Wash physics pushing
  46. struct washentity_t
  47. {
  48. DECLARE_DATADESC();
  49. EHANDLE hEntity;
  50. float flWashStartTime;
  51. };
  52. #define BASECHOPPER_WASH_ALTITUDE 1024.0f
  53. //=========================================================
  54. //=========================================================
  55. class CBaseHelicopter : public CAI_TrackPather
  56. {
  57. public:
  58. DECLARE_CLASS( CBaseHelicopter, CAI_TrackPather );
  59. DECLARE_DATADESC();
  60. DECLARE_SERVERCLASS();
  61. CBaseHelicopter( void );
  62. void Spawn( void );
  63. void Precache( void );
  64. virtual void UpdateOnRemove();
  65. void Event_Killed( const CTakeDamageInfo &info );
  66. void StopLoopingSounds();
  67. int BloodColor( void ) { return DONT_BLEED; }
  68. void GibMonster( void );
  69. Class_T Classify ( void ) { return CLASS_COMBINE; }
  70. void CallDyingThink( void ) { DyingThink(); }
  71. bool HasEnemy( void ) { return GetEnemy() != NULL; }
  72. virtual void GatherEnemyConditions( CBaseEntity *pEnemy );
  73. virtual bool ChooseEnemy( void );
  74. virtual void HelicopterPostThink( void ) { };
  75. virtual void FlyTouch( CBaseEntity *pOther );
  76. virtual void CrashTouch( CBaseEntity *pOther );
  77. virtual void HelicopterThink( void );
  78. virtual void DyingThink( void );
  79. virtual void NullThink( void );
  80. virtual void Startup ( void );
  81. virtual void Flight( void );
  82. virtual void ShowDamage( void ) {};
  83. void UpdatePlayerDopplerShift( void );
  84. virtual void Hunt( void );
  85. virtual bool IsCrashing( void ) { return m_lifeState != LIFE_ALIVE; }
  86. virtual float GetAcceleration( void ) { return 5; }
  87. virtual void ApplySidewaysDrag( const Vector &vecRight );
  88. virtual void ApplyGeneralDrag( void );
  89. void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  90. virtual bool FireGun( void );
  91. virtual float GetRotorVolume( void );
  92. virtual void InitializeRotorSound( void );
  93. virtual void UpdateRotorSoundPitch( int iPitch );
  94. virtual void AimRocketGun(void) {};
  95. virtual void FireRocket( Vector vLaunchPos, Vector vLaunchDir ) {};
  96. virtual bool GetTrackPatherTarget( Vector *pPos );
  97. virtual CBaseEntity *GetTrackPatherTargetEnt();
  98. void DrawDebugGeometryOverlays(void);
  99. // Rotor washes
  100. virtual void DrawRotorWash( float flAltitude, const Vector &vecRotorOrigin );
  101. void DoRotorPhysicsPush( const Vector &vecRotorOrigin, float flAltitude );
  102. bool DoWashPush( washentity_t *pWash, const Vector &vecWashOrigin );
  103. void StopRotorWash( void );
  104. // Purpose: Marks the entity for deletion
  105. void InputKill( inputdata_t &inputdata );
  106. void DelayedKillThink( );
  107. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  108. // Helicopters never burn
  109. virtual void Ignite( float flFlameLifetime, bool bNPCOnly, float flSize, bool bCalledByLevelDesigner ) { return; }
  110. protected:
  111. void HelicopterMove( );
  112. // Updates the enemy
  113. void UpdateEnemy();
  114. // Override the desired position if your derived helicopter is doing something special
  115. virtual void UpdateDesiredPosition( void );
  116. // Updates the facing direction
  117. virtual void UpdateFacingDirection();
  118. // Fire weapons
  119. void FireWeapons();
  120. // Computes the actual position to fly to
  121. void ComputeActualTargetPosition( float flSpeed, float flTime, float flPerpDist, Vector *pDest, bool bApplyNoise = true );
  122. // Gets the max speed of the helicopter
  123. virtual float GetMaxSpeed();
  124. virtual float GetMaxSpeedFiring();
  125. // Updates the enemy
  126. virtual float EnemySearchDistance( );
  127. // Rotor wash think
  128. void RotorWashThink( void );
  129. // Purpose: Push an airboat in our wash
  130. void DoWashPushOnAirboat( CBaseEntity *pAirboat, const Vector &vecWashToAirboat, float flWashAmount );
  131. // Updates the rotor wash volume
  132. virtual void UpdateRotorWashVolume();
  133. // Rotor sound
  134. void InputEnableRotorSound( inputdata_t &inputdata );
  135. void InputDisableRotorSound( inputdata_t &inputdata );
  136. protected:
  137. CSoundPatch *m_pRotorSound; // Rotor loop played when the player can see the helicopter
  138. CSoundPatch *m_pRotorBlast; // Sound played when the helicopter's pushing around physics objects
  139. float m_flForce;
  140. int m_fHelicopterFlags;
  141. Vector m_vecDesiredFaceDir;
  142. float m_flLastSeen;
  143. float m_flPrevSeen;
  144. int m_iSoundState; // don't save this
  145. Vector m_vecTargetPosition;
  146. float m_flMaxSpeed; // Maximum speed of the helicopter.
  147. float m_flMaxSpeedFiring; // Maximum speed of the helicopter whilst firing guns.
  148. float m_flGoalSpeed; // Goal speed
  149. float m_flInitialSpeed;
  150. float m_flRandomOffsetTime;
  151. Vector m_vecRandomOffset;
  152. float m_flRotorWashEntitySearchTime;
  153. bool m_bSuppressSound;
  154. EHANDLE m_hRotorWash; // Attached rotorwash entity
  155. // Inputs
  156. void InputActivate( inputdata_t &inputdata );
  157. // Inputs
  158. void InputGunOn( inputdata_t &inputdata );
  159. void InputGunOff( inputdata_t &inputdata );
  160. void InputMissileOn( inputdata_t &inputdata );
  161. void InputMissileOff( inputdata_t &inputdata );
  162. void InputEnableRotorWash( inputdata_t &inputdata );
  163. void InputDisableRotorWash( inputdata_t &inputdata );
  164. void InputMoveTopSpeed( inputdata_t &inputdata ); // Causes the helicopter to immediately accelerate to its desired velocity
  165. void InputMoveSpecifiedSpeed( inputdata_t &inputdata );
  166. void InputSetAngles( inputdata_t &inputdata ); // Sets the angles of the helicopter
  167. protected:
  168. // Custom conservative collision volumes
  169. Vector m_cullBoxMins;
  170. Vector m_cullBoxMaxs;
  171. // Wash physics pushing
  172. CUtlVector< washentity_t > m_hEntitiesPushedByWash;
  173. void SetStartupTime( float time ) { m_flStartupTime = time; }
  174. private:
  175. CNetworkVar( float, m_flStartupTime );
  176. };
  177. //-----------------------------------------------------------------------------
  178. // This entity is used to create little force spheres that the helicopter
  179. // should avoid.
  180. //-----------------------------------------------------------------------------
  181. class CAvoidSphere : public CBaseEntity
  182. {
  183. DECLARE_DATADESC();
  184. public:
  185. DECLARE_CLASS( CAvoidSphere, CBaseEntity );
  186. void Init( float flRadius );
  187. virtual void Activate();
  188. virtual void UpdateOnRemove();
  189. static void ComputeAvoidanceForces( CBaseEntity *pEntity, float flEntityRadius, float flAvoidTime, Vector *pVecAvoidForce );
  190. private:
  191. typedef CHandle<CAvoidSphere> AvoidSphereHandle_t;
  192. float m_flRadius;
  193. static CUtlVector< AvoidSphereHandle_t > s_AvoidSpheres;
  194. };
  195. //-----------------------------------------------------------------------------
  196. // This entity is used to create little force boxes that the helicopter
  197. // should avoid.
  198. //-----------------------------------------------------------------------------
  199. class CAvoidBox : public CBaseEntity
  200. {
  201. DECLARE_DATADESC();
  202. public:
  203. DECLARE_CLASS( CAvoidBox, CBaseEntity );
  204. virtual void Spawn( );
  205. virtual void Activate();
  206. virtual void UpdateOnRemove();
  207. static void ComputeAvoidanceForces( CBaseEntity *pEntity, float flEntityRadius, float flAvoidTime, Vector *pVecAvoidForce );
  208. private:
  209. typedef CHandle<CAvoidBox> AvoidBoxHandle_t;
  210. static CUtlVector< AvoidBoxHandle_t > s_AvoidBoxes;
  211. };
  212. #endif // CBASEHELICOPTER_H