Counter Strike : Global Offensive Source Code
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.

132 lines
3.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef AI_BASENPC_FLYER_H
  8. #define AI_BASENPC_FLYER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "ai_basenpc.h"
  13. #include "ai_navigator.h"
  14. //-----------------------------------------------------------------------------
  15. // The combot.
  16. //-----------------------------------------------------------------------------
  17. abstract_class CAI_BaseFlyingBot : public CAI_BaseNPC
  18. {
  19. DECLARE_CLASS( CAI_BaseFlyingBot, CAI_BaseNPC );
  20. public:
  21. DECLARE_DATADESC();
  22. void StartTask( const Task_t *pTask );
  23. void GetVelocity(Vector *vVelocity, AngularImpulse *vAngVelocity);
  24. virtual QAngle BodyAngles();
  25. protected:
  26. CAI_BaseFlyingBot();
  27. Vector VelocityToAvoidObstacles(float flInterval);
  28. virtual float MinGroundDist(void);
  29. void TurnHeadToTarget( float flInterval, const Vector &moveTarget );
  30. void MoveInDirection( float flInterval, const Vector &targetDir,
  31. float accelXY, float accelZ, float decay)
  32. {
  33. decay = ExponentialDecay( decay, 1.0, flInterval );
  34. accelXY *= flInterval;
  35. accelZ *= flInterval;
  36. m_vCurrentVelocity.x = ( decay * m_vCurrentVelocity.x + accelXY * targetDir.x );
  37. m_vCurrentVelocity.y = ( decay * m_vCurrentVelocity.y + accelXY * targetDir.y );
  38. m_vCurrentVelocity.z = ( decay * m_vCurrentVelocity.z + accelZ * targetDir.z );
  39. }
  40. void MoveToLocation( float flInterval, const Vector &target,
  41. float accelXY, float accelZ, float decay)
  42. {
  43. Vector targetDir = target - GetLocalOrigin();
  44. VectorNormalize(targetDir);
  45. MoveInDirection(flInterval, targetDir, accelXY, accelZ, decay);
  46. }
  47. void Decelerate( float flInterval, float decay )
  48. {
  49. decay *= flInterval;
  50. m_vCurrentVelocity.x = (decay * m_vCurrentVelocity.x);
  51. m_vCurrentVelocity.y = (decay * m_vCurrentVelocity.y);
  52. m_vCurrentVelocity.z = (decay * m_vCurrentVelocity.z);
  53. }
  54. void AddNoiseToVelocity( float noiseScale = 1.0 )
  55. {
  56. if( m_vNoiseMod.x )
  57. {
  58. m_vCurrentVelocity.x += noiseScale*sin(m_vNoiseMod.x * gpGlobals->curtime + m_vNoiseMod.x);
  59. }
  60. if( m_vNoiseMod.y )
  61. {
  62. m_vCurrentVelocity.y += noiseScale*cos(m_vNoiseMod.y * gpGlobals->curtime + m_vNoiseMod.y);
  63. }
  64. if( m_vNoiseMod.z )
  65. {
  66. m_vCurrentVelocity.z -= noiseScale*cos(m_vNoiseMod.z * gpGlobals->curtime + m_vNoiseMod.z);
  67. }
  68. }
  69. void LimitSpeed( float zLimit, float maxSpeed = -1 )
  70. {
  71. if ( maxSpeed == -1 )
  72. maxSpeed = m_flSpeed;
  73. if (m_vCurrentVelocity.Length() > maxSpeed)
  74. {
  75. VectorNormalize(m_vCurrentVelocity);
  76. m_vCurrentVelocity *= maxSpeed;
  77. }
  78. // Limit fall speed
  79. if (zLimit > 0 && m_vCurrentVelocity.z < -zLimit)
  80. {
  81. m_vCurrentVelocity.z = -zLimit;
  82. }
  83. }
  84. AI_NavPathProgress_t ProgressFlyPath( float flInterval,
  85. const CBaseEntity *pNewTarget,
  86. unsigned collisionMask,
  87. bool bNewTrySimplify = true,
  88. float strictPointTolerance = 32.0 );
  89. virtual float GetHeadTurnRate( void ) { return 15.0f; } // Degrees per second
  90. const Vector &GetCurrentVelocity() const { return m_vCurrentVelocity; }
  91. void SetCurrentVelocity(const Vector &vNewVel) { m_vCurrentVelocity = vNewVel; }
  92. const Vector &GetNoiseMod() const { return m_vNoiseMod; }
  93. void SetNoiseMod( float x, float y, float z ) { m_vNoiseMod.Init( x, y, z ); }
  94. void SetNoiseMod( const Vector &noise ) { m_vNoiseMod = noise; }
  95. virtual void MoveToTarget(float flInterval, const Vector &MoveTarget) = 0;
  96. void TranslateNavGoal( CBaseEntity *pTarget, Vector &chasePosition );
  97. // -------------------------------
  98. // Movement vars
  99. // -------------------------------
  100. Vector m_vCurrentVelocity;
  101. Vector m_vCurrentAngularVelocity;
  102. Vector m_vCurrentBanking;
  103. Vector m_vNoiseMod;
  104. float m_fHeadYaw;
  105. Vector m_vLastPatrolDir;
  106. };
  107. #endif // AI_BASENPC_FLYER_H