mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-22 16:12:19 +00:00
281 lines
6.6 KiB
Plaintext
281 lines
6.6 KiB
Plaintext
//--------------------------------------------
|
|
// Base omni device
|
|
//--------------------------------------------
|
|
/obj/machinery/atmospherics/omni
|
|
name = "omni device"
|
|
icon = 'icons/atmos/omni_devices.dmi'
|
|
icon_state = "base"
|
|
use_power = 1
|
|
initialize_directions = 0
|
|
level = 1
|
|
|
|
var/configuring = 0
|
|
//var/target_pressure = ONE_ATMOSPHERE //a base type as abstract as this should NOT be making these kinds of assumptions
|
|
|
|
var/base_icon
|
|
|
|
var/tag_north = ATM_NONE
|
|
var/tag_south = ATM_NONE
|
|
var/tag_east = ATM_NONE
|
|
var/tag_west = ATM_NONE
|
|
|
|
var/list/on_states = list()
|
|
var/list/off_states = list()
|
|
|
|
var/underlays_current[4]
|
|
|
|
var/list/ports = new()
|
|
|
|
/obj/machinery/atmospherics/omni/Initialize()
|
|
icon_state = "base"
|
|
ports = new()
|
|
for(var/d in cardinal)
|
|
var/datum/omni_port/new_port = new(src, d)
|
|
switch(d)
|
|
if(NORTH)
|
|
new_port.mode = tag_north
|
|
if(SOUTH)
|
|
new_port.mode = tag_south
|
|
if(EAST)
|
|
new_port.mode = tag_east
|
|
if(WEST)
|
|
new_port.mode = tag_west
|
|
if(new_port.mode > 0)
|
|
initialize_directions |= d
|
|
ports += new_port
|
|
. = ..()
|
|
|
|
/obj/machinery/atmospherics/omni/update_icon()
|
|
cut_overlays()
|
|
var/list/to_add = list(base_icon)
|
|
if(stat & NOPOWER)
|
|
to_add += off_states
|
|
else if(error_check())
|
|
to_add += "error"
|
|
else if (use_power)
|
|
to_add[1] = "[base_icon]_glow"
|
|
to_add += on_states
|
|
else
|
|
to_add += off_states
|
|
|
|
add_overlay(to_add)
|
|
|
|
underlays = underlays_current
|
|
|
|
/obj/machinery/atmospherics/omni/proc/error_check()
|
|
return
|
|
|
|
/obj/machinery/atmospherics/omni/machinery_process()
|
|
last_power_draw = 0
|
|
last_flow_rate = 0
|
|
|
|
if(error_check())
|
|
use_power = 0
|
|
|
|
if((stat & (NOPOWER|BROKEN)) || !use_power)
|
|
return 0
|
|
return 1
|
|
|
|
/obj/machinery/atmospherics/omni/power_change()
|
|
var/old_stat = stat
|
|
..()
|
|
if(old_stat != stat)
|
|
update_icon()
|
|
|
|
/obj/machinery/atmospherics/omni/attackby(var/obj/item/weapon/W as obj, var/mob/user as mob)
|
|
if(!iswrench(W))
|
|
return ..()
|
|
|
|
var/int_pressure = 0
|
|
for(var/datum/omni_port/P in ports)
|
|
int_pressure += P.air.return_pressure()
|
|
var/datum/gas_mixture/env_air = loc.return_air()
|
|
if ((int_pressure - env_air.return_pressure()) > 2*ONE_ATMOSPHERE)
|
|
user << "<span class='warning'>You cannot unwrench \the [src], it is too exerted due to internal pressure.</span>"
|
|
add_fingerprint(user)
|
|
return 1
|
|
user << "<span class='notice'>You begin to unfasten \the [src]...</span>"
|
|
playsound(src.loc, 'sound/items/Ratchet.ogg', 50, 1)
|
|
if(do_after(user, 40, act_target = src))
|
|
user.visible_message( \
|
|
"<span class='notice'>\The [user] unfastens \the [src].</span>", \
|
|
"<span class='notice'>You have unfastened \the [src].</span>", \
|
|
"You hear a ratchet.")
|
|
new /obj/item/pipe(loc, make_from=src)
|
|
qdel(src)
|
|
|
|
/obj/machinery/atmospherics/omni/attack_hand(user as mob)
|
|
if(..())
|
|
return
|
|
|
|
src.add_fingerprint(usr)
|
|
ui_interact(user)
|
|
return
|
|
|
|
/obj/machinery/atmospherics/omni/proc/update_port_icons()
|
|
if(!check_icon_cache())
|
|
return
|
|
|
|
on_states.Cut()
|
|
off_states.Cut()
|
|
|
|
for(var/datum/omni_port/P in ports)
|
|
var/ref_layer = 0
|
|
switch(P.dir)
|
|
if(NORTH)
|
|
ref_layer = 1
|
|
if(SOUTH)
|
|
ref_layer = 2
|
|
if(EAST)
|
|
ref_layer = 3
|
|
if(WEST)
|
|
ref_layer = 4
|
|
|
|
if(!ref_layer)
|
|
continue
|
|
|
|
var/list/underlay_icon = select_port_icons(P)
|
|
if(underlay_icon)
|
|
if(P.node)
|
|
underlays_current[ref_layer] = underlay_icon
|
|
else
|
|
underlays_current[ref_layer] = null
|
|
else
|
|
underlays_current[ref_layer] = null
|
|
|
|
update_icon()
|
|
|
|
// Assumes on_states and off_states have been cut if required.
|
|
/obj/machinery/atmospherics/omni/proc/select_port_icons(datum/omni_port/P)
|
|
if(!istype(P))
|
|
return
|
|
|
|
if(P.mode > 0)
|
|
var/ic_dir = dir_name(P.dir)
|
|
var/ic_on = ic_dir
|
|
var/ic_off = ic_dir
|
|
switch(P.mode)
|
|
if(ATM_INPUT)
|
|
ic_on += "_in_glow"
|
|
ic_off += "_in"
|
|
if(ATM_OUTPUT)
|
|
ic_on += "_out_glow"
|
|
ic_off += "_out"
|
|
if(ATM_O2 to ATM_N2O)
|
|
ic_on += "_filter"
|
|
ic_off += "_out"
|
|
|
|
on_states += ic_on
|
|
off_states += ic_off
|
|
|
|
var/turf/T = get_turf(src)
|
|
if(!istype(T))
|
|
return
|
|
if(!T.is_plating() && istype(P.node, /obj/machinery/atmospherics/pipe) && P.node.level == 1 )
|
|
. = icon_manager.get_atmos_icon("underlay", P.dir, color_cache_name(P.node), "down")
|
|
else
|
|
. = icon_manager.get_atmos_icon("underlay", P.dir, color_cache_name(P.node), "intact")
|
|
|
|
/obj/machinery/atmospherics/omni/update_underlays()
|
|
for(var/datum/omni_port/P in ports)
|
|
P.update = 1
|
|
update_ports()
|
|
|
|
/obj/machinery/atmospherics/omni/hide(var/i)
|
|
update_underlays()
|
|
|
|
/obj/machinery/atmospherics/omni/proc/update_ports()
|
|
sort_ports()
|
|
update_port_icons()
|
|
for(var/datum/omni_port/P in ports)
|
|
P.update = 0
|
|
|
|
/obj/machinery/atmospherics/omni/proc/sort_ports()
|
|
return
|
|
|
|
|
|
// Housekeeping and pipe network stuff below
|
|
|
|
/obj/machinery/atmospherics/omni/network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference)
|
|
for(var/datum/omni_port/P in ports)
|
|
if(reference == P.node)
|
|
P.network = new_network
|
|
break
|
|
|
|
if(new_network.normal_members.Find(src))
|
|
return 0
|
|
|
|
new_network.normal_members += src
|
|
|
|
return null
|
|
|
|
/obj/machinery/atmospherics/omni/Destroy()
|
|
loc = null
|
|
|
|
for(var/datum/omni_port/P in ports)
|
|
if(P.node)
|
|
P.node.disconnect(src)
|
|
qdel(P.network)
|
|
P.node = null
|
|
|
|
return ..()
|
|
|
|
/obj/machinery/atmospherics/omni/atmos_init()
|
|
for(var/datum/omni_port/P in ports)
|
|
if(P.node || P.mode == 0)
|
|
continue
|
|
for(var/obj/machinery/atmospherics/target in get_step(src, P.dir))
|
|
if(target.initialize_directions & get_dir(target,src))
|
|
if (check_connect_types(target,src))
|
|
P.node = target
|
|
break
|
|
|
|
for(var/datum/omni_port/P in ports)
|
|
P.update = 1
|
|
|
|
update_ports()
|
|
|
|
/obj/machinery/atmospherics/omni/build_network()
|
|
for(var/datum/omni_port/P in ports)
|
|
if(!P.network && P.node)
|
|
P.network = new /datum/pipe_network()
|
|
P.network.normal_members += src
|
|
P.network.build_network(P.node, src)
|
|
|
|
/obj/machinery/atmospherics/omni/return_network(obj/machinery/atmospherics/reference)
|
|
build_network()
|
|
|
|
for(var/datum/omni_port/P in ports)
|
|
if(reference == P.node)
|
|
return P.network
|
|
|
|
return null
|
|
|
|
/obj/machinery/atmospherics/omni/reassign_network(datum/pipe_network/old_network, datum/pipe_network/new_network)
|
|
for(var/datum/omni_port/P in ports)
|
|
if(P.network == old_network)
|
|
P.network = new_network
|
|
|
|
return 1
|
|
|
|
/obj/machinery/atmospherics/omni/return_network_air(datum/pipe_network/reference)
|
|
var/list/results = list()
|
|
|
|
for(var/datum/omni_port/P in ports)
|
|
if(P.network == reference)
|
|
results += P.air
|
|
|
|
return results
|
|
|
|
/obj/machinery/atmospherics/omni/disconnect(obj/machinery/atmospherics/reference)
|
|
for(var/datum/omni_port/P in ports)
|
|
if(reference == P.node)
|
|
qdel(P.network)
|
|
P.node = null
|
|
P.update = 1
|
|
break
|
|
|
|
update_ports()
|
|
|
|
return null
|