mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-13 19:52:40 +00:00
Improves update_use_power() proc
Now no longer misses power usage on the tick that it is called
This commit is contained in:
@@ -68,11 +68,12 @@ Thus, the two variables affect pump operation are set in New():
|
|||||||
if(stat & (NOPOWER|BROKEN))
|
if(stat & (NOPOWER|BROKEN))
|
||||||
return
|
return
|
||||||
if(!on)
|
if(!on)
|
||||||
|
update_use_power(0)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
var/output_starting_pressure = air2.return_pressure()
|
var/output_starting_pressure = air2.return_pressure()
|
||||||
if( (target_pressure - output_starting_pressure) < 0.01) //No need to pump gas if target is already reached!
|
if( (target_pressure - output_starting_pressure) < 0.01) //No need to pump gas if target is already reached!
|
||||||
update_power_usage(0)
|
update_use_power(0)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
var/output_volume = air2.volume
|
var/output_volume = air2.volume
|
||||||
@@ -111,9 +112,9 @@ Thus, the two variables affect pump operation are set in New():
|
|||||||
//pump draws power and heats gas according to 2nd law of thermodynamics
|
//pump draws power and heats gas according to 2nd law of thermodynamics
|
||||||
var/power_draw = round(transfer_moles*specific_power)
|
var/power_draw = round(transfer_moles*specific_power)
|
||||||
air2.add_thermal_energy(power_draw)
|
air2.add_thermal_energy(power_draw)
|
||||||
update_power_usage(power_draw)
|
handle_power_draw(power_draw)
|
||||||
else
|
else
|
||||||
update_power_usage(0)
|
handle_power_draw(idle_power_usage)
|
||||||
|
|
||||||
if(network1)
|
if(network1)
|
||||||
network1.update = 1
|
network1.update = 1
|
||||||
@@ -123,6 +124,18 @@ Thus, the two variables affect pump operation are set in New():
|
|||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
//This proc handles power usages so that we only have to call use_power() when the pump is loaded but not at full load.
|
||||||
|
/obj/machinery/atmospherics/binary/pump/proc/handle_power_draw(var/usage_amount)
|
||||||
|
if (usage_amount > active_power_usage - 5)
|
||||||
|
update_use_power(2)
|
||||||
|
else
|
||||||
|
update_use_power(1)
|
||||||
|
|
||||||
|
if (usage_amount > idle_power_usage)
|
||||||
|
use_power(usage_amount) //in practice it's pretty rare that we will get here, so calling use_power() is alright.
|
||||||
|
|
||||||
|
last_power_draw = usage_amount
|
||||||
|
|
||||||
//Radio remote control
|
//Radio remote control
|
||||||
|
|
||||||
/obj/machinery/atmospherics/binary/pump/proc/set_frequency(new_frequency)
|
/obj/machinery/atmospherics/binary/pump/proc/set_frequency(new_frequency)
|
||||||
@@ -151,23 +164,6 @@ Thus, the two variables affect pump operation are set in New():
|
|||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
//this proc handles power usages so that we only have to call use_power() when the pump is loaded but not at full load.
|
|
||||||
/obj/machinery/atmospherics/binary/pump/proc/update_power_usage(var/usage_amount)
|
|
||||||
if (usage_amount > active_power_usage - 5)
|
|
||||||
if (use_power < 2)
|
|
||||||
update_use_power(2)
|
|
||||||
else
|
|
||||||
if (use_power >= 2)
|
|
||||||
update_use_power(1)
|
|
||||||
|
|
||||||
if (usage_amount > idle_power_usage)
|
|
||||||
use_power(usage_amount) //in practice it's pretty rare that we will get here, so calling use_power() is alright.
|
|
||||||
|
|
||||||
last_power_draw = usage_amount
|
|
||||||
if (use_power > 0)
|
|
||||||
last_power_draw = max(last_power_draw, idle_power_usage)
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/binary/pump/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
|
/obj/machinery/atmospherics/binary/pump/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
|
||||||
if(stat & (BROKEN|NOPOWER))
|
if(stat & (BROKEN|NOPOWER))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -163,7 +163,15 @@ Class Procs:
|
|||||||
return //don't need to do anything
|
return //don't need to do anything
|
||||||
|
|
||||||
use_power = new_use_power
|
use_power = new_use_power
|
||||||
use_power(0) //force area power update
|
|
||||||
|
//force area power update
|
||||||
|
//use_power() forces an area power update on the next tick so have to pass the correct power amount for this tick
|
||||||
|
if (use_power >= 2)
|
||||||
|
use_power(active_power_usage)
|
||||||
|
else if (use_power == 1)
|
||||||
|
use_power(idle_power_usage)
|
||||||
|
else
|
||||||
|
use_power(0)
|
||||||
|
|
||||||
/obj/machinery/proc/auto_use_power()
|
/obj/machinery/proc/auto_use_power()
|
||||||
if(!powered(power_channel))
|
if(!powered(power_channel))
|
||||||
|
|||||||
Reference in New Issue
Block a user