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.

106 lines
3.6 KiB

  1. // NextBotPathFollow.h
  2. // Path following
  3. // Author: Michael Booth, April 2005
  4. //========= Copyright Valve Corporation, All rights reserved. ============//
  5. #ifndef _NEXT_BOT_PATH_FOLLOWER_
  6. #define _NEXT_BOT_PATH_FOLLOWER_
  7. #include "nav_mesh.h"
  8. #include "nav_pathfind.h"
  9. #include "NextBotPath.h"
  10. class INextBot;
  11. class ILocomotion;
  12. //--------------------------------------------------------------------------------------------------------
  13. /**
  14. * A PathFollower extends a Path to include mechanisms to move along (follow) it
  15. */
  16. class PathFollower : public Path
  17. {
  18. public:
  19. PathFollower( void );
  20. virtual ~PathFollower();
  21. virtual void Invalidate( void ); // (EXTEND) cause the path to become invalid
  22. virtual void Draw( const Path::Segment *start = NULL ) const; // (EXTEND) draw the path for debugging
  23. virtual void OnPathChanged( INextBot *bot, Path::ResultType result ); // invoked when the path is (re)computed (path is valid at the time of this call)
  24. virtual void Update( INextBot *bot ); // move bot along path
  25. virtual const Path::Segment *GetCurrentGoal( void ) const; // return current goal along the path we are trying to reach
  26. virtual void SetMinLookAheadDistance( float value ); // minimum range movement goal must be along path
  27. virtual CBaseEntity *GetHindrance( void ) const; // returns entity that is hindering our progress along the path
  28. virtual bool IsDiscontinuityAhead( INextBot *bot, Path::SegmentType type, float range = -1.0f ) const; // return true if there is a the given discontinuity ahead in the path within the given range (-1 = entire remaining path)
  29. void SetGoalTolerance( float range ); // set tolerance within at which we're considered to be at our goal
  30. private:
  31. const Path::Segment *m_goal; // our current goal along the path
  32. float m_minLookAheadRange;
  33. bool CheckProgress( INextBot *bot );
  34. bool IsAtGoal( INextBot *bot ) const; // return true if reached current path goal
  35. //bool IsOnStairs( INextBot *bot ) const; // return true if bot is standing on a stairway
  36. bool m_isOnStairs;
  37. CountdownTimer m_avoidTimer; // do avoid check more often if we recently avoided
  38. CountdownTimer m_waitTimer; // for waiting for a blocker to move off our path
  39. CHandle< CBaseEntity > m_hindrance;
  40. // debug display data for avoid volumes
  41. bool m_didAvoidCheck;
  42. Vector m_leftFrom;
  43. Vector m_leftTo;
  44. bool m_isLeftClear;
  45. Vector m_rightFrom;
  46. Vector m_rightTo;
  47. bool m_isRightClear;
  48. Vector m_hullMin, m_hullMax;
  49. void AdjustSpeed( INextBot *bot ); // adjust speed based on path curvature
  50. Vector Avoid( INextBot *bot, const Vector &goalPos, const Vector &forward, const Vector &left ); // avoidance movements for very nearby obstacles. returns modified goal position
  51. bool Climbing( INextBot *bot, const Path::Segment *goal, const Vector &forward, const Vector &left, float goalRange ); // climb up ledges
  52. bool JumpOverGaps( INextBot *bot, const Path::Segment *goal, const Vector &forward, const Vector &left, float goalRange ); // jump over gaps
  53. bool LadderUpdate( INextBot *bot ); // move bot along ladder
  54. CBaseEntity *FindBlocker( INextBot *bot ); // if entity is returned, it is blocking us from continuing along our path
  55. float m_goalTolerance;
  56. };
  57. inline void PathFollower::SetGoalTolerance( float range )
  58. {
  59. m_goalTolerance = range;
  60. }
  61. inline const Path::Segment *PathFollower::GetCurrentGoal( void ) const
  62. {
  63. return m_goal;
  64. }
  65. inline void PathFollower::SetMinLookAheadDistance( float value )
  66. {
  67. m_minLookAheadRange = value;
  68. }
  69. inline CBaseEntity *PathFollower::GetHindrance( void ) const
  70. {
  71. return m_hindrance;
  72. }
  73. #endif // _NEXT_BOT_PATH_FOLLOWER_