Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
[PORT] Ports tgstation/tgstation#51453 real quick (#3149)
Browse files Browse the repository at this point in the history
* Ports tgstation/tgstation#51453 real quick

* Fixes turf atmos getting deleted.

* Moves the gas transfer procs to the gas mixture.

* Fixes emp act to behave like before

* Fixes tanks exploding

* prevents pipenet related warnings

Co-authored-by: nemvar <47324920+nemvar@users.noreply.github.com>
  • Loading branch information
2 people authored and Poly-The-Parrot committed Dec 15, 2020
1 parent 3de85c6 commit 89630c9
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 81 deletions.
43 changes: 43 additions & 0 deletions code/modules/atmospherics/gasmixtures/gas_mixture.dm
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,46 @@ get_true_breath_pressure(pp) --> gas_pp = pp/breath_pp*total_moles()
*/

/datum/gas_mixture/turf

/// Pumps gas from src to output_air. Amount depends on target_pressure
/datum/gas_mixture/proc/pump_gas_to(datum/gas_mixture/output_air, target_pressure)
var/output_starting_pressure = output_air.return_pressure()

if((target_pressure - output_starting_pressure) < 0.01)
//No need to pump gas if target is already reached!
return

//Calculate necessary moles to transfer using PV=nRT
if((total_moles() > 0) && (return_temperature()>0))
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles = pressure_delta*output_air.return_volume()/(return_temperature() * R_IDEAL_GAS_EQUATION)

//Actually transfer the gas
var/datum/gas_mixture/removed = remove(transfer_moles)
output_air.merge(removed)
return TRUE
return FALSE

/// Releases gas from src to output air. This means that it can not transfer air to gas mixture with higher pressure.
/datum/gas_mixture/proc/release_gas_to(datum/gas_mixture/output_air, target_pressure)
var/output_starting_pressure = output_air.return_pressure()
var/input_starting_pressure = return_pressure()

if(output_starting_pressure >= min(target_pressure,input_starting_pressure-10))
//No need to pump gas if target is already reached or input pressure is too low
//Need at least 10 KPa difference to overcome friction in the mechanism
return FALSE

//Calculate necessary moles to transfer using PV = nRT
if((total_moles() > 0) && (return_temperature()>0))
var/pressure_delta = min(target_pressure - output_starting_pressure, (input_starting_pressure - output_starting_pressure)/2)
//Can not have a pressure delta that would cause output_pressure > input_pressure

var/transfer_moles = pressure_delta*output_air.return_volume()/(return_temperature() * R_IDEAL_GAS_EQUATION)

//Actually transfer the gas
var/datum/gas_mixture/removed = remove(transfer_moles)
output_air.merge(removed)
return TRUE
return FALSE

Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,9 @@ Passive gate is similar to the regular pump except:

var/datum/gas_mixture/air1 = airs[1]
var/datum/gas_mixture/air2 = airs[2]

var/output_starting_pressure = air2.return_pressure()
var/input_starting_pressure = air1.return_pressure()

if(output_starting_pressure >= min(target_pressure,input_starting_pressure-10))
//No need to pump gas if target is already reached or input pressure is too low
//Need at least 10 KPa difference to overcome friction in the mechanism
return

//Calculate necessary moles to transfer using PV = nRT
if((air1.total_moles() > 0) && (air1.return_temperature()>0))
var/pressure_delta = min(target_pressure - output_starting_pressure, (input_starting_pressure - output_starting_pressure)/2)
//Can not have a pressure delta that would cause output_pressure > input_pressure

var/transfer_moles = pressure_delta*air2.return_volume()/(air1.return_temperature() * R_IDEAL_GAS_EQUATION)

//Actually transfer the gas
var/datum/gas_mixture/removed = air1.remove(transfer_moles)
air2.merge(removed)

if(air1.release_gas_to(air2, target_pressure))
update_parents()


//Radio remote control

/obj/machinery/atmospherics/components/binary/passive_gate/proc/set_frequency(new_frequency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,7 @@
var/datum/gas_mixture/air1 = airs[1]
var/datum/gas_mixture/air2 = airs[2]

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!
return

//Calculate necessary moles to transfer using PV=nRT
if((air1.total_moles() > 0) && (air1.return_temperature()>0))
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles = pressure_delta*air2.return_volume()/(air1.return_temperature() * R_IDEAL_GAS_EQUATION)

//Actually transfer the gas
var/datum/gas_mixture/removed = air1.remove(transfer_moles)
air2.merge(removed)

if(air1.pump_gas_to(air2, target_pressure))
update_parents()

//Radio remote control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
// Pipenet stuff; housekeeping

/obj/machinery/atmospherics/components/nullifyNode(i)
// Every node has a parent pipeline and an air associated with it.
nullifyPipenet(parents[i])
QDEL_NULL(airs[i])
// Every node has a parent pipeline and an air associated with it, but we need to accomdate for edge cases like init dir cache building...
if(parents[i])
nullifyPipenet(parents[i])
if(airs[i])
QDEL_NULL(airs[i])
..()

/obj/machinery/atmospherics/components/on_construction()
Expand Down
25 changes: 5 additions & 20 deletions code/modules/atmospherics/machinery/portable/canister.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


var/valve_open = FALSE
var/obj/machinery/atmospherics/components/binary/passive_gate/pump
var/release_log = ""

volume = 1000
Expand Down Expand Up @@ -200,17 +199,8 @@
air_contents.copy_from(existing_mixture)
else
create_gas()
pump = new(src, FALSE)
pump.on = TRUE
pump.stat = 0
pump.build_network()

update_icon()

/obj/machinery/portable_atmospherics/canister/Destroy()
qdel(pump)
pump = null
return ..()

/obj/machinery/portable_atmospherics/canister/proc/create_gas()
if(gas_type)
Expand Down Expand Up @@ -349,22 +339,17 @@
if(timing && valve_timer < world.time)
valve_open = !valve_open
timing = FALSE

// Handle gas transfer.
if(valve_open)
var/turf/T = get_turf(src)
pump.airs[1] = air_contents
pump.airs[2] = holding ? holding.air_contents : T.return_air()
pump.target_pressure = release_pressure
var/datum/gas_mixture/target_air = holding ? holding.air_contents : T.return_air()

pump.process_atmos() // Pump gas.
if(!holding)
air_update_turf() // Update the environment if needed.
else
pump.airs[1] = null
pump.airs[2] = null
if(air_contents.release_gas_to(target_air, release_pressure) && !holding)
air_update_turf()

update_icon()


/obj/machinery/portable_atmospherics/canister/ui_state(mob/user)
return GLOB.physical_state

Expand Down
36 changes: 14 additions & 22 deletions code/modules/atmospherics/machinery/portable/pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,14 @@

var/on = FALSE
var/direction = PUMP_OUT
var/obj/machinery/atmospherics/components/binary/pump/pump
var/target_pressure = ONE_ATMOSPHERE

volume = 1000

/obj/machinery/portable_atmospherics/pump/Initialize()
. = ..()
pump = new(src, FALSE)
pump.on = TRUE
pump.stat = 0
pump.build_network()

/obj/machinery/portable_atmospherics/pump/Destroy()
var/turf/T = get_turf(src)
T.assume_air(air_contents)
air_update_turf()
QDEL_NULL(pump)
return ..()

/obj/machinery/portable_atmospherics/pump/update_icon()
Expand All @@ -43,20 +35,20 @@
/obj/machinery/portable_atmospherics/pump/process_atmos()
..()
if(!on)
pump.airs[1] = null
pump.airs[2] = null
return

var/turf/T = get_turf(src)
if(direction == PUMP_OUT) // Hook up the internal pump.
pump.airs[1] = holding ? holding.air_contents : air_contents
pump.airs[2] = holding ? air_contents : T.return_air()
var/datum/gas_mixture/sending
var/datum/gas_mixture/receiving
if(direction == PUMP_OUT) // Hook up the "internal" pump.
sending = (holding ? holding.air_contents : air_contents)
receiving = (holding ? air_contents : T.return_air())
else
pump.airs[1] = holding ? air_contents : T.return_air()
pump.airs[2] = holding ? holding.air_contents : air_contents
sending = (holding ? air_contents : T.return_air())
receiving = (holding ? holding.air_contents : air_contents)


pump.process_atmos() // Pump gas.
if(!holding)
if(sending.pump_gas_to(receiving, target_pressure) && !holding)
air_update_turf() // Update the environment if needed.

/obj/machinery/portable_atmospherics/pump/emp_act(severity)
Expand All @@ -68,7 +60,7 @@
on = !on
if(prob(100 / severity))
direction = PUMP_OUT
pump.target_pressure = rand(0, 100 * ONE_ATMOSPHERE)
target_pressure = rand(0, 100 * ONE_ATMOSPHERE)
update_icon()

/obj/machinery/portable_atmospherics/pump/replace_tank(mob/living/user, close_valve)
Expand Down Expand Up @@ -98,7 +90,7 @@
data["direction"] = direction == PUMP_IN ? TRUE : FALSE
data["connected"] = connected_port ? TRUE : FALSE
data["pressure"] = round(air_contents.return_pressure() ? air_contents.return_pressure() : 0)
data["target_pressure"] = round(pump.target_pressure ? pump.target_pressure : 0)
data["target_pressure"] = round(target_pressure ? target_pressure : 0)
data["default_pressure"] = round(PUMP_DEFAULT_PRESSURE)
data["min_pressure"] = round(PUMP_MIN_PRESSURE)
data["max_pressure"] = round(PUMP_MAX_PRESSURE)
Expand Down Expand Up @@ -149,8 +141,8 @@
pressure = text2num(pressure)
. = TRUE
if(.)
pump.target_pressure = clamp(round(pressure), PUMP_MIN_PRESSURE, PUMP_MAX_PRESSURE)
investigate_log("was set to [pump.target_pressure] kPa by [key_name(usr)].", INVESTIGATE_ATMOS)
target_pressure = clamp(round(pressure), PUMP_MIN_PRESSURE, PUMP_MAX_PRESSURE)
investigate_log("was set to [target_pressure] kPa by [key_name(usr)].", INVESTIGATE_ATMOS)
if("eject")
if(holding)
replace_tank(usr, FALSE)
Expand Down

0 comments on commit 89630c9

Please sign in to comment.