mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 10:21:11 +00:00
Actually fixes AStar runtimes (#26264)
This commit is contained in:
@@ -110,7 +110,7 @@ var/global/list/pathmakers = list()
|
||||
exclude = nexclude
|
||||
debug = ndebug
|
||||
path_count++
|
||||
PM_id = "PM_[path_count]"
|
||||
PM_id = "PM_[path_count]_\ref[owner]"
|
||||
open.Enqueue(new /PathNode(start,null,0,call(start,dist)(end),0,PM_id))
|
||||
pathmakers.Add(src)
|
||||
|
||||
@@ -119,6 +119,9 @@ var/global/list/pathmakers = list()
|
||||
astar_debug("owner no longer exists [owner?"owner is destroyed":"no owner"]")
|
||||
qdel(src)
|
||||
return FALSE
|
||||
if(gcDestroyed)
|
||||
astar_debug("We are being deleted")
|
||||
return FALSE
|
||||
if(get_turf(owner) != start)
|
||||
astar_debug("owner not in start position")
|
||||
fail()
|
||||
@@ -209,7 +212,7 @@ var/global/list/pathmakers = list()
|
||||
PNode.distance_from_start = call(cur.source,dist)(T)
|
||||
PNode.distance_from_end = newenddist
|
||||
PNode.calc_f()
|
||||
if(!open.ReSort(PNode.source))//reorder the changed element in the list
|
||||
if(!open.ReSort(PNode))//reorder the changed element in the list
|
||||
astar_debug("failed to reorder, requeuing")
|
||||
open.Enqueue(PNode)
|
||||
astar_debug("open:[open.List().len]")
|
||||
|
||||
@@ -145,7 +145,7 @@ var/list/diseases = typesof(/datum/disease) - /datum/disease
|
||||
|
||||
if(isturf(source.loc))
|
||||
for(var/mob/living/carbon/M in oview(check_range, source))
|
||||
if(isturf(M.loc) && quick_AStar(source.loc, M, /turf/proc/AdjacentTurfs, /turf/proc/Distance, check_range))
|
||||
if(isturf(M.loc) && quick_AStar(source.loc, M, /turf/proc/AdjacentTurfs, /turf/proc/Distance, check_range, reference="\ref[src]"))
|
||||
M.contract_disease(src, 0, 1, force_spread)
|
||||
|
||||
/datum/disease/proc/process()
|
||||
|
||||
@@ -194,7 +194,7 @@ proc/AStar(source, proc_to_call, start,end,adjacent,dist,maxnodes,maxnodedepth =
|
||||
// The main difference is that it'll be caculated immediately and transmitted to the bot rather than waiting for the path to be made.
|
||||
// Currently, security bots are using this method to chase suspsects.
|
||||
// You MUST have the start and end be turfs.
|
||||
proc/quick_AStar(start,end,adjacent,dist,maxnodes,maxnodedepth = 30,mintargetdist,minnodedist,id=null, var/turf/exclude=null)
|
||||
proc/quick_AStar(start,end,adjacent,dist,maxnodes,maxnodedepth = 30,mintargetdist,minnodedist,id=null, var/turf/exclude=null, var/reference)
|
||||
ASSERT(!istype(end,/area)) //Because yeah some things might be doing this and we want to know what
|
||||
var/PriorityQueue/open = new /PriorityQueue(/proc/PathWeightCompare) //the open list, ordered using the PathWeightCompare proc, from lower f to higher
|
||||
var/list/closed = new() //the closed list
|
||||
@@ -241,28 +241,28 @@ proc/quick_AStar(start,end,adjacent,dist,maxnodes,maxnodedepth = 30,mintargetdis
|
||||
continue
|
||||
|
||||
var/newenddist = call(T,dist)(end)
|
||||
var/PathNode/PNode = T.FindPathNode("unique")
|
||||
var/PathNode/PNode = T.FindPathNode("unique_[reference]")
|
||||
if(!PNode) //is not already in open list, so add it
|
||||
open.Enqueue(new /PathNode(T,cur,call(cur.source,dist)(T),newenddist,cur.nodecount+1,"unique"))
|
||||
open.Enqueue(new /PathNode(T,cur,call(cur.source,dist)(T),newenddist,cur.nodecount+1,"unique_[reference]"))
|
||||
else //is already in open list, check if it's a better way from the current turf
|
||||
if(newenddist < PNode.distance_from_end)
|
||||
|
||||
PNode.prevNode = cur
|
||||
PNode.distance_from_start = newenddist
|
||||
PNode.calc_f()
|
||||
open.ReSort(PNode.source)//reorder the changed element in the list
|
||||
open.ReSort(PNode)//reorder the changed element in the list
|
||||
|
||||
}
|
||||
|
||||
//cleanup
|
||||
for(var/PathNode/PN in open.L)
|
||||
PN.source.PathNodes["unique"] = null
|
||||
PN.source.PathNodes.Remove("unique")
|
||||
PN.source.PathNodes["unique_[reference]"] = null
|
||||
PN.source.PathNodes.Remove("unique_[reference]")
|
||||
qdel(PN)
|
||||
for(var/turf/T in closed)
|
||||
var/PathNode/PN = T.FindPathNode("unique")
|
||||
T.PathNodes["unique"] = null
|
||||
T.PathNodes.Remove("unique")
|
||||
var/PathNode/PN = T.FindPathNode("unique_[reference]")
|
||||
T.PathNodes["unique_[reference]"] = null
|
||||
T.PathNodes.Remove("unique_[reference]")
|
||||
qdel(PN)
|
||||
|
||||
//if the path is longer than maxnodes, then don't return it
|
||||
|
||||
@@ -960,7 +960,7 @@ var/list/datum/dna/hivemind_bank = list()
|
||||
return 0 //One is inside, the other is outside something.
|
||||
if(sting_range < 2)
|
||||
return Adjacent(M)
|
||||
if(quick_AStar(src.loc, M.loc, /turf/proc/AdjacentTurfs, /turf/proc/Distance, sting_range)) //If a path exists, good!
|
||||
if(quick_AStar(src.loc, M.loc, /turf/proc/AdjacentTurfs, /turf/proc/Distance, sting_range, reference="\ref[src]")) //If a path exists, good!
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
@@ -379,7 +379,7 @@
|
||||
log_astar_beacon("[new_destination]")
|
||||
if ((get_dist(src, target) < 13) && !(flags & BOT_NOT_CHASING)) // For beepers and ED209
|
||||
// IMPORTANT: Quick AStar only takes TURFS as arguments.
|
||||
path = quick_AStar(src.loc, get_turf(target), /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, max(10,get_dist(src,target)*3), id=botcard, exclude=avoid)
|
||||
path = quick_AStar(src.loc, get_turf(target), /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, max(10,get_dist(src,target)*3), id=botcard, exclude=avoid, reference="\ref[src]")
|
||||
if (!path) // Important because if quick_Astar fails, it returns null, not an empty list.
|
||||
path = list()
|
||||
return TRUE
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
if(locs.len >= 3) //we found 3 locations and thats all we need
|
||||
break
|
||||
var/turf/T = get_step(user, direction) //getting a loc in that direction
|
||||
if(quick_AStar(user.loc, T, /turf/proc/AdjacentTurfs, /turf/proc/Distance, 1)) // if a path exists, so no dense objects in the way its valid salid
|
||||
if(quick_AStar(user.loc, T, /turf/proc/AdjacentTurfs, /turf/proc/Distance, 1, reference="\ref[src]")) // if a path exists, so no dense objects in the way its valid salid
|
||||
locs += T
|
||||
else
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ var/list/pitbulls_exclude_kinlist = list() //all pitbulls go in here so pitbulls
|
||||
if(locs.len >= 3) //we found 3 locations and thats all we need
|
||||
break
|
||||
var/turf/T = get_step(user, direction) //getting a loc in that direction
|
||||
if(quick_AStar(get_turf(user), T, /turf/proc/AdjacentTurfs, /turf/proc/Distance, 1)) // if a path exists, so no dense objects in the way its valid salid
|
||||
if(quick_AStar(get_turf(user), T, /turf/proc/AdjacentTurfs, /turf/proc/Distance, 1, reference="\ref[src]")) // if a path exists, so no dense objects in the way its valid salid
|
||||
locs += T
|
||||
|
||||
if(locs.len < 3) //if we only found one location, spawn more on top of our tile so we dont get stacked pitbulls
|
||||
|
||||
Reference in New Issue
Block a user