[MIRROR] atmos binary devices code cleanup + docs (#3525)

* atmos binary devices code cleanup + docs (#57019)

* atmos binary devices code cleanup + docs

Co-authored-by: Ghilker <42839747+Ghilker@users.noreply.github.com>
This commit is contained in:
SkyratBot
2021-02-20 01:48:19 +01:00
committed by GitHub
parent 7a30eb2eae
commit fddd4fd8f0
9 changed files with 132 additions and 95 deletions
@@ -16,7 +16,11 @@
/obj/machinery/atmospherics/components/binary/getNodeConnects()
return list(turn(dir, 180), dir)
///Used by binary devices to set what the offset will be for each layer
/**
* Used by binary devices to set what the offset will be for each layer, called in update_icon_nopipes()
* Arguments:
* * -pipe_layer: is the pipe layer the component should be set to
*/
/obj/machinery/atmospherics/components/binary/proc/set_overlay_offset(pipe_layer)
switch(pipe_layer)
if(1, 3, 5)
@@ -1,5 +1,5 @@
//Acts like a normal vent, but has an input AND output.
///pressure_checks defines for external_pressure_bound and input_pressure_min
#define EXT_BOUND 1
#define INPUT_MIN 2
#define OUTPUT_MAX 4
@@ -16,22 +16,23 @@
hide = TRUE
///Variable for radio frequency
var/frequency = 0
///Variable for radio id
var/id = null
///Stores the radio connection
var/datum/radio_frequency/radio_connection
var/pump_direction = 1 //0 = siphoning, 1 = releasing
///Indicates that the direction of the pump, if 0 is siphoning, if 1 is releasing
var/pump_direction = 1
///Set the maximum allowed external pressure
var/external_pressure_bound = ONE_ATMOSPHERE
///Set the maximum pressure at the input port
var/input_pressure_min = 0
///Set the maximum pressure at the output port
var/output_pressure_max = 0
///Set the flag for the pressure bound
var/pressure_checks = EXT_BOUND
//EXT_BOUND: Do not pass external_pressure_bound
//INPUT_MIN: Do not pass input_pressure_min
//OUTPUT_MAX: Do not pass output_pressure_max
/obj/machinery/atmospherics/components/binary/dp_vent_pump/Destroy()
SSradio.remove_object(src, frequency)
return ..()
@@ -48,8 +49,6 @@
icon_state = pump_direction ? "vent_out" : "vent_in"
/obj/machinery/atmospherics/components/binary/dp_vent_pump/process_atmos()
..()
if(!on)
return
var/datum/gas_mixture/air1 = airs[1]
@@ -66,20 +65,22 @@
if(pressure_checks&INPUT_MIN)
pressure_delta = min(pressure_delta, (air1.return_pressure() - input_pressure_min))
if(pressure_delta > 0)
if(air1.temperature > 0)
var/transfer_moles = (pressure_delta*environment.volume)/(air1.temperature * R_IDEAL_GAS_EQUATION)
if(pressure_delta <= 0)
return
if(air1.temperature <= 0)
return
var/transfer_moles = (pressure_delta*environment.volume)/(air1.temperature * R_IDEAL_GAS_EQUATION)
var/datum/gas_mixture/removed = air1.remove(transfer_moles)
//Removed can be null if there is no atmosphere in air1
if(!removed)
return
var/datum/gas_mixture/removed = air1.remove(transfer_moles)
//Removed can be null if there is no atmosphere in air1
if(!removed)
return
loc.assume_air(removed)
air_update_turf(FALSE, FALSE)
loc.assume_air(removed)
air_update_turf(FALSE, FALSE)
var/datum/pipeline/parent1 = parents[1]
parent1.update = TRUE
var/datum/pipeline/parent1 = parents[1]
parent1.update = TRUE
else //external -> output
var/pressure_delta = 10000
@@ -89,29 +90,39 @@
if(pressure_checks&INPUT_MIN)
pressure_delta = min(pressure_delta, (output_pressure_max - air2.return_pressure()))
if(pressure_delta > 0)
if(environment.temperature > 0)
var/transfer_moles = (pressure_delta*air2.volume)/(environment.temperature * R_IDEAL_GAS_EQUATION)
if(pressure_delta <= 0)
return
if(environment.temperature <= 0)
return
var/transfer_moles = (pressure_delta*air2.volume)/(environment.temperature * R_IDEAL_GAS_EQUATION)
var/datum/gas_mixture/removed = loc.remove_air(transfer_moles)
//removed can be null if there is no air in the location
if(!removed)
return
var/datum/gas_mixture/removed = loc.remove_air(transfer_moles)
//removed can be null if there is no air in the location
if(!removed)
return
air2.merge(removed)
air_update_turf(FALSE, FALSE)
air2.merge(removed)
air_update_turf(FALSE, FALSE)
var/datum/pipeline/parent2 = parents[2]
parent2.update = TRUE
var/datum/pipeline/parent2 = parents[2]
parent2.update = TRUE
//Radio remote control
/**
* Called in atmosinit(), used to change or remove the radio frequency from the component
* Arguments:
* * -new_frequency: the frequency that should be used for the radio to attach to the component, use 0 to remove the radio
*/
/obj/machinery/atmospherics/components/binary/dp_vent_pump/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)
/**
* Called in atmosinit(), send the component status to the radio device connected
*/
/obj/machinery/atmospherics/components/binary/dp_vent_pump/proc/broadcast_status()
if(!radio_connection)
return
@@ -9,23 +9,21 @@ Passive gate is similar to the regular pump except:
/obj/machinery/atmospherics/components/binary/passive_gate
icon_state = "passgate_map-3"
name = "passive gate"
desc = "A one-way air valve that does not require power. Passes gas when the output pressure is lower than the target pressure."
can_unwrench = TRUE
shift_underlay_only = FALSE
interaction_flags_machine = INTERACT_MACHINE_OFFLINE | INTERACT_MACHINE_WIRES_IF_OPEN | INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OPEN_SILICON | INTERACT_MACHINE_SET_MACHINE
var/target_pressure = ONE_ATMOSPHERE
var/frequency = 0
var/id = null
var/datum/radio_frequency/radio_connection
construction_type = /obj/item/pipe/directional
pipe_state = "passivegate"
///Set the target pressure the component should arrive to
var/target_pressure = ONE_ATMOSPHERE
///Variable for radio frequency
var/frequency = 0
///Variable for radio id
var/id = null
///Stores the radio connection
var/datum/radio_frequency/radio_connection
/obj/machinery/atmospherics/components/binary/passive_gate/CtrlClick(mob/user)
if(can_interact(user))
@@ -53,7 +51,6 @@ Passive gate is similar to the regular pump except:
add_overlay(getpipeimage(icon, "passgate_on-[set_overlay_offset(piping_layer)]"))
/obj/machinery/atmospherics/components/binary/passive_gate/process_atmos()
..()
if(!on)
return
@@ -62,15 +59,22 @@ Passive gate is similar to the regular pump except:
if(air1.release_gas_to(air2, target_pressure))
update_parents()
//Radio remote control
/**
* Called in atmosinit(), used to change or remove the radio frequency from the component
* Arguments:
* * -new_frequency: the frequency that should be used for the radio to attach to the component, use 0 to remove the radio
*/
/obj/machinery/atmospherics/components/binary/passive_gate/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)
/**
* Called in atmosinit(), send the component status to the radio device connected
*/
/obj/machinery/atmospherics/components/binary/passive_gate/proc/broadcast_status()
if(!radio_connection)
return
@@ -2,10 +2,10 @@
icon_state = "pvalve_map-3"
name = "pressure valve"
desc = "An activable one way 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
construction_type = /obj/item/pipe/directional
pipe_state = "pvalve"
///Amount of pressure needed before the valve for it to open
var/target_pressure = ONE_ATMOSPHERE
///Frequency for radio signaling
@@ -17,9 +17,6 @@
///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
@@ -65,12 +62,22 @@
is_gas_flowing = FALSE
update_icon_nopipes()
//Radio remote control
/**
* Called in atmosinit(), used to change or remove the radio frequency from the component
* Arguments:
* * -new_frequency: the frequency that should be used for the radio to attach to the component, use 0 to remove the radio
*/
/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)
/**
* Called in atmosinit(), send the component status to the radio device connected
*/
/obj/machinery/atmospherics/components/binary/pressure_valve/proc/broadcast_status()
if(!radio_connection)
return
@@ -14,18 +14,18 @@
icon_state = "pump_map-3"
name = "gas pump"
desc = "A pump that moves gas by pressure."
can_unwrench = TRUE
shift_underlay_only = FALSE
var/target_pressure = ONE_ATMOSPHERE
var/frequency = 0
var/id = null
var/datum/radio_frequency/radio_connection
construction_type = /obj/item/pipe/directional
pipe_state = "pump"
///Pressure that the pump will reach when on
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
/obj/machinery/atmospherics/components/binary/pump/CtrlClick(mob/user)
if(can_interact(user))
@@ -52,7 +52,6 @@
icon_state = (on && is_operational) ? "pump_on-[set_overlay_offset(piping_layer)]" : "pump_off-[set_overlay_offset(piping_layer)]"
/obj/machinery/atmospherics/components/binary/pump/process_atmos()
// ..()
if(!on || !is_operational)
return
@@ -62,13 +61,20 @@
if(air1.pump_gas_to(air2, target_pressure))
update_parents()
//Radio remote control
/**
* Called in atmosinit(), used to change or remove the radio frequency from the component
* Arguments:
* * -new_frequency: the frequency that should be used for the radio to attach to the component, use 0 to remove the radio
*/
/obj/machinery/atmospherics/components/binary/pump/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)
/**
* Called in atmosinit(), send the component status to the radio device connected
*/
/obj/machinery/atmospherics/components/binary/pump/proc/broadcast_status()
if(!radio_connection)
return
@@ -2,12 +2,10 @@
icon_state = "tgate_map-3"
name = "temperature gate"
desc = "An activable gate that compares the input temperature with the interface set temperature to check if the gas can flow from the input side to the output side or not."
can_unwrench = TRUE
shift_underlay_only = FALSE
construction_type = /obj/item/pipe/directional
pipe_state = "tgate"
///If the temperature of the mix before the gate is lower than this, the gas will flow (if inverted, if the temperature of the mix before the gate is higher than this)
var/target_temperature = T0C
///Minimum allowed temperature
@@ -2,18 +2,15 @@
icon_state = "tpump_map-3"
name = "temperature pump"
desc = "A pump that moves heat from one pipeline to another. The input will get cooler, and the output will get hotter."
can_unwrench = TRUE
shift_underlay_only = FALSE
construction_type = /obj/item/pipe/directional
pipe_state = "tpump"
///Percent of the heat delta to transfer
var/heat_transfer_rate = 0
///Maximum allowed transfer percentage
var/max_heat_transfer_rate = 100
construction_type = /obj/item/pipe/directional
pipe_state = "tpump"
/obj/machinery/atmospherics/components/binary/temperature_pump/CtrlClick(mob/user)
if(can_interact(user))
on = !on
@@ -1,27 +1,22 @@
/*
It's like a regular ol' straight pipe, but you can turn it on and off.
*/
#define MANUAL_VALVE "m"
#define DIGITAL_VALVE "d"
/obj/machinery/atmospherics/components/binary/valve
icon_state = "mvalve_map-3"
name = "manual valve"
desc = "A pipe with a valve that can be used to disable flow of gas through it."
can_unwrench = TRUE
shift_underlay_only = FALSE
interaction_flags_machine = INTERACT_MACHINE_OFFLINE | INTERACT_MACHINE_OPEN //Intentionally no allow_silicon flag
pipe_flags = PIPING_CARDINAL_AUTONORMALIZE
var/frequency = 0
var/id = null
var/valve_type = "m" //lets us have a nice, clean, OOP update_icon_nopipes()
construction_type = /obj/item/pipe/binary
pipe_state = "mvalve"
///Type of valve (manual or digital), used to set the icon of the component in update_icon_nopipes()
var/valve_type = MANUAL_VALVE
///Bool to stop interactions while the opening/closing animation is going
var/switching = FALSE
/obj/machinery/atmospherics/components/binary/valve/update_icon_nopipes(animation = FALSE)
@@ -30,6 +25,9 @@ It's like a regular ol' straight pipe, but you can turn it on and off.
flick("[valve_type]valve_[on][!on]-[set_overlay_offset(piping_layer)]", src)
icon_state = "[valve_type]valve_[on ? "on" : "off"]-[set_overlay_offset(piping_layer)]"
/**
* Called by finish_interact(), switch between open and closed, reconcile the air between two pipelines
*/
/obj/machinery/atmospherics/components/binary/valve/proc/toggle()
if(on)
on = FALSE
@@ -49,19 +47,21 @@ It's like a regular ol' straight pipe, but you can turn it on and off.
return
update_icon_nopipes(TRUE)
switching = TRUE
addtimer(CALLBACK(src, .proc/finish_interact), 10)
addtimer(CALLBACK(src, .proc/finish_interact), 1 SECONDS)
/**
* Called by iteract() after a 1 second timer, calls toggle(), allows another interaction with the component.
*/
/obj/machinery/atmospherics/components/binary/valve/proc/finish_interact()
toggle()
switching = FALSE
/obj/machinery/atmospherics/components/binary/valve/digital // can be controlled by AI
icon_state = "dvalve_map-3"
name = "digital valve"
desc = "A digitally controlled valve."
valve_type = "d"
valve_type = DIGITAL_VALVE
pipe_state = "dvalve"
interaction_flags_machine = INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OFFLINE | INTERACT_MACHINE_OPEN | INTERACT_MACHINE_OPEN_SILICON
@@ -71,8 +71,7 @@ It's like a regular ol' straight pipe, but you can turn it on and off.
normalize_cardinal_directions()
icon_state = "dvalve_nopower-[set_overlay_offset(piping_layer)]"
return
..()
return..()
/obj/machinery/atmospherics/components/binary/valve/layer2
piping_layer = 2
@@ -111,3 +110,6 @@ It's like a regular ol' straight pipe, but you can turn it on and off.
/obj/machinery/atmospherics/components/binary/valve/digital/on/layer4
piping_layer = 4
icon_state = "dvalve_map-4"
#undef MANUAL_VALVE
#undef DIGITAL_VALVE
@@ -14,19 +14,20 @@
icon_state = "volpump_map-3"
name = "volumetric gas pump"
desc = "A pump that moves gas by volume."
can_unwrench = TRUE
shift_underlay_only = FALSE
var/transfer_rate = MAX_TRANSFER_RATE
var/overclocked = FALSE
var/frequency = 0
var/id = null
var/datum/radio_frequency/radio_connection
construction_type = /obj/item/pipe/directional
pipe_state = "volumepump"
///Transfer rate of the component in L/s
var/transfer_rate = MAX_TRANSFER_RATE
///Check if the component has been overclocked
var/overclocked = FALSE
///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
/obj/machinery/atmospherics/components/binary/volume_pump/CtrlClick(mob/user)
if(can_interact(user))
@@ -51,7 +52,6 @@
icon_state = on && is_operational ? "volpump_on-[set_overlay_offset(piping_layer)]" : "volpump_off-[set_overlay_offset(piping_layer)]"
/obj/machinery/atmospherics/components/binary/volume_pump/process_atmos(delta_time)
// ..()
if(!on || !is_operational)
return
@@ -90,12 +90,20 @@
if(overclocked)
. += "Its warning light is on[on ? " and it's spewing gas!" : "."]"
/**
* Called in atmosinit(), used to change or remove the radio frequency from the component
* Arguments:
* * -new_frequency: the frequency that should be used for the radio to attach to the component, use 0 to remove the radio
*/
/obj/machinery/atmospherics/components/binary/volume_pump/proc/set_frequency(new_frequency)
SSradio.remove_object(src, frequency)
frequency = new_frequency
if(frequency)
radio_connection = SSradio.add_object(src, frequency)
radio_connection = SSradio.add_object(src, frequency, filter = RADIO_ATMOSIA)
/**
* Called in atmosinit(), send the component status to the radio device connected
*/
/obj/machinery/atmospherics/components/binary/volume_pump/proc/broadcast_status()
if(!radio_connection)
return
@@ -123,7 +131,7 @@
return data
/obj/machinery/atmospherics/components/binary/volume_pump/atmosinit()
..()
. = ..()
set_frequency(frequency)