diff --git a/code/__HELPERS/experimental.dm b/code/__HELPERS/experimental.dm index 7a96bb88278..042f13ebed0 100644 --- a/code/__HELPERS/experimental.dm +++ b/code/__HELPERS/experimental.dm @@ -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. * diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 0c54e235118..88a0761916b 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -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) diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index eac1a662f61..738aad3d432 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -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 diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index c39840d801c..71881991b25 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -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