From aea3eda738a240759d972582f8ba588b4afb73cd Mon Sep 17 00:00:00 2001 From: SkyMarshal Date: Sun, 12 Aug 2012 19:33:21 -0700 Subject: [PATCH] Floodfill experimental improvement, lets hope it fixes crashes. --- code/ZAS/Functions.dm | 58 ++++++++++++++++--------------------------- code/ZAS/ZAS_Turfs.dm | 9 +++---- 2 files changed, 26 insertions(+), 41 deletions(-) diff --git a/code/ZAS/Functions.dm b/code/ZAS/Functions.dm index 81c9de64e0a..a6722899280 100644 --- a/code/ZAS/Functions.dm +++ b/code/ZAS/Functions.dm @@ -8,49 +8,35 @@ proc/FloodFill(turf/start) list open = list(start) closed = list() - doors = list() while(open.len) - for(var/turf/T in open) - //Stop if there's a door, even if it's open. These are handled by indirect connection. - if(!T.HasDoor()) + var/turf/T = pick(open) - for(var/d in cardinal) - var/turf/O = get_step(T,d) - //Simple pass check. - if(istype(O) && !(O in open) && !(O in doors) && !(O in closed) && O.ZCanPass(T)) - open += O - else - doors |= T - open -= T - continue + for(var/d in cardinal) + var/turf/O = get_step(T,d) - open -= T - closed += T + if(istype(O) && !(O in open) && !(O in closed) && O.ZCanPass(T)) - if(closed.len) - for(var/turf/T in doors) - var/force_connection = 1 - var/turf/simulated/O = get_step(T,NORTH) - if(O in closed) - closed += T - continue - else if(T.ZCanPass(O) && istype(O)) - force_connection = 0 + if(!T.HasDoor()) + open += O - O = get_step(T,WEST) - if(O in closed) - closed += T - continue - else if(force_connection && T.ZCanPass(O) && istype(O)) - force_connection = 0 + else + if(d == SOUTH || d == EAST) + //doors prefer connecting to zones to the north north or west + closed += O - if(force_connection) - O = get_step(T,SOUTH) - if(O in closed) - closed += T - else if((!T.ZCanPass(O) || !istype(O)) && get_step(T,EAST) in closed) - closed += T + else + //see if we need to force an attempted connection + //(there are no potentially viable zones to the north/west of the door) + var/turf/W = get_step(O, WEST) + var/turf/N = get_step(O, NORTH) + + if( (!istype(N) || !O.ZCanPass(N)) && (!istype(W) || !O.ZCanPass(W)) ) + //If it cannot connect either to the north or west, connect it! + closed += O + + open -= T + closed += T return closed diff --git a/code/ZAS/ZAS_Turfs.dm b/code/ZAS/ZAS_Turfs.dm index 92754fe92e2..c58ae4c658d 100644 --- a/code/ZAS/ZAS_Turfs.dm +++ b/code/ZAS/ZAS_Turfs.dm @@ -88,7 +88,7 @@ turf for(var/direction in cardinal) var/turf/simulated/floor/target = get_step(src,direction) if(istype(target)) - air_master.tiles_to_update.Add(target) + air_master.tiles_to_update |= target Del() if(active_hotspot) @@ -172,10 +172,9 @@ turf if(air_check_directions&direction) //I can connect air in this direction if(!CanPass(null, T, 0, 0)) //If either block air, we must look to see if the adjacent turfs need rebuilt. if(T.zone && !T.zone.rebuild) - for(var/direction2 in cardinal - direction) //Check all other directions for air that might be connected. - var/turf/simulated/NT = get_step(src, direction2) - if(NT && NT.zone && NT.zone == T.zone && !NT.HasDoor()) - T.zone.rebuild = 1 + var/turf/simulated/NT = get_step(src, reverse_direction(direction)) + if(istype(NT) && NT.zone && NT.zone == T.zone) + T.zone.rebuild = 1 else ZConnect(src,T)