From fdbbcfe59a32b956d624882189564e778c5bf258 Mon Sep 17 00:00:00 2001 From: Putnam Date: Wed, 8 Jan 2020 17:05:43 -0800 Subject: [PATCH] it's functional, sprite time --- code/game/objects/items/RPD.dm | 1 + .../components/binary_devices/gated_valve.dm | 119 ++++++++++++++++++ .../atmospherics/machinery/datum_pipeline.dm | 5 + tgstation.dme | 1 + 4 files changed, 126 insertions(+) create mode 100644 code/modules/atmospherics/machinery/components/binary_devices/gated_valve.dm diff --git a/code/game/objects/items/RPD.dm b/code/game/objects/items/RPD.dm index 141f7e510a..cefb17dd65 100644 --- a/code/game/objects/items/RPD.dm +++ b/code/game/objects/items/RPD.dm @@ -25,6 +25,7 @@ GLOBAL_LIST_INIT(atmos_pipe_recipes, list( "Devices" = list( new /datum/pipe_info/pipe("Connector", /obj/machinery/atmospherics/components/unary/portables_connector), new /datum/pipe_info/pipe("Unary Vent", /obj/machinery/atmospherics/components/unary/vent_pump), + new /datum/pipe_info/pipe("Gated Valve", /obj/machinery/atmospherics/components/binary/gated_valve), new /datum/pipe_info/pipe("Gas Pump", /obj/machinery/atmospherics/components/binary/pump), new /datum/pipe_info/pipe("Passive Gate", /obj/machinery/atmospherics/components/binary/passive_gate), new /datum/pipe_info/pipe("Volume Pump", /obj/machinery/atmospherics/components/binary/volume_pump), diff --git a/code/modules/atmospherics/machinery/components/binary_devices/gated_valve.dm b/code/modules/atmospherics/machinery/components/binary_devices/gated_valve.dm new file mode 100644 index 0000000000..9dbab39564 --- /dev/null +++ b/code/modules/atmospherics/machinery/components/binary_devices/gated_valve.dm @@ -0,0 +1,119 @@ +/* +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/datum_pipeline.dm b/code/modules/atmospherics/machinery/datum_pipeline.dm index db8a8e90ad..fb585d9296 100644 --- a/code/modules/atmospherics/machinery/datum_pipeline.dm +++ b/code/modules/atmospherics/machinery/datum_pipeline.dm @@ -227,6 +227,11 @@ if(V.on) PL |= V.parents[1] PL |= V.parents[2] + else if (istype(atmosmch, /obj/machinery/atmospherics/components/binary/gated_valve)) // i hate this + var/obj/machinery/atmospherics/components/binary/gated_valve/V = atmosmch + if(V.cur_open) + PL |= V.parents[1] + PL |= V.parents[2] else if (istype(atmosmch, /obj/machinery/atmospherics/components/unary/portables_connector)) var/obj/machinery/atmospherics/components/unary/portables_connector/C = atmosmch if(C.connected_device) diff --git a/tgstation.dme b/tgstation.dme index 33a4251dd7..ccc2614f8e 100755 --- a/tgstation.dme +++ b/tgstation.dme @@ -1461,6 +1461,7 @@ #include "code\modules\atmospherics\machinery\components\binary_devices\binary_devices.dm" #include "code\modules\atmospherics\machinery\components\binary_devices\circulator.dm" #include "code\modules\atmospherics\machinery\components\binary_devices\dp_vent_pump.dm" +#include "code\modules\atmospherics\machinery\components\binary_devices\gated_valve.dm" #include "code\modules\atmospherics\machinery\components\binary_devices\passive_gate.dm" #include "code\modules\atmospherics\machinery\components\binary_devices\pump.dm" #include "code\modules\atmospherics\machinery\components\binary_devices\valve.dm"