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.

209 lines
8.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef AI_PATHFINDER_H
  8. #define AI_PATHFINDER_H
  9. #include "ai_component.h"
  10. #include "ai_navtype.h"
  11. #if defined( _WIN32 )
  12. #pragma once
  13. #endif
  14. struct AIMoveTrace_t;
  15. struct OverlayLine_t;
  16. struct AI_Waypoint_t;
  17. class CAI_Link;
  18. class CAI_Network;
  19. class CAI_Node;
  20. //-----------------------------------------------------------------------------
  21. // The type of route to build
  22. enum RouteBuildFlags_e
  23. {
  24. bits_BUILD_GROUND = 0x00000001, //
  25. bits_BUILD_JUMP = 0x00000002, //
  26. bits_BUILD_FLY = 0x00000004, //
  27. bits_BUILD_CLIMB = 0x00000008, //
  28. bits_BUILD_CRAWL = 0x00000010, //
  29. bits_BUILD_GIVEWAY = 0x00000020, //
  30. bits_BUILD_TRIANG = 0x00000040, //
  31. bits_BUILD_IGNORE_NPCS = 0x00000080, // Ignore collisions with NPCs
  32. bits_BUILD_COLLIDE_NPCS = 0x00000100, // Use collisions with NPCs (redundant for argument clarity)
  33. bits_BUILD_GET_CLOSE = 0x00000200, // the route will be built even if it can't reach the destination
  34. bits_BUILD_NO_LOCAL_NAV = 0x00000400, // No local navigation
  35. bits_BUILD_UNLIMITED_DISTANCE = 0x00000800, // Path can be an unlimited distance away
  36. };
  37. //-----------------------------------------------------------------------------
  38. // CAI_Pathfinder
  39. //
  40. // Purpose: Executes pathfinds through an associated network.
  41. //
  42. //-----------------------------------------------------------------------------
  43. class CAI_Pathfinder : public CAI_Component
  44. {
  45. public:
  46. CAI_Pathfinder( CAI_BaseNPC *pOuter )
  47. : CAI_Component(pOuter),
  48. m_flLastStaleLinkCheckTime( 0 ),
  49. m_pNetwork( NULL )
  50. {
  51. }
  52. void Init( CAI_Network *pNetwork );
  53. //---------------------------------
  54. int NearestNodeToNPC();
  55. int NearestNodeToPoint( const Vector &vecOrigin );
  56. virtual AI_Waypoint_t* FindBestPath (int startID, int endID);
  57. AI_Waypoint_t* FindShortRandomPath (int startID, float minPathLength, const Vector &vDirection = vec3_origin);
  58. // --------------------------------
  59. bool IsLinkUsable(CAI_Link *pLink, int startID);
  60. // --------------------------------
  61. AI_Waypoint_t *BuildRoute( const Vector &vStart, const Vector &vEnd, CBaseEntity *pTarget, float goalTolerance, Navigation_t curNavType = NAV_NONE, int nBuildFlags = 0 );
  62. void UnlockRouteNodes( AI_Waypoint_t * );
  63. // --------------------------------
  64. void SetIgnoreBadLinks() { m_bIgnoreStaleLinks = true; } // lasts only for the next pathfind
  65. // --------------------------------
  66. virtual AI_Waypoint_t *BuildNodeRoute( const Vector &vStart, const Vector &vEnd, int buildFlags, float goalTolerance );
  67. virtual AI_Waypoint_t *BuildLocalRoute( const Vector &vStart, const Vector &vEnd, CBaseEntity const *pTarget, int endFlags, int nodeID, int buildFlags, float goalTolerance);
  68. virtual AI_Waypoint_t *BuildRadialRoute( const Vector &vStartPos, const Vector &vCenterPos, const Vector &vGoalPos, float flRadius, float flArc, float flStepDist, bool bClockwise, float goalTolerance, bool bAirRoute );
  69. virtual AI_Waypoint_t *BuildTriangulationRoute( const Vector &vStart,
  70. const Vector &vEnd, CBaseEntity const *pTarget, int endFlags, int nodeID,
  71. float flYaw, float flDistToBlocker, Navigation_t navType);
  72. virtual AI_Waypoint_t *BuildOBBAvoidanceRoute( const Vector &vStart, const Vector &vEnd,
  73. const CBaseEntity *pObstruction, const CBaseEntity *pTarget,
  74. Navigation_t navType );
  75. // --------------------------------
  76. bool Triangulate( Navigation_t navType, const Vector &vecStart, const Vector &vecEnd,
  77. float flDistToBlocker, CBaseEntity const *pTargetEnt, Vector *pApex );
  78. // --------------------------------
  79. void DrawDebugGeometryOverlays( int m_debugOverlays );
  80. protected:
  81. virtual bool CanUseLocalNavigation() { return true; }
  82. private:
  83. friend class CPathfindNearestNodeFilter;
  84. //---------------------------------
  85. AI_Waypoint_t* RouteToNode(const Vector &vecOrigin, int buildFlags, int nodeID, float goalTolerance);
  86. AI_Waypoint_t* RouteFromNode(const Vector &vecOrigin, int buildFlags, int nodeID, float goalTolerance);
  87. AI_Waypoint_t * BuildNearestNodeRoute( const Vector &vGoal, bool bToNode, int buildFlags, float goalTolerance, int *pNearestNode );
  88. //---------------------------------
  89. AI_Waypoint_t* MakeRouteFromParents(int *parentArray, int endID);
  90. AI_Waypoint_t* CreateNodeWaypoint( Hull_t hullType, int nodeID, int nodeFlags = 0 );
  91. AI_Waypoint_t* BuildRouteThroughPoints( Vector *vecPoints, int nNumPoints, int nDirection, int nStartIndex, int nEndIndex, Navigation_t navType, CBaseEntity *pTarget );
  92. bool IsLinkStillStale(int moveType, CAI_Link *nodeLink);
  93. // --------------------------------
  94. // Builds a simple route (no triangulation, no making way)
  95. AI_Waypoint_t *BuildSimpleRoute( Navigation_t navType, const Vector &vStart, const Vector &vEnd,
  96. const CBaseEntity *pTarget, int endFlags, int nodeID, int nodeTargetType, float flYaw);
  97. // Builds a complex route (triangulation, making way)
  98. AI_Waypoint_t *BuildComplexRoute( Navigation_t navType, const Vector &vStart,
  99. const Vector &vEnd, const CBaseEntity *pTarget, int endFlags, int nodeID,
  100. int buildFlags, float flYaw, float goalTolerance, float maxLocalNavDistance );
  101. AI_Waypoint_t *BuildGroundRoute( const Vector &vStart, const Vector &vEnd, CBaseEntity const *pTarget, int endFlags, int nodeID, int buildFlags, float flYaw, float goalTolerance );
  102. AI_Waypoint_t *BuildFlyRoute( const Vector &vStart, const Vector &vEnd, CBaseEntity const *pTarget, int endFlags, int nodeID, int buildFlags, float flYaw, float goalTolerance );
  103. AI_Waypoint_t *BuildCrawlRoute( const Vector &vStart, const Vector &vEnd, CBaseEntity const *pTarget, int endFlags, int nodeID, int buildFlags, float flYaw, float goalTolerance );
  104. AI_Waypoint_t *BuildJumpRoute( const Vector &vStart, const Vector &vEnd, CBaseEntity const *pTarget, int endFlags, int nodeID, int buildFlags, float flYaw );
  105. AI_Waypoint_t *BuildClimbRoute( const Vector &vStart, const Vector &vEnd, CBaseEntity const *pTarget, int endFlags, int nodeID, int buildFlags, float flYaw );
  106. // Computes the link type
  107. Navigation_t ComputeWaypointType( bool *pWantsPreciseMovement, CAI_Node **ppNodes, int parentID, int destID );
  108. // --------------------------------
  109. bool TestTriangulationRoute( Navigation_t navType, const Vector& vecStart,
  110. const Vector &vecApex, const Vector &vecEnd, const CBaseEntity *pTargetEnt, AIMoveTrace_t *pStartTrace );
  111. // --------------------------------
  112. bool CheckStaleRoute( const Vector &vStart, const Vector &vEnd, int moveTypes);
  113. bool CheckStaleNavTypeRoute( Navigation_t navType, const Vector &vStart, const Vector &vEnd );
  114. // --------------------------------
  115. bool CanGiveWay( const Vector& vStart, const Vector& vEnd, CBaseEntity *pNPCBlocker );
  116. // --------------------------------
  117. bool UseStrongOptimizations();
  118. // --------------------------------
  119. // Debugging fields and functions
  120. class CTriDebugOverlay
  121. {
  122. public:
  123. CTriDebugOverlay()
  124. : m_debugTriOverlayLine( NULL )
  125. {
  126. }
  127. void AddTriOverlayLines( const Vector &vecStart, const Vector &vecApex, const Vector &vecEnd, const AIMoveTrace_t &startTrace, const AIMoveTrace_t &endTrace, bool bPathClear );
  128. void ClearTriOverlayLines(void);
  129. void FadeTriOverlayLines(void);
  130. void Draw(int npcDebugOverlays);
  131. private:
  132. void AddTriOverlayLine(const Vector &origin, const Vector &dest, int r, int g, int b, bool noDepthTest);
  133. OverlayLine_t **m_debugTriOverlayLine;
  134. };
  135. CTriDebugOverlay m_TriDebugOverlay;
  136. //---------------------------------
  137. float m_flLastStaleLinkCheckTime; // Last time I check for a stale link
  138. bool m_bIgnoreStaleLinks;
  139. //---------------------------------
  140. CAI_Network *GetNetwork() { return m_pNetwork; }
  141. const CAI_Network *GetNetwork() const { return m_pNetwork; }
  142. CAI_Network *m_pNetwork;
  143. public:
  144. DECLARE_SIMPLE_DATADESC();
  145. };
  146. //-----------------------------------------------------------------------------
  147. #endif // AI_PATHFINDER_H