Improves update_use_power() proc

Now no longer misses power usage on the tick that it is called
This commit is contained in:
mwerezak
2014-07-15 20:32:43 -04:00
parent 1011800d78
commit aeb3537ae4
2 changed files with 25 additions and 21 deletions

View File

@@ -68,11 +68,12 @@ Thus, the two variables affect pump operation are set in New():
if(stat & (NOPOWER|BROKEN))
return
if(!on)
update_use_power(0)
return 0
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!
update_power_usage(0)
update_use_power(0)
return 1
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
var/power_draw = round(transfer_moles*specific_power)
air2.add_thermal_energy(power_draw)
update_power_usage(power_draw)
handle_power_draw(power_draw)
else
update_power_usage(0)
handle_power_draw(idle_power_usage)
if(network1)
network1.update = 1
@@ -123,6 +124,18 @@ Thus, the two variables affect pump operation are set in New():
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
/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
//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)
if(stat & (BROKEN|NOPOWER))
return

View File

@@ -163,7 +163,15 @@ Class Procs:
return //don't need to do anything
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()
if(!powered(power_channel))