GetPathLength: add optional depth parameter

This is also exposed by the PathFinder defcore entry.
console-destruction
Maikel de Vries 2016-09-25 21:48:19 +02:00
parent 0e76c85531
commit 679eedaf50
2 changed files with 9 additions and 1 deletions

View File

@ -30,6 +30,11 @@
<name>endy</name>
<desc>Y coordinate of end position. Always global coordinate.</desc>
</param>
<param>
<type>int</type>
<name>depth</name>
<desc>Determines search depth of the pathfinder algorithm (range from 1 - 10 with default 1). Warning: higher values may slow down the game. See also the PathFinder entry in the <emlink href="definition/properties.html">DefCore</emlink>.</desc>
</param>
</params>
</syntax>
<desc>Searches for a path from start point to end point using the pathfinding algorithm as used by clonks and returns the length of the found path. Returns <code>nil</code> if no path was found.</desc>

View File

@ -2019,12 +2019,15 @@ private:
PathInfo *pPathInfo;
};
static Nillable<long> FnGetPathLength(C4PropList * _this, long iFromX, long iFromY, long iToX, long iToY)
static Nillable<long> FnGetPathLength(C4PropList * _this, long iFromX, long iFromY, long iToX, long iToY, long iLevel)
{
PathInfo PathInfo;
PathInfo.ilx = iFromX;
PathInfo.ily = iFromY;
PathInfo.ilen = 0;
if (!iLevel)
iLevel = 1;
Game.PathFinder.SetLevel(iLevel);
if (!Game.PathFinder.Find(iFromX, iFromY, iToX, iToY, SumPathLength(&PathInfo)))
return C4Void();
return PathInfo.ilen + Distance(PathInfo.ilx, PathInfo.ily, iToX, iToY);