mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 10:21:11 +00:00
Added on_moved support to /datum/power_connections.
This commit is contained in:
@@ -35,6 +35,9 @@
|
||||
// Flick animation shit
|
||||
var/atom/movable/overlay/c_animation = null
|
||||
|
||||
// Powernet /datum/power_connections. *Uninitialized until used to conserve memory*
|
||||
var/list/power_connections = null
|
||||
|
||||
// holy water
|
||||
var/holy = 0
|
||||
|
||||
|
||||
@@ -16,15 +16,62 @@
|
||||
var/machine_flags = 0 // Emulate machinery flags.
|
||||
var/inMachineList = 0
|
||||
|
||||
var/parentMoveKey = null
|
||||
var/turf/turf = null // Updated in addToTurf()/removeFromTurf()
|
||||
|
||||
/datum/power_connection/New(var/obj/parent)
|
||||
src.parent = parent
|
||||
power_machines |= src
|
||||
|
||||
// Used for updating turf power_connection lists when moved.
|
||||
parentMoveKey = parent.on_moved.Add(src, "parent_moved")
|
||||
addToTurf()
|
||||
|
||||
/datum/power_connection/Destroy()
|
||||
disconnect()
|
||||
power_machines -= parent
|
||||
|
||||
// Remember to tell our turf that we're gone.
|
||||
removeFromTurf()
|
||||
parent.on_moved.Remove(parentMoveKey)
|
||||
|
||||
..()
|
||||
|
||||
// CALLBACK from parent.on_moved.
|
||||
// This should never happen, except when Singuloth is doing its shenanigans, as rebuilding
|
||||
// powernets is extremely slow.
|
||||
/datum/power_connection/proc/parent_moved(var/list/args)
|
||||
removeFromTurf() // Removes old ref
|
||||
addToTurf() // Adds new one
|
||||
|
||||
// Powernets need to know what power equipment is on a turf when adding a cable to it.
|
||||
// So, we tell the turf to tell the powernet about us, since we don't have a loc.
|
||||
/datum/power_connection/proc/addToTurf()
|
||||
// Get AND REMEMBER the turf that's going to hold the ref.
|
||||
turf = get_turf(parent)
|
||||
if(!turf)
|
||||
// We've been sucked into a black hole, god help us
|
||||
return
|
||||
if(turf.power_connections == null)
|
||||
turf.power_connections = list(src)
|
||||
else
|
||||
turf.power_connections += src
|
||||
|
||||
/datum/power_connection/proc/removeFromTurf()
|
||||
if(!turf)
|
||||
return
|
||||
// We don't grab the current turf here because we're removing the reference from the turf that has it.
|
||||
turf.power_connections -= src
|
||||
|
||||
// Clean up after ourselves.
|
||||
if(turf.power_connections.len == 0)
|
||||
turf.power_connections = null
|
||||
|
||||
// Tell the rest of the code that we're turfless.
|
||||
// EVEN THOUGH THE REST OF THE CODE SHOULDN'T CARE.
|
||||
turf=null
|
||||
|
||||
// Called when powernet reports excess watts.
|
||||
/datum/power_connection/proc/excess(var/netexcess)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user