[MIRROR] components_base.dm code cleanup + docs (#3522)

* components_base.dm code cleanup + docs (#57018)

* components_base.dm code cleanup + docs

Co-authored-by: Ghilker <42839747+Ghilker@users.noreply.github.com>
This commit is contained in:
SkyratBot
2021-02-20 00:47:25 +00:00
committed by GitHub
co-authored by Ghilker
parent ebcc204146
commit 8f0a62d175
@@ -3,12 +3,15 @@
/obj/machinery/atmospherics/components
hide = FALSE
var/welded = FALSE //Used on pumps and scrubbers
///Is the component welded?
var/welded = FALSE
///Should the component should show the pipe underneath it?
var/showpipe = TRUE
var/shift_underlay_only = TRUE //Layering only shifts underlay?
///When the component is on a non default layer should we shift everything? Or just the underlay pipe
var/shift_underlay_only = TRUE
///Stores the component pipeline
var/list/datum/pipeline/parents
///Stores the component gas mixture
var/list/datum/gas_mixture/airs
/obj/machinery/atmospherics/components/New()
@@ -30,9 +33,15 @@
// Iconnery
/**
* Called by update_icon(), used individually by each component to determine the icon state without the pipe in consideration
*/
/obj/machinery/atmospherics/components/proc/update_icon_nopipes()
return
/**
* Called in Initialize(), set the showpipe var to true or false depending on the situation, calls update_icon()
*/
/obj/machinery/atmospherics/components/proc/hide_pipe(datum/source, covered)
showpipe = !covered
update_appearance()
@@ -50,11 +59,12 @@
var/connected = 0 //Direction bitset
for(var/i in 1 to device_type) //adds intact pieces
if(nodes[i])
var/obj/machinery/atmospherics/node = nodes[i]
var/image/img = get_pipe_underlay("pipe_intact", get_dir(src, node), node.pipe_color)
underlays += img
connected |= img.dir
if(!nodes[i])
continue
var/obj/machinery/atmospherics/node = nodes[i]
var/image/img = get_pipe_underlay("pipe_intact", get_dir(src, node), node.pipe_color)
underlays += img
connected |= img.dir
for(var/direction in GLOB.cardinals)
if((initialize_directions & direction) && !(connected & direction))
@@ -64,6 +74,13 @@
PIPING_LAYER_SHIFT(src, piping_layer)
return ..()
/**
* Called by update_icon() when showpipe is TRUE, set the image for the underlay pipe
* Arguments:
* * -state: icon_state of the selected pipe
* * -dir: direction of the pipe
* * -color: color of the pipe
*/
/obj/machinery/atmospherics/components/proc/get_pipe_underlay(state, dir, color = null)
if(color)
. = getpipeimage('icons/obj/atmospherics/components/binary_devices.dmi', state, dir, color, piping_layer = shift_underlay_only ? piping_layer : 3)
@@ -84,11 +101,17 @@
/obj/machinery/atmospherics/components/build_network()
for(var/i in 1 to device_type)
if(!parents[i])
parents[i] = new /datum/pipeline()
var/datum/pipeline/P = parents[i]
P.build_pipeline(src)
if(parents[i])
continue
parents[i] = new /datum/pipeline()
var/datum/pipeline/P = parents[i]
P.build_pipeline(src)
/**
* Called by nullifyNode(), used to remove the pipeline the component is attached to
* Arguments:
* * -reference: the pipeline the component is attached to
*/
/obj/machinery/atmospherics/components/proc/nullifyPipenet(datum/pipeline/reference)
if(!reference)
CRASH("nullifyPipenet(null) called by [type] on [COORD(src)]")
@@ -127,43 +150,37 @@
parents[parents.Find(Old)] = New
/obj/machinery/atmospherics/components/unsafe_pressure_release(mob/user, pressures)
..()
. = ..()
var/turf/T = get_turf(src)
if(T)
//Remove the gas from airs and assume it
var/datum/gas_mixture/environment = T.return_air()
var/lost = null
var/times_lost = 0
for(var/i in 1 to device_type)
var/datum/gas_mixture/air = airs[i]
lost += pressures*environment.volume/(air.temperature * R_IDEAL_GAS_EQUATION)
times_lost++
var/shared_loss = lost/times_lost
if(!T)
return
//Remove the gas from airs and assume it
var/datum/gas_mixture/environment = T.return_air()
var/lost = null
var/times_lost = 0
for(var/i in 1 to device_type)
var/datum/gas_mixture/air = airs[i]
lost += pressures*environment.volume/(air.temperature * R_IDEAL_GAS_EQUATION)
times_lost++
var/shared_loss = lost/times_lost
var/datum/gas_mixture/to_release
for(var/i in 1 to device_type)
var/datum/gas_mixture/air = airs[i]
if(!to_release)
to_release = air.remove(shared_loss)
continue
to_release.merge(air.remove(shared_loss))
T.assume_air(to_release)
air_update_turf(FALSE, FALSE)
/obj/machinery/atmospherics/components/proc/safe_input(title, text, default_set)
var/new_value = input(usr,text,title,default_set) as num|null
if (isnull(new_value))
return default_set
if(usr.canUseTopic(src))
return new_value
return default_set
var/datum/gas_mixture/to_release
for(var/i in 1 to device_type)
var/datum/gas_mixture/air = airs[i]
if(!to_release)
to_release = air.remove(shared_loss)
continue
to_release.merge(air.remove(shared_loss))
T.assume_air(to_release)
air_update_turf(FALSE, FALSE)
// Helpers
/**
* Called in most atmos processes and gas handling situations, update the parents pipelines of the devices connected to the source component
* This way gases won't get stuck
*/
/obj/machinery/atmospherics/components/proc/update_parents()
for(var/i in 1 to device_type)
var/datum/pipeline/parent = parents[i]