Skip to content

Commit

Permalink
Fixes turf atmos getting deleted. (tgstation#51453)
Browse files Browse the repository at this point in the history
* Fixes turf atmos getting deleted.

* Moves the gas transfer procs to the gas mixture.

* Fixes emp act to behave like before

* Fixes tanks exploding
  • Loading branch information
haukeschuemann authored and RigglePrime committed Jun 6, 2022
1 parent 312a62a commit f01f1c3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 69 deletions.
45 changes: 44 additions & 1 deletion code/modules/atmospherics/gasmixtures/gas_mixture.dm
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,47 @@ get_true_breath_pressure(pp) --> gas_pp = pp/breath_pp*total_moles()
10/20*5 = 2.5
10 = 2.5/5*20
*/
**/

/// 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 FALSE

//Calculate necessary moles to transfer using PV=nRT
if((total_moles() > 0) && (temperature>0))
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles = pressure_delta*output_air.volume/(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) && (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.volume/(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 @@ -43,26 +43,7 @@ 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.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.volume/(air1.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()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,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.temperature>0))
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles = pressure_delta*air2.volume/(air1.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
35 changes: 16 additions & 19 deletions code/modules/atmospherics/machinery/portable/canister.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
density = TRUE

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

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

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 @@ -340,21 +330,28 @@
if(timing && valve_timer < world.time)
valve_open = !valve_open
timing = FALSE
if(!valve_open)
pump.airs[1] = null
pump.airs[2] = null
return

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
// Handle gas transfer.
if(valve_open)
var/turf/T = get_turf(src)
var/datum/gas_mixture/target_air = holding ? holding.air_contents : T.return_air()

if(air_contents.release_gas_to(target_air, release_pressure) && !holding)
air_update_turf()

pump.process_atmos() // Pump gas.
if(!holding)
air_update_turf() // Update the environment if needed.
update_icon()

var/our_pressure = air_contents.return_pressure()
var/our_temperature = air_contents.return_temperature()

///function used to check the limit of the canisters and also set the amount of damage that the canister can recieve, if the heat and pressure are way higher than the limit the more damage will be done
if(our_temperature > heat_limit || our_pressure > pressure_limit)
take_damage(clamp((our_temperature/heat_limit) * (our_pressure/pressure_limit), 5, 50), BURN, 0)
return

/obj/machinery/portable_atmospherics/canister/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, \
datum/tgui/master_ui = null, datum/ui_state/state = GLOB.physical_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
Expand Down
27 changes: 13 additions & 14 deletions code/modules/atmospherics/machinery/portable/pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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

volume = 1000

Expand All @@ -26,7 +26,6 @@
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 @@ -41,20 +40,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)
var/datum/gas_mixture/sending
var/datum/gas_mixture/receiving
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()
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 @@ -66,7 +65,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 All @@ -93,7 +92,7 @@
data["direction"] = direction
data["connected"] = connected_port ? 1 : 0
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 @@ -146,8 +145,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 f01f1c3

Please sign in to comment.