From 2c1b2874ecb9bff3709d3de7368cec45548b72eb Mon Sep 17 00:00:00 2001 From: Vi3trice <80771500+Vi3trice@users.noreply.github.com> Date: Tue, 3 Jan 2023 01:07:40 -0500 Subject: [PATCH] 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 --- code/game/turfs/turf.dm | 102 ++++------------------------------ code/modules/fish/fishtank.dm | 2 +- 2 files changed, 11 insertions(+), 93 deletions(-) diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index c1c2c238364..c55913c0205 100644 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -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 diff --git a/code/modules/fish/fishtank.dm b/code/modules/fish/fishtank.dm index 9229dd483c8..b1ab9d3fc64 100644 --- a/code/modules/fish/fishtank.dm +++ b/code/modules/fish/fishtank.dm @@ -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))