mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-29 15:08:02 +01:00
Makes Static Power Safer & Fixes Negative Power Issues
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
var/power_channel = PW_CHANNEL_EQUIPMENT
|
||||
/// The powernet this machine is connected to
|
||||
var/datum/local_powernet/machine_powernet = null
|
||||
/// Has power been initialized on this machine? Set in Initialize(), prevents all power updates to the local powernet until this is TRUE to avoid weird numbers.
|
||||
var/power_initialized = FALSE
|
||||
|
||||
/// how badly will it shock you?
|
||||
var/siemens_strength = 0.7
|
||||
@@ -45,9 +47,10 @@
|
||||
machine_powernet.register_machine(src)
|
||||
switch(power_state)
|
||||
if(IDLE_POWER_USE)
|
||||
add_static_power(power_channel, idle_power_consumption)
|
||||
_add_static_power(power_channel, idle_power_consumption)
|
||||
if(ACTIVE_POWER_USE)
|
||||
add_static_power(power_channel, active_power_consumption)
|
||||
_add_static_power(power_channel, active_power_consumption)
|
||||
power_initialized = TRUE
|
||||
|
||||
if(!speed_process)
|
||||
START_PROCESSING(SSmachines, src)
|
||||
@@ -102,17 +105,21 @@
|
||||
|
||||
// use active power from the local powernet
|
||||
/obj/machinery/proc/use_power(amount, channel)
|
||||
if(!has_power())
|
||||
if(!has_power() || !power_initialized)
|
||||
return FALSE
|
||||
if(!channel)
|
||||
channel = power_channel
|
||||
return machine_powernet.use_active_power(channel, amount)
|
||||
|
||||
/obj/machinery/proc/add_static_power(channel, amount)
|
||||
machine_powernet.adjust_static_power(channel, amount)
|
||||
/// Helper proc to positively adjust static power tracking on the machine's powernet, not meant for general use!
|
||||
/obj/machinery/proc/_add_static_power(channel, amount)
|
||||
PRIVATE_PROC(TRUE)
|
||||
machine_powernet?.adjust_static_power(channel, amount)
|
||||
|
||||
/obj/machinery/proc/remove_static_power(channel, amount)
|
||||
machine_powernet.adjust_static_power(channel, -amount)
|
||||
/// Helper proc to negatively adjust static power tracking on the machine's powernet, not meant for general use!
|
||||
/obj/machinery/proc/_remove_static_power(channel, amount)
|
||||
PRIVATE_PROC(TRUE)
|
||||
machine_powernet?.adjust_static_power(channel, -amount)
|
||||
|
||||
/*
|
||||
* # power_change()
|
||||
@@ -143,26 +150,34 @@
|
||||
/obj/machinery/proc/change_power_mode(use_type = IDLE_POWER_USE)
|
||||
if(isnull(use_type) || use_type == power_state || !machine_powernet || !power_channel) //if there is no powernet/channel, just end it here
|
||||
return
|
||||
if(!power_initialized)
|
||||
return FALSE // we set static power values in Initialize(), do not update static consumption until after initialization or you will get weird values on powernet
|
||||
switch(power_state)
|
||||
if(IDLE_POWER_USE)
|
||||
remove_static_power(power_channel, idle_power_consumption)
|
||||
_remove_static_power(power_channel, idle_power_consumption)
|
||||
if(ACTIVE_POWER_USE)
|
||||
remove_static_power(power_channel, active_power_consumption)
|
||||
_remove_static_power(power_channel, active_power_consumption)
|
||||
|
||||
switch(use_type)
|
||||
if(IDLE_POWER_USE)
|
||||
add_static_power(power_channel, idle_power_consumption)
|
||||
_add_static_power(power_channel, idle_power_consumption)
|
||||
if(ACTIVE_POWER_USE)
|
||||
add_static_power(power_channel, active_power_consumption)
|
||||
_add_static_power(power_channel, active_power_consumption)
|
||||
|
||||
power_state = use_type
|
||||
|
||||
/// Safely changes the static power on the local powernet based on an adjustment in idle power
|
||||
/obj/machinery/proc/update_idle_power_consumption(channel = power_channel, amount)
|
||||
if(!power_initialized)
|
||||
return FALSE // we set static power values in Initialize(), do not update static consumption until after initialization or you will get weird values on powernet
|
||||
if(power_state == IDLE_POWER_USE)
|
||||
machine_powernet.adjust_static_power(power_channel, amount - idle_power_consumption)
|
||||
idle_power_consumption = amount
|
||||
|
||||
/// Safely changes the static power on the local powernet based on an adjustment in active power
|
||||
/obj/machinery/proc/update_active_power_consumption(channel = power_channel, amount)
|
||||
if(!power_initialized)
|
||||
return FALSE // we set static power values in Initialize(), do not update static consumption until after initialization or you will get weird values on powernet
|
||||
if(power_state == ACTIVE_POWER_USE)
|
||||
machine_powernet.adjust_static_power(power_channel, amount - active_power_consumption)
|
||||
active_power_consumption = amount
|
||||
|
||||
@@ -181,10 +181,6 @@
|
||||
var/on = FALSE
|
||||
/// Is the light currently turning on?
|
||||
var/turning_on = FALSE
|
||||
/// If the light state has changed since the last 'update()', also update the power requirements
|
||||
var/light_state = FALSE
|
||||
/// How much power does it use?
|
||||
var/static_power_used = 0
|
||||
/// Light range (Also used in power calculation)
|
||||
var/brightness_range = 8
|
||||
/// Light intensity
|
||||
@@ -371,17 +367,10 @@
|
||||
else if(!turned_off())
|
||||
set_emergency_lights()
|
||||
else // Turning off
|
||||
change_power_mode(IDLE_POWER_USE)
|
||||
change_power_mode(NO_POWER_USE)
|
||||
set_light(0)
|
||||
update_icon()
|
||||
active_power_consumption = (brightness_range * 10)
|
||||
if(on != light_state) // Light was turned on/off, so update the power usage
|
||||
light_state = on
|
||||
if(on)
|
||||
static_power_used = brightness_range * 20 //20W per unit of luminosity
|
||||
add_static_power(PW_CHANNEL_LIGHTING, static_power_used)
|
||||
else
|
||||
remove_static_power(PW_CHANNEL_LIGHTING, static_power_used)
|
||||
update_active_power_consumption(PW_CHANNEL_LIGHTING, brightness_range * 10)
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,8 +41,6 @@
|
||||
var/environment_consumption = 0
|
||||
|
||||
/* Total consumption vars, tracking vars that only count aggregate consumption from active power channels */
|
||||
/// The amount of the total power consumed passively in power cycles (i.e, each cycle), does not include power channels that are off
|
||||
var/passive_consumption = 0
|
||||
/// The amount of total power consumed consumed in only this cycle
|
||||
var/active_consumption = 0
|
||||
|
||||
@@ -85,17 +83,14 @@
|
||||
if(PW_CHANNEL_EQUIPMENT)
|
||||
if(equipment_powered == new_state)
|
||||
return
|
||||
passive_consumption += (passive_equipment_consumption * (new_state ? 1 : -1))
|
||||
equipment_powered = new_state
|
||||
if(PW_CHANNEL_LIGHTING)
|
||||
if(lighting_powered == new_state)
|
||||
return
|
||||
passive_consumption += (passive_lighting_consumption * (new_state ? 1 : -1))
|
||||
lighting_powered = new_state
|
||||
if(PW_CHANNEL_ENVIRONMENT)
|
||||
if(environment_powered == new_state)
|
||||
return
|
||||
passive_consumption += (passive_environment_consumption * (new_state ? 1 : -1))
|
||||
environment_powered = new_state
|
||||
power_change()
|
||||
|
||||
@@ -150,12 +145,11 @@
|
||||
passive_environment_consumption += amount
|
||||
else
|
||||
return FALSE
|
||||
if(has_power(channel)) // our total consumption vars don't track unpowered channels, so don't change the var if there's no power
|
||||
passive_consumption += amount
|
||||
return TRUE
|
||||
|
||||
/// Returns the local powernets total power usage between all three of its channels, only includes usage on currently powered channels
|
||||
/datum/local_powernet/proc/get_total_usage()
|
||||
return passive_consumption + active_consumption
|
||||
return get_channel_usage(PW_CHANNEL_EQUIPMENT) + get_channel_usage(PW_CHANNEL_LIGHTING) + get_channel_usage(PW_CHANNEL_ENVIRONMENT)
|
||||
|
||||
/// returns active + passive power of a channel, if the channel is not powered it returns 0 watts
|
||||
/datum/local_powernet/proc/get_channel_usage(channel)
|
||||
|
||||
Reference in New Issue
Block a user