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.

149 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef AI_BASENPC_PHYSICSFLYER_H
  8. #define AI_BASENPC_PHYSICSFLYER_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_BasePhysicsFlyingBot : public CAI_BaseNPC, public IMotionEvent
  18. {
  19. DECLARE_CLASS( CAI_BasePhysicsFlyingBot, 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. virtual bool ShouldSavePhysics() { return true; }
  26. protected:
  27. CAI_BasePhysicsFlyingBot();
  28. ~CAI_BasePhysicsFlyingBot();
  29. Vector VelocityToAvoidObstacles(float flInterval);
  30. virtual float MinGroundDist(void);
  31. virtual void TurnHeadToTarget( float flInterval, const Vector &moveTarget );
  32. void MoveInDirection( float flInterval, const Vector &targetDir,
  33. float accelXY, float accelZ, float decay)
  34. {
  35. decay = ExponentialDecay( decay, 1.0, flInterval );
  36. accelXY *= flInterval;
  37. accelZ *= flInterval;
  38. m_vCurrentVelocity.x = ( decay * m_vCurrentVelocity.x + accelXY * targetDir.x );
  39. m_vCurrentVelocity.y = ( decay * m_vCurrentVelocity.y + accelXY * targetDir.y );
  40. m_vCurrentVelocity.z = ( decay * m_vCurrentVelocity.z + accelZ * targetDir.z );
  41. }
  42. void MoveToLocation( float flInterval, const Vector &target,
  43. float accelXY, float accelZ, float decay)
  44. {
  45. Vector targetDir = target - GetLocalOrigin();
  46. VectorNormalize(targetDir);
  47. MoveInDirection(flInterval, targetDir, accelXY, accelZ, decay);
  48. }
  49. void Decelerate( float flInterval, float decay )
  50. {
  51. decay *= flInterval;
  52. m_vCurrentVelocity.x = (decay * m_vCurrentVelocity.x);
  53. m_vCurrentVelocity.y = (decay * m_vCurrentVelocity.y);
  54. m_vCurrentVelocity.z = (decay * m_vCurrentVelocity.z);
  55. }
  56. void AddNoiseToVelocity( float noiseScale = 1.0 )
  57. {
  58. if( m_vNoiseMod.x )
  59. {
  60. m_vCurrentVelocity.x += noiseScale*sin(m_vNoiseMod.x * gpGlobals->curtime + m_vNoiseMod.x);
  61. }
  62. if( m_vNoiseMod.y )
  63. {
  64. m_vCurrentVelocity.y += noiseScale*cos(m_vNoiseMod.y * gpGlobals->curtime + m_vNoiseMod.y);
  65. }
  66. if( m_vNoiseMod.z )
  67. {
  68. m_vCurrentVelocity.z -= noiseScale*cos(m_vNoiseMod.z * gpGlobals->curtime + m_vNoiseMod.z);
  69. }
  70. }
  71. void LimitSpeed( float zLimit, float maxSpeed = -1 )
  72. {
  73. if ( maxSpeed == -1 )
  74. maxSpeed = m_flSpeed;
  75. if (m_vCurrentVelocity.Length() > maxSpeed)
  76. {
  77. VectorNormalize(m_vCurrentVelocity);
  78. m_vCurrentVelocity *= maxSpeed;
  79. }
  80. // Limit fall speed
  81. if (zLimit > 0 && m_vCurrentVelocity.z < -zLimit)
  82. {
  83. m_vCurrentVelocity.z = -zLimit;
  84. }
  85. }
  86. AI_NavPathProgress_t ProgressFlyPath( float flInterval,
  87. const CBaseEntity *pNewTarget,
  88. unsigned collisionMask,
  89. bool bNewTrySimplify = true,
  90. float strictPointTolerance = 32.0 );
  91. const Vector &GetCurrentVelocity() const { return m_vCurrentVelocity; }
  92. void SetCurrentVelocity(const Vector &vNewVel) { m_vCurrentVelocity = vNewVel; }
  93. const Vector &GetNoiseMod() const { return m_vNoiseMod; }
  94. void SetNoiseMod( float x, float y, float z ) { m_vNoiseMod.Init( x, y, z ); }
  95. void SetNoiseMod( const Vector &noise ) { m_vNoiseMod = noise; }
  96. void TranslateNavGoal( CBaseEntity *pTarget, Vector &chasePosition );
  97. virtual void MoveToTarget(float flInterval, const Vector &MoveTarget) = 0;
  98. virtual float GetHeadTurnRate( void ) { return 15.0f; } // Degrees per second
  99. bool CreateVPhysics( void );
  100. IMotionEvent::simresult_e Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular );
  101. virtual void ClampMotorForces( Vector &linear, AngularImpulse &angular )
  102. {
  103. // limit reaction forces
  104. linear.x = clamp( linear.x, -3000, 3000 );
  105. linear.y = clamp( linear.y, -3000, 3000 );
  106. linear.z = clamp( linear.z, -3000, 3000 );
  107. // add in weightlessness
  108. linear.z += 800;
  109. }
  110. // -------------------------------
  111. // Movement vars
  112. // -------------------------------
  113. Vector m_vCurrentVelocity;
  114. Vector m_vCurrentBanking;
  115. Vector m_vNoiseMod;
  116. float m_fHeadYaw;
  117. Vector m_vLastPatrolDir;
  118. IPhysicsMotionController *m_pMotionController;
  119. };
  120. #endif // AI_BASENPC_PHYSICSFLYER_H