Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes turf atmos getting deleted. #51453

Merged
merged 5 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -486,3 +486,46 @@ 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 @@ -60,26 +60,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 @@ -61,21 +61,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
33 changes: 11 additions & 22 deletions code/modules/atmospherics/machinery/portable/canister.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
ui_y = 232

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

volume = 1000
Expand Down Expand Up @@ -261,16 +260,8 @@
air_contents.copy_from(existing_mixture)
else
create_gas()
pump = new(src, FALSE)
pump.on = TRUE
pump.machine_stat = 0
SSair.add_to_rebuild_queue(pump)
update_overlays()

/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 @@ -394,25 +385,23 @@
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()
var/pressure = air_contents.return_pressure()
var/temperature = air_contents.return_temperature()

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(temperature > heat_limit || pressure > pressure_limit)
take_damage(clamp((temperature/heat_limit) * (pressure/pressure_limit), 5, 50), BURN, 0)
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, \
Expand Down
34 changes: 13 additions & 21 deletions code/modules/atmospherics/machinery/portable/pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,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.machine_stat = 0
SSair.add_to_rebuild_queue(pump)

/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_state()
Expand All @@ -58,20 +50,20 @@
return

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 @@ -83,7 +75,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 @@ -110,7 +102,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 @@ -161,8 +153,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