summaryrefslogtreecommitdiff
path: root/game/server/cstrike/cs_nav_pathfind.h
diff options
context:
space:
mode:
Diffstat (limited to 'game/server/cstrike/cs_nav_pathfind.h')
-rw-r--r--game/server/cstrike/cs_nav_pathfind.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/game/server/cstrike/cs_nav_pathfind.h b/game/server/cstrike/cs_nav_pathfind.h
new file mode 100644
index 0000000..042179b
--- /dev/null
+++ b/game/server/cstrike/cs_nav_pathfind.h
@@ -0,0 +1,65 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//=============================================================================//
+// nav_pathfind.h
+// Path-finding mechanisms using the Navigation Mesh
+// Author: Michael S. Booth ([email protected]), January 2003
+
+#ifndef _CS_NAV_PATHFIND_H_
+#define _CS_NAV_PATHFIND_H_
+
+#include "nav_pathfind.h"
+
+//--------------------------------------------------------------------------------------------------------------
+/**
+ * Compute travel distance along shortest path from startPos to goalPos.
+ * Return -1 if can't reach endPos from goalPos.
+ */
+template< typename CostFunctor >
+float NavAreaTravelDistance( const Vector &startPos, const Vector &goalPos, CostFunctor &costFunc )
+{
+ CNavArea *startArea = TheNavMesh->GetNearestNavArea( startPos );
+ if (startArea == NULL)
+ {
+ return -1.0f;
+ }
+
+ // compute path between areas using given cost heuristic
+ CNavArea *goalArea = NULL;
+ if (NavAreaBuildPath( startArea, NULL, &goalPos, costFunc, &goalArea ) == false)
+ {
+ return -1.0f;
+ }
+
+ // compute distance along path
+ if (goalArea->GetParent() == NULL)
+ {
+ // both points are in the same area - return euclidean distance
+ return (goalPos - startPos).Length();
+ }
+ else
+ {
+ CNavArea *area;
+ float distance;
+
+ // goalPos is assumed to be inside goalArea (or very close to it) - skip to next area
+ area = goalArea->GetParent();
+ distance = (goalPos - area->GetCenter()).Length();
+
+ for( ; area->GetParent(); area = area->GetParent() )
+ {
+ distance += (area->GetCenter() - area->GetParent()->GetCenter()).Length();
+ }
+
+ // add in distance to startPos
+ distance += (startPos - area->GetCenter()).Length();
+
+ return distance;
+ }
+}
+
+#endif // _CS_NAV_PATHFIND_H_