Changes astar from using a turf var to a proc list (#21947)

Fixes a runtime related to two bots trying to path through the same turf, and should improve the overall cost.

The runtime was caused by one bot pathing through a square, then getting check tick sleeped and the second both pathing through the same square.

Because the pnode lived on the turf it would assume that it had already seen that turf and try to resort the open heap, causing a bad index runtime as that turf was not in it's own open list
This commit is contained in:
Shadowlight213
2016-12-06 12:22:22 -08:00
committed by oranges
parent 4f181774e5
commit e70dd7590b
2 changed files with 15 additions and 16 deletions

View File

@@ -43,7 +43,6 @@ Actual Adjacent procs :
g = pg
h = ph
f = g + h
source.PNode = src
nt = pnt
/PathNode/proc/calc_f()
@@ -70,7 +69,7 @@ Actual Adjacent procs :
//the actual algorithm
/proc/AStar(caller, end, dist, maxnodes, maxnodedepth = 30, mintargetdist, adjacent = /turf/proc/reachableAdjacentTurfs, id=null, turf/exclude=null, simulated_only = 1)
var/list/pnodelist = list()
//sanitation
var/start = get_turf(caller)
if(!start)
@@ -123,23 +122,25 @@ Actual Adjacent procs :
continue
var/newg = cur.g + call(cur.source,dist)(T)
if(!T.PNode) //is not already in open list, so add it
open.Insert(new /PathNode(T,cur,newg,call(T,dist)(end),cur.nt+1))
var/PathNode/P = pnodelist[T]
if(!P)
//is not already in open list, so add it
var/PathNode/newnode = new /PathNode(T,cur,newg,call(T,dist)(end),cur.nt+1)
open.Insert(newnode)
pnodelist[T] = newnode
else //is already in open list, check if it's a better way from the current turf
if(newg < T.PNode.g)
T.PNode.prevNode = cur
T.PNode.g = newg
T.PNode.calc_f()
T.PNode.nt = cur.nt + 1
open.ReSort(T.PNode)//reorder the changed element in the list
if(newg < P.g)
P.prevNode = cur
P.g = newg
P.calc_f()
P.nt = cur.nt + 1
open.ReSort(P)//reorder the changed element in the list
CHECK_TICK
//cleaning after us
for(var/PathNode/PN in open.L)
PN.source.PNode = null
for(var/turf/T in closed)
T.PNode = null
pnodelist = null
//reverse the path to get it from start to finish
if(path)