From a7cf50923062362bf3e3239a352418f9d874ef69 Mon Sep 17 00:00:00 2001 From: Putnam Date: Thu, 9 Jan 2020 03:43:06 -0800 Subject: [PATCH] relief valve. --- .../components/binary_devices/gated_valve.dm | 119 ------------------ .../components/unary_devices/relief_valve.dm | 59 +++++++++ 2 files changed, 59 insertions(+), 119 deletions(-) delete mode 100644 code/modules/atmospherics/machinery/components/binary_devices/gated_valve.dm create mode 100644 code/modules/atmospherics/machinery/components/unary_devices/relief_valve.dm diff --git a/code/modules/atmospherics/machinery/components/binary_devices/gated_valve.dm b/code/modules/atmospherics/machinery/components/binary_devices/gated_valve.dm deleted file mode 100644 index 9dbab39564..0000000000 --- a/code/modules/atmospherics/machinery/components/binary_devices/gated_valve.dm +++ /dev/null @@ -1,119 +0,0 @@ -/* -Like a manual valve, except it has some resistance that makes it open up only at a given pressure. -*/ - -/obj/machinery/atmospherics/components/binary/gated_valve - icon_state = "mvalve_map" - name = "gated valve" - desc = "A valve with a resistor inside that doesn't open until there's a certain amount of pressure on either side." - can_unwrench = TRUE - interaction_flags_machine = INTERACT_MACHINE_OFFLINE | INTERACT_MACHINE_WIRES_IF_OPEN | INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OPEN_SILICON | INTERACT_MACHINE_SET_MACHINE - construction_type = /obj/item/pipe/binary - pipe_state = "mvalve" - - var/switching = FALSE - var/cur_open = FALSE - var/target_pressure = ONE_ATMOSPHERE - -/obj/machinery/atmospherics/components/binary/gated_valve/update_icon_nopipes(animation = 0) - normalize_dir() - if(animation) - flick("mvalve_[cur_open][!cur_open]",src) - icon_state = "mvalve_[cur_open?"on":"off"]" - -/obj/machinery/atmospherics/components/binary/gated_valve/proc/open() - cur_open = TRUE - update_icon_nopipes() - update_parents() - var/datum/pipeline/parent1 = parents[1] - parent1.reconcile_air() - -/obj/machinery/atmospherics/components/binary/gated_valve/proc/close() - cur_open = FALSE - update_icon_nopipes() - -/obj/machinery/atmospherics/components/binary/gated_valve/proc/normalize_dir() - if(dir==SOUTH) - setDir(NORTH) - else if(dir==WEST) - setDir(EAST) - -/obj/machinery/atmospherics/components/binary/gated_valve/layer1 // SHIT IS FUCKED - piping_layer = PIPING_LAYER_MIN - pixel_x = -PIPING_LAYER_P_X - pixel_y = -PIPING_LAYER_P_Y - -/obj/machinery/atmospherics/components/binary/gated_valve/layer3 - piping_layer = PIPING_LAYER_MAX - pixel_x = PIPING_LAYER_P_X - pixel_y = PIPING_LAYER_P_Y - -/obj/machinery/atmospherics/components/binary/gated_valve/on - on = TRUE - -/obj/machinery/atmospherics/components/binary/gated_valve/on/layer1 - piping_layer = PIPING_LAYER_MIN - pixel_x = -PIPING_LAYER_P_X - pixel_y = -PIPING_LAYER_P_Y - -/obj/machinery/atmospherics/components/binary/gated_valve/on/layer3 - piping_layer = PIPING_LAYER_MAX - pixel_x = PIPING_LAYER_P_X - pixel_y = PIPING_LAYER_P_Y - -/obj/machinery/atmospherics/components/binary/gated_valve/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, \ - datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state) - ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open) - if(!ui) - ui = new(user, src, ui_key, "atmos_pump", name, 335, 115, master_ui, state) - ui.open() - -/obj/machinery/atmospherics/components/binary/gated_valve/ui_data() - var/data = list() - data["on"] = on - data["pressure"] = round(target_pressure) - data["max_pressure"] = round(MAX_OUTPUT_PRESSURE) - return data - -/obj/machinery/atmospherics/components/binary/gated_valve/ui_act(action, params) - if(..()) - return - switch(action) - if("power") - on = !on - investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", INVESTIGATE_ATMOS) - . = TRUE - if("pressure") - var/pressure = params["pressure"] - if(pressure == "max") - pressure = MAX_OUTPUT_PRESSURE - . = TRUE - else if(pressure == "input") - pressure = input("New output pressure (0-[MAX_OUTPUT_PRESSURE] kPa):", name, target_pressure) as num|null - if(!isnull(pressure) || !..()) - . = TRUE - else if(text2num(pressure) != null) - pressure = text2num(pressure) - . = TRUE - if(.) - target_pressure = CLAMP(pressure, 0, MAX_OUTPUT_PRESSURE) - investigate_log("was set to [target_pressure] kPa by [key_name(usr)]", INVESTIGATE_ATMOS) - update_icon() - -/obj/machinery/atmospherics/components/binary/gated_valve/process_atmos() - ..() - if(!on) - if(cur_open) - close() - return - var/datum/gas_mixture/air1 = airs[1] - var/datum/gas_mixture/air2 = airs[2] - - var/starting_pressure1 = air1.return_pressure() - var/starting_pressure2 = air2.return_pressure() - var/pressure_difference = abs(starting_pressure1 - starting_pressure2) - - if(!cur_open && pressure_difference > target_pressure) - open() - else if(cur_open && (starting_pressure1 < target_pressure) && (starting_pressure2 < target_pressure)) - close() diff --git a/code/modules/atmospherics/machinery/components/unary_devices/relief_valve.dm b/code/modules/atmospherics/machinery/components/unary_devices/relief_valve.dm new file mode 100644 index 0000000000..dd7d8f5221 --- /dev/null +++ b/code/modules/atmospherics/machinery/components/unary_devices/relief_valve.dm @@ -0,0 +1,59 @@ +/obj/machinery/atmospherics/components/unary/relief_valve + name = "pressure relief valve" + desc = "A valve that opens to the air at a certain pressure, then closes once it goes below another." + icon = 'icons/obj/atmospherics/components/unary_devices.dmi' + icon_state = "relief_valve-e" + var/opened = FALSE + var/open_pressure = ONE_ATMOSPHERE * 3 + var/close_pressure = ONE_ATMOSPHERE + pipe_state = "relief_valve-e" + +/obj/machinery/atmospherics/components/unary/relief_valve/layer1 + piping_layer = PIPING_LAYER_MIN + pixel_x = -PIPING_LAYER_P_X + pixel_y = -PIPING_LAYER_P_Y + +/obj/machinery/atmospherics/components/unary/relief_valve/layer3 + piping_layer = PIPING_LAYER_MAX + pixel_x = PIPING_LAYER_P_X + pixel_y = PIPING_LAYER_P_Y + +/obj/machinery/atmospherics/components/unary/relief_valve/atmos + var/close_pressure = ONE_ATMOSPHERE * 2 + +/obj/machinery/atmospherics/components/unary/relief_valve/atmos/atmos_waste + name = "atmos waste relief valve" + id = ATMOS_GAS_MONITOR_WASTE_ATMOS + +/obj/machinery/atmospherics/components/unary/relief_valve/update_icon_nopipes() + cut_overlays() + + if(!nodes[1] || !opened || !is_operational()) + icon_state = "relief_valve-e" + return + + icon_state = "relief_valve-e-blown" + +/obj/machinery/atmospherics/components/unary/outlet_injector/process_atmos() + ..() + + if(!is_operational()) + return + + var/datum/gas_mixture/air_contents = airs[1] + var/our_pressure = air_contents.return_pressure() + if(opened && our_pressure < close_pressure) + opened = FALSE + else if(!opened && our_pressure >= open_pressure) + opened = TRUE + if(opened && air_contents.temperature > 0) + var/datum/gas_mixture/environment = loc.return_air() + var/pressure_delta = our_pressure - environment.return_pressure() + var/transfer_moles = pressure_delta*environment.volume/(air1.temperature * R_IDEAL_GAS_EQUATION) + if(transfer_moles > 0) + var/datum/gas_mixture/removed = air_contents.remove(transfer_moles) + + loc.assume_air(removed) + air_update_turf() + + update_parents()