Lua PathFinder: Difference between revisions

From Spring
Jump to navigationJump to search
Kloot (talk | contribs)
document the new LuaPathFinder callouts
Flozi (talk | contribs)
→PathNodeCosts: 104.0 - implement Path.GetPathNodeCosts
 
(8 intermediate revisions by 3 users not shown)
Line 10: Line 10:


== Path UserData Object ==
== Path UserData Object ==
'''Path:GetEstimatedPath'''
'''Path:GetPathWayPoints'''
   ( ) -> nil | {
   ( ) -> nil | {
     [1] = { x,y,z }, ...
     [1] = { x,y,z }, ...
Line 18: Line 18:
     [3] = startIdxOfDetailedEstimatedPath2,
     [3] = startIdxOfDetailedEstimatedPath2,
   }
   }
<font color="#55ee99">GetEstimatedPath() returns 2 tables:  1 table with the waypoints and 1 table with 3 indices (in the waypoint table) when a new (more lazy) pathfinding algorithm  begins.  So the waypoint table contains 3 different levels of details.</font>
<font color="#55ee99">GetPathWayPoints() returns 2 tables:  1 table with the waypoints and 1 table with 3 indices (in the waypoint table) when a new (more lazy) pathfinding algorithm  begins.  So the waypoint table contains 3 different levels of details.</font>


'''Path:Next'''
'''Path:Next'''
Line 24: Line 24:
     [, number radius = 0 ]
     [, number radius = 0 ]
   ) -> nil | number x, number y, number z
   ) -> nil | number x, number y, number z
<font color="#55ee99">Path:Next() returns the next waypoint in the path.  Unlike GetEstimatedPath() in which the resolution of the waypoints decreases, Next updates the path so the resolution will increase as it approaches the target.</font>
<font color="#55ee99">Path:Next() returns the next waypoint in the path.  Unlike GetPathWayPoints() in which the resolution of the waypoints decreases, Next updates the path so the resolution will increase as it approaches the target.</font>


Note that ''Path'' in ''Path:GetEstimatedPath'' and ''Path:Next'' is not part of the command, but rather a reference to the path Object created by ''Spring.RequestPath''.  It must match the path Object (case sensitive).
Note that ''Path'' in ''Path:GetPathWayPoints'' and ''Path:Next'' is not part of the command, but rather a reference to the path Object created by ''Spring.RequestPath''.  It must match the path Object (case sensitive).




The following functions allow manipulating the cost of nodes visited by the pathfinding algorithm through numbered additive overlays (arrays). Only one overlay can be active at once, but as many as desired may be created with '''InitPathNodeCostsArray'''. The active layer is set by '''SetPathNodeCosts'''. <font color="red" style="font-weight:600">IMPORTANT: the size of a newly created layer can be arbitrary, but ideally should match the heightmap dimensions. '''GetPathNodeCost''' ALWAYS takes heightmap coordinates as arguments, which are internally converted to the resolution of the active node-overlay (if any).</font>
==Further Reading==
 
{{forumlink|topic=22953&start=2|title=a forum thread}}
 
 
=PathNodeCosts=
 
The following functions allow manipulating the cost of nodes visited by the pathfinding algorithm through numbered additive overlays (arrays). Only one overlay can be active at once, but as many as desired may be created with '''InitPathNodeCostsArray'''. The active layer is set by '''SetPathNodeCosts'''.<br/>
 
<span class="note">NOTE: There are separate arrays for synced & unsynced! - don't ask when the unsynced one is used ... -</span>
 
<span class="warning">IMPORTANT: the size of a newly created layer can be arbitrary, but ideally should match the heightmap dimensions. '''GetPathNodeCost''' ALWAYS takes heightmap coordinates as arguments, which are internally converted to the resolution of the active node-overlay (if any).</span>


'''Path.InitPathNodeCostsArray'''
'''Path.InitPathNodeCostsArray'''
Line 38: Line 49:
'''Path.SetPathNodeCosts'''
'''Path.SetPathNodeCosts'''
   (number arrayID) -> boolean success
   (number arrayID) -> boolean success
'''Path.GetPathNodeCosts''' {{new|104.0}}
  (number arrayID) -> nil | table overlayCosts


'''Path.SetPathNodeCost'''
'''Path.SetPathNodeCost'''

Latest revision as of 12:46, 22 December 2017

Development < Lua Scripting < Lua PathFinder

PathFinder

Path.RequestPath

 ( string "MoveTypeName" | number moveID,
   number start_x, number start_y, number start_z,
   number end_x,   number end_y,   number end_z
   [, number radius = 8 ]
 ) -> nil | pathObject path (see below)

Path UserData Object

Path:GetPathWayPoints

 ( ) -> nil | {
    [1] = { x,y,z }, ...
  },{
    [1] = startIdxOfDetailedPath,
    [2] = startIdxOfDetailedEstimatedPath1,
    [3] = startIdxOfDetailedEstimatedPath2,
  }

GetPathWayPoints() returns 2 tables: 1 table with the waypoints and 1 table with 3 indices (in the waypoint table) when a new (more lazy) pathfinding algorithm begins. So the waypoint table contains 3 different levels of details.

Path:Next

 ( number pos_x, number pos_y, number pos_z,
   [, number radius = 0 ]
 ) -> nil | number x, number y, number z

Path:Next() returns the next waypoint in the path. Unlike GetPathWayPoints() in which the resolution of the waypoints decreases, Next updates the path so the resolution will increase as it approaches the target.

Note that Path in Path:GetPathWayPoints and Path:Next is not part of the command, but rather a reference to the path Object created by Spring.RequestPath. It must match the path Object (case sensitive).


Further Reading

a forum thread


PathNodeCosts

The following functions allow manipulating the cost of nodes visited by the pathfinding algorithm through numbered additive overlays (arrays). Only one overlay can be active at once, but as many as desired may be created with InitPathNodeCostsArray. The active layer is set by SetPathNodeCosts.

NOTE: There are separate arrays for synced & unsynced! - don't ask when the unsynced one is used ... -

IMPORTANT: the size of a newly created layer can be arbitrary, but ideally should match the heightmap dimensions. GetPathNodeCost ALWAYS takes heightmap coordinates as arguments, which are internally converted to the resolution of the active node-overlay (if any).

Path.InitPathNodeCostsArray

 (number arrayID, number numNodesX, number numNodesZ) -> boolean success

Path.FreePathNodeCostsArray

 (number arrayID) -> boolean success

Path.SetPathNodeCosts

 (number arrayID) -> boolean success

Path.GetPathNodeCosts New in version 104.0

 (number arrayID) -> nil | table overlayCosts

Path.SetPathNodeCost

 (number arrayID, number nodeArrayIndex, number cost) -> boolean success

Path.GetPathNodeCost

 (number arrayID, number heightMapX, number heightMapZ) -> number nodeCost