From 7e65984ae2ec4e7eaaecc8da0bfa75642c3489c7 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Sat, 12 Jul 2014 19:59:49 -0400 Subject: [PATCH] Implements pump power draw --- .../components/binary_devices/pump.dm | 51 +++++++++++++++---- code/game/machinery/machinery.dm | 5 ++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/code/ATMOSPHERICS/components/binary_devices/pump.dm b/code/ATMOSPHERICS/components/binary_devices/pump.dm index 78f5d121ff..3518fc4497 100644 --- a/code/ATMOSPHERICS/components/binary_devices/pump.dm +++ b/code/ATMOSPHERICS/components/binary_devices/pump.dm @@ -22,6 +22,10 @@ obj/machinery/atmospherics/binary/pump var/on = 0 var/target_pressure = ONE_ATMOSPHERE var/power_rating = 7500 //A measure of how powerful the pump is, in Watts. 7500 W ~ 10 HP + + //The maximum amount of volume in Liters the pump can transfer in 1 second. + //This is limited by how fast the pump can spin without breaking, and means you can't instantly fill up the distro even when it's empty (at 10000, it will take about 15 seconds) + var/max_volume_transfer = 10000 use_power = 1 idle_power_usage = 10 //10 W for internal circuitry and stuff @@ -29,12 +33,17 @@ obj/machinery/atmospherics/binary/pump var/frequency = 0 var/id = null var/datum/radio_frequency/radio_connection + + New() + ..() + active_power_usage = power_rating //make sure this is equal to the max power rating so that auto use power works correctly highcap name = "High capacity gas pump" desc = "A high capacity pump" - target_pressure = 15000000 + target_pressure = 15000000 //15 GPa? Really? + power_rating = 112500 //150 Horsepower on on = 1 @@ -62,46 +71,65 @@ obj/machinery/atmospherics/binary/pump 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! + if (use_power >= 2) + update_use_power(1) return 1 + + var/output_volume = air2.volume + if (network2 && network2.air_transient) + output_volume = network2.air_transient.volume + output_volume = min(output_volume, max_volume_transfer) //Calculate necessary moles to transfer using PV=nRT if((air1.total_moles() > 0) && (air1.temperature > 0 || air2.temperature > 0)) var/air_temperature = (air2.temperature > 0)? air2.temperature : air1.temperature var/pressure_delta = target_pressure - output_starting_pressure - var/transfer_moles = pressure_delta*air2.volume/(air_temperature * R_IDEAL_GAS_EQUATION) //The number of moles that would have to be transfered to bring air2 to the target pressure + var/transfer_moles = pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION) //The number of moles that would have to be transfered to bring air2 to the target pressure //estimate the amount of energy required var/specific_entropy = air2.specific_entropy() - air1.specific_entropy() //air2 is gaining moles, air1 is loosing var/specific_power = 0 - src.visible_message("DEBUG: [src] >>> terminal pressures: sink = [air2.return_pressure()] kPa, source = [air1.return_pressure()] kPa") - src.visible_message("DEBUG: [src] >>> specific entropy = [air2.specific_entropy()] - [air1.specific_entropy()] = [specific_entropy] J/K") + //src.visible_message("DEBUG: [src] >>> terminal pressures: sink = [air2.return_pressure()] kPa, source = [air1.return_pressure()] kPa") + //src.visible_message("DEBUG: [src] >>> specific entropy = [air2.specific_entropy()] - [air1.specific_entropy()] = [specific_entropy] J/K") //if specific_entropy >= 0 then gas just flows naturally and we are not limited by how powerful the pump is. if (specific_entropy < 0) specific_power = -specific_entropy*air_temperature //how much power we need per mole - src.visible_message("DEBUG: [src] >>> limiting transfer_moles to [power_rating / (air_temperature * -specific_entropy)] mol") + //src.visible_message("DEBUG: [src] >>> limiting transfer_moles to [power_rating / (air_temperature * -specific_entropy)] mol") transfer_moles = min(transfer_moles, power_rating / specific_power) //Actually transfer the gas var/datum/gas_mixture/removed = air1.remove(transfer_moles) air2.merge(removed) - src.visible_message("DEBUG: [src] >>> entropy_change = [specific_entropy*transfer_moles] J/K") + //src.visible_message("DEBUG: [src] >>> entropy_change = [specific_entropy*transfer_moles] J/K") //if specific_entropy >= 0 then gas is flowing naturally and we don't need to use extra power if (specific_entropy < 0) //pump draws power and heats gas according to 2nd law of thermodynamics - - var/power_draw = transfer_moles*specific_power + var/power_draw = round(transfer_moles*specific_power) air2.add_thermal_energy(power_draw) - use_power(power_draw) + + if (power_draw >= power_rating - 5) //if we are close enough to max power just active_power_usage + if (use_power < 2) + update_use_power(2) + else + if (use_power >= 2) + update_use_power(1) + //src.visible_message("DEBUG: [src] >>> Forcing area power update: use_power changed to [use_power]") + + if (power_draw > idle_power_usage) + use_power(power_draw) + else + if (use_power >= 2) + update_use_power(1) + //src.visible_message("DEBUG: [src] >>> Forcing area power update: use_power changed to [use_power]") - src.visible_message("DEBUG: [src] >>> drawing [power_draw] W of power.") + //src.visible_message("DEBUG: [src] >>> drawing [power_draw] W of power.") if(network1) network1.update = 1 @@ -163,6 +191,7 @@ obj/machinery/atmospherics/binary/pump if("power_toggle" in signal.data) on = !on + update_use_power(on) if("set_output_pressure" in signal.data) target_pressure = between( diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index e13147f5fb..accd117cd2 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -157,6 +157,11 @@ Class Procs: if(prob(50)) del(src) +//sets the use_power var and then forces an area power update +/obj/machinery/proc/update_use_power(var/new_use_power) + use_power = new_use_power + use_power(0) //force area power update + /obj/machinery/proc/auto_use_power() if(!powered(power_channel)) return 0