From aeb3537ae444a8675bd79cde71a2cb38a6450003 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Tue, 15 Jul 2014 20:32:43 -0400 Subject: [PATCH] Improves update_use_power() proc Now no longer misses power usage on the tick that it is called --- .../components/binary_devices/pump.dm | 36 +++++++++---------- code/game/machinery/machinery.dm | 10 +++++- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/code/ATMOSPHERICS/components/binary_devices/pump.dm b/code/ATMOSPHERICS/components/binary_devices/pump.dm index 6d4da0c8e0..ffba6fbe41 100644 --- a/code/ATMOSPHERICS/components/binary_devices/pump.dm +++ b/code/ATMOSPHERICS/components/binary_devices/pump.dm @@ -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 diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index 4e4c4f9024..c1438b236d 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -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))