mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-13 03:33:21 +00:00
Eliminated duplicate code in trinary components.
- Consolidate common functions into trinary_base - The only real difference in atmos_init was which direction each node would connect in. Delegated that to an overridable proc, and the rest can be consolidated. Same story for update_underlays() - Used similar patterns on tvalves which also are trinary even tho they are not subtyes of trinary (for some reason)
This commit is contained in:
@@ -46,6 +46,11 @@ Pipelines + Other Objects -> Pipe network
|
|||||||
/obj/machinery/atmospherics/proc/init_dir()
|
/obj/machinery/atmospherics/proc/init_dir()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
// Get the direction each node is facing to connect.
|
||||||
|
// It now returns as a list so it can be fetched nicely, each entry corresponds to node of same number.
|
||||||
|
/obj/machinery/atmospherics/proc/get_node_connect_dirs()
|
||||||
|
return
|
||||||
|
|
||||||
// Initializes nodes by looking at neighboring atmospherics machinery to connect to.
|
// Initializes nodes by looking at neighboring atmospherics machinery to connect to.
|
||||||
// When we're being constructed at runtime, atmos_init() is called by the construction code.
|
// When we're being constructed at runtime, atmos_init() is called by the construction code.
|
||||||
// When dynamically loading a map atmos_init is called by the maploader (initTemplateBounds proc)
|
// When dynamically loading a map atmos_init is called by the maploader (initTemplateBounds proc)
|
||||||
|
|||||||
@@ -72,31 +72,6 @@
|
|||||||
icon_state += "off"
|
icon_state += "off"
|
||||||
use_power = 0
|
use_power = 0
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/atmos_filter/update_underlays()
|
|
||||||
if(..())
|
|
||||||
underlays.Cut()
|
|
||||||
var/turf/T = get_turf(src)
|
|
||||||
if(!istype(T))
|
|
||||||
return
|
|
||||||
|
|
||||||
add_underlay(T, node1, turn(dir, -180))
|
|
||||||
|
|
||||||
if(istype(src, /obj/machinery/atmospherics/trinary/atmos_filter/m_filter))
|
|
||||||
add_underlay(T, node2, turn(dir, 90))
|
|
||||||
else
|
|
||||||
add_underlay(T, node2, turn(dir, -90))
|
|
||||||
|
|
||||||
add_underlay(T, node3, dir)
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/atmos_filter/hide(var/i)
|
|
||||||
update_underlays()
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/atmos_filter/power_change()
|
|
||||||
var/old_stat = stat
|
|
||||||
..()
|
|
||||||
if(old_stat != stat)
|
|
||||||
update_icon()
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/atmos_filter/process()
|
/obj/machinery/atmospherics/trinary/atmos_filter/process()
|
||||||
..()
|
..()
|
||||||
|
|
||||||
@@ -241,7 +216,7 @@
|
|||||||
dir = SOUTH
|
dir = SOUTH
|
||||||
initialize_directions = SOUTH|NORTH|EAST
|
initialize_directions = SOUTH|NORTH|EAST
|
||||||
|
|
||||||
obj/machinery/atmospherics/trinary/atmos_filter/m_filter/init_dir()
|
/obj/machinery/atmospherics/trinary/atmos_filter/m_filter/init_dir()
|
||||||
switch(dir)
|
switch(dir)
|
||||||
if(NORTH)
|
if(NORTH)
|
||||||
initialize_directions = WEST|NORTH|SOUTH
|
initialize_directions = WEST|NORTH|SOUTH
|
||||||
@@ -252,27 +227,8 @@ obj/machinery/atmospherics/trinary/atmos_filter/m_filter/init_dir()
|
|||||||
if(WEST)
|
if(WEST)
|
||||||
initialize_directions = WEST|SOUTH|EAST
|
initialize_directions = WEST|SOUTH|EAST
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/atmos_filter/m_filter/atmos_init()
|
/obj/machinery/atmospherics/trinary/atmos_filter/m_filter/get_node_connect_dirs()
|
||||||
if(node1 && node2 && node3) return
|
|
||||||
|
|
||||||
var/node1_connect = turn(dir, -180)
|
var/node1_connect = turn(dir, -180)
|
||||||
var/node2_connect = turn(dir, 90)
|
var/node2_connect = turn(dir, 90)
|
||||||
var/node3_connect = dir
|
var/node3_connect = dir
|
||||||
|
return list(node1_connect, node2_connect, node3_connect)
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node1_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node1 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node2_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node2 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node3_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node3 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
update_icon()
|
|
||||||
update_underlays()
|
|
||||||
|
|||||||
@@ -35,34 +35,6 @@
|
|||||||
icon_state += "off"
|
icon_state += "off"
|
||||||
use_power = 0
|
use_power = 0
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/mixer/update_underlays()
|
|
||||||
if(..())
|
|
||||||
underlays.Cut()
|
|
||||||
var/turf/T = get_turf(src)
|
|
||||||
if(!istype(T))
|
|
||||||
return
|
|
||||||
|
|
||||||
if(istype(src, /obj/machinery/atmospherics/trinary/mixer/t_mixer))
|
|
||||||
add_underlay(T, node1, turn(dir, -90))
|
|
||||||
else
|
|
||||||
add_underlay(T, node1, turn(dir, -180))
|
|
||||||
|
|
||||||
if(istype(src, /obj/machinery/atmospherics/trinary/mixer/m_mixer) || istype(src, /obj/machinery/atmospherics/trinary/mixer/t_mixer))
|
|
||||||
add_underlay(T, node2, turn(dir, 90))
|
|
||||||
else
|
|
||||||
add_underlay(T, node2, turn(dir, -90))
|
|
||||||
|
|
||||||
add_underlay(T, node3, dir)
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/mixer/hide(var/i)
|
|
||||||
update_underlays()
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/mixer/power_change()
|
|
||||||
var/old_stat = stat
|
|
||||||
..()
|
|
||||||
if(old_stat != stat)
|
|
||||||
update_icon()
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/mixer/New()
|
/obj/machinery/atmospherics/trinary/mixer/New()
|
||||||
..()
|
..()
|
||||||
air1.volume = ATMOS_DEFAULT_VOLUME_MIXER
|
air1.volume = ATMOS_DEFAULT_VOLUME_MIXER
|
||||||
@@ -173,6 +145,9 @@
|
|||||||
src.updateUsrDialog()
|
src.updateUsrDialog()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
//
|
||||||
|
// "T" Orientation - Inputs are on oposite sides instead of adjacent
|
||||||
|
//
|
||||||
obj/machinery/atmospherics/trinary/mixer/t_mixer
|
obj/machinery/atmospherics/trinary/mixer/t_mixer
|
||||||
icon_state = "tmap"
|
icon_state = "tmap"
|
||||||
|
|
||||||
@@ -181,7 +156,7 @@ obj/machinery/atmospherics/trinary/mixer/t_mixer
|
|||||||
|
|
||||||
//node 3 is the outlet, nodes 1 & 2 are intakes
|
//node 3 is the outlet, nodes 1 & 2 are intakes
|
||||||
|
|
||||||
obj/machinery/atmospherics/trinary/mixer/t_mixer/init_dir()
|
/obj/machinery/atmospherics/trinary/mixer/t_mixer/init_dir()
|
||||||
switch(dir)
|
switch(dir)
|
||||||
if(NORTH)
|
if(NORTH)
|
||||||
initialize_directions = EAST|NORTH|WEST
|
initialize_directions = EAST|NORTH|WEST
|
||||||
@@ -192,33 +167,16 @@ obj/machinery/atmospherics/trinary/mixer/t_mixer/init_dir()
|
|||||||
if(WEST)
|
if(WEST)
|
||||||
initialize_directions = WEST|NORTH|SOUTH
|
initialize_directions = WEST|NORTH|SOUTH
|
||||||
|
|
||||||
obj/machinery/atmospherics/trinary/mixer/t_mixer/atmos_init()
|
/obj/machinery/atmospherics/trinary/mixer/t_mixer/get_node_connect_dirs()
|
||||||
..()
|
|
||||||
if(node1 && node2 && node3) return
|
|
||||||
|
|
||||||
var/node1_connect = turn(dir, -90)
|
var/node1_connect = turn(dir, -90)
|
||||||
var/node2_connect = turn(dir, 90)
|
var/node2_connect = turn(dir, 90)
|
||||||
var/node3_connect = dir
|
var/node3_connect = dir
|
||||||
|
return list(node1_connect, node2_connect, node3_connect)
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node1_connect))
|
//
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
// Mirrored Orientation - Flips the output dir to opposite side from normal.
|
||||||
node1 = target
|
//
|
||||||
break
|
/obj/machinery/atmospherics/trinary/mixer/m_mixer
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node2_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node2 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node3_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node3 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
update_icon()
|
|
||||||
update_underlays()
|
|
||||||
|
|
||||||
obj/machinery/atmospherics/trinary/mixer/m_mixer
|
|
||||||
icon_state = "mmap"
|
icon_state = "mmap"
|
||||||
|
|
||||||
dir = SOUTH
|
dir = SOUTH
|
||||||
@@ -226,7 +184,7 @@ obj/machinery/atmospherics/trinary/mixer/m_mixer
|
|||||||
|
|
||||||
//node 3 is the outlet, nodes 1 & 2 are intakes
|
//node 3 is the outlet, nodes 1 & 2 are intakes
|
||||||
|
|
||||||
obj/machinery/atmospherics/trinary/mixer/m_mixer/init_dir()
|
/obj/machinery/atmospherics/trinary/mixer/m_mixer/init_dir()
|
||||||
switch(dir)
|
switch(dir)
|
||||||
if(NORTH)
|
if(NORTH)
|
||||||
initialize_directions = WEST|NORTH|SOUTH
|
initialize_directions = WEST|NORTH|SOUTH
|
||||||
@@ -237,28 +195,8 @@ obj/machinery/atmospherics/trinary/mixer/m_mixer/init_dir()
|
|||||||
if(WEST)
|
if(WEST)
|
||||||
initialize_directions = WEST|SOUTH|EAST
|
initialize_directions = WEST|SOUTH|EAST
|
||||||
|
|
||||||
obj/machinery/atmospherics/trinary/mixer/m_mixer/atmos_init()
|
/obj/machinery/atmospherics/trinary/mixer/m_mixer/get_node_connect_dirs()
|
||||||
..()
|
|
||||||
if(node1 && node2 && node3) return
|
|
||||||
|
|
||||||
var/node1_connect = turn(dir, -180)
|
var/node1_connect = turn(dir, -180)
|
||||||
var/node2_connect = turn(dir, 90)
|
var/node2_connect = turn(dir, 90)
|
||||||
var/node3_connect = dir
|
var/node3_connect = dir
|
||||||
|
return list(node1_connect, node2_connect, node3_connect)
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node1_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node1 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node2_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node2 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node3_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node3 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
update_icon()
|
|
||||||
update_underlays()
|
|
||||||
|
|||||||
@@ -35,6 +35,26 @@
|
|||||||
if(WEST)
|
if(WEST)
|
||||||
initialize_directions = WEST|NORTH|EAST
|
initialize_directions = WEST|NORTH|EAST
|
||||||
|
|
||||||
|
/obj/machinery/atmospherics/trinary/update_underlays()
|
||||||
|
if(..())
|
||||||
|
underlays.Cut()
|
||||||
|
var/turf/T = get_turf(src)
|
||||||
|
if(!istype(T))
|
||||||
|
return
|
||||||
|
var/list/node_connects = get_node_connect_dirs()
|
||||||
|
add_underlay(T, node1, node_connects[1])
|
||||||
|
add_underlay(T, node2, node_connects[2])
|
||||||
|
add_underlay(T, node3, node_connects[3])
|
||||||
|
|
||||||
|
/obj/machinery/atmospherics/trinary/hide(var/i)
|
||||||
|
update_underlays()
|
||||||
|
|
||||||
|
/obj/machinery/atmospherics/trinary/power_change()
|
||||||
|
var/old_stat = stat
|
||||||
|
. = ..()
|
||||||
|
if(old_stat != stat)
|
||||||
|
update_icon()
|
||||||
|
|
||||||
// Housekeeping and pipe network stuff below
|
// Housekeeping and pipe network stuff below
|
||||||
/obj/machinery/atmospherics/trinary/network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference)
|
/obj/machinery/atmospherics/trinary/network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference)
|
||||||
if(reference == node1)
|
if(reference == node1)
|
||||||
@@ -70,26 +90,31 @@
|
|||||||
node2 = null
|
node2 = null
|
||||||
node3 = null
|
node3 = null
|
||||||
|
|
||||||
|
// Get the direction each node is facing to connect.
|
||||||
|
// It now returns as a list so it can be fetched nicely, each entry corresponds to node of same number.
|
||||||
|
/obj/machinery/atmospherics/trinary/get_node_connect_dirs()
|
||||||
|
var/node1_connect = turn(dir, 180)
|
||||||
|
var/node2_connect = turn(dir, -90)
|
||||||
|
var/node3_connect = dir
|
||||||
|
return list(node1_connect, node2_connect, node3_connect)
|
||||||
|
|
||||||
/obj/machinery/atmospherics/trinary/atmos_init()
|
/obj/machinery/atmospherics/trinary/atmos_init()
|
||||||
if(node1 && node2 && node3)
|
if(node1 && node2 && node3)
|
||||||
return
|
return
|
||||||
|
|
||||||
var/node1_connect = turn(dir, -180)
|
var/list/node_connects = get_node_connect_dirs()
|
||||||
var/node2_connect = turn(dir, -90)
|
|
||||||
var/node3_connect = dir
|
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node1_connect))
|
for(var/obj/machinery/atmospherics/target in get_step(src,node_connects[1]))
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
if(target.initialize_directions & get_dir(target,src))
|
||||||
if (check_connect_types(target,src))
|
if (check_connect_types(target,src))
|
||||||
node1 = target
|
node1 = target
|
||||||
break
|
break
|
||||||
|
for(var/obj/machinery/atmospherics/target in get_step(src,node_connects[2]))
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node2_connect))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
if(target.initialize_directions & get_dir(target,src))
|
||||||
if (check_connect_types(target,src))
|
if (check_connect_types(target,src))
|
||||||
node2 = target
|
node2 = target
|
||||||
break
|
break
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node3_connect))
|
for(var/obj/machinery/atmospherics/target in get_step(src,node_connects[3]))
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
if(target.initialize_directions & get_dir(target,src))
|
||||||
if (check_connect_types(target,src))
|
if (check_connect_types(target,src))
|
||||||
node3 = target
|
node3 = target
|
||||||
|
|||||||
@@ -34,14 +34,10 @@
|
|||||||
var/turf/T = get_turf(src)
|
var/turf/T = get_turf(src)
|
||||||
if(!istype(T))
|
if(!istype(T))
|
||||||
return
|
return
|
||||||
add_underlay(T, node1, turn(dir, -180))
|
var/list/node_connects = get_node_connect_dirs()
|
||||||
|
add_underlay(T, node1, node_connects[1])
|
||||||
if(istype(src, /obj/machinery/atmospherics/tvalve/mirrored))
|
add_underlay(T, node2, node_connects[2])
|
||||||
add_underlay(T, node2, turn(dir, 90))
|
add_underlay(T, node3, node_connects[3])
|
||||||
else
|
|
||||||
add_underlay(T, node2, turn(dir, -90))
|
|
||||||
|
|
||||||
add_underlay(T, node3, dir)
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/tvalve/hide(var/i)
|
/obj/machinery/atmospherics/tvalve/hide(var/i)
|
||||||
update_underlays()
|
update_underlays()
|
||||||
@@ -179,26 +175,29 @@
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
/obj/machinery/atmospherics/tvalve/get_node_connect_dirs()
|
||||||
|
var/node1_connect = turn(dir, 180)
|
||||||
|
var/node2_connect = turn(dir, -90)
|
||||||
|
var/node3_connect = dir
|
||||||
|
return list(node1_connect, node2_connect, node3_connect)
|
||||||
|
|
||||||
/obj/machinery/atmospherics/tvalve/atmos_init()
|
/obj/machinery/atmospherics/tvalve/atmos_init()
|
||||||
var/node1_dir
|
if(node1 && node2 && node3)
|
||||||
var/node2_dir
|
return
|
||||||
var/node3_dir
|
|
||||||
|
|
||||||
node1_dir = turn(dir, 180)
|
var/list/node_connects = get_node_connect_dirs()
|
||||||
node2_dir = turn(dir, -90)
|
|
||||||
node3_dir = dir
|
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node1_dir))
|
for(var/obj/machinery/atmospherics/target in get_step(src,node_connects[1]))
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
if(target.initialize_directions & get_dir(target,src))
|
||||||
if (check_connect_types(target,src))
|
if (check_connect_types(target,src))
|
||||||
node1 = target
|
node1 = target
|
||||||
break
|
break
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node2_dir))
|
for(var/obj/machinery/atmospherics/target in get_step(src,node_connects[2]))
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
if(target.initialize_directions & get_dir(target,src))
|
||||||
if (check_connect_types(target,src))
|
if (check_connect_types(target,src))
|
||||||
node2 = target
|
node2 = target
|
||||||
break
|
break
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node3_dir))
|
for(var/obj/machinery/atmospherics/target in get_step(src,node_connects[3]))
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
if(target.initialize_directions & get_dir(target,src))
|
||||||
if (check_connect_types(target,src))
|
if (check_connect_types(target,src))
|
||||||
node3 = target
|
node3 = target
|
||||||
@@ -379,30 +378,11 @@
|
|||||||
if(WEST)
|
if(WEST)
|
||||||
initialize_directions = EAST|WEST|SOUTH
|
initialize_directions = EAST|WEST|SOUTH
|
||||||
|
|
||||||
/obj/machinery/atmospherics/tvalve/mirrored/atmos_init()
|
/obj/machinery/atmospherics/tvalve/mirrored/get_node_connect_dirs()
|
||||||
var/node1_dir
|
var/node1_connect = turn(dir, 180)
|
||||||
var/node2_dir
|
var/node2_connect = turn(dir, 90)
|
||||||
var/node3_dir
|
var/node3_connect = dir
|
||||||
|
return list(node1_connect, node2_connect, node3_connect)
|
||||||
node1_dir = turn(dir, 180)
|
|
||||||
node2_dir = turn(dir, 90)
|
|
||||||
node3_dir = dir
|
|
||||||
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node1_dir))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node1 = target
|
|
||||||
break
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node2_dir))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node2 = target
|
|
||||||
break
|
|
||||||
for(var/obj/machinery/atmospherics/target in get_step(src,node3_dir))
|
|
||||||
if(target.initialize_directions & get_dir(target,src))
|
|
||||||
node3 = target
|
|
||||||
break
|
|
||||||
|
|
||||||
update_icon()
|
|
||||||
update_underlays()
|
|
||||||
|
|
||||||
/obj/machinery/atmospherics/tvalve/mirrored/update_icon(animation)
|
/obj/machinery/atmospherics/tvalve/mirrored/update_icon(animation)
|
||||||
if(animation)
|
if(animation)
|
||||||
|
|||||||
Reference in New Issue
Block a user