From 14b57e356091db7720c061197395ae1210bcca87 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Sun, 3 Aug 2014 22:41:31 -0400 Subject: [PATCH] Pipe networks now cache their total volume --- .../components/binary_devices/dp_vent_pump.dm | 6 ++++-- .../components/binary_devices/pump.dm | 21 ++++++++----------- .../components/unary/vent_pump.dm | 6 ++++-- .../components/unary/vent_scrubber.dm | 17 ++++++++------- code/ATMOSPHERICS/datum_pipe_network.dm | 5 +++++ 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm b/code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm index e3df72628c4..56f69ee14b0 100644 --- a/code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm +++ b/code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm @@ -124,7 +124,7 @@ network1.update = 1 else //external -> internal if (node2 && (environment.temperature || air2.temperature)) - var/output_volume = air2.volume * air2.group_multiplier + var/output_volume = air2.volume + (network2? network2.volume : 0) var/air_temperature = air2.temperature? air2.temperature : environment.temperature var/transfer_moles = pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION) @@ -203,7 +203,9 @@ /obj/machinery/atmospherics/binary/dp_vent_pump/examine() set src in oview(1) ..() - usr << "A small gauge in the corner reads [round(last_flow_rate, 0.1)] L/s; [round(last_power_draw)] W" + + if (get_dist(usr, src) <= 1) + usr << "A small gauge in the corner reads [round(last_flow_rate, 0.1)] L/s; [round(last_power_draw)] W" /obj/machinery/atmospherics/unary/vent_pump/power_change() var/old_stat = stat diff --git a/code/ATMOSPHERICS/components/binary_devices/pump.dm b/code/ATMOSPHERICS/components/binary_devices/pump.dm index b6842327067..b4958022b22 100644 --- a/code/ATMOSPHERICS/components/binary_devices/pump.dm +++ b/code/ATMOSPHERICS/components/binary_devices/pump.dm @@ -74,18 +74,15 @@ Thus, the two variables affect pump operation are set in New(): var/power_draw = -1 var/pressure_delta = target_pressure - air2.return_pressure() - if(pressure_delta > 0.01) - /* TODO Uncomment this once we have a good way to get the volume of a pipe network. - if (air1.temperature > 0 || air2.temperature > 0) - //Figure out how much gas to transfer to meet the target pressure. - var/air_temperature = (sink.temperature > 0)? sink.temperature : source.temperature - - var/output_volume = sink.volume * sink.group_multiplier - - //Return the number of moles that would have to be transfered to bring sink to the target pressure - var/transfer_moles = pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION) - */ - power_draw = pump_gas(air1, air2, air1.total_moles, active_power_usage) + if(pressure_delta > 0.01 && (air1.temperature > 0 || air2.temperature > 0)) + //Figure out how much gas to transfer to meet the target pressure. + var/air_temperature = (air2.temperature > 0)? air2.temperature : air1.temperature + var/output_volume = air2.volume + (network2? network2.volume : 0) + + //get the number of moles that would have to be transfered to bring sink to the target pressure + var/transfer_moles = pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION) + + power_draw = pump_gas(air1, air2, transfer_moles, active_power_usage) if(network1) network1.update = 1 diff --git a/code/ATMOSPHERICS/components/unary/vent_pump.dm b/code/ATMOSPHERICS/components/unary/vent_pump.dm index 3948addde69..eb69e21ce85 100644 --- a/code/ATMOSPHERICS/components/unary/vent_pump.dm +++ b/code/ATMOSPHERICS/components/unary/vent_pump.dm @@ -80,6 +80,7 @@ /obj/machinery/atmospherics/unary/vent_pump/high_volume name = "Large Air Vent" power_channel = EQUIP + active_power_usage = 15000 //15 kW ~ 20 HP /obj/machinery/atmospherics/unary/vent_pump/high_volume/New() ..() @@ -161,7 +162,7 @@ power_draw = pump_gas(air_contents, environment, transfer_moles, active_power_usage) else //external -> internal - var/output_volume = air_contents.volume * air_contents.group_multiplier + var/output_volume = air_contents.volume + (network? network.volume : 0) var/air_temperature = air_contents.temperature? air_contents.temperature : environment.temperature var/transfer_moles = pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION) @@ -362,7 +363,8 @@ /obj/machinery/atmospherics/unary/vent_pump/examine() set src in oview(1) ..() - usr << "A small gauge in the corner reads [round(last_flow_rate, 0.1)] L/s; [round(last_power_draw)] W" + if (get_dist(usr, src) <= 1) + usr << "A small gauge in the corner reads [round(last_flow_rate, 0.1)] L/s; [round(last_power_draw)] W" if(welded) usr << "It seems welded shut." diff --git a/code/ATMOSPHERICS/components/unary/vent_scrubber.dm b/code/ATMOSPHERICS/components/unary/vent_scrubber.dm index 8c768869eb0..44e13ffd3ea 100644 --- a/code/ATMOSPHERICS/components/unary/vent_scrubber.dm +++ b/code/ATMOSPHERICS/components/unary/vent_scrubber.dm @@ -7,6 +7,7 @@ use_power = 1 idle_power_usage = 150 //internal circuitry, friction losses and stuff active_power_usage = 7500 //This also doubles as a measure of how powerful the pump is, in Watts. 7500 W ~ 10 HP + var/last_power_draw = 0 level = 1 @@ -113,14 +114,14 @@ set_frequency(frequency) /obj/machinery/atmospherics/unary/vent_scrubber/process() - ..() - if(stat & (NOPOWER|BROKEN)) - return + ..() if (!node) on = 0 //broadcast_status() - if(!on) + if(!on || (stat & (NOPOWER|BROKEN))) update_use_power(0) //we got here because a player turned a pump off - definitely want to update. + last_flow_rate = 0 + last_power_draw = 0 return 0 var/datum/gas_mixture/environment = loc.return_air() @@ -140,9 +141,10 @@ if (power_draw < 0) //update_use_power(0) use_power = 0 //don't force update. Sure, we will continue to use power even though we're not pumping anything, but it is easier on the CPU + last_power_draw = 0 + last_flow_rate = 0 else - //last_power_draw = power_draw - handle_power_draw(power_draw) + last_power_draw = handle_power_draw(power_draw) if(network) network.update = 1 @@ -252,7 +254,8 @@ /obj/machinery/atmospherics/unary/vent_scrubber/examine() set src in oview(1) ..() - usr << "A small gauge in the corner reads [round(last_flow_rate, 0.1)] L/s" + if (get_dist(usr, src) <= 1) + usr << "A small gauge in the corner reads [round(last_flow_rate, 0.1)] L/s; [round(last_power_draw)] W" /obj/machinery/atmospherics/unary/vent_scrubber/Del() if(initial_loc) diff --git a/code/ATMOSPHERICS/datum_pipe_network.dm b/code/ATMOSPHERICS/datum_pipe_network.dm index 0728ff1f4a3..4098c15c31b 100644 --- a/code/ATMOSPHERICS/datum_pipe_network.dm +++ b/code/ATMOSPHERICS/datum_pipe_network.dm @@ -2,6 +2,7 @@ var/global/list/datum/pipe_network/pipe_networks = list() datum/pipe_network var/list/datum/gas_mixture/gases = list() //All of the gas_mixtures continuously connected in this network + var/volume = 0 //caches the total volume for atmos machines to use in gas calculations var/list/obj/machinery/atmospherics/normal_members = list() var/list/datum/pipeline/line_members = list() @@ -61,6 +62,7 @@ datum/pipe_network //Go through membership roster and make sure gases is up to date gases = list() + volume = 0 for(var/obj/machinery/atmospherics/normal_member in normal_members) var/result = normal_member.return_network_air(src) @@ -68,6 +70,9 @@ datum/pipe_network for(var/datum/pipeline/line_member in line_members) gases += line_member.air + + for(var/datum/gas_mixture/air in gases) + volume += air.volume proc/reconcile_air() equalize_gases(gases)