diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/cstrike/cs_nav_pathfind.h | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/server/cstrike/cs_nav_pathfind.h')
| -rw-r--r-- | game/server/cstrike/cs_nav_pathfind.h | 65 |
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_ |