From e36410de2542ffd1611542ccea5e8d14c0d13fda Mon Sep 17 00:00:00 2001 From: Leshana Date: Thu, 23 Apr 2020 23:00:23 -0400 Subject: [PATCH] Address static power review suggestions. --- code/game/area/areas.dm | 3 ++- code/game/machinery/machinery.dm | 2 -- code/game/machinery/machinery_power.dm | 15 +++++---------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 9cd2f2d86e..3c1a70cd1d 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -289,12 +289,13 @@ oneoff_light += amount if(ENVIRON) oneoff_environ += amount + return amount // This is used by machines to properly update the area of power changes. /area/proc/power_use_change(old_amount, new_amount, chan) use_power_static(new_amount - old_amount, chan) // Simultaneously subtract old_amount and add new_amount. -// Not a proc you want to use directly unless you know what you are doing; see use_power_oneoff below instead. +// Not a proc you want to use directly unless you know what you are doing; see use_power_oneoff above instead. /area/proc/use_power_static(var/amount, var/chan) switch(chan) if(EQUIP) diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index b5f719b258..7402f0ddb5 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -65,8 +65,6 @@ Class Procs: use_power_oneoff(amount, chan=CURRENT_CHANNEL) 'game/machinery/machinery_power.dm' Deducts 'amount' from the power channel 'chan' of the area that contains the object. - If it's autocalled then everything is normal, if something else calls use_power we are going to - need to recalculate the power two ticks in a row. power_change() 'game/machinery/machinery_power.dm' Called by the area that contains the object when ever that area under goes a diff --git a/code/game/machinery/machinery_power.dm b/code/game/machinery/machinery_power.dm index 85c9fe2c1c..a052ee01ce 100644 --- a/code/game/machinery/machinery_power.dm +++ b/code/game/machinery/machinery_power.dm @@ -1,6 +1,6 @@ // // /obj/machinery POWER USAGE CODE HERE! GO GO GADGET STATIC POWER! -// Note: You can dinf /obj/machinery/power power usage code in power.dm +// Note: You can find /obj/machinery/power power usage code in power.dm // // The following four machinery variables determine the "static" amount of power used every power cycle: // - use_power, idle_power_usage, active_power_usage, power_channel @@ -20,17 +20,13 @@ // 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 = CURRENT_CHANNEL) // defaults to power_channel - - if(!src.loc) - return 0 - //Don't do this. It allows machines that set use_power to 0 when off (many machines) to //be turned on again and used after a power failure because they never gain the NOPOWER flag. //if(!use_power) // return 1 - var/area/A = src.loc.loc // make sure it's in an area - if(!A || !isarea(A)) + var/area/A = get_area(src) // make sure it's in an area + if(!A) return 0 // if not, then not powered if(chan == CURRENT_CHANNEL) chan = power_channel @@ -61,12 +57,11 @@ // Returns actual amount drawn (In theory this could be less than the amount asked for. In pratice it won't be FOR NOW) /obj/machinery/proc/use_power_oneoff(var/amount, var/chan = CURRENT_CHANNEL) var/area/A = get_area(src) // make sure it's in an area - if(!A || !isarea(A)) + if(!A) return if(chan == CURRENT_CHANNEL) chan = power_channel - A.use_power_oneoff(amount, chan) - return amount // TODO - Return A.use_power_oneoff()'s retval once it returns something. + return A.use_power_oneoff(amount, chan) // Check if we CAN use a given amount of extra power as a one off. Returns amount we could use without actually using it. // For backwards compatibilty this returns true if the channel is powered. This is consistant with pre-static-power