mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-08-29 06:58:30 +01:00
Implements "static" area machinery power usage
- Instead of using auto_use_power to re-tally up machinery's power usage every cycle, track the steady "static" load separately from the transient "oneoff" usage. Machines then only need to inform the area when they use oneoff power or *change* their steady usage. - Remove auto_use_power and stop SSmachines from calling it. - Add vars to track "static" usage for each of the three power channels to /area - Rename the existing three vars to "oneoff" so its clear what they mean (and to catch people accidentally updating them directly) - Update area power procs and APCs to use the new variables. - Rename /area/proc/use_power() to use_power_oneoff() to make it clear what it is doing. - Deprecate /obj/machinery/use_power() in favor of use_power_oneoff() but don't delete yet. Can transition gradually. - Add logic to the update_power procs on machines to calculate the deltas and update static area power whenever their usage changes. - Add logic to machines to update area power when they are created, destroyed, or move. - Moved /obj/machinery procs related to area power usage into machinery_power.dm to make them easier to find. - Added or updated comments in several places to explain what is going on and how to use it.
This commit is contained in:
@@ -160,7 +160,7 @@
|
||||
var/area/A = get_area(src)
|
||||
if(A)
|
||||
if(A.powered(EQUIP) && assembly.give_power(power_amount))
|
||||
A.use_power(power_amount, EQUIP)
|
||||
A.use_power_oneoff(power_amount, EQUIP)
|
||||
// give_power() handles CELLRATE on its own.
|
||||
|
||||
// Interacts with the powernet.
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
power_usage += tesla_link.passive_charging_rate
|
||||
battery_module.battery.give(tesla_link.passive_charging_rate * CELLRATE)
|
||||
|
||||
A.use_power(power_usage, EQUIP)
|
||||
A.use_power_oneoff(power_usage, EQUIP)
|
||||
return TRUE
|
||||
|
||||
// Handles power-related things, such as battery interaction, recharging, shutdown when it's discharged
|
||||
|
||||
@@ -12,10 +12,6 @@
|
||||
// Power
|
||||
//
|
||||
|
||||
// This will have this machine have its area eat this much power next tick, and not afterwards. Do not use for continued power draw.
|
||||
/obj/machinery/proc/use_power_oneoff(var/amount, var/chan = -1)
|
||||
return use_power(amount, chan)
|
||||
|
||||
// Change one of the power consumption vars
|
||||
/obj/machinery/proc/change_power_consumption(new_power_consumption, use_power_mode = USE_POWER_IDLE)
|
||||
switch(use_power_mode)
|
||||
@@ -95,7 +91,7 @@
|
||||
/obj/machinery/computer/ship/attack_ghost(mob/user)
|
||||
interface_interact(user)
|
||||
|
||||
// If you don't call parent in this proc, you must make all appropriate checks yourself.
|
||||
// If you don't call parent in this proc, you must make all appropriate checks yourself.
|
||||
// If you do, you must respect the return value.
|
||||
/obj/machinery/computer/ship/attack_hand(mob/user)
|
||||
if((. = ..()))
|
||||
|
||||
@@ -34,10 +34,10 @@
|
||||
// controls power to devices in that area
|
||||
// may be opened to change power cell
|
||||
// three different channels (lighting/equipment/environ) - may each be set to on, off, or auto
|
||||
#define POWERCHAN_OFF 0
|
||||
#define POWERCHAN_OFF_AUTO 1
|
||||
#define POWERCHAN_ON 2
|
||||
#define POWERCHAN_ON_AUTO 3
|
||||
#define POWERCHAN_OFF 0 // Power channel is off and will stay that way dammit
|
||||
#define POWERCHAN_OFF_AUTO 1 // Power channel is off until power rises above a threshold
|
||||
#define POWERCHAN_ON 2 // Power channel is on until there is no power
|
||||
#define POWERCHAN_ON_AUTO 3 // Power channel is on until power drops below a threshold
|
||||
|
||||
//NOTE: STUFF STOLEN FROM AIRLOCK.DM thx
|
||||
|
||||
@@ -1037,10 +1037,9 @@
|
||||
return 0
|
||||
|
||||
/obj/machinery/power/apc/process()
|
||||
|
||||
if(stat & (BROKEN|MAINT))
|
||||
return
|
||||
if(!area.requires_power)
|
||||
return PROCESS_KILL
|
||||
if(stat & (BROKEN|MAINT))
|
||||
return
|
||||
if(failure_timer)
|
||||
update()
|
||||
@@ -1049,9 +1048,9 @@
|
||||
force_update = 1
|
||||
return
|
||||
|
||||
lastused_light = area.usage(LIGHT)
|
||||
lastused_equip = area.usage(EQUIP)
|
||||
lastused_environ = area.usage(ENVIRON)
|
||||
lastused_light = area.usage(LIGHT, lighting >= POWERCHAN_ON)
|
||||
lastused_equip = area.usage(EQUIP, equipment >= POWERCHAN_ON)
|
||||
lastused_environ = area.usage(ENVIRON, environ >= POWERCHAN_ON)
|
||||
area.clear_usage()
|
||||
|
||||
lastused_total = lastused_light + lastused_equip + lastused_environ
|
||||
|
||||
@@ -64,44 +64,6 @@
|
||||
/obj/machinery/power/proc/disconnect_terminal() // machines without a terminal will just return, no harm no fowl.
|
||||
return
|
||||
|
||||
// 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) // 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))
|
||||
return 0 // if not, then not powered
|
||||
if(chan == -1)
|
||||
chan = power_channel
|
||||
return A.powered(chan) // return power status of the area
|
||||
|
||||
// increment the power usage stats for an area
|
||||
/obj/machinery/proc/use_power(var/amount, var/chan = -1) // defaults to power_channel
|
||||
var/area/A = get_area(src) // make sure it's in an area
|
||||
if(!A || !isarea(A))
|
||||
return
|
||||
if(chan == -1)
|
||||
chan = power_channel
|
||||
A.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
|
||||
// can override if needed
|
||||
if(powered(power_channel))
|
||||
stat &= ~NOPOWER
|
||||
else
|
||||
|
||||
stat |= NOPOWER
|
||||
return
|
||||
|
||||
// connect the machine to a powernet if a node cable is present on the turf
|
||||
/obj/machinery/power/proc/connect_to_network()
|
||||
var/turf/T = src.loc
|
||||
@@ -372,7 +334,7 @@
|
||||
var/drained_energy = drained_hp*20
|
||||
|
||||
if (source_area)
|
||||
source_area.use_power(drained_energy/CELLRATE)
|
||||
source_area.use_power_oneoff(drained_energy/CELLRATE, EQUIP)
|
||||
else if (istype(power_source,/datum/powernet))
|
||||
var/drained_power = drained_energy/CELLRATE
|
||||
drained_power = PN.draw_power(drained_power)
|
||||
|
||||
@@ -267,7 +267,7 @@
|
||||
return
|
||||
if(chan == -1)
|
||||
chan = power_channel
|
||||
A.use_power(amount, chan)
|
||||
A.use_power_oneoff(amount, chan)
|
||||
|
||||
/obj/machinery/portable_atmospherics/powered/reagent_distillery/process()
|
||||
..()
|
||||
|
||||
Reference in New Issue
Block a user