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.

190 lines
6.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef AI_ROUTE_H
  8. #define AI_ROUTE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "ai_basenpc.h"
  13. #include "mathlib/vector.h"
  14. #include "ai_network.h"
  15. #include "ai_node.h"
  16. #include "ai_waypoint.h"
  17. struct AI_Waypoint_t;
  18. struct OverlayLine_t;
  19. class CAI_BaseNPC;
  20. //=============================================================================
  21. // >> CAI_Path
  22. //=============================================================================
  23. #define DEF_WAYPOINT_TOLERANCE (0.1)
  24. class CAI_Path
  25. {
  26. //-----------------------------------------------------------------
  27. public:
  28. void SetWaypoints(AI_Waypoint_t* route, bool fSetGoalFromLast = false) ;
  29. void PrependWaypoints( AI_Waypoint_t *pWaypoints );
  30. void PrependWaypoint( const Vector &newPoint, Navigation_t navType, unsigned waypointFlags );
  31. bool IsEmpty() const { return m_Waypoints.IsEmpty(); }
  32. AI_Waypoint_t * GetCurWaypoint() { return m_Waypoints.GetFirst(); }
  33. const AI_Waypoint_t *GetCurWaypoint() const { return m_Waypoints.GetFirst(); }
  34. AI_Waypoint_t * GetGoalWaypoint() { return m_Waypoints.GetLast(); }
  35. const AI_Waypoint_t *GetGoalWaypoint() const { return m_Waypoints.GetLast(); }
  36. const Vector & CurWaypointPos() const;
  37. const Vector & NextWaypointPos() const;
  38. float CurWaypointYaw() const;
  39. int CurWaypointFlags() const;
  40. Navigation_t CurWaypointNavType() const;
  41. AI_Waypoint_t * GetTransitionWaypoint();
  42. //---------------------------------
  43. float GetPathLength();
  44. float GetPathDistanceToGoal( const Vector &);
  45. float GetStartTime() const { return m_routeStartTime; }
  46. //---------------------------------
  47. // How close do we need to get to the goal
  48. //---------------------------------
  49. void SetGoalTolerance(float tolerance) { m_goalTolerance = tolerance; }
  50. float GetGoalTolerance() const { return m_goalTolerance; }
  51. void SetWaypointTolerance(float tolerance) { m_waypointTolerance = tolerance; }
  52. float GetWaypointTolerance() const { return m_waypointTolerance; }
  53. //---------------------------------
  54. // The activity to use during motion
  55. //---------------------------------
  56. Activity GetMovementActivity() const { return m_activity; }
  57. Activity SetMovementActivity(Activity activity);
  58. int GetMovementSequence() const { return m_sequence; }
  59. int SetMovementSequence(int sequence) { return (m_sequence = sequence); }
  60. Activity GetArrivalActivity( ) const;
  61. void SetArrivalActivity(Activity activity);
  62. int GetArrivalSequence( ) const;
  63. void SetArrivalSequence(int sequence);
  64. void SetGoalDirection( const Vector &goalDirection );
  65. void SetGoalDirection( CBaseEntity *pTarget );
  66. Vector GetGoalDirection( const Vector &startPos );
  67. void SetGoalSpeed( float flSpeed );
  68. void SetGoalSpeed( CBaseEntity *pTarget );
  69. float GetGoalSpeed( const Vector &startPos );
  70. void SetGoalStoppingDistance( float flDistance );
  71. float GetGoalStoppingDistance( ) const;
  72. //---------------------------------
  73. // Target of this path
  74. //---------------------------------
  75. void SetTarget(CBaseEntity * pTarget ) { m_target = pTarget; }
  76. void ClearTarget() { m_target = NULL; m_vecTargetOffset = vec3_origin; }
  77. void SetTargetOffset( const Vector &vecOffset) { m_vecTargetOffset = vecOffset; }
  78. CBaseEntity * GetTarget() { return m_target; }
  79. void SetGoalType(GoalType_t goalType); // Set the goal type
  80. void SetGoalPosition(const Vector &goalPos); // Set the goal position
  81. void SetLastNodeAsGoal(bool bReset = false); // Sets last node as goal and goal position
  82. void ResetGoalPosition(const Vector &goalPos); // Reset the goal position
  83. // Returns the *base* goal position (without the offset applied)
  84. const Vector& BaseGoalPosition() const;
  85. // Returns the *actual* goal position (with the offset applied)
  86. const Vector & ActualGoalPosition(void) const; // Get the goal position
  87. GoalType_t GoalType(void) const; // Get the goal type
  88. void SetGoalFlags( unsigned flags ) { m_goalFlags = flags; }
  89. unsigned GoalFlags( void ) const; // Get the goal flags
  90. void Advance( void ); // Advance to next waypoint if possible
  91. bool CurWaypointIsGoal(void) const;
  92. void Clear(void);
  93. CAI_Path();
  94. ~CAI_Path();
  95. //---------------------------------
  96. int GetLastNodeReached() { return m_iLastNodeReached; }
  97. void ClearWaypoints()
  98. {
  99. m_Waypoints.RemoveAll();
  100. m_iLastNodeReached = NO_NODE;
  101. }
  102. private:
  103. // Computes the goal distance for each waypoint along the route
  104. static void ComputeRouteGoalDistances(AI_Waypoint_t *pGoalWaypoint);
  105. //---------------------------------
  106. CAI_WaypointList m_Waypoints;
  107. //---------------------------------
  108. float m_goalTolerance; // How close do we need to get to the goal
  109. Activity m_activity; // The activity to use during motion
  110. int m_sequence; // The sequence to use during motion
  111. EHANDLE m_target; // Target of this path
  112. Vector m_vecTargetOffset; // offset from the target in world space
  113. float m_waypointTolerance;
  114. //---------------------------------
  115. Activity m_arrivalActivity;
  116. int m_arrivalSequence;
  117. //---------------------------------
  118. int m_iLastNodeReached; // What was the last node that I reached
  119. bool m_bGoalPosSet; // Was goal position set (used to check for errors)
  120. Vector m_goalPos; // Our ultimate goal position
  121. bool m_bGoalTypeSet; // Was goal position set (used to check for errors)
  122. GoalType_t m_goalType; // Type of goal
  123. unsigned m_goalFlags; // Goal flags
  124. //---------------------------------
  125. float m_routeStartTime;
  126. //---------------------------------
  127. Vector m_goalDirection;
  128. EHANDLE m_goalDirectionTarget;
  129. float m_goalSpeed;
  130. EHANDLE m_goalSpeedTarget;
  131. float m_goalStoppingDistance; // Distance we want to stop before the goal
  132. //---------------------------------
  133. static AI_Waypoint_t gm_InvalidWaypoint;
  134. DECLARE_SIMPLE_DATADESC();
  135. };
  136. #endif // AI_ROUTE_H