From b7c13bc4b6cebd20106d3df6a3c13d68c8e48a29 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Mon, 4 Aug 2014 16:53:13 -0400 Subject: [PATCH] Allows atmos helpers to be used with portable_atmos --- code/ATMOSPHERICS/_atmospherics_helpers.dm | 58 ++++++++++++++----- .../components/binary_devices/dp_vent_pump.dm | 4 +- .../components/binary_devices/passive_gate.dm | 2 +- .../components/binary_devices/pump.dm | 2 +- .../components/omni_devices/filter.dm | 2 +- .../components/omni_devices/mixer.dm | 2 +- .../components/trinary_devices/filter.dm | 2 +- .../components/trinary_devices/mixer.dm | 2 +- .../components/unary/outlet_injector.dm | 2 +- .../components/unary/vent_pump.dm | 8 ++- .../components/unary/vent_scrubber.dm | 4 +- 11 files changed, 62 insertions(+), 26 deletions(-) diff --git a/code/ATMOSPHERICS/_atmospherics_helpers.dm b/code/ATMOSPHERICS/_atmospherics_helpers.dm index 51160d1950..1bef13fbef 100644 --- a/code/ATMOSPHERICS/_atmospherics_helpers.dm +++ b/code/ATMOSPHERICS/_atmospherics_helpers.dm @@ -8,13 +8,14 @@ */ -/obj/machinery/atmospherics/var/last_flow_rate = 0 //Can't return multiple values, unfortunately +/obj/machinery/atmospherics/var/last_flow_rate = 0 +/obj/machinery/portable_atmospherics/var/last_flow_rate = 0 //Generalized gas pumping proc. //Moves gas from one gas_mixture to another and returns the amount of power needed (assuming 1 second), or -1 if no gas was pumped. //transfer_moles - Limits the amount of moles to transfer. The actual amount of gas moved may also be limited by available_power, if given. //available_power - the maximum amount of power that may be used when moving gas. If null then the transfer is not limited by power. -/obj/machinery/atmospherics/proc/pump_gas(var/datum/gas_mixture/source, var/datum/gas_mixture/sink, var/transfer_moles = null, var/available_power = null) +/proc/pump_gas(var/obj/machinery/M, var/datum/gas_mixture/source, var/datum/gas_mixture/sink, var/transfer_moles = null, var/available_power = null) if (source.total_moles < MINUMUM_MOLES_TO_PUMP) //if we cant transfer enough gas just stop to avoid further processing return -1 @@ -31,7 +32,13 @@ if (transfer_moles < MINUMUM_MOLES_TO_PUMP) //if we cant transfer enough gas just stop to avoid further processing return -1 - last_flow_rate = (transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + //Update flow rate meter + if (istype(M, /obj/machinery/atmospherics)) + var/obj/machinery/atmospherics/A = M + A.last_flow_rate = (transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + if (istype(M, /obj/machinery/portable_atmospherics)) + var/obj/machinery/portable_atmospherics/P = M + P.last_flow_rate = (transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here var/datum/gas_mixture/removed = source.remove(transfer_moles) if (!removed) //Just in case @@ -50,7 +57,7 @@ //filtering - A list of gasids to be scrubbed from source //total_transfer_moles - Limits the amount of moles to scrub. The actual amount of gas scrubbed may also be limited by available_power, if given. //available_power - the maximum amount of power that may be used when scrubbing gas. If null then the scrubbing is not limited by power. -/obj/machinery/atmospherics/proc/scrub_gas(var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink, var/total_transfer_moles = null, var/available_power = null) +/proc/scrub_gas(var/obj/machinery/M, var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink, var/total_transfer_moles = null, var/available_power = null) if (source.total_moles < MINUMUM_MOLES_TO_FILTER) //if we cant transfer enough gas just stop to avoid further processing return -1 @@ -89,8 +96,15 @@ if (total_transfer_moles < MINUMUM_MOLES_TO_FILTER) //if we cant transfer enough gas just stop to avoid further processing return -1 + //Update flow rate var + if (istype(M, /obj/machinery/atmospherics)) + var/obj/machinery/atmospherics/A = M + A.last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + if (istype(M, /obj/machinery/portable_atmospherics)) + var/obj/machinery/portable_atmospherics/P = M + P.last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + var/power_draw = 0 - last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here for (var/g in filtering) var/transfer_moles = source.gas[g] //filter gas in proportion to the mole ratio @@ -117,7 +131,7 @@ //filtering - A list of gasids to be filtered. These gasses get moved to sink_filtered, while the other gasses get moved to sink_clean. //total_transfer_moles - Limits the amount of moles to input. The actual amount of gas filtered may also be limited by available_power, if given. //available_power - the maximum amount of power that may be used when filtering gas. If null then the filtering is not limited by power. -/obj/machinery/atmospherics/proc/filter_gas(var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink_filtered, var/datum/gas_mixture/sink_clean, var/total_transfer_moles = null, var/available_power = null) +/proc/filter_gas(var/obj/machinery/M, var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink_filtered, var/datum/gas_mixture/sink_clean, var/total_transfer_moles = null, var/available_power = null) if (source.total_moles < MINUMUM_MOLES_TO_FILTER) //if we cant transfer enough gas just stop to avoid further processing return -1 @@ -154,7 +168,13 @@ if (total_transfer_moles < MINUMUM_MOLES_TO_FILTER) //if we cant transfer enough gas just stop to avoid further processing return -1 - last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + //Update flow rate var + if (istype(M, /obj/machinery/atmospherics)) + var/obj/machinery/atmospherics/A = M + A.last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + if (istype(M, /obj/machinery/portable_atmospherics)) + var/obj/machinery/portable_atmospherics/P = M + P.last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here var/datum/gas_mixture/removed = source.remove(total_transfer_moles) if (!removed) //Just in case @@ -188,7 +208,7 @@ //For omni devices. Instead filtering is an associative list mapping gasids to gas mixtures. //I don't like the copypasta, but I decided to keep both versions of gas filtering as filter_gas is slightly faster (doesn't create as many temporary lists, doesn't call update_values() as much) //filter_gas can be removed and replaced with this proc if need be. -/obj/machinery/atmospherics/proc/filter_gas_multi(var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink_clean, var/total_transfer_moles = null, var/available_power = null) +/proc/filter_gas_multi(var/obj/machinery/M, var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink_clean, var/total_transfer_moles = null, var/available_power = null) if (source.total_moles < MINUMUM_MOLES_TO_FILTER) //if we cant transfer enough gas just stop to avoid further processing return -1 @@ -226,7 +246,13 @@ if (total_transfer_moles < MINUMUM_MOLES_TO_FILTER) //if we cant transfer enough gas just stop to avoid further processing return -1 - last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + //Update Flow Rate var + if (istype(M, /obj/machinery/atmospherics)) + var/obj/machinery/atmospherics/A = M + A.last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + if (istype(M, /obj/machinery/portable_atmospherics)) + var/obj/machinery/portable_atmospherics/P = M + P.last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here var/datum/gas_mixture/removed = source.remove(total_transfer_moles) if (!removed) //Just in case @@ -262,7 +288,7 @@ //Similar deal as the other atmos process procs. //mix_sources maps input gas mixtures to mix ratios. The mix ratios MUST add up to 1. -/obj/machinery/atmospherics/proc/mix_gas(var/list/mix_sources, var/datum/gas_mixture/sink, var/total_transfer_moles = null, var/available_power = null) +/proc/mix_gas(var/obj/machinery/M, var/list/mix_sources, var/datum/gas_mixture/sink, var/total_transfer_moles = null, var/available_power = null) if (!mix_sources.len) return -1 @@ -304,7 +330,13 @@ if (total_transfer_moles < MINUMUM_MOLES_TO_FILTER) //if we cant transfer enough gas just stop to avoid further processing return -1 - last_flow_rate = (total_transfer_moles/total_input_moles)*total_input_volume //group_multiplier gets divided out here + //Update flow rate var + if (istype(M, /obj/machinery/atmospherics)) + var/obj/machinery/atmospherics/A = M + A.last_flow_rate = (total_transfer_moles/total_input_moles)*total_input_volume //group_multiplier gets divided out here + if (istype(M, /obj/machinery/portable_atmospherics)) + var/obj/machinery/portable_atmospherics/P = M + P.last_flow_rate = (total_transfer_moles/total_input_moles)*total_input_volume //group_multiplier gets divided out here var/total_power_draw = 0 for (var/datum/gas_mixture/source in mix_sources) @@ -329,7 +361,7 @@ */ //Calculates the amount of power needed to move one mole from source to sink. -/obj/machinery/atmospherics/proc/calculate_specific_power(datum/gas_mixture/source, datum/gas_mixture/sink) +/proc/calculate_specific_power(datum/gas_mixture/source, datum/gas_mixture/sink) //Calculate the amount of energy required var/air_temperature = (sink.temperature > 0)? sink.temperature : source.temperature var/specific_entropy = sink.specific_entropy() - source.specific_entropy() //environment is gaining moles, air_contents is loosing @@ -342,7 +374,7 @@ return specific_power //Calculates the amount of power needed to move one mole of a certain gas from source to sink. -/obj/machinery/atmospherics/proc/calculate_specific_power_gas(var/gasid, datum/gas_mixture/source, datum/gas_mixture/sink) +/proc/calculate_specific_power_gas(var/gasid, datum/gas_mixture/source, datum/gas_mixture/sink) //Calculate the amount of energy required var/air_temperature = (sink.temperature > 0)? sink.temperature : source.temperature var/specific_entropy = sink.specific_entropy_gas(gasid) - source.specific_entropy_gas(gasid) //environment is gaining moles, air_contents is loosing diff --git a/code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm b/code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm index ef3066104a..1da0a6eb71 100644 --- a/code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm +++ b/code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm @@ -118,7 +118,7 @@ var/air_temperature = environment.temperature? environment.temperature : air1.temperature var/transfer_moles = pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION) - power_draw = pump_gas(air1, environment, transfer_moles, active_power_usage) + power_draw = pump_gas(src, air1, environment, transfer_moles, active_power_usage) if(power_draw >= 0 && network1) network1.update = 1 @@ -131,7 +131,7 @@ //limit flow rate from turfs transfer_moles = min(transfer_moles, environment.total_moles*MAX_SIPHON_FLOWRATE/environment.volume) //group_multiplier gets divided out here - power_draw = pump_gas(environment, air2, transfer_moles, active_power_usage) + power_draw = pump_gas(src, environment, air2, transfer_moles, active_power_usage) if(power_draw >= 0 && network2) network2.update = 1 diff --git a/code/ATMOSPHERICS/components/binary_devices/passive_gate.dm b/code/ATMOSPHERICS/components/binary_devices/passive_gate.dm index 22715cb348..e70b478b14 100644 --- a/code/ATMOSPHERICS/components/binary_devices/passive_gate.dm +++ b/code/ATMOSPHERICS/components/binary_devices/passive_gate.dm @@ -82,7 +82,7 @@ transfer_moles = min(transfer_moles, pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION)) //pump_gas() will return a negative number if no flow occurred - var/flow = pump_gas(air1, air2, transfer_moles, available_power=0) //available_power=0 means we only move gas if it would flow naturally + var/flow = pump_gas(src, air1, air2, transfer_moles, available_power=0) //available_power=0 means we only move gas if it would flow naturally if (flow >= 0) if(network1) diff --git a/code/ATMOSPHERICS/components/binary_devices/pump.dm b/code/ATMOSPHERICS/components/binary_devices/pump.dm index 9ce6f3b72d..fbcd70f4e2 100644 --- a/code/ATMOSPHERICS/components/binary_devices/pump.dm +++ b/code/ATMOSPHERICS/components/binary_devices/pump.dm @@ -82,7 +82,7 @@ Thus, the two variables affect pump operation are set in New(): //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) + power_draw = pump_gas(src, air1, air2, transfer_moles, active_power_usage) if (power_draw < 0) //update_use_power(0) diff --git a/code/ATMOSPHERICS/components/omni_devices/filter.dm b/code/ATMOSPHERICS/components/omni_devices/filter.dm index 7393f47c47..e5188b7da4 100644 --- a/code/ATMOSPHERICS/components/omni_devices/filter.dm +++ b/code/ATMOSPHERICS/components/omni_devices/filter.dm @@ -75,7 +75,7 @@ var/power_draw = -1 if (transfer_moles > MINUMUM_MOLES_TO_FILTER) - power_draw = filter_gas_multi(filtering_outputs, input_air, output_air, transfer_moles, active_power_usage) + power_draw = filter_gas_multi(src, filtering_outputs, input_air, output_air, transfer_moles, active_power_usage) if (power_draw < 0) //update_use_power(0) diff --git a/code/ATMOSPHERICS/components/omni_devices/mixer.dm b/code/ATMOSPHERICS/components/omni_devices/mixer.dm index 4162000c6a..89c148a943 100644 --- a/code/ATMOSPHERICS/components/omni_devices/mixer.dm +++ b/code/ATMOSPHERICS/components/omni_devices/mixer.dm @@ -114,7 +114,7 @@ var/power_draw = -1 if (transfer_moles > MINUMUM_MOLES_TO_FILTER) - power_draw = mix_gas(mixing_inputs, output, transfer_moles, active_power_usage) + power_draw = mix_gas(src, mixing_inputs, output, transfer_moles, active_power_usage) if (power_draw < 0) //update_use_power(0) diff --git a/code/ATMOSPHERICS/components/trinary_devices/filter.dm b/code/ATMOSPHERICS/components/trinary_devices/filter.dm index 89e6ce94d3..7590c453e4 100755 --- a/code/ATMOSPHERICS/components/trinary_devices/filter.dm +++ b/code/ATMOSPHERICS/components/trinary_devices/filter.dm @@ -96,7 +96,7 @@ var/power_draw = -1 if (transfer_moles > MINUMUM_MOLES_TO_FILTER) - power_draw = filter_gas(filtered_out, air1, air2, air3, transfer_moles, active_power_usage) + power_draw = filter_gas(src, filtered_out, air1, air2, air3, transfer_moles, active_power_usage) if(network2) network2.update = 1 diff --git a/code/ATMOSPHERICS/components/trinary_devices/mixer.dm b/code/ATMOSPHERICS/components/trinary_devices/mixer.dm index 7684f7e9d5..051a2ced27 100644 --- a/code/ATMOSPHERICS/components/trinary_devices/mixer.dm +++ b/code/ATMOSPHERICS/components/trinary_devices/mixer.dm @@ -86,7 +86,7 @@ var/power_draw = -1 if (transfer_moles > MINUMUM_MOLES_TO_FILTER) - power_draw = mix_gas(mixing_inputs, air3, transfer_moles, active_power_usage) + power_draw = mix_gas(src, mixing_inputs, air3, transfer_moles, active_power_usage) if(network1 && mixing_inputs[air1]) network1.update = 1 diff --git a/code/ATMOSPHERICS/components/unary/outlet_injector.dm b/code/ATMOSPHERICS/components/unary/outlet_injector.dm index 1f5e1fe363..f0f1e6241c 100644 --- a/code/ATMOSPHERICS/components/unary/outlet_injector.dm +++ b/code/ATMOSPHERICS/components/unary/outlet_injector.dm @@ -87,7 +87,7 @@ injecting = 1 if(air_contents.temperature > 0) - var/power_used = pump_gas(air_contents, environment, air_contents.total_moles, inject_power) + var/power_used = pump_gas(src, air_contents, environment, air_contents.total_moles, inject_power) use_power(power_used) if(network) diff --git a/code/ATMOSPHERICS/components/unary/vent_pump.dm b/code/ATMOSPHERICS/components/unary/vent_pump.dm index 23dd7132db..7e409f859d 100644 --- a/code/ATMOSPHERICS/components/unary/vent_pump.dm +++ b/code/ATMOSPHERICS/components/unary/vent_pump.dm @@ -153,14 +153,16 @@ //Figure out the target pressure difference var/pressure_delta = get_pressure_delta(environment) + //src.visible_message("DEBUG >>> [src]: pressure_delta = [pressure_delta]") if((environment.temperature || air_contents.temperature) && pressure_delta > 0.5) if(pump_direction) //internal -> external var/output_volume = environment.volume * environment.group_multiplier var/air_temperature = environment.temperature? environment.temperature : air_contents.temperature var/transfer_moles = pressure_delta*output_volume/(air_temperature * R_IDEAL_GAS_EQUATION) + //src.visible_message("DEBUG >>> [src]: output_volume = [output_volume]L; air_temperature = [air_temperature]K; transfer_moles = [transfer_moles] mol") - power_draw = pump_gas(air_contents, environment, transfer_moles, active_power_usage) + power_draw = pump_gas(src, air_contents, environment, transfer_moles, active_power_usage) else //external -> internal var/output_volume = air_contents.volume + (network? network.volume : 0) var/air_temperature = air_contents.temperature? air_contents.temperature : environment.temperature @@ -169,7 +171,7 @@ //limit flow rate from turfs transfer_moles = min(transfer_moles, environment.total_moles*MAX_SIPHON_FLOWRATE/environment.volume) //group_multiplier gets divided out here - power_draw = pump_gas(environment, air_contents, transfer_moles, active_power_usage) + power_draw = pump_gas(src, environment, air_contents, transfer_moles, active_power_usage) if (power_draw < 0) last_power_draw = 0 @@ -364,6 +366,8 @@ ..() 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" + else + usr << "You are too far away to read the gauge." 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 97deaedc92..e6aff41464 100644 --- a/code/ATMOSPHERICS/components/unary/vent_scrubber.dm +++ b/code/ATMOSPHERICS/components/unary/vent_scrubber.dm @@ -131,12 +131,12 @@ //limit flow rate from turfs var/transfer_moles = min(environment.total_moles, environment.total_moles*MAX_SCRUBBER_FLOWRATE/environment.volume) //group_multiplier gets divided out here - power_draw = scrub_gas(scrubbing_gas, environment, air_contents, transfer_moles, active_power_usage) + power_draw = scrub_gas(src, scrubbing_gas, environment, air_contents, transfer_moles, active_power_usage) else //Just siphon all air //limit flow rate from turfs var/transfer_moles = min(environment.total_moles, environment.total_moles*MAX_SIPHON_FLOWRATE/environment.volume) //group_multiplier gets divided out here - power_draw = pump_gas(environment, air_contents, transfer_moles, active_power_usage) + power_draw = pump_gas(src, environment, air_contents, transfer_moles, active_power_usage) if (power_draw < 0) //update_use_power(0)