mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-22 19:47:22 +01:00
Merge tgstation r4633 into bs12_with_tgport
Conflicts: code/defines/obj/costume.dm code/game/gamemodes/cult/runes.dm code/game/machinery/computer/communications.dm code/game/machinery/telecomms/broadcaster.dm code/game/objects/structures/crates_lockers/closets/fitness.dm code/modules/mob/living/simple_animal/life.dm code/modules/mob/living/simple_animal/parrot.dm code/modules/power/power.dm code/modules/power/switch.dm Signed-off-by: Cael_Aislinn <cael_aislinn@yahoo.com.au>
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
var/main_status = 0
|
||||
var/wiresexposed = 0
|
||||
var/apcwires = 15
|
||||
netnum = -1 // set so that APCs aren't found as powernet nodes
|
||||
powernet = 0 // set so that APCs aren't found as powernet nodes //Hackish, Horrible, was like this before I changed it :(
|
||||
var/malfhack = 0 //New var for my changes to AI malf. --NeoFite
|
||||
var/mob/living/silicon/ai/malfai = null //See above --NeoFite
|
||||
// luminosity = 1
|
||||
|
||||
+66
-108
@@ -35,21 +35,13 @@
|
||||
|
||||
NC.mergeConnectedNetworks(NC.d2)
|
||||
NC.mergeConnectedNetworksOnTurf()
|
||||
if(netnum == 0 && NC.netnum == 0)
|
||||
var/datum/powernet/PN = new()
|
||||
|
||||
PN.number = powernets.len + 1
|
||||
powernets += PN
|
||||
NC.netnum = PN.number
|
||||
netnum = PN.number
|
||||
PN.cables += NC
|
||||
PN.nodes += src
|
||||
powernet = PN
|
||||
else if(netnum == 0)
|
||||
netnum = NC.netnum
|
||||
var/datum/powernet/PN = powernets[netnum]
|
||||
powernet = PN
|
||||
PN.nodes += src
|
||||
if(powernet==null)
|
||||
if(NC.powernet == null)
|
||||
NC.powernet = new()
|
||||
powernets += NC.powernet
|
||||
NC.powernet.cables += NC
|
||||
powernet = NC.powernet
|
||||
NC.powernet.nodes += src
|
||||
NC.mergeConnectedNetworksOnTurf()
|
||||
|
||||
coil.use(1)
|
||||
@@ -82,15 +74,11 @@
|
||||
cable_list += src
|
||||
|
||||
|
||||
/obj/structure/cable/Del() // called when a cable is deleted
|
||||
|
||||
if(!defer_powernet_rebuild) // set if network will be rebuilt manually
|
||||
if(netnum && powernets && (powernets.len >= netnum) && (netnum >= 1) ) // make sure cable & powernet data is valid
|
||||
var/datum/powernet/PN = powernets[netnum]
|
||||
PN.cut_cable(src) // updated the powernets
|
||||
/obj/structure/cable/Del() // called when a cable is deleted
|
||||
if(!defer_powernet_rebuild) // set if network will be rebuilt manually
|
||||
if(powernet)
|
||||
powernet.cut_cable(src) // update the powernets
|
||||
cable_list -= src
|
||||
// else
|
||||
// if(Debug) diary << "Defered cable deletion at [x],[y]: #[netnum]"
|
||||
..() // then go ahead and delete the cable
|
||||
|
||||
/obj/structure/cable/hide(var/i)
|
||||
@@ -107,11 +95,8 @@
|
||||
|
||||
|
||||
// returns the powernet this cable belongs to
|
||||
/obj/structure/cable/proc/get_powernet()
|
||||
var/datum/powernet/PN // find the powernet
|
||||
if(netnum && powernets && powernets.len >= netnum)
|
||||
PN = powernets[netnum]
|
||||
return PN
|
||||
/obj/structure/cable/proc/get_powernet() //TODO: remove this as it is obsolete
|
||||
return powernet
|
||||
|
||||
/obj/structure/cable/attack_hand(mob/user)
|
||||
if(ishuman(user))
|
||||
@@ -127,9 +112,9 @@
|
||||
|
||||
if(istype(W, /obj/item/weapon/wirecutters))
|
||||
|
||||
if(power_switch)
|
||||
user << "\red This piece of cable is tied to a power switch. Flip the switch to remove it."
|
||||
return
|
||||
// if(power_switch)
|
||||
// user << "\red This piece of cable is tied to a power switch. Flip the switch to remove it."
|
||||
// return
|
||||
|
||||
if (shock(user, 50))
|
||||
return
|
||||
@@ -174,7 +159,7 @@
|
||||
/obj/structure/cable/proc/shock(mob/user, prb, var/siemens_coeff = 1.0)
|
||||
if(!prob(prb))
|
||||
return 0
|
||||
if (electrocute_mob(user, powernets[src.netnum], src, siemens_coeff))
|
||||
if (electrocute_mob(user, powernet, src, siemens_coeff))
|
||||
var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread
|
||||
s.set_up(5, 1, src)
|
||||
s.start()
|
||||
@@ -334,11 +319,9 @@
|
||||
C.add_fingerprint(user)
|
||||
C.updateicon()
|
||||
|
||||
var/datum/powernet/PN = new()
|
||||
PN.number = powernets.len + 1
|
||||
powernets += PN
|
||||
C.netnum = PN.number
|
||||
PN.cables += C
|
||||
C.powernet = new()
|
||||
powernets += C.powernet
|
||||
C.powernet.cables += C
|
||||
|
||||
C.mergeConnectedNetworks(C.d2)
|
||||
C.mergeConnectedNetworksOnTurf()
|
||||
@@ -399,11 +382,11 @@
|
||||
NC.add_fingerprint()
|
||||
NC.updateicon()
|
||||
|
||||
NC.netnum = C.netnum
|
||||
var/datum/powernet/PN = powernets[C.netnum]
|
||||
PN.cables += NC
|
||||
NC.mergeConnectedNetworks(NC.d2)
|
||||
NC.mergeConnectedNetworksOnTurf()
|
||||
if(C.powernet)
|
||||
NC.powernet = C.powernet
|
||||
NC.powernet.cables += NC
|
||||
NC.mergeConnectedNetworks(NC.d2)
|
||||
NC.mergeConnectedNetworksOnTurf()
|
||||
use(1)
|
||||
if (NC.shock(user, 50))
|
||||
if (prob(50)) //fail
|
||||
@@ -453,7 +436,7 @@
|
||||
|
||||
/obj/structure/cable/proc/mergeConnectedNetworks(var/direction)
|
||||
var/turf/TB
|
||||
if((d1 == direction || d2 == direction) != 1)
|
||||
if(!(d1 == direction || d2 == direction))
|
||||
return
|
||||
TB = get_step(src, direction)
|
||||
|
||||
@@ -469,79 +452,54 @@
|
||||
|
||||
if(TC.d1 == fdir || TC.d2 == fdir)
|
||||
|
||||
if(!netnum)
|
||||
var/datum/powernet/PN = powernets[TC.netnum]
|
||||
netnum = TC.netnum
|
||||
PN = powernets[netnum]
|
||||
PN.cables += src
|
||||
continue
|
||||
if(!TC.powernet)
|
||||
TC.powernet = new()
|
||||
powernets += TC.powernet
|
||||
TC.powernet.cables += TC
|
||||
|
||||
if(powernet)
|
||||
merge_powernets(powernet,TC.powernet)
|
||||
else
|
||||
powernet = TC.powernet
|
||||
powernet.cables += src
|
||||
|
||||
|
||||
if(TC.netnum != netnum)
|
||||
var/datum/powernet/PN = powernets[netnum]
|
||||
var/datum/powernet/TPN = powernets[TC.netnum]
|
||||
|
||||
PN.merge_powernets(TPN)
|
||||
|
||||
/obj/structure/cable/proc/mergeConnectedNetworksOnTurf()
|
||||
if(!powernet)
|
||||
powernet = new()
|
||||
powernets += powernet
|
||||
powernet.cables += src
|
||||
|
||||
for(var/AM in loc)
|
||||
if(istype(AM,/obj/structure/cable))
|
||||
var/obj/structure/cable/C = AM
|
||||
if(C.powernet == powernet) continue
|
||||
if(C.powernet)
|
||||
merge_powernets(powernet, C.powernet)
|
||||
else
|
||||
C.powernet = powernet
|
||||
powernet.cables += C
|
||||
|
||||
for(var/obj/structure/cable/C in loc)
|
||||
else if(istype(AM,/obj/machinery/power/apc))
|
||||
var/obj/machinery/power/apc/N = AM
|
||||
if(!N.terminal) continue
|
||||
if(N.terminal.powernet)
|
||||
merge_powernets(powernet, N.terminal.powernet)
|
||||
else
|
||||
N.terminal.powernet = powernet
|
||||
powernet.nodes += N.terminal
|
||||
|
||||
else if(istype(AM,/obj/machinery/power))
|
||||
var/obj/machinery/power/M = AM
|
||||
if(M.powernet == powernet) continue
|
||||
if(M.powernet)
|
||||
merge_powernets(powernet, M.powernet)
|
||||
else
|
||||
M.powernet = powernet
|
||||
powernet.nodes += M
|
||||
|
||||
if(!C)
|
||||
continue
|
||||
|
||||
if(C == src)
|
||||
continue
|
||||
if(netnum == 0)
|
||||
var/datum/powernet/PN = powernets[C.netnum]
|
||||
netnum = C.netnum
|
||||
PN.cables += src
|
||||
continue
|
||||
|
||||
var/datum/powernet/PN = powernets[netnum]
|
||||
var/datum/powernet/TPN = powernets[C.netnum]
|
||||
|
||||
PN.merge_powernets(TPN)
|
||||
|
||||
for(var/obj/machinery/power/M in loc)
|
||||
|
||||
if(!M)
|
||||
continue
|
||||
|
||||
if(!M.netnum)
|
||||
var/datum/powernet/PN = powernets[netnum]
|
||||
PN.nodes += M
|
||||
M.netnum = netnum
|
||||
M.powernet = powernets[M.netnum]
|
||||
|
||||
if(M.netnum < 0)
|
||||
continue
|
||||
|
||||
var/datum/powernet/PN = powernets[netnum]
|
||||
var/datum/powernet/TPN = powernets[M.netnum]
|
||||
|
||||
PN.merge_powernets(TPN)
|
||||
|
||||
for(var/obj/machinery/power/apc/N in loc)
|
||||
if(!N) continue
|
||||
|
||||
var/obj/machinery/power/M
|
||||
M = N.terminal
|
||||
if(!M) continue
|
||||
|
||||
if(!M.netnum)
|
||||
if(!netnum)continue
|
||||
var/datum/powernet/PN = powernets[netnum]
|
||||
PN.nodes += M
|
||||
M.netnum = netnum
|
||||
M.powernet = powernets[M.netnum]
|
||||
continue
|
||||
|
||||
var/datum/powernet/PN = powernets[netnum]
|
||||
var/datum/powernet/TPN = powernets[M.netnum]
|
||||
|
||||
PN.merge_powernets(TPN)
|
||||
|
||||
obj/structure/cable/proc/cableColor(var/colorC)
|
||||
var/color_n = "red"
|
||||
|
||||
+166
-213
@@ -3,7 +3,6 @@
|
||||
icon = 'icons/obj/power.dmi'
|
||||
anchored = 1.0
|
||||
var/datum/powernet/powernet = null
|
||||
var/netnum = 0
|
||||
var/directwired = 1 // by default, power machines are connected by a cable in a neighbouring turf
|
||||
// if set to 0, requires a 0-X cable on this turf
|
||||
use_power = 0
|
||||
@@ -43,7 +42,7 @@
|
||||
if(!A || !isarea(A) || !A.master)
|
||||
return 0 // if not, then not powered
|
||||
|
||||
return A.master.powered(power_channel) // return power status of the area
|
||||
return A.master.powered(chan) // return power status of the area
|
||||
|
||||
// increment the power usage stats for an area
|
||||
|
||||
@@ -72,263 +71,213 @@
|
||||
// rebuild all power networks from scratch
|
||||
|
||||
/proc/makepowernets()
|
||||
|
||||
var/netcount = 0
|
||||
powernets = list()
|
||||
for(var/datum/powernet/PN in powernets)
|
||||
del(PN)
|
||||
powernets.Cut()
|
||||
|
||||
for(var/obj/structure/cable/PC in cable_list)
|
||||
PC.netnum = 0
|
||||
for(var/obj/machinery/power/M in machines)
|
||||
if(M.netnum >=0)
|
||||
M.netnum = 0
|
||||
|
||||
|
||||
for(var/obj/structure/cable/PC in cable_list)
|
||||
if(!PC.netnum)
|
||||
PC.netnum = ++netcount
|
||||
|
||||
if(Debug) world.log << "Starting mpn at [PC.x],[PC.y] ([PC.d1]/[PC.d2]) #[netcount]"
|
||||
powernet_nextlink(PC, PC.netnum)
|
||||
|
||||
if(Debug) world.log << "[netcount] powernets found"
|
||||
|
||||
for(var/L = 1 to netcount)
|
||||
var/datum/powernet/PN = new()
|
||||
powernets += PN
|
||||
PN.number = L
|
||||
if(!PC.powernet)
|
||||
PC.powernet = new()
|
||||
powernets += PC.powernet
|
||||
// if(Debug) world.log << "Starting mpn at [PC.x],[PC.y] ([PC.d1]/[PC.d2])"
|
||||
powernet_nextlink(PC,PC.powernet)
|
||||
|
||||
// if(Debug) world.log << "[powernets.len] powernets found"
|
||||
|
||||
for(var/obj/structure/cable/C in cable_list)
|
||||
var/datum/powernet/PN = powernets[C.netnum]
|
||||
PN.cables += C
|
||||
if(!C.powernet) continue
|
||||
C.powernet.cables += C
|
||||
|
||||
for(var/obj/machinery/power/M in machines)
|
||||
if(M.netnum<=0) // APCs have netnum=-1 so they don't count as network nodes directly
|
||||
continue
|
||||
|
||||
M.powernet = powernets[M.netnum]
|
||||
if(!M.powernet) continue // APCs have powernet=0 so they don't count as network nodes directly
|
||||
M.powernet.nodes += M
|
||||
|
||||
|
||||
// returns a list of all power-related objects (nodes, cable, junctions) in turf,
|
||||
// excluding source, that match the direction d
|
||||
// if unmarked==1, only return those with netnum==0
|
||||
|
||||
// if unmarked==1, only return those with no powernet
|
||||
/proc/power_list(var/turf/T, var/source, var/d, var/unmarked=0)
|
||||
var/list/result = list()
|
||||
var/fdir = (!d)? 0 : turn(d, 180) // the opposite direction to d (or 0 if d==0)
|
||||
. = list()
|
||||
var/fdir = (!d)? 0 : turn(d, 180) // the opposite direction to d (or 0 if d==0)
|
||||
// world.log << "d=[d] fdir=[fdir]"
|
||||
for(var/AM in T)
|
||||
if(AM == source) continue //we don't want to return source
|
||||
|
||||
for(var/obj/machinery/power/P in T)
|
||||
if(P.netnum < 0) // exclude APCs
|
||||
continue
|
||||
if(istype(AM,/obj/machinery/power))
|
||||
var/obj/machinery/power/P = AM
|
||||
if(P.powernet == 0) continue // exclude APCs which have powernet=0
|
||||
|
||||
if(P.directwired) // true if this machine covers the whole turf (so can be joined to a cable on neighbour turf)
|
||||
if(!unmarked || !P.netnum)
|
||||
result += P
|
||||
else if(d == 0) // otherwise, need a 0-X cable on same turf to connect
|
||||
if(!unmarked || !P.netnum)
|
||||
result += P
|
||||
if(!unmarked || !P.powernet) //if unmarked=1 we only return things with no powernet
|
||||
if(P.directwired || (d == 0))
|
||||
. += P
|
||||
|
||||
else if(istype(AM,/obj/structure/cable))
|
||||
var/obj/structure/cable/C = AM
|
||||
|
||||
for(var/obj/structure/cable/C in T)
|
||||
if(C.d1 == fdir || C.d2 == fdir)
|
||||
if(!unmarked || !C.netnum)
|
||||
result += C
|
||||
|
||||
result -= source
|
||||
|
||||
return result
|
||||
if(!unmarked || !C.powernet)
|
||||
if(C.d1 == fdir || C.d2 == fdir)
|
||||
. += C
|
||||
return .
|
||||
|
||||
|
||||
/obj/structure/cable/proc/get_connections()
|
||||
. = list() // this will be a list of all connected power objects
|
||||
var/turf/T = loc
|
||||
|
||||
var/list/res = list() // this will be a list of all connected power objects
|
||||
|
||||
var/turf/T
|
||||
if(!d1)
|
||||
T = src.loc // if d1=0, same turf as src
|
||||
else
|
||||
T = get_step(src, d1)
|
||||
|
||||
res += power_list(T, src , d1, 1)
|
||||
if(d1) T = get_step(src, d1)
|
||||
if(T) . += power_list(T, src, d1, 1)
|
||||
|
||||
T = get_step(src, d2)
|
||||
if(T) . += power_list(T, src, d2, 1)
|
||||
|
||||
res += power_list(T, src, d2, 1)
|
||||
|
||||
return res
|
||||
return .
|
||||
|
||||
|
||||
/obj/machinery/power/proc/get_connections()
|
||||
if(!directwired) return get_indirect_connections()
|
||||
|
||||
if(!directwired)
|
||||
return get_indirect_connections()
|
||||
|
||||
var/list/res = list()
|
||||
. = list()
|
||||
var/cdir
|
||||
|
||||
for(var/turf/T in orange(1, src))
|
||||
|
||||
cdir = get_dir(T, src)
|
||||
for(var/card in cardinal)
|
||||
var/turf/T = get_step(loc,card)
|
||||
cdir = get_dir(T,loc)
|
||||
|
||||
for(var/obj/structure/cable/C in T)
|
||||
|
||||
if(C.netnum)
|
||||
continue
|
||||
|
||||
if(C.powernet) continue
|
||||
if(C.d1 == cdir || C.d2 == cdir)
|
||||
res += C
|
||||
|
||||
return res
|
||||
. += C
|
||||
return .
|
||||
|
||||
/obj/machinery/power/proc/get_indirect_connections()
|
||||
|
||||
var/list/res = list()
|
||||
|
||||
for(var/obj/structure/cable/C in src.loc)
|
||||
|
||||
if(C.netnum)
|
||||
continue
|
||||
|
||||
. = list()
|
||||
for(var/obj/structure/cable/C in loc)
|
||||
if(C.powernet) continue
|
||||
if(C.d1 == 0)
|
||||
res += C
|
||||
|
||||
return res
|
||||
. += C
|
||||
return .
|
||||
|
||||
|
||||
/proc/powernet_nextlink(var/obj/O, var/num)
|
||||
|
||||
/proc/powernet_nextlink(var/obj/O, var/datum/powernet/PN)
|
||||
var/list/P
|
||||
|
||||
//world.log << "start: [O] at [O.x].[O.y]"
|
||||
|
||||
|
||||
while(1)
|
||||
|
||||
if( istype(O, /obj/structure/cable) )
|
||||
if( istype(O,/obj/structure/cable) )
|
||||
var/obj/structure/cable/C = O
|
||||
|
||||
C.netnum = num
|
||||
C.powernet = PN
|
||||
P = C.get_connections()
|
||||
|
||||
else if( istype(O, /obj/machinery/power) )
|
||||
|
||||
else if( istype(O,/obj/machinery/power) )
|
||||
var/obj/machinery/power/M = O
|
||||
|
||||
M.netnum = num
|
||||
M.powernet = PN
|
||||
P = M.get_connections()
|
||||
|
||||
if(P.len == 0)
|
||||
//world.log << "end1"
|
||||
return
|
||||
if(P.len == 0) return
|
||||
|
||||
O = P[1]
|
||||
|
||||
|
||||
for(var/L = 2 to P.len)
|
||||
|
||||
powernet_nextlink(P[L], num)
|
||||
|
||||
//world.log << "next: [O] at [O.x].[O.y]"
|
||||
powernet_nextlink(P[L], PN)
|
||||
|
||||
|
||||
// cut a powernet at this cable object
|
||||
|
||||
/datum/powernet/proc/cut_cable(var/obj/structure/cable/C)
|
||||
|
||||
var/turf/T1 = C.loc
|
||||
if(C.d1)
|
||||
T1 = get_step(C, C.d1)
|
||||
if(!T1) return
|
||||
|
||||
var/turf/T2
|
||||
if(C.d2) T2 = get_step(T1, C.d2)
|
||||
if(C.d1) T1 = get_step(T1, C.d1)
|
||||
|
||||
var/turf/T2 = get_step(C, C.d2)
|
||||
|
||||
var/list/P1 = power_list(T1, C, C.d1) // what joins on to cut cable in dir1
|
||||
|
||||
var/list/P2 = power_list(T2, C, C.d2) // what joins on to cut cable in dir2
|
||||
|
||||
if(Debug)
|
||||
for(var/obj/O in P1)
|
||||
world.log << "P1: [O] at [O.x] [O.y] : [istype(O, /obj/structure/cable) ? "[O:d1]/[O:d2]" : null] "
|
||||
for(var/obj/O in P2)
|
||||
world.log << "P2: [O] at [O.x] [O.y] : [istype(O, /obj/structure/cable) ? "[O:d1]/[O:d2]" : null] "
|
||||
// if(Debug)
|
||||
// for(var/obj/O in P1)
|
||||
// world.log << "P1: [O] at [O.x] [O.y] : [istype(O, /obj/structure/cable) ? "[O:d1]/[O:d2]" : null] "
|
||||
// for(var/obj/O in P2)
|
||||
// world.log << "P2: [O] at [O.x] [O.y] : [istype(O, /obj/structure/cable) ? "[O:d1]/[O:d2]" : null] "
|
||||
|
||||
|
||||
|
||||
if(P1.len == 0 || P2.len ==0) // if nothing in either list, then the cable was an endpoint
|
||||
// no need to rebuild the powernet, just remove cut cable from the list
|
||||
cables -= C
|
||||
if(Debug) world.log << "Was end of cable"
|
||||
if(P1.len == 0 || P2.len == 0)//if nothing in either list, then the cable was an endpoint no need to rebuild the powernet,
|
||||
cables -= C //just remove cut cable from the list
|
||||
// if(Debug) world.log << "Was end of cable"
|
||||
return
|
||||
|
||||
// zero the netnum of all cables & nodes in this powernet
|
||||
|
||||
for(var/obj/structure/cable/OC in cables)
|
||||
OC.netnum = 0
|
||||
for(var/obj/machinery/power/OM in nodes)
|
||||
OM.netnum = 0
|
||||
|
||||
//null the powernet reference of all cables & nodes in this powernet
|
||||
var/i=1
|
||||
while(i<=cables.len)
|
||||
var/obj/structure/cable/Cable = cables[i]
|
||||
if(Cable)
|
||||
Cable.powernet = null
|
||||
if(Cable == C)
|
||||
cables.Cut(i,i+1)
|
||||
continue
|
||||
i++
|
||||
i=1
|
||||
while(i<=nodes.len)
|
||||
var/obj/machinery/power/Node = nodes[i]
|
||||
if(Node) Node.powernet = null
|
||||
i++
|
||||
|
||||
// remove the cut cable from the network
|
||||
C.netnum = -1
|
||||
// C.netnum = -1
|
||||
C.loc = null
|
||||
cables -= C
|
||||
|
||||
|
||||
|
||||
powernet_nextlink(P1[1], number) // propagate network from 1st side of cable, using current netnum
|
||||
powernet_nextlink(P1[1], src) // propagate network from 1st side of cable, using current netnum //TODO?
|
||||
|
||||
// now test to see if propagation reached to the other side
|
||||
// if so, then there's a loop in the network
|
||||
|
||||
var/notlooped = 0
|
||||
for(var/obj/O in P2)
|
||||
for(var/O in P2)
|
||||
if( istype(O, /obj/machinery/power) )
|
||||
var/obj/machinery/power/OM = O
|
||||
if(OM.netnum != number)
|
||||
var/obj/machinery/power/Machine = O
|
||||
if(Machine.powernet != src)
|
||||
notlooped = 1
|
||||
break
|
||||
else if( istype(O, /obj/structure/cable) )
|
||||
var/obj/structure/cable/OC = O
|
||||
if(OC.netnum != number)
|
||||
var/obj/structure/cable/Cable = O
|
||||
if(Cable.powernet != src)
|
||||
notlooped = 1
|
||||
break
|
||||
|
||||
if(notlooped)
|
||||
|
||||
// not looped, so make a new powernet
|
||||
|
||||
var/datum/powernet/PN = new()
|
||||
powernets += PN
|
||||
PN.number = powernets.len
|
||||
|
||||
if(Debug) world.log << "Was not looped: spliting PN#[number] ([cables.len];[nodes.len])"
|
||||
// if(Debug) world.log << "Was not looped: spliting PN#[number] ([cables.len];[nodes.len])"
|
||||
|
||||
for(var/obj/structure/cable/OC in cables)
|
||||
i=1
|
||||
while(i<=cables.len)
|
||||
var/obj/structure/cable/Cable = cables[i]
|
||||
if(Cable && !Cable.powernet) // non-connected cables will have powernet=null, since they weren't reached by propagation
|
||||
Cable.powernet = PN
|
||||
cables.Cut(i,i+1) // remove from old network & add to new one
|
||||
PN.cables += Cable
|
||||
continue
|
||||
i++
|
||||
|
||||
if(!OC.netnum) // non-connected cables will have netnum==0, since they weren't reached by propagation
|
||||
i=1
|
||||
while(i<=nodes.len)
|
||||
var/obj/machinery/power/Node = nodes[i]
|
||||
if(Node && !Node.powernet)
|
||||
Node.powernet = PN
|
||||
nodes.Cut(i,i+1)
|
||||
PN.nodes += Node
|
||||
continue
|
||||
i++
|
||||
|
||||
OC.netnum = PN.number
|
||||
cables -= OC
|
||||
PN.cables += OC // remove from old network & add to new one
|
||||
|
||||
for(var/obj/machinery/power/OM in nodes)
|
||||
if(!OM.netnum)
|
||||
OM.netnum = PN.number
|
||||
OM.powernet = PN
|
||||
nodes -= OM
|
||||
PN.nodes += OM // same for power machines
|
||||
|
||||
if(Debug)
|
||||
world.log << "Old PN#[number] : ([cables.len];[nodes.len])"
|
||||
world.log << "New PN#[PN.number] : ([PN.cables.len];[PN.nodes.len])"
|
||||
|
||||
else
|
||||
if(Debug)
|
||||
world.log << "Was looped."
|
||||
//there is a loop, so nothing to be done
|
||||
return
|
||||
|
||||
return
|
||||
// if(Debug)
|
||||
// world.log << "Old PN#[number] : ([cables.len];[nodes.len])"
|
||||
// world.log << "New PN#[PN.number] : ([PN.cables.len];[PN.nodes.len])"
|
||||
//
|
||||
// else
|
||||
// if(Debug)
|
||||
// world.log << "Was looped."
|
||||
// //there is a loop, so nothing to be done
|
||||
// return
|
||||
|
||||
|
||||
|
||||
@@ -379,52 +328,57 @@
|
||||
return min(rand(10,20),rand(10,20))*/
|
||||
if (1000000 to INFINITY)
|
||||
return min(rand(50,160),rand(50,160))
|
||||
if (200000 to 1000000-1)
|
||||
if (200000 to 1000000)
|
||||
return min(rand(25,80),rand(25,80))
|
||||
if (100000 to 200000-1)//Ave powernet
|
||||
if (100000 to 200000)//Ave powernet
|
||||
return min(rand(20,60),rand(20,60))
|
||||
if (50000 to 100000-1)
|
||||
if (50000 to 100000)
|
||||
return min(rand(15,40),rand(15,40))
|
||||
if (1000 to 50000-1)
|
||||
if (1000 to 50000)
|
||||
return min(rand(10,20),rand(10,20))
|
||||
else
|
||||
return 0
|
||||
|
||||
/datum/powernet/proc/merge_powernets(var/datum/powernet/P)
|
||||
// The powernet that calls this proc will consume the other powernet - Rockdtben
|
||||
//The powernet that calls this proc will consume the other powernet - Rockdtben
|
||||
//TODO: rewrite so the larger net absorbs the smaller net
|
||||
/proc/merge_powernets(var/datum/powernet/net1, var/datum/powernet/net2)
|
||||
if(!net1 || !net2) return
|
||||
if(net1 == net2) return
|
||||
|
||||
if(src == P)
|
||||
return
|
||||
//We assume net1 is larger. If net2 is in fact larger we are just going to make them switch places to reduce on code.
|
||||
if(net1.cables.len < net2.cables.len) //net2 is larger than net1. Let's switch them around
|
||||
var/temp = net1
|
||||
net1 = net2
|
||||
net2 = temp
|
||||
|
||||
if(nodes.len >= P.nodes.len)
|
||||
nodes += P.nodes
|
||||
else
|
||||
P.nodes += nodes
|
||||
nodes = P.nodes
|
||||
for(var/obj/machinery/power/M in nodes)
|
||||
M.netnum = number
|
||||
M.powernet = powernets[M.netnum] // Thanks to Derp__
|
||||
for(var/i=1,i<=net2.nodes.len,i++) //merge net2 into net1
|
||||
var/obj/machinery/power/Node = net2.nodes[i]
|
||||
if(Node)
|
||||
Node.powernet = net1
|
||||
net1.nodes += Node
|
||||
|
||||
for(var/i=1,i<=net2.cables.len,i++)
|
||||
var/obj/structure/cable/Cable = net2.cables[i]
|
||||
if(Cable)
|
||||
Cable.powernet = net1
|
||||
net1.cables += Cable
|
||||
|
||||
del(net2)
|
||||
return net1
|
||||
|
||||
if(cables.len >= P.cables.len)
|
||||
cables += P.cables
|
||||
else
|
||||
P.cables += cables
|
||||
cables = P.cables
|
||||
for(var/obj/structure/cable/C in cables)
|
||||
C.netnum = number
|
||||
del P
|
||||
|
||||
/obj/machinery/power/proc/connect_to_network()
|
||||
var/turf/T = src.loc
|
||||
var/obj/structure/cable/C = T.get_cable_node()
|
||||
if (!C || !C.netnum)
|
||||
return
|
||||
makepowernets() //TODO: find fast way
|
||||
if(!C || !C.powernet) return
|
||||
// makepowernets() //TODO: find fast way //EWWWW what are you doing!?
|
||||
powernet = C.powernet
|
||||
powernet.nodes += src
|
||||
|
||||
/obj/machinery/power/proc/disconnect_from_network()
|
||||
//TODO: dunno how to do that
|
||||
return
|
||||
if(!powernet) return
|
||||
powernet.nodes -= src
|
||||
powernet = null
|
||||
|
||||
/turf/proc/get_cable_node()
|
||||
if(!istype(src, /turf/simulated/floor))
|
||||
@@ -447,31 +401,29 @@
|
||||
//source is an object caused electrocuting (airlock, grille, etc)
|
||||
//No animations will be performed by this proc.
|
||||
/proc/electrocute_mob(mob/living/carbon/M as mob, var/power_source, var/obj/source, var/siemens_coeff = 1.0)
|
||||
if(istype(M.loc,/obj/mecha))
|
||||
return 0
|
||||
if(istype(M.loc,/obj/mecha)) return 0 //feckin mechs are dumb
|
||||
if(istype(M,/mob/living/carbon/human))
|
||||
var/mob/living/carbon/human/H = M
|
||||
if(H.gloves)
|
||||
var/obj/item/clothing/gloves/G = H.gloves
|
||||
var/siem_coef = G.siemens_coefficient
|
||||
if(siem_coef == 0) //to avoid spamming with insulated glvoes on
|
||||
return 0
|
||||
if(G.siemens_coefficient == 0) return 0 //to avoid spamming with insulated glvoes on
|
||||
|
||||
var/area/source_area
|
||||
if (istype(power_source,/area))
|
||||
if(istype(power_source,/area))
|
||||
source_area = power_source
|
||||
power_source = source_area.get_apc()
|
||||
if (istype(power_source,/obj/structure/cable))
|
||||
var/obj/structure/cable/tmp = power_source
|
||||
power_source = powernets[tmp.netnum]
|
||||
if(istype(power_source,/obj/structure/cable))
|
||||
var/obj/structure/cable/Cable = power_source
|
||||
power_source = Cable.powernet
|
||||
|
||||
var/datum/powernet/PN
|
||||
var/obj/item/weapon/cell/cell
|
||||
|
||||
if (istype(power_source,/datum/powernet))
|
||||
if(istype(power_source,/datum/powernet))
|
||||
PN = power_source
|
||||
else if (istype(power_source,/obj/item/weapon/cell))
|
||||
else if(istype(power_source,/obj/item/weapon/cell))
|
||||
cell = power_source
|
||||
else if (istype(power_source,/obj/machinery/power/apc))
|
||||
else if(istype(power_source,/obj/machinery/power/apc))
|
||||
var/obj/machinery/power/apc/apc = power_source
|
||||
cell = apc.cell
|
||||
if (apc.terminal)
|
||||
@@ -506,4 +458,5 @@
|
||||
PN.newload+=drained_power
|
||||
else if (istype(power_source, /obj/item/weapon/cell))
|
||||
cell.use(drained_energy)
|
||||
return drained_energy
|
||||
return drained_energy
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//After it knows this it creates the number of cables from the center to each of the cables attempting to conenct. These cables cannot be removed
|
||||
//with wirecutters. When the switch is turned off it removes all the cables on the tile it's on.
|
||||
//The switch uses a 5s delay to prevent powernet change spamming.
|
||||
|
||||
/*
|
||||
/obj/structure/powerswitch
|
||||
name = "power switch"
|
||||
desc = "A switch that controls power."
|
||||
@@ -81,4 +81,5 @@
|
||||
else
|
||||
icon_state = icon_state_off
|
||||
for(var/obj/structure/cable/C in src.loc)
|
||||
del(C)
|
||||
del(C)
|
||||
*/
|
||||
Reference in New Issue
Block a user