Clean up of AStar procs, rework one into an independant adjacent turf proc (#20011)

* Should have done that the first time around

* Update turf.dm

* Got the order reversed
This commit is contained in:
Vi3trice
2023-01-03 01:07:40 -05:00
committed by GitHub
parent 1c05e8aa5e
commit 2c1b2874ec
2 changed files with 11 additions and 93 deletions
+10 -92
View File
@@ -372,107 +372,25 @@
/turf/proc/burn_down()
return
/////////////////////////////////////////////////////////////////////////
// Navigation procs
// Used for A-star pathfinding
////////////////////////////////////////////////////////////////////////
///////////////////////////
//Cardinal only movements
///////////////////////////
// Returns the surrounding cardinal turfs with open links
// Including through doors openable with the ID
/turf/proc/CardinalTurfsWithAccess(obj/item/card/id/ID)
var/list/L = new()
var/turf/simulated/T
for(var/dir in GLOB.cardinal)
T = get_step(src, dir)
if(istype(T) && !T.density)
if(!LinkBlockedWithAccess(src, T, ID))
L.Add(T)
return L
// Returns the surrounding cardinal turfs with open links
// Don't check for ID, doors passable only if open
/turf/proc/CardinalTurfs()
var/list/L = new()
var/turf/simulated/T
for(var/dir in GLOB.cardinal)
T = get_step(src, dir)
if(istype(T) && !T.density)
if(!CanAtmosPass(T))
L.Add(T)
return L
///////////////////////////
//All directions movements
///////////////////////////
// Returns the surrounding simulated turfs with open links
// Including through doors openable with the ID
/turf/proc/AdjacentTurfsWithAccess(obj/item/card/id/ID = null, list/closed)//check access if one is passed
var/list/L = new()
var/turf/simulated/T
for(var/dir in GLOB.alldirs2) //arbitrarily ordered list to favor non-diagonal moves in case of ties
T = get_step(src, dir)
if(T in closed) //turf already proceeded in A*
continue
if(istype(T) && !T.density)
if(!LinkBlockedWithAccess(src, T, ID))
L.Add(T)
return L
//Idem, but don't check for ID and goes through open doors
/turf/proc/AdjacentTurfs(list/closed)
var/list/L = new()
var/turf/simulated/T
for(var/dir in GLOB.alldirs2) //arbitrarily ordered list to favor non-diagonal moves in case of ties
T = get_step(src, dir)
if(T in closed) //turf already proceeded by A*
continue
if(istype(T) && !T.density)
if(!CanAtmosPass(T))
L.Add(T)
return L
// check for all turfs, including space ones
/turf/proc/AdjacentTurfsSpace(obj/item/card/id/ID = null, list/closed)//check access if one is passed
/// Returns the adjacent turfs. Can check for density or cardinal directions only instead of all 8, or just dense turfs entirely. dense_only takes precedence over open_only.
/turf/proc/AdjacentTurfs(open_only = FALSE, cardinal_only = FALSE, dense_only = FALSE)
var/list/L = new()
var/turf/T
for(var/dir in GLOB.alldirs2) //arbitrarily ordered list to favor non-diagonal moves in case of ties
var/list/directions = cardinal_only ? GLOB.cardinal : GLOB.alldirs
for(var/dir in directions)
T = get_step(src, dir)
if(T in closed) //turf already proceeded by A*
if(!istype(T))
continue
if(istype(T) && !T.density)
if(!ID)
if(!CanAtmosPass(T))
L.Add(T)
else
if(!LinkBlockedWithAccess(src, T, ID))
L.Add(T)
if(dense_only && !T.density)
continue
if((open_only && T.density) && !dense_only)
continue
L.Add(T)
return L
//////////////////////////////
//Distance procs
//////////////////////////////
//Distance associates with all directions movement
/turf/proc/Distance(turf/T)
return get_dist(src, T)
// This Distance proc assumes that only cardinal movement is
// possible. It results in more efficient (CPU-wise) pathing
// for bots and anything else that only moves in cardinal dirs.
/turf/proc/Distance_cardinal(turf/T)
if(!src || !T)
return 0
return abs(src.x - T.x) + abs(src.y - T.y)
////////////////////////////////////////////////////
/turf/acid_act(acidpwr, acid_volume)
. = TRUE
var/acid_type = /obj/effect/acid
+1 -1
View File
@@ -377,7 +377,7 @@
if("tank") //Fishtank: Wets it's own tile and the 4 adjacent tiles (cardinal directions)
if(istype(T))
T.MakeSlippery()
for(var/turf/simulated/ST in T.CardinalTurfs())
for(var/turf/simulated/ST in T.AdjacentTurfs(open_only = TRUE, cardinal_only = TRUE))
ST.MakeSlippery()
if("wall") //Wall-tank: Wets it's own tile and the surrounding 8 tiles (3x3 square)
for(var/turf/simulated/ST in spiral_range_turfs(1, loc))