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.

219 lines
6.9 KiB

  1. // NextBotPlayerLocomotion.h
  2. // Locomotor for CBasePlayer derived bots
  3. // Author: Michael Booth, November 2005
  4. // Copyright (c) 2005 Turtle Rock Studios, Inc. - All Rights Reserved
  5. #ifndef _NEXT_BOT_PLAYER_LOCOMOTION_H_
  6. #define _NEXT_BOT_PLAYER_LOCOMOTION_H_
  7. #include "NextBot.h"
  8. #include "NextBotLocomotionInterface.h"
  9. #include "Path/NextBotPathFollow.h"
  10. class CBasePlayer;
  11. //--------------------------------------------------------------------------------------------------
  12. /**
  13. * Basic player locomotion implementation
  14. */
  15. class PlayerLocomotion : public ILocomotion
  16. {
  17. public:
  18. DECLARE_CLASS( PlayerLocomotion, ILocomotion );
  19. PlayerLocomotion( INextBot *bot );
  20. virtual ~PlayerLocomotion() { }
  21. virtual void Reset( void ); // reset to initial state
  22. virtual void Update( void ); // update internal state
  23. virtual void Approach( const Vector &pos, float goalWeight = 1.0f ); // move directly towards the given position
  24. virtual void DriveTo( const Vector &pos ); // Move the bot to the precise given position immediately,
  25. //
  26. // ILocomotion modifiers
  27. //
  28. virtual bool ClimbUpToLedge( const Vector &landingGoal, const Vector &landingForward, const CBaseEntity *obstacle ); // initiate a jump to an adjacent high ledge, return false if climb can't start
  29. virtual void JumpAcrossGap( const Vector &landingGoal, const Vector &landingForward ); // initiate a jump across an empty volume of space to far side
  30. virtual void Jump( void ); // initiate a simple undirected jump in the air
  31. virtual bool IsClimbingOrJumping( void ) const; // is jumping in any form
  32. virtual bool IsClimbingUpToLedge( void ) const; // is climbing up to a high ledge
  33. virtual bool IsJumpingAcrossGap( void ) const; // is jumping across a gap to the far side
  34. virtual void Run( void ); // set desired movement speed to running
  35. virtual void Walk( void ); // set desired movement speed to walking
  36. virtual void Stop( void ); // set desired movement speed to stopped
  37. virtual bool IsRunning( void ) const;
  38. virtual void SetDesiredSpeed( float speed ); // set desired speed for locomotor movement
  39. virtual float GetDesiredSpeed( void ) const; // returns the current desired speed
  40. virtual void SetMinimumSpeedLimit( float limit ); // speed cannot drop below this
  41. virtual void SetMaximumSpeedLimit( float limit ); // speed cannot rise above this
  42. virtual bool IsOnGround( void ) const; // return true if standing on something
  43. virtual CBaseEntity *GetGround( void ) const; // return the current ground entity or NULL if not on the ground
  44. virtual const Vector &GetGroundNormal( void ) const; // surface normal of the ground we are in contact with
  45. virtual void ClimbLadder( const CNavLadder *ladder, const CNavArea *dismountGoal ); // climb the given ladder to the top and dismount
  46. virtual void DescendLadder( const CNavLadder *ladder, const CNavArea *dismountGoal ); // descend the given ladder to the bottom and dismount
  47. virtual bool IsUsingLadder( void ) const;
  48. virtual bool IsAscendingOrDescendingLadder( void ) const; // we are actually on the ladder right now, either climbing up or down
  49. virtual bool IsAbleToAutoCenterOnLadder( void ) const;
  50. virtual void FaceTowards( const Vector &target ); // rotate body to face towards "target"
  51. virtual void SetDesiredLean( const QAngle &lean ) { }
  52. virtual const QAngle &GetDesiredLean( void ) const { static QAngle junk; return junk; }
  53. //
  54. // ILocomotion information
  55. //
  56. virtual const Vector &GetFeet( void ) const; // return position of "feet" - point below centroid of bot at feet level
  57. virtual float GetStepHeight( void ) const; // if delta Z is greater than this, we have to jump to get up
  58. virtual float GetMaxJumpHeight( void ) const; // return maximum height of a jump
  59. virtual float GetDeathDropHeight( void ) const; // distance at which we will die if we fall
  60. virtual float GetRunSpeed( void ) const; // get maximum running speed
  61. virtual float GetWalkSpeed( void ) const; // get maximum walking speed
  62. virtual float GetMaxAcceleration( void ) const; // return maximum acceleration of locomotor
  63. virtual float GetMaxDeceleration( void ) const; // return maximum deceleration of locomotor
  64. virtual const Vector &GetVelocity( void ) const; // return current world space velocity
  65. protected:
  66. virtual void AdjustPosture( const Vector &moveGoal );
  67. private:
  68. CBasePlayer *m_player; // the player we are locomoting
  69. mutable bool m_isJumping;
  70. CountdownTimer m_jumpTimer;
  71. bool m_isClimbingUpToLedge;
  72. bool m_isJumpingAcrossGap;
  73. Vector m_landingGoal;
  74. bool m_hasLeftTheGround;
  75. float m_desiredSpeed;
  76. float m_minSpeedLimit;
  77. float m_maxSpeedLimit;
  78. bool TraverseLadder( void ); // when climbing/descending a ladder
  79. enum LadderState
  80. {
  81. NO_LADDER, // not using a ladder
  82. APPROACHING_ASCENDING_LADDER,
  83. APPROACHING_DESCENDING_LADDER,
  84. ASCENDING_LADDER,
  85. DESCENDING_LADDER,
  86. DISMOUNTING_LADDER_TOP,
  87. DISMOUNTING_LADDER_BOTTOM,
  88. };
  89. LadderState m_ladderState;
  90. LadderState ApproachAscendingLadder( void );
  91. LadderState ApproachDescendingLadder( void );
  92. LadderState AscendLadder( void );
  93. LadderState DescendLadder( void );
  94. LadderState DismountLadderTop( void );
  95. LadderState DismountLadderBottom( void );
  96. const CNavLadder *m_ladderInfo;
  97. const CNavArea *m_ladderDismountGoal;
  98. CountdownTimer m_ladderTimer; // a "give up" timer if things go awry
  99. bool IsClimbPossible( INextBot *me, const CBaseEntity *obstacle ) const;
  100. };
  101. inline float PlayerLocomotion::GetStepHeight( void ) const
  102. {
  103. return 18.0f;
  104. }
  105. inline float PlayerLocomotion::GetMaxJumpHeight( void ) const
  106. {
  107. return 57.0f;
  108. }
  109. inline float PlayerLocomotion::GetDeathDropHeight( void ) const
  110. {
  111. return 200.0f;
  112. }
  113. inline float PlayerLocomotion::GetMaxAcceleration( void ) const
  114. {
  115. return 100.0f;
  116. }
  117. inline float PlayerLocomotion::GetMaxDeceleration( void ) const
  118. {
  119. return 200.0f;
  120. }
  121. inline void PlayerLocomotion::Run( void )
  122. {
  123. m_desiredSpeed = GetRunSpeed();
  124. }
  125. inline void PlayerLocomotion::Walk( void )
  126. {
  127. m_desiredSpeed = GetWalkSpeed();
  128. }
  129. inline void PlayerLocomotion::Stop( void )
  130. {
  131. m_desiredSpeed = 0.0f;
  132. }
  133. inline bool PlayerLocomotion::IsRunning( void ) const
  134. {
  135. return true;
  136. }
  137. inline void PlayerLocomotion::SetDesiredSpeed( float speed )
  138. {
  139. m_desiredSpeed = speed;
  140. }
  141. inline float PlayerLocomotion::GetDesiredSpeed( void ) const
  142. {
  143. return clamp( m_desiredSpeed, m_minSpeedLimit, m_maxSpeedLimit );
  144. }
  145. inline void PlayerLocomotion::SetMinimumSpeedLimit( float limit )
  146. {
  147. m_minSpeedLimit = limit;
  148. }
  149. inline void PlayerLocomotion::SetMaximumSpeedLimit( float limit )
  150. {
  151. m_maxSpeedLimit = limit;
  152. }
  153. inline bool PlayerLocomotion::IsAbleToAutoCenterOnLadder( void ) const
  154. {
  155. return IsUsingLadder() && (m_ladderState == ASCENDING_LADDER || m_ladderState == DESCENDING_LADDER);
  156. }
  157. inline bool PlayerLocomotion::IsAscendingOrDescendingLadder( void ) const
  158. {
  159. switch( m_ladderState )
  160. {
  161. case ASCENDING_LADDER:
  162. case DESCENDING_LADDER:
  163. case DISMOUNTING_LADDER_TOP:
  164. case DISMOUNTING_LADDER_BOTTOM:
  165. return true;
  166. }
  167. return false;
  168. }
  169. #endif // _NEXT_BOT_PLAYER_LOCOMOTION_H_