forked from Mirrors/openclonk
GetPathLength: add optional depth parameter
This is also exposed by the PathFinder defcore entry.console-destruction
parent
0e76c85531
commit
679eedaf50
|
@ -30,6 +30,11 @@
|
||||||
<name>endy</name>
|
<name>endy</name>
|
||||||
<desc>Y coordinate of end position. Always global coordinate.</desc>
|
<desc>Y coordinate of end position. Always global coordinate.</desc>
|
||||||
</param>
|
</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>
|
</params>
|
||||||
</syntax>
|
</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>
|
<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>
|
||||||
|
|
|
@ -2019,12 +2019,15 @@ private:
|
||||||
PathInfo *pPathInfo;
|
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 PathInfo;
|
||||||
PathInfo.ilx = iFromX;
|
PathInfo.ilx = iFromX;
|
||||||
PathInfo.ily = iFromY;
|
PathInfo.ily = iFromY;
|
||||||
PathInfo.ilen = 0;
|
PathInfo.ilen = 0;
|
||||||
|
if (!iLevel)
|
||||||
|
iLevel = 1;
|
||||||
|
Game.PathFinder.SetLevel(iLevel);
|
||||||
if (!Game.PathFinder.Find(iFromX, iFromY, iToX, iToY, SumPathLength(&PathInfo)))
|
if (!Game.PathFinder.Find(iFromX, iFromY, iToX, iToY, SumPathLength(&PathInfo)))
|
||||||
return C4Void();
|
return C4Void();
|
||||||
return PathInfo.ilen + Distance(PathInfo.ilx, PathInfo.ily, iToX, iToY);
|
return PathInfo.ilen + Distance(PathInfo.ilx, PathInfo.ily, iToX, iToY);
|
||||||
|
|
Loading…
Reference in New Issue