From b1415003b40bc8b72147a923ae53b499d1c215af Mon Sep 17 00:00:00 2001 From: rockdtben Date: Mon, 25 Jul 2011 01:34:07 +0000 Subject: [PATCH] git-svn-id: http://tgstation13.googlecode.com/svn/trunk@1920 316c924e-a436-60f5-8080-3fe189b3f50e --- code/modules/power/cable.dm | 77 +++++++------------------------------ code/modules/power/power.dm | 1 + 2 files changed, 15 insertions(+), 63 deletions(-) diff --git a/code/modules/power/cable.dm b/code/modules/power/cable.dm index af82c7d3363..0d6ea353d2f 100644 --- a/code/modules/power/cable.dm +++ b/code/modules/power/cable.dm @@ -454,40 +454,14 @@ if(TC.netnum != netnum) var/datum/powernet/PN = powernets[netnum] var/datum/powernet/TPN = powernets[TC.netnum] - var/kingNetnum = netnum - if(PN.cables.len + PN.nodes.len < TPN.cables.len + TPN.nodes.len) - kingNetnum = TC.netnum - var/datum/powernet/temp = PN - PN = TPN - TPN = temp - for(var/obj/cable/C in TPN.cables) - TPN.cables -= C - PN.cables += C - C.netnum = kingNetnum - for(var/obj/machinery/power/M in TPN.nodes) - if(M.netnum < 0) // APCs have netnum=-1 so they don't count as network nodes directly - continue - TPN.nodes -= M - PN.nodes += M - M.netnum = kingNetnum - M.powernet = powernets[M.netnum] - TC.netnum = kingNetnum - TPN.cables -= TC - PN.cables += TC - for(var/obj/machinery/power/M in TB) - if(!netnum) - if(!M.netnum) - continue - else - netnum = M.netnum - var/datum/powernet/PN = powernets[netnum] - PN.nodes += src + + PN.merge_powernets(TPN) /obj/cable/proc/mergeConnectedNetworksOnTurf() - var/turf/TB - TB = loc - for(var/obj/cable/C in TB) + + for(var/obj/cable/C in loc) + if(C == src) continue if(netnum == 0) @@ -495,19 +469,13 @@ netnum = C.netnum PN.cables += src continue + var/datum/powernet/PN = powernets[netnum] var/datum/powernet/TPN = powernets[C.netnum] - var/kingNetnum = netnum - if(PN.cables.len + PN.nodes.len < TPN.cables.len + TPN.nodes.len) - kingNetnum = C.netnum - var/datum/powernet/temp = PN - PN = TPN - TPN = temp - TPN.cables -= C - PN.cables += C - C.netnum = kingNetnum - for(var/obj/machinery/power/M in TB) + PN.merge_powernets(TPN) + + for(var/obj/machinery/power/M in loc) if(M.netnum < 0) continue @@ -519,18 +487,10 @@ var/datum/powernet/PN = powernets[netnum] var/datum/powernet/TPN = powernets[M.netnum] - var/kingNetnum = netnum - if(PN.cables.len + PN.nodes.len < TPN.cables.len + TPN.nodes.len) - kingNetnum = M.netnum - var/datum/powernet/temp = PN - PN = TPN - TPN = temp - TPN.nodes -= M - PN.nodes += M - M.netnum = kingNetnum - M.powernet = powernets[M.netnum] - for(var/obj/machinery/power/apc/N in TB) + PN.merge_powernets(TPN) + + for(var/obj/machinery/power/apc/N in loc) var/obj/machinery/power/M M = N.terminal @@ -545,17 +505,8 @@ var/datum/powernet/PN = powernets[netnum] var/datum/powernet/TPN = powernets[M.netnum] - var/kingNetnum = netnum - if(PN.cables.len + PN.nodes.len < TPN.cables.len + TPN.nodes.len) - kingNetnum = M.netnum - var/datum/powernet/temp = PN - PN = TPN - TPN = temp - TPN.nodes -= M - PN.nodes += M - M.netnum = kingNetnum - M.powernet = powernets[M.netnum] + PN.merge_powernets(TPN) obj/cable/proc/cableColor(var/colorC) var/color_n = "red" @@ -570,4 +521,4 @@ obj/cable/proc/cableColor(var/colorC) if("green") icon = 'power_cond_green.dmi' if("blue") - icon = 'power_cond_blue.dmi' \ No newline at end of file + icon = 'power_cond_blue.dmi' diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index f3a3e946d42..2a566927d61 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -387,6 +387,7 @@ cables = P.cables for(var/obj/cable/C in cables) C.netnum = number + del P /obj/machinery/power/proc/connect_to_network() var/turf/T = src.loc