diff --git a/code/ATMOSPHERICS/atmospherics_helpers.dm b/code/ATMOSPHERICS/atmospherics_helpers.dm index 1b9523cc15..e59fcc52b2 100644 --- a/code/ATMOSPHERICS/atmospherics_helpers.dm +++ b/code/ATMOSPHERICS/atmospherics_helpers.dm @@ -1,7 +1,14 @@ +/* + Atmos processes + + These procs generalize various processes used by atmos machinery, such as pumping, filtering, or scrubbing gas, allowing them to be reused elsewhere. +*/ + + //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, however power will still be used! +//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/var/last_flow_rate = 0 //Can't return multiple values, unfortunately... @@ -17,10 +24,10 @@ if (available_power && specific_power > 0) transfer_moles = min(transfer_moles, available_power / specific_power) - if (transfer_moles < MINUMUM_MOLES_TO_PUMP) + if (transfer_moles < MINUMUM_MOLES_TO_PUMP) //we check this repeatedly so that we do as little processing as possible return -1 - last_flow_rate = (transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + 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 (isnull(removed)) //not sure why this would happen, but it does at the very beginning of the game @@ -28,39 +35,42 @@ var/power_draw = specific_power*transfer_moles if (power_draw > 0) - removed.add_thermal_energy(power_draw) //1st law - energy is conserved + removed.add_thermal_energy(power_draw) //1st law - energy is conserved sink.merge(removed) return power_draw -//Generalized gas filtering proc. -//Filters the gasses specified by filtering from one gas_mixture to another and returns the amount of power needed (assuming 1 second), or -1 if no gas was filtered. -//filtering - A list of gasids to be filtered from source -//total_transfer_moles - Limits the amount of moles to filter. 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, however power will still be used! -/obj/machinery/atmospherics/proc/filter_gas(var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink, var/total_transfer_moles = null, var/available_power = null) +//Generalized gas scrubbing proc. +//Selectively moves specified gasses one gas_mixture to another and returns the amount of power needed (assuming 1 second), or -1 if no gas was filtered. +//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) if (source.total_moles < MINUMUM_MOLES_TO_FILTER) return -1 filtering &= source.gas //only filter gasses that are actually there. - //Filter it - var/total_specific_power = 0 //the power required to remove one mole of filterable gas + //Determine the specific power of each filterable gas type, and the total amount of filterable gas var/total_filterable_moles = 0 - var/list/specific_power_gas = list() + var/list/specific_power_gas = list() //the power required to remove one mole of pure gas, for each gas type for (var/g in filtering) if (source.gas[g] < MINUMUM_MOLES_TO_FILTER) continue var/specific_power = calculate_specific_power_gas(g, source, sink)/ATMOS_FILTER_EFFICIENCY specific_power_gas[g] = specific_power - total_specific_power += specific_power total_filterable_moles += source.gas[g] if (total_filterable_moles < MINUMUM_MOLES_TO_FILTER) return -1 + var/total_specific_power = 0 //the power required to remove one mole of filterable gas + for (var/g in filtering) + var/ratio = source.gas[g]/total_filterable_moles //converts the specific power per mole of pure gas to specific power per mole of filterable gas mix + total_specific_power = specific_power_gas[g]*ratio + //Figure out how much of each gas to filter if (!total_transfer_moles) total_transfer_moles = total_filterable_moles @@ -71,11 +81,11 @@ if (available_power && total_specific_power > 0) total_transfer_moles = min(total_transfer_moles, available_power/total_specific_power) - if (total_transfer_moles < MINUMUM_MOLES_TO_FILTER) + if (total_transfer_moles < MINUMUM_MOLES_TO_FILTER) //we check this repeatedly so that we do as little processing as possible return -1 var/power_draw = 0 - last_flow_rate = (total_transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here + 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 diff --git a/code/ATMOSPHERICS/components/unary/vent_scrubber.dm b/code/ATMOSPHERICS/components/unary/vent_scrubber.dm index 7e6f9a3600..268018badd 100644 --- a/code/ATMOSPHERICS/components/unary/vent_scrubber.dm +++ b/code/ATMOSPHERICS/components/unary/vent_scrubber.dm @@ -128,7 +128,7 @@ //limit flow rate from turfs var/transfer_moles = min(environment.total_moles, environment.total_moles*MAX_FILTER_FLOWRATE/environment.volume) //group_multiplier gets divided out here - power_draw = filter_gas(scrubbing_gas, environment, air_contents, transfer_moles, active_power_usage) + power_draw = scrub_gas(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 diff --git a/code/ZAS/_gas_mixture_xgm.dm b/code/ZAS/_gas_mixture_xgm.dm index 8d2e8d9c3e..0016224299 100644 --- a/code/ZAS/_gas_mixture_xgm.dm +++ b/code/ZAS/_gas_mixture_xgm.dm @@ -119,8 +119,7 @@ . += ratio * specific_entropy_gas(g) . /= total_moles -//Returns the ideal gas specific entropy of a specific gas in the mix. This is the entropy per mole of /pure/ gas. -//It's important not to get that mixed up with the mixed entropy, which takes into account mole ratios (I did, it was bad). +//Returns the ideal gas specific entropy of a specific gas in the mix. This is the entropy due to that gas per mole of /that/ gas in the mixture, not the entropy due to that gas per mole of gas mixture. /datum/gas_mixture/proc/specific_entropy_gas(var/gasid) if (!(gasid in gas) || gas[gasid] == 0) return SPECIFIC_ENTROPY_VACUUM //that gas isn't here