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