Address static power review suggestions.

This commit is contained in:
Leshana
2020-04-23 23:00:23 -04:00
parent ba7da5b9b8
commit e36410de25
3 changed files with 7 additions and 13 deletions

View File

@@ -289,12 +289,13 @@
oneoff_light += amount oneoff_light += amount
if(ENVIRON) if(ENVIRON)
oneoff_environ += amount oneoff_environ += amount
return amount
// This is used by machines to properly update the area of power changes. // This is used by machines to properly update the area of power changes.
/area/proc/power_use_change(old_amount, new_amount, chan) /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. 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) /area/proc/use_power_static(var/amount, var/chan)
switch(chan) switch(chan)
if(EQUIP) if(EQUIP)

View File

@@ -65,8 +65,6 @@ Class Procs:
use_power_oneoff(amount, chan=CURRENT_CHANNEL) 'game/machinery/machinery_power.dm' 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. 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' power_change() 'game/machinery/machinery_power.dm'
Called by the area that contains the object when ever that area under goes a Called by the area that contains the object when ever that area under goes a

View File

@@ -1,6 +1,6 @@
// //
// /obj/machinery POWER USAGE CODE HERE! GO GO GADGET STATIC POWER! // /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: // 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 // - 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). // returns true if the area has power on given channel (or doesn't require power).
// defaults to power_channel // defaults to power_channel
/obj/machinery/proc/powered(var/chan = CURRENT_CHANNEL) // 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 //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. //be turned on again and used after a power failure because they never gain the NOPOWER flag.
//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 = get_area(src) // make sure it's in an area
if(!A || !isarea(A)) if(!A)
return 0 // if not, then not powered return 0 // if not, then not powered
if(chan == CURRENT_CHANNEL) if(chan == CURRENT_CHANNEL)
chan = power_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) // 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) /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 var/area/A = get_area(src) // make sure it's in an area
if(!A || !isarea(A)) if(!A)
return return
if(chan == CURRENT_CHANNEL) if(chan == CURRENT_CHANNEL)
chan = power_channel chan = power_channel
A.use_power_oneoff(amount, chan) return A.use_power_oneoff(amount, chan)
return amount // TODO - Return A.use_power_oneoff()'s retval once it returns something.
// Check if we CAN use a given amount of extra power as a one off. Returns amount we could use without actually using it. // 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 // For backwards compatibilty this returns true if the channel is powered. This is consistant with pre-static-power