mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-09 16:14:13 +00:00
Refactor powered and use_power procs.
This commit is contained in:
@@ -31,14 +31,6 @@
|
||||
. = i
|
||||
i = findtext(A, B, i + 1)
|
||||
|
||||
/obj/machinery/proc/getArea()
|
||||
var/area/A = loc.loc
|
||||
|
||||
if (A != myArea)
|
||||
myArea = A
|
||||
|
||||
. = myArea
|
||||
|
||||
/**
|
||||
* Object pooling.
|
||||
*
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
src:Topic(href, href_list)
|
||||
return null
|
||||
|
||||
/proc/get_area(O)
|
||||
var/atom/location = O
|
||||
var/i
|
||||
for(i=1, i<=20, i++)
|
||||
if(isarea(location))
|
||||
return location
|
||||
else if (istype(location))
|
||||
location = location.loc
|
||||
else
|
||||
return null
|
||||
return 0
|
||||
/proc/get_area(const/atom/O)
|
||||
if (isnull(O))
|
||||
return
|
||||
|
||||
var/atom/A = O
|
||||
|
||||
while (!isarea(A))
|
||||
if (istype(A))
|
||||
A = A.loc
|
||||
|
||||
return A
|
||||
|
||||
/proc/get_area_master(O)
|
||||
var/area/A = get_area(O)
|
||||
|
||||
@@ -112,31 +112,22 @@ Class Procs:
|
||||
var/global/gl_uid = 1
|
||||
var/custom_aghost_alerts=0
|
||||
var/panel_open = 0
|
||||
var/area/myArea
|
||||
|
||||
var/inMachineList = 1 // For debugging.
|
||||
var/area/mchArea
|
||||
|
||||
/obj/machinery/New()
|
||||
addAtProcessing()
|
||||
mchArea = get_src(area)
|
||||
machines.Add(src)
|
||||
return ..()
|
||||
|
||||
/obj/machinery/proc/addAtProcessing()
|
||||
if (use_power)
|
||||
myArea = get_area_master(src)
|
||||
|
||||
machines += src
|
||||
|
||||
/obj/machinery/proc/removeAtProcessing()
|
||||
if (myArea)
|
||||
myArea = null
|
||||
|
||||
machines -= src
|
||||
|
||||
/obj/machinery/Destroy()
|
||||
if (src in machines)
|
||||
removeAtProcessing()
|
||||
machines.Remove(src)
|
||||
|
||||
..()
|
||||
mchArea = null
|
||||
|
||||
return ..()
|
||||
|
||||
/obj/machinery/process() // If you dont use process or power why are you here
|
||||
return PROCESS_KILL
|
||||
|
||||
@@ -34,10 +34,11 @@
|
||||
else
|
||||
return 0
|
||||
|
||||
// returns true if the area has power on given channel (or doesn't require power).
|
||||
// defaults to power_channel
|
||||
|
||||
/obj/machinery/proc/powered(var/chan = -1)
|
||||
/*
|
||||
* Returns true if the area has power on given channel (or doesn't require power).
|
||||
* Defaults to power_channel.
|
||||
*/
|
||||
/obj/machinery/proc/powered(var/chan = power_channel)
|
||||
|
||||
if(!src.loc)
|
||||
return 0
|
||||
@@ -45,30 +46,24 @@
|
||||
if(!use_power)
|
||||
return 1
|
||||
|
||||
var/area/A = src.loc.loc // make sure it's in an area
|
||||
if(!A || !isarea(A) || !A.master)
|
||||
return 0 // if not, then not powered
|
||||
if(chan == -1)
|
||||
chan = power_channel
|
||||
return A.master.powered(chan) // return power status of the area
|
||||
var/area/A = mchArea // Make sure it's in an area.
|
||||
|
||||
// increment the power usage stats for an area
|
||||
if (!A || !A.master)
|
||||
return 0 // If not, then not powered.
|
||||
|
||||
/obj/machinery/proc/use_power(var/amount, var/chan = -1) // defaults to power_channel
|
||||
var/A = getArea()
|
||||
return A.master.powered(chan) // Return power status of the area.
|
||||
|
||||
if(!A || !isarea(A))
|
||||
/*
|
||||
* Increment the power usage stats for an area.
|
||||
* Defaults to power_channel.
|
||||
*/
|
||||
/obj/machinery/proc/use_power(const/amount, var/chan = power_channel)
|
||||
var/area/A = mchArea
|
||||
|
||||
if (!A || !A.master)
|
||||
return
|
||||
|
||||
var/area/B = A
|
||||
|
||||
if (!B.master)
|
||||
return
|
||||
|
||||
if (-1 == chan)
|
||||
chan = power_channel
|
||||
|
||||
B.master.use_power(amount, chan)
|
||||
A.master.use_power(amount, chan)
|
||||
|
||||
/obj/machinery/proc/power_change() // called whenever the power settings of the containing area change
|
||||
// by default, check equipment channel & set flag
|
||||
|
||||
Reference in New Issue
Block a user