Files
Yogstation/code/modules/atmospherics/machinery/components/components_base.dm
Katherine Kiefer 575cbe8c3e little trolling
2022-05-30 18:47:18 +10:00

167 lines
5.0 KiB
Plaintext

// So much of atmospherics.dm was used solely by components, so separating this makes things all a lot cleaner.
// On top of that, now people can add component-speciic procs/vars if they want!
/obj/machinery/atmospherics/components
var/welded = FALSE //Used on pumps and scrubbers
var/showpipe = TRUE
var/shift_underlay_only = TRUE //Layering only shifts underlay?
var/list/datum/pipeline/parents
var/list/datum/gas_mixture/airs
/obj/machinery/atmospherics/components/New()
parents = new(device_type)
airs = new(device_type)
..()
for(var/i in 1 to device_type)
var/datum/gas_mixture/A = new(200)
airs[i] = A
// Iconnery
/obj/machinery/atmospherics/components/proc/update_icon_nopipes()
return
/obj/machinery/atmospherics/components/update_icon()
update_icon_nopipes()
underlays.Cut()
plane = showpipe ? GAME_PLANE : FLOOR_PLANE
if(!showpipe)
return ..()
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
for(var/direction in GLOB.cardinals)
if((initialize_directions & direction) && !(connected & direction))
underlays += get_pipe_underlay("pipe_exposed", direction)
if(!shift_underlay_only)
PIPING_LAYER_SHIFT(src, piping_layer)
return ..()
/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)
else
. = getpipeimage('icons/obj/atmospherics/components/binary_devices.dmi', state, dir, piping_layer = shift_underlay_only ? piping_layer : 3)
// Pipenet stuff; housekeeping
/obj/machinery/atmospherics/components/nullifyNode(i)
if(nodes[i])
nullifyPipenet(parents[i])
QDEL_NULL(airs[i])
..()
/obj/machinery/atmospherics/components/on_construction()
..()
update_parents()
/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)
/obj/machinery/atmospherics/components/proc/nullifyPipenet(datum/pipeline/reference)
if(!reference)
CRASH("nullifyPipenet(null) called by [type] on [COORD(src)]")
var/i = parents.Find(reference)
reference.other_airs -= airs[i]
reference.other_atmosmch -= src
parents[i] = null
// We should return every air sharing a parent
/obj/machinery/atmospherics/components/returnPipenetAir(datum/pipeline/reference)
for(var/i in 1 to device_type)
if(parents[i] == reference)
if(.)
if(!islist(.))
. = list(.)
. += airs[i]
else
. = airs[i]
/obj/machinery/atmospherics/components/pipeline_expansion(datum/pipeline/reference)
if(reference)
return list(nodes[parents.Find(reference)])
return ..()
/obj/machinery/atmospherics/components/setPipenet(datum/pipeline/reference, obj/machinery/atmospherics/A)
parents[nodes.Find(A)] = reference
/obj/machinery/atmospherics/components/returnPipenet(obj/machinery/atmospherics/A = nodes[1]) //returns parents[1] if called without argument
return parents[nodes.Find(A)]
/obj/machinery/atmospherics/components/replacePipenet(datum/pipeline/Old, datum/pipeline/New)
parents[parents.Find(Old)] = New
/obj/machinery/atmospherics/components/unsafe_pressure_release(var/mob/user, var/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.return_volume()/(air.return_temperature() * R_IDEAL_GAS_EQUATION)
times_lost++
var/shared_loss = lost/times_lost
for(var/i in 1 to device_type)
var/datum/gas_mixture/air = airs[i]
T.assume_air_moles(air, shared_loss)
air_update_turf()
/obj/machinery/atmospherics/components/proc/safe_input(var/title, var/text, var/default_set)
var/new_value = input(usr,text,title,default_set) as num
if(usr.canUseTopic(src))
return new_value
return default_set
// Helpers
/obj/machinery/atmospherics/components/proc/update_parents()
for(var/i in 1 to device_type)
var/datum/pipeline/parent = parents[i]
if(!parent)
//WARNING("Component is missing a pipenet! Rebuilding...")
//At pre-SSair_rebuild_pipenets times, not having a parent wasn't supposed to happen
SSair.add_to_rebuild_queue(src)
continue
parent.update = PIPENET_UPDATE_STATUS_RECONCILE_NEEDED
/obj/machinery/atmospherics/components/returnPipenets()
. = list()
for(var/i in 1 to device_type)
. += returnPipenet(nodes[i])
// UI Stuff
/obj/machinery/atmospherics/components/ui_status(mob/user)
if(allowed(user))
return ..()
to_chat(user, span_danger("Access denied."))
return UI_CLOSE
// Tool acts
/obj/machinery/atmospherics/components/analyzer_act(mob/living/user, obj/item/I)
atmosanalyzer_scan(airs, user, src)