From a9b511d30e9eadea569fa94d055ef2ed7351cd37 Mon Sep 17 00:00:00 2001 From: Lucy Date: Wed, 22 Dec 2021 20:01:30 -0500 Subject: [PATCH] AGH --- code/__DEFINES/atmospherics.dm | 5 +++++ .../atmospherics/gasmixtures/reactions.dm | 14 +++++++++++++ .../components/binary_devices/dp_vent_pump.dm | 14 ++++++------- .../components/binary_devices/passive_gate.dm | 21 +------------------ .../binary_devices/temperature_pump.dm | 21 +++++++++++++++---- .../components/binary_devices/valve.dm | 11 ++++++++++ .../machinery/components/components_base.dm | 7 ++++--- .../components/trinary_devices/mixer.dm | 6 +++--- .../machinery/portable/canister.dm | 16 ++++++-------- .../portable/portable_atmospherics.dm | 6 +++--- 10 files changed, 71 insertions(+), 50 deletions(-) diff --git a/code/__DEFINES/atmospherics.dm b/code/__DEFINES/atmospherics.dm index 6eb8838790a2..42d43965e70d 100644 --- a/code/__DEFINES/atmospherics.dm +++ b/code/__DEFINES/atmospherics.dm @@ -497,3 +497,8 @@ GLOBAL_LIST_INIT(pipe_paint_colors, list( #define MIASMA_CORPSE_MOLES 0.02 #define MIASMA_GIBS_MOLES 0.005 + +//PIPENET UPDATE STATUS +#define PIPENET_UPDATE_STATUS_DORMANT 0 +#define PIPENET_UPDATE_STATUS_REACT_NEEDED 1 +#define PIPENET_UPDATE_STATUS_RECONCILE_NEEDED 2 diff --git a/code/modules/atmospherics/gasmixtures/reactions.dm b/code/modules/atmospherics/gasmixtures/reactions.dm index 74323abf79b2..125bc99962f7 100644 --- a/code/modules/atmospherics/gasmixtures/reactions.dm +++ b/code/modules/atmospherics/gasmixtures/reactions.dm @@ -157,6 +157,20 @@ nobliumformation = 1001 if(istype(location) && prob(10)) radiation_pulse(location, energy_released/TRITIUM_BURN_RADIOACTIVITY_FACTOR) +/proc/fusion_ball(datum/holder, reaction_energy, instability) + var/turf/open/location + if (istype(holder,/datum/pipeline)) //Find the tile the reaction is occuring on, or a random part of the network if it's a pipenet. + var/datum/pipeline/fusion_pipenet = holder + location = get_turf(pick(fusion_pipenet.members)) + else + location = get_turf(holder) + if(location) + var/particle_chance = ((PARTICLE_CHANCE_CONSTANT)/(reaction_energy-PARTICLE_CHANCE_CONSTANT)) + 1//Asymptopically approaches 100% as the energy of the reaction goes up. + if(prob(PERCENT(particle_chance))) + location.fire_nuclear_particle() + var/rad_power = max((FUSION_RAD_COEFFICIENT/instability) + FUSION_RAD_MAX,0) + radiation_pulse(location,rad_power) + /datum/gas_reaction/tritfire/react(datum/gas_mixture/air, datum/holder) var/energy_released = 0 var/old_heat_capacity = air.heat_capacity() diff --git a/code/modules/atmospherics/machinery/components/binary_devices/dp_vent_pump.dm b/code/modules/atmospherics/machinery/components/binary_devices/dp_vent_pump.dm index 5969ea088525..da6dd7075993 100644 --- a/code/modules/atmospherics/machinery/components/binary_devices/dp_vent_pump.dm +++ b/code/modules/atmospherics/machinery/components/binary_devices/dp_vent_pump.dm @@ -53,7 +53,8 @@ /obj/machinery/atmospherics/components/binary/dp_vent_pump/process_atmos() ..() - + if(welded || !is_operational() || !isopenturf(loc)) + return FALSE if(!on) return var/datum/gas_mixture/air1 = airs[1] @@ -75,13 +76,13 @@ var/transfer_moles = pressure_delta*environment.return_volume()/(air1.return_temperature() * R_IDEAL_GAS_EQUATION) loc.assume_air_moles(air1, transfer_moles) + air_update_turf() var/datum/pipeline/parent1 = parents[1] - parent1.update = 1 + parent1.update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED else //external -> output - if(environment.return_pressure() > 0) var/our_multiplier = air2.return_volume() / (environment.return_temperature() * R_IDEAL_GAS_EQUATION) var/moles_delta = 10000 * our_multiplier @@ -89,16 +90,15 @@ moles_delta = min(moles_delta, (environment_pressure - output_pressure_max) * environment.return_volume() / (environment.return_temperature() * R_IDEAL_GAS_EQUATION)) if(pressure_checks&INPUT_MIN) moles_delta = min(moles_delta, (input_pressure_min - air2.return_pressure()) * our_multiplier) - + if(moles_delta > 0) loc.transfer_air(air2, moles_delta) air_update_turf() var/datum/pipeline/parent2 = parents[2] - parent2.update = 1 - - //Radio remote control + parent2.update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED +//Radio remote control /obj/machinery/atmospherics/components/binary/dp_vent_pump/proc/set_frequency(new_frequency) SSradio.remove_object(src, frequency) frequency = new_frequency diff --git a/code/modules/atmospherics/machinery/components/binary_devices/passive_gate.dm b/code/modules/atmospherics/machinery/components/binary_devices/passive_gate.dm index bdb23355e1d6..51c2dc18aabe 100644 --- a/code/modules/atmospherics/machinery/components/binary_devices/passive_gate.dm +++ b/code/modules/atmospherics/machinery/components/binary_devices/passive_gate.dm @@ -57,26 +57,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.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() diff --git a/code/modules/atmospherics/machinery/components/binary_devices/temperature_pump.dm b/code/modules/atmospherics/machinery/components/binary_devices/temperature_pump.dm index 3c7a39dd59c1..2049e940824d 100644 --- a/code/modules/atmospherics/machinery/components/binary_devices/temperature_pump.dm +++ b/code/modules/atmospherics/machinery/components/binary_devices/temperature_pump.dm @@ -32,18 +32,31 @@ icon_state = "tpump_[on && is_operational() ? "on" : "off"]-[set_overlay_offset(piping_layer)]" /obj/machinery/atmospherics/components/binary/temperature_pump/process_atmos() - ..() + if(!on || !is_operational()) return var/datum/gas_mixture/air_input = airs[1] var/datum/gas_mixture/air_output = airs[2] - if((air_output.return_temperature() + heat_transfer_rate) >= air_input.return_temperature() || (air_input.return_temperature() - heat_transfer_rate) <= TCRYO) + if(!QUANTIZE(air_input.total_moles()) || !QUANTIZE(air_output.total_moles())) //Don't transfer if there's no gas return + var/datum/gas_mixture/remove_input = air_input.remove_ratio(0.9) + var/datum/gas_mixture/remove_output = air_output.remove_ratio(0.9) + + var/coolant_temperature_delta = remove_input.return_temperature() - remove_output.return_temperature() + + if(coolant_temperature_delta > 0) + var/input_capacity = remove_input.heat_capacity() + var/output_capacity = air_output.heat_capacity() + + var/cooling_heat_amount = (heat_transfer_rate * 0.01) * coolant_temperature_delta * (input_capacity * output_capacity / (input_capacity + output_capacity)) + remove_input.set_temperature(max(remove_input.return_temperature() - (cooling_heat_amount / input_capacity), TCMB)) + remove_output.set_temperature(max(remove_output.return_temperature() + (cooling_heat_amount / output_capacity), TCMB)) + + air_input.merge(remove_input) + air_output.merge(remove_output) - air_input.set_temperature(air_input.return_temperature() - heat_transfer_rate) - air_output.set_temperature(air_output.return_temperature() + heat_transfer_rate) update_parents() /obj/machinery/atmospherics/components/binary/temperature_pump/ui_interact(mob/user, datum/tgui/ui) diff --git a/code/modules/atmospherics/machinery/components/binary_devices/valve.dm b/code/modules/atmospherics/machinery/components/binary_devices/valve.dm index 1974d31816fd..336c2c50f7f7 100644 --- a/code/modules/atmospherics/machinery/components/binary_devices/valve.dm +++ b/code/modules/atmospherics/machinery/components/binary_devices/valve.dm @@ -24,6 +24,17 @@ It's like a regular ol' straight pipe, but you can turn it on and off. var/switching = FALSE + +/obj/machinery/atmospherics/components/binary/valve/Destroy() + //Should only happen on extreme circumstances + if(on) + //Let's give presumably now-severed pipenets a chance to scramble for what's happening at next SSair fire() + if(parents[1]) + parents[1].update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED + if(parents[2]) + parents[2].update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED + . = ..() + /obj/machinery/atmospherics/components/binary/valve/update_icon_nopipes(animation = FALSE) normalize_cardinal_directions() if(animation) diff --git a/code/modules/atmospherics/machinery/components/components_base.dm b/code/modules/atmospherics/machinery/components/components_base.dm index 353d5163e6e8..a52d5235a57a 100644 --- a/code/modules/atmospherics/machinery/components/components_base.dm +++ b/code/modules/atmospherics/machinery/components/components_base.dm @@ -133,10 +133,11 @@ for(var/i in 1 to device_type) var/datum/pipeline/parent = parents[i] if(!parent) - WARNING("Component is missing a pipenet! Rebuilding...") + //WARNING("Component is missing a pipenet! Rebuilding...") + //At pre-SSair_rebuild_pipenets times, not having a parent wasn't supposed to happen SSair.add_to_rebuild_queue(src) - else - parent.update = 1 + continue + parent.update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED /obj/machinery/atmospherics/components/returnPipenets() . = list() diff --git a/code/modules/atmospherics/machinery/components/trinary_devices/mixer.dm b/code/modules/atmospherics/machinery/components/trinary_devices/mixer.dm index 145d1cb9a2fb..d1fc2b20cb01 100644 --- a/code/modules/atmospherics/machinery/components/trinary_devices/mixer.dm +++ b/code/modules/atmospherics/machinery/components/trinary_devices/mixer.dm @@ -110,15 +110,15 @@ if(transfer_moles1) air1.transfer_to(air3, transfer_moles1) var/datum/pipeline/parent1 = parents[1] - parent1.update = TRUE + parent1.update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED if(transfer_moles2) air2.transfer_to(air3, transfer_moles2) var/datum/pipeline/parent2 = parents[2] - parent2.update = TRUE + parent2.update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED var/datum/pipeline/parent3 = parents[3] - parent3.update = TRUE + parent3.update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED /obj/machinery/atmospherics/components/trinary/mixer/ui_interact(mob/user, datum/tgui/ui) ui = SStgui.try_update_ui(user, src, ui) diff --git a/code/modules/atmospherics/machinery/portable/canister.dm b/code/modules/atmospherics/machinery/portable/canister.dm index aae7c7a8090e..e299e6f03429 100644 --- a/code/modules/atmospherics/machinery/portable/canister.dm +++ b/code/modules/atmospherics/machinery/portable/canister.dm @@ -466,21 +466,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 - - pump.process_atmos() // Pump gas. - if(!holding) - air_update_turf() // Update the environment if needed. - else - pump.airs[1] = null - pump.airs[2] = null + 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() update_icon() + /obj/machinery/portable_atmospherics/canister/ui_state(mob/user) return GLOB.physical_state diff --git a/code/modules/atmospherics/machinery/portable/portable_atmospherics.dm b/code/modules/atmospherics/machinery/portable/portable_atmospherics.dm index 73a692ea5d08..c6191a50a22a 100644 --- a/code/modules/atmospherics/machinery/portable/portable_atmospherics.dm +++ b/code/modules/atmospherics/machinery/portable/portable_atmospherics.dm @@ -45,7 +45,7 @@ return ..() /obj/machinery/portable_atmospherics/process_atmos() - if(!connected_port) // Pipe network handles reactions if connected. + if(!connected_port && air_contents != null && src != null) // Pipe network handles reactions if connected. air_contents.react(src) /obj/machinery/portable_atmospherics/return_air() @@ -63,8 +63,7 @@ //Perform the connection connected_port = new_port connected_port.connected_device = src - var/datum/pipeline/connected_port_parent = connected_port.parents[1] - connected_port_parent.reconcile_air() + connected_port.parents[1].update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED anchored = TRUE //Prevent movement pixel_x = new_port.pixel_x @@ -72,6 +71,7 @@ update_icon() return TRUE + /obj/machinery/portable_atmospherics/Move() . = ..() if(.)