From 7d0c1f047a9e8ecbf8b3bb64bf811b3ec9b4f7af Mon Sep 17 00:00:00 2001 From: SkyMarshal Date: Fri, 6 Sep 2013 21:03:46 -0700 Subject: [PATCH] There we go, rebuilding works right now. Also has a slightly bugged verb that demonstrates how the rebuilding works, but you need to somehow prevent a zone from updating for it to show more than one "id" --- code/ZAS/Debug.dm | 79 +++++++++++++++++++++++++++++ code/ZAS/Functions.dm | 2 +- code/ZAS/ZAS_Zones.dm | 28 +++++----- code/modules/admin/verbs/mapping.dm | 1 + 4 files changed, 94 insertions(+), 16 deletions(-) diff --git a/code/ZAS/Debug.dm b/code/ZAS/Debug.dm index 69047b56b6..b2a2f4c9e5 100644 --- a/code/ZAS/Debug.dm +++ b/code/ZAS/Debug.dm @@ -131,3 +131,82 @@ zone/proc/DebugDisplay(client/client) var/turf/zloc = pick(Z.contents) client << "\red Illegal air datum shared by: [zloc.loc.name]" + +client/proc/TestZASRebuild() +// var/turf/turf = get_turf(mob) + var/zone/current_zone = mob.loc:zone + if(!current_zone) + src << "There is no zone there!" + return + + var/list/current_adjacents = list() + var/list/overlays = list() + var/adjacent_id + var/lowest_id + + var/list/identical_ids = list() + var/list/turfs = current_zone.contents.Copy() + var/current_identifier = 1 + + src << "[turfs[1]] = [turfs[turfs[1]]]" + + for(var/turf/simulated/current in turfs) + lowest_id = null + current_adjacents = list() + + for(var/direction in cardinal) + if( !(current.air_check_directions & direction)) + continue + var/turf/simulated/adjacent = get_step(current, direction) + if(turfs.Find(adjacent)) + current_adjacents += adjacent + adjacent_id = turfs[adjacent] + + if(adjacent_id && (!lowest_id || adjacent_id < lowest_id)) + lowest_id = adjacent_id + + if(!lowest_id) + lowest_id = current_identifier++ + identical_ids += lowest_id + overlays += image('icons/misc/debug_rebuild.dmi',, "[lowest_id]") + + for(var/turf/simulated/adjacent in current_adjacents) + adjacent_id = turfs[adjacent] + if(adjacent_id != lowest_id) + if(adjacent_id) + adjacent.overlays -= overlays[adjacent_id] + identical_ids[adjacent_id] = lowest_id + + turfs[adjacent] = lowest_id + adjacent.overlays += overlays[lowest_id] + + sleep(5) + + turfs[current] = lowest_id + current.overlays += overlays[lowest_id] + sleep(5) + + var/list/final_arrangement = list() + + for(var/turf/simulated/current in turfs) + current_identifier = identical_ids[turfs[current]] + current.overlays -= overlays[turfs[current]] + current.overlays += overlays[current_identifier] + sleep(5) + + if( current_identifier > final_arrangement.len ) + final_arrangement.len = current_identifier + final_arrangement[current_identifier] = list(current) + + else + final_arrangement[current_identifier] += current + + //lazy but fast + final_arrangement.Remove(null) + + src << final_arrangement.len + + for(var/turf/current in turfs) + current.overlays -= overlays + + return final_arrangement diff --git a/code/ZAS/Functions.dm b/code/ZAS/Functions.dm index 2b38abb228..4a1ffaaea2 100644 --- a/code/ZAS/Functions.dm +++ b/code/ZAS/Functions.dm @@ -157,7 +157,7 @@ proc/ZConnect(turf/simulated/A,turf/simulated/B) if(!A.zone || !B.zone) return if(A.zone == B.zone) return - if(A.CanPass(null, B, 0, 0) && A.zone.air.compare(B.zone.air)) + if(A.CanPass(null, B, 1.5, 1) && A.zone.air.compare(B.zone.air)) return ZMerge(A.zone,B.zone) //Ensure the connection isn't already made. diff --git a/code/ZAS/ZAS_Zones.dm b/code/ZAS/ZAS_Zones.dm index b51c5fbd69..37aabee83b 100644 --- a/code/ZAS/ZAS_Zones.dm +++ b/code/ZAS/ZAS_Zones.dm @@ -497,22 +497,22 @@ zone/proc/Rebuild() //Implements a two-pass connected component labeling algorithm to determine if the zone is, in fact, split. /zone/proc/IsolateContents() - var/turf/simulated/current - var/turf/simulated/adjacent var/list/current_adjacents = list() var/adjacent_id var/lowest_id var/list/identical_ids = list() - var/turfs = contents.Copy() + var/list/turfs = contents.Copy() var/current_identifier = 1 - for(current in turfs) + for(var/turf/simulated/current in turfs) lowest_id = null current_adjacents = list() - for(var/direction in current.air_check_directions) - adjacent = get_step(current, direction) + for(var/direction in cardinal) + if( !(current.air_check_directions & direction)) + continue + var/turf/simulated/adjacent = get_step(current, direction) if(adjacent in turfs) current_adjacents += adjacent adjacent_id = turfs[adjacent] @@ -522,21 +522,19 @@ zone/proc/Rebuild() if(!lowest_id) lowest_id = current_identifier++ + identical_ids += lowest_id - for(adjacent in current_adjacents) + for(var/turf/simulated/adjacent in current_adjacents) adjacent_id = turfs[adjacent] - if(adjacent_id) - if(identical_ids.len < adjacent_id) - identical_ids.len = adjacent_id - - identical_ids[adjacent_id] = lowest_id - - turfs[adjacent] = lowest_id + if(adjacent_id != lowest_id) + if(adjacent_id) + identical_ids[adjacent_id] = lowest_id + turfs[adjacent] = lowest_id turfs[current] = lowest_id var/list/final_arrangement = list() - for(current in turfs) + for(var/turf/simulated/current in turfs) current_identifier = identical_ids[turfs[current]] if( current_identifier > final_arrangement.len ) diff --git a/code/modules/admin/verbs/mapping.dm b/code/modules/admin/verbs/mapping.dm index 9872c5e5a0..76f1b42046 100644 --- a/code/modules/admin/verbs/mapping.dm +++ b/code/modules/admin/verbs/mapping.dm @@ -162,6 +162,7 @@ var/intercom_range_display_status = 0 src.verbs += /client/proc/Zone_Info src.verbs += /client/proc/Test_ZAS_Connection src.verbs += /client/proc/ZoneTick + src.verbs += /client/proc/TestZASRebuild //src.verbs += /client/proc/cmd_admin_rejuvenate feedback_add_details("admin_verb","mDV") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!