diff --git a/code/game/objects/items/RPD.dm b/code/game/objects/items/RPD.dm index c91f7557eb2..2cc7e05a2b8 100644 --- a/code/game/objects/items/RPD.dm +++ b/code/game/objects/items/RPD.dm @@ -33,6 +33,7 @@ GLOBAL_LIST_INIT(atmos_pipe_recipes, list( new /datum/pipe_info/pipe("Passive Vent", /obj/machinery/atmospherics/components/unary/passive_vent), new /datum/pipe_info/pipe("Manual Valve", /obj/machinery/atmospherics/components/binary/valve), new /datum/pipe_info/pipe("Digital Valve", /obj/machinery/atmospherics/components/binary/valve/digital), + new /datum/pipe_info/pipe("Pressure Valve", /obj/machinery/atmospherics/components/binary/pressure_valve), new /datum/pipe_info/meter("Meter"), ), "Heat Exchange" = list( diff --git a/code/modules/atmospherics/machinery/components/binary_devices/pressure_valve.dm b/code/modules/atmospherics/machinery/components/binary_devices/pressure_valve.dm new file mode 100644 index 00000000000..f378009a0b5 --- /dev/null +++ b/code/modules/atmospherics/machinery/components/binary_devices/pressure_valve.dm @@ -0,0 +1,176 @@ +/obj/machinery/atmospherics/components/binary/pressure_valve + icon_state = "pvalve_map-2" + name = "pressure valve" + desc = "An activable valve that let gas pass through if the pressure on the input side is higher than the set pressure." + + can_unwrench = TRUE + shift_underlay_only = FALSE + + ///Amount of pressure needed before the valve for it to open + var/target_pressure = ONE_ATMOSPHERE + ///Frequency for radio signaling + var/frequency = 0 + ///ID for radio signaling + var/id = null + ///Connection to the radio processing + var/datum/radio_frequency/radio_connection + ///Check if the gas is moving from one pipenet to the other + var/is_gas_flowing = FALSE + + construction_type = /obj/item/pipe/directional + pipe_state = "pvalve" + +/obj/machinery/atmospherics/components/binary/pressure_valve/CtrlClick(mob/user) + if(can_interact(user)) + on = !on + investigate_log("was turned [on ? "on" : "off"] by [key_name(user)]", INVESTIGATE_ATMOS) + update_icon() + return ..() + +/obj/machinery/atmospherics/components/binary/pressure_valve/AltClick(mob/user) + if(can_interact(user)) + target_pressure = MAX_OUTPUT_PRESSURE + investigate_log("was set to [target_pressure] kPa by [key_name(user)]", INVESTIGATE_ATMOS) + update_icon() + return ..() + +/obj/machinery/atmospherics/components/binary/pressure_valve/Destroy() + SSradio.remove_object(src,frequency) + if(radio_connection) + radio_connection = null + return ..() + +/obj/machinery/atmospherics/components/binary/pressure_valve/update_icon_nopipes() + if(on && is_operational && is_gas_flowing) + icon_state = "pvalve_flow" + else if(on && is_operational && !is_gas_flowing) + icon_state = "pvalve_on" + else + icon_state = "pvalve_off" + +/obj/machinery/atmospherics/components/binary/pressure_valve/process_atmos() + + if(!on || !is_operational) + return + + var/datum/gas_mixture/air1 = airs[1] + var/datum/gas_mixture/air2 = airs[2] + + if(air1.return_pressure() > target_pressure) + if(air1.pump_gas_to(air2, air1.return_pressure())) + update_parents() + is_gas_flowing = TRUE + update_icon_nopipes() + else + is_gas_flowing = FALSE + update_icon_nopipes() + +/obj/machinery/atmospherics/components/binary/pressure_valve/proc/set_frequency(new_frequency) + SSradio.remove_object(src, frequency) + frequency = new_frequency + if(frequency) + radio_connection = SSradio.add_object(src, frequency, filter = RADIO_ATMOSIA) + +/obj/machinery/atmospherics/components/binary/pressure_valve/proc/broadcast_status() + if(!radio_connection) + return + + var/datum/signal/signal = new(list( + "tag" = id, + "device" = "AGP", + "power" = on, + "target_output" = target_pressure, + "sigtype" = "status" + )) + radio_connection.post_signal(src, signal, filter = RADIO_ATMOSIA) + +/obj/machinery/atmospherics/components/binary/pressure_valve/ui_interact(mob/user, datum/tgui/ui) + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "AtmosPump", name) + ui.open() + +/obj/machinery/atmospherics/components/binary/pressure_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/pressure_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(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/pressure_valve/atmosinit() + . = ..() + if(frequency) + set_frequency(frequency) + +/obj/machinery/atmospherics/components/binary/pressure_valve/receive_signal(datum/signal/signal) + if(!signal.data["tag"] || (signal.data["tag"] != id) || (signal.data["sigtype"]!="command")) + return + + var/old_on = on //for logging + + if("power" in signal.data) + on = text2num(signal.data["power"]) + + if("power_toggle" in signal.data) + on = !on + + if("set_output_pressure" in signal.data) + target_pressure = clamp(text2num(signal.data["set_output_pressure"]),0,ONE_ATMOSPHERE*50) + + if(on != old_on) + investigate_log("was turned [on ? "on" : "off"] by a remote signal", INVESTIGATE_ATMOS) + + if("status" in signal.data) + broadcast_status() + return + + broadcast_status() + update_icon() + +/obj/machinery/atmospherics/components/binary/pressure_valve/can_unwrench(mob/user) + . = ..() + if(. && on && is_operational) + to_chat(user, "You cannot unwrench [src], turn it off first!") + return FALSE + + +/obj/machinery/atmospherics/components/binary/pressure_valve/layer1 + piping_layer = 1 + icon_state= "pvalve_map-1" + +/obj/machinery/atmospherics/components/binary/pressure_valve/layer3 + piping_layer = 3 + icon_state= "pvalve_map-3" + +/obj/machinery/atmospherics/components/binary/pressure_valve/on + on = TRUE + icon_state = "pvalve_on_map-2" + +/obj/machinery/atmospherics/components/binary/pressure_valve/on/layer1 + piping_layer = 1 + icon_state= "pvalve_on_map-1" + +/obj/machinery/atmospherics/components/binary/pressure_valve/on/layer3 + piping_layer = 3 + icon_state= "pvalve_on_map-3" diff --git a/icons/obj/atmospherics/components/binary_devices.dmi b/icons/obj/atmospherics/components/binary_devices.dmi index c35d6d0e550..212589d183e 100644 Binary files a/icons/obj/atmospherics/components/binary_devices.dmi and b/icons/obj/atmospherics/components/binary_devices.dmi differ diff --git a/icons/obj/atmospherics/pipes/pipe_item.dmi b/icons/obj/atmospherics/pipes/pipe_item.dmi index a7501045f9e..1ce202ee7cd 100644 Binary files a/icons/obj/atmospherics/pipes/pipe_item.dmi and b/icons/obj/atmospherics/pipes/pipe_item.dmi differ diff --git a/tgstation.dme b/tgstation.dme index 7d76cbf1f8a..c9ec525ab14 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -1628,6 +1628,7 @@ #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\passive_gate.dm" +#include "code\modules\atmospherics\machinery\components\binary_devices\pressure_valve.dm" #include "code\modules\atmospherics\machinery\components\binary_devices\pump.dm" #include "code\modules\atmospherics\machinery\components\binary_devices\valve.dm" #include "code\modules\atmospherics\machinery\components\binary_devices\volume_pump.dm"