From b70451cda6b149178259b0d4c740cb43be7c32e2 Mon Sep 17 00:00:00 2001 From: Leshana Date: Wed, 21 Feb 2018 20:43:40 -0500 Subject: [PATCH 1/3] 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) --- code/ATMOSPHERICS/atmospherics.dm | 5 ++ .../components/trinary_devices/filter.dm | 50 +---------- .../components/trinary_devices/mixer.dm | 88 +++---------------- .../trinary_devices/trinary_base.dm | 39 ++++++-- code/ATMOSPHERICS/components/tvalve.dm | 62 +++++-------- 5 files changed, 74 insertions(+), 170 deletions(-) diff --git a/code/ATMOSPHERICS/atmospherics.dm b/code/ATMOSPHERICS/atmospherics.dm index 0502f2b8f8f..59163e1b82a 100644 --- a/code/ATMOSPHERICS/atmospherics.dm +++ b/code/ATMOSPHERICS/atmospherics.dm @@ -46,6 +46,11 @@ Pipelines + Other Objects -> Pipe network /obj/machinery/atmospherics/proc/init_dir() 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. // 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) diff --git a/code/ATMOSPHERICS/components/trinary_devices/filter.dm b/code/ATMOSPHERICS/components/trinary_devices/filter.dm index 10708f4185a..97e318577b5 100755 --- a/code/ATMOSPHERICS/components/trinary_devices/filter.dm +++ b/code/ATMOSPHERICS/components/trinary_devices/filter.dm @@ -72,31 +72,6 @@ icon_state += "off" 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() ..() @@ -241,7 +216,7 @@ dir = SOUTH 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) if(NORTH) initialize_directions = WEST|NORTH|SOUTH @@ -252,27 +227,8 @@ obj/machinery/atmospherics/trinary/atmos_filter/m_filter/init_dir() if(WEST) initialize_directions = WEST|SOUTH|EAST -/obj/machinery/atmospherics/trinary/atmos_filter/m_filter/atmos_init() - if(node1 && node2 && node3) return - +/obj/machinery/atmospherics/trinary/atmos_filter/m_filter/get_node_connect_dirs() var/node1_connect = turn(dir, -180) var/node2_connect = turn(dir, 90) var/node3_connect = dir - - 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() + return list(node1_connect, node2_connect, node3_connect) diff --git a/code/ATMOSPHERICS/components/trinary_devices/mixer.dm b/code/ATMOSPHERICS/components/trinary_devices/mixer.dm index 5739a57895e..3361708ae48 100644 --- a/code/ATMOSPHERICS/components/trinary_devices/mixer.dm +++ b/code/ATMOSPHERICS/components/trinary_devices/mixer.dm @@ -35,34 +35,6 @@ icon_state += "off" 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() ..() air1.volume = ATMOS_DEFAULT_VOLUME_MIXER @@ -173,6 +145,9 @@ src.updateUsrDialog() return +// +// "T" Orientation - Inputs are on oposite sides instead of adjacent +// obj/machinery/atmospherics/trinary/mixer/t_mixer icon_state = "tmap" @@ -181,7 +156,7 @@ obj/machinery/atmospherics/trinary/mixer/t_mixer //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) if(NORTH) initialize_directions = EAST|NORTH|WEST @@ -192,33 +167,16 @@ obj/machinery/atmospherics/trinary/mixer/t_mixer/init_dir() if(WEST) initialize_directions = WEST|NORTH|SOUTH -obj/machinery/atmospherics/trinary/mixer/t_mixer/atmos_init() - ..() - if(node1 && node2 && node3) return - +/obj/machinery/atmospherics/trinary/mixer/t_mixer/get_node_connect_dirs() var/node1_connect = turn(dir, -90) var/node2_connect = turn(dir, 90) 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() - -obj/machinery/atmospherics/trinary/mixer/m_mixer +// +// Mirrored Orientation - Flips the output dir to opposite side from normal. +// +/obj/machinery/atmospherics/trinary/mixer/m_mixer icon_state = "mmap" dir = SOUTH @@ -226,7 +184,7 @@ obj/machinery/atmospherics/trinary/mixer/m_mixer //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) if(NORTH) initialize_directions = WEST|NORTH|SOUTH @@ -237,28 +195,8 @@ obj/machinery/atmospherics/trinary/mixer/m_mixer/init_dir() if(WEST) initialize_directions = WEST|SOUTH|EAST -obj/machinery/atmospherics/trinary/mixer/m_mixer/atmos_init() - ..() - if(node1 && node2 && node3) return - +/obj/machinery/atmospherics/trinary/mixer/m_mixer/get_node_connect_dirs() var/node1_connect = turn(dir, -180) var/node2_connect = turn(dir, 90) var/node3_connect = dir - - 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() + return list(node1_connect, node2_connect, node3_connect) diff --git a/code/ATMOSPHERICS/components/trinary_devices/trinary_base.dm b/code/ATMOSPHERICS/components/trinary_devices/trinary_base.dm index 807523fe7a0..43ded8e13f9 100644 --- a/code/ATMOSPHERICS/components/trinary_devices/trinary_base.dm +++ b/code/ATMOSPHERICS/components/trinary_devices/trinary_base.dm @@ -35,6 +35,26 @@ if(WEST) 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 /obj/machinery/atmospherics/trinary/network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference) if(reference == node1) @@ -70,26 +90,31 @@ node2 = 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() if(node1 && node2 && node3) return - var/node1_connect = turn(dir, -180) - var/node2_connect = turn(dir, -90) - var/node3_connect = dir + var/list/node_connects = get_node_connect_dirs() - 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 (check_connect_types(target,src)) node1 = target break - - for(var/obj/machinery/atmospherics/target in get_step(src,node2_connect)) + for(var/obj/machinery/atmospherics/target in get_step(src,node_connects[2])) if(target.initialize_directions & get_dir(target,src)) if (check_connect_types(target,src)) node2 = target 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 (check_connect_types(target,src)) node3 = target diff --git a/code/ATMOSPHERICS/components/tvalve.dm b/code/ATMOSPHERICS/components/tvalve.dm index 9f7e80f97fd..6c2264321e8 100644 --- a/code/ATMOSPHERICS/components/tvalve.dm +++ b/code/ATMOSPHERICS/components/tvalve.dm @@ -34,14 +34,10 @@ var/turf/T = get_turf(src) if(!istype(T)) return - add_underlay(T, node1, turn(dir, -180)) - - if(istype(src, /obj/machinery/atmospherics/tvalve/mirrored)) - add_underlay(T, node2, turn(dir, 90)) - else - add_underlay(T, node2, turn(dir, -90)) - - add_underlay(T, node3, dir) + 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/tvalve/hide(var/i) update_underlays() @@ -179,26 +175,29 @@ 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() - var/node1_dir - var/node2_dir - var/node3_dir + if(node1 && node2 && node3) + return - node1_dir = turn(dir, 180) - node2_dir = turn(dir, -90) - node3_dir = dir + var/list/node_connects = get_node_connect_dirs() - 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 (check_connect_types(target,src)) node1 = target 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 (check_connect_types(target,src)) node2 = target 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 (check_connect_types(target,src)) node3 = target @@ -379,30 +378,11 @@ if(WEST) initialize_directions = EAST|WEST|SOUTH -/obj/machinery/atmospherics/tvalve/mirrored/atmos_init() - var/node1_dir - var/node2_dir - var/node3_dir - - 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/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/mirrored/update_icon(animation) if(animation) From 1d3697c68a4c6a323abda38ab266c60e6a9467a1 Mon Sep 17 00:00:00 2001 From: Leshana Date: Thu, 22 Feb 2018 14:11:49 -0500 Subject: [PATCH 2/3] Went even farther in consolidation of trinary atmospherics. - We can eliminate any overridden methods at all on flipped trinary devices by making a `mirrored` and `tee` variable! This allows us to do things like flip them without delete/spawning. - T-Valves are also basically trinary. Sadly they are not a subtype, so to share code with them I have to put it into an outside proc. But still worth it. --- .../components/trinary_devices/filter.dm | 42 +-------- .../components/trinary_devices/mixer.dm | 65 +------------ .../trinary_devices/trinary_base.dm | 91 ++++++++++++++++--- code/ATMOSPHERICS/components/tvalve.dm | 47 ++-------- 4 files changed, 95 insertions(+), 150 deletions(-) diff --git a/code/ATMOSPHERICS/components/trinary_devices/filter.dm b/code/ATMOSPHERICS/components/trinary_devices/filter.dm index 97e318577b5..94924baedcd 100755 --- a/code/ATMOSPHERICS/components/trinary_devices/filter.dm +++ b/code/ATMOSPHERICS/components/trinary_devices/filter.dm @@ -59,7 +59,7 @@ . = ..() /obj/machinery/atmospherics/trinary/atmos_filter/update_icon() - if(istype(src, /obj/machinery/atmospherics/trinary/atmos_filter/m_filter)) + if(mirrored) icon_state = "m" else icon_state = "" @@ -108,24 +108,6 @@ if(frequency) set_frequency(frequency) -/obj/machinery/atmospherics/trinary/atmos_filter/attackby(var/obj/item/weapon/W as obj, var/mob/user as mob) - if (!istype(W, /obj/item/weapon/wrench)) - return ..() - if(!can_unwrench()) - to_chat(user, "You cannot unwrench \the [src], it too exerted due to internal pressure.") - add_fingerprint(user) - return 1 - playsound(src, W.usesound, 50, 1) - to_chat(user, "You begin to unfasten \the [src]...") - if (do_after(user, 40 * W.toolspeed)) - user.visible_message( \ - "\The [user] unfastens \the [src].", \ - "You have unfastened \the [src].", \ - "You hear a ratchet.") - new /obj/item/pipe(loc, make_from=src) - qdel(src) - - /obj/machinery/atmospherics/trinary/atmos_filter/attack_hand(user as mob) // -- TLE if(..()) return @@ -210,25 +192,11 @@ */ return +// +// Mirrored Orientation - Flips the output dir to opposite side from normal. +// /obj/machinery/atmospherics/trinary/atmos_filter/m_filter icon_state = "mmap" - dir = SOUTH initialize_directions = SOUTH|NORTH|EAST - -/obj/machinery/atmospherics/trinary/atmos_filter/m_filter/init_dir() - switch(dir) - if(NORTH) - initialize_directions = WEST|NORTH|SOUTH - if(SOUTH) - initialize_directions = SOUTH|EAST|NORTH - if(EAST) - initialize_directions = EAST|WEST|NORTH - if(WEST) - initialize_directions = WEST|SOUTH|EAST - -/obj/machinery/atmospherics/trinary/atmos_filter/m_filter/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) + mirrored = TRUE diff --git a/code/ATMOSPHERICS/components/trinary_devices/mixer.dm b/code/ATMOSPHERICS/components/trinary_devices/mixer.dm index 3361708ae48..2a70fe15917 100644 --- a/code/ATMOSPHERICS/components/trinary_devices/mixer.dm +++ b/code/ATMOSPHERICS/components/trinary_devices/mixer.dm @@ -20,10 +20,10 @@ //node 3 is the outlet, nodes 1 & 2 are intakes /obj/machinery/atmospherics/trinary/mixer/update_icon(var/safety = 0) - if(istype(src, /obj/machinery/atmospherics/trinary/mixer/m_mixer)) - icon_state = "m" - else if(istype(src, /obj/machinery/atmospherics/trinary/mixer/t_mixer)) + if(tee) icon_state = "t" + else if(mirrored) + icon_state = "m" else icon_state = "" @@ -75,23 +75,6 @@ return 1 -/obj/machinery/atmospherics/trinary/mixer/attackby(var/obj/item/weapon/W as obj, var/mob/user as mob) - if (!istype(W, /obj/item/weapon/wrench)) - return ..() - if(!can_unwrench()) - to_chat(user, "You cannot unwrench \the [src], it too exerted due to internal pressure.") - add_fingerprint(user) - return 1 - playsound(src, W.usesound, 50, 1) - to_chat(user, "You begin to unfasten \the [src]...") - if (do_after(user, 40 * W.toolspeed)) - user.visible_message( \ - "\The [user] unfastens \the [src].", \ - "You have unfastened \the [src].", \ - "You hear ratchet.") - new /obj/item/pipe(loc, make_from=src) - qdel(src) - /obj/machinery/atmospherics/trinary/mixer/attack_hand(user as mob) if(..()) return @@ -150,53 +133,15 @@ // obj/machinery/atmospherics/trinary/mixer/t_mixer icon_state = "tmap" - dir = SOUTH initialize_directions = SOUTH|EAST|WEST - - //node 3 is the outlet, nodes 1 & 2 are intakes - -/obj/machinery/atmospherics/trinary/mixer/t_mixer/init_dir() - switch(dir) - if(NORTH) - initialize_directions = EAST|NORTH|WEST - if(SOUTH) - initialize_directions = SOUTH|WEST|EAST - if(EAST) - initialize_directions = EAST|NORTH|SOUTH - if(WEST) - initialize_directions = WEST|NORTH|SOUTH - -/obj/machinery/atmospherics/trinary/mixer/t_mixer/get_node_connect_dirs() - var/node1_connect = turn(dir, -90) - var/node2_connect = turn(dir, 90) - var/node3_connect = dir - return list(node1_connect, node2_connect, node3_connect) + tee = TRUE // // Mirrored Orientation - Flips the output dir to opposite side from normal. // /obj/machinery/atmospherics/trinary/mixer/m_mixer icon_state = "mmap" - dir = SOUTH initialize_directions = SOUTH|NORTH|EAST - - //node 3 is the outlet, nodes 1 & 2 are intakes - -/obj/machinery/atmospherics/trinary/mixer/m_mixer/init_dir() - switch(dir) - if(NORTH) - initialize_directions = WEST|NORTH|SOUTH - if(SOUTH) - initialize_directions = SOUTH|EAST|NORTH - if(EAST) - initialize_directions = EAST|WEST|NORTH - if(WEST) - initialize_directions = WEST|SOUTH|EAST - -/obj/machinery/atmospherics/trinary/mixer/m_mixer/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) + mirrored = TRUE diff --git a/code/ATMOSPHERICS/components/trinary_devices/trinary_base.dm b/code/ATMOSPHERICS/components/trinary_devices/trinary_base.dm index 43ded8e13f9..79aa77dc6f8 100644 --- a/code/ATMOSPHERICS/components/trinary_devices/trinary_base.dm +++ b/code/ATMOSPHERICS/components/trinary_devices/trinary_base.dm @@ -3,6 +3,9 @@ initialize_directions = SOUTH|NORTH|WEST use_power = 0 + var/mirrored = FALSE + var/tee = FALSE + var/datum/gas_mixture/air1 var/datum/gas_mixture/air2 var/datum/gas_mixture/air3 @@ -25,15 +28,7 @@ air3.volume = 200 /obj/machinery/atmospherics/trinary/init_dir() - switch(dir) - if(NORTH) - initialize_directions = EAST|NORTH|SOUTH - if(SOUTH) - initialize_directions = SOUTH|WEST|NORTH - if(EAST) - initialize_directions = EAST|WEST|SOUTH - if(WEST) - initialize_directions = WEST|NORTH|EAST + initialize_directions = get_initialize_directions_trinary(dir, mirrored, tee) /obj/machinery/atmospherics/trinary/update_underlays() if(..()) @@ -55,6 +50,23 @@ if(old_stat != stat) update_icon() +/obj/machinery/atmospherics/trinary/attackby(var/obj/item/weapon/W as obj, var/mob/user as mob) + if (!istype(W, /obj/item/weapon/wrench)) + return ..() + if(!can_unwrench()) + to_chat(user, "You cannot unwrench \the [src], it too exerted due to internal pressure.") + add_fingerprint(user) + return 1 + playsound(src, W.usesound, 50, 1) + to_chat(user, "You begin to unfasten \the [src]...") + if (do_after(user, 40 * W.toolspeed)) + user.visible_message( \ + "\The [user] unfastens \the [src].", \ + "You have unfastened \the [src].", \ + "You hear a ratchet.") + new /obj/item/pipe(loc, make_from=src) + qdel(src) + // Housekeeping and pipe network stuff below /obj/machinery/atmospherics/trinary/network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference) if(reference == node1) @@ -93,10 +105,7 @@ // 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) + return get_node_connect_dirs_trinary(dir, mirrored, tee) /obj/machinery/atmospherics/trinary/atmos_init() if(node1 && node2 && node3) @@ -191,4 +200,58 @@ update_underlays() - return null \ No newline at end of file + return null + +// Trinary init_dir() logic in a separate proc so it can be referenced from "trinary-ish" places like T-Valves +// TODO - Someday refactor those places under atmospherics/trinary +/proc/get_initialize_directions_trinary(var/dir, var/mirrored = FALSE, var/tee = FALSE) + if(tee) + switch(dir) + if(NORTH) + return EAST|NORTH|WEST + if(SOUTH) + return SOUTH|WEST|EAST + if(EAST) + return EAST|NORTH|SOUTH + if(WEST) + return WEST|NORTH|SOUTH + else if(mirrored) + switch(dir) + if(NORTH) + return WEST|NORTH|SOUTH + if(SOUTH) + return SOUTH|EAST|NORTH + if(EAST) + return EAST|WEST|NORTH + if(WEST) + return WEST|SOUTH|EAST + else + switch(dir) + if(NORTH) + return EAST|NORTH|SOUTH + if(SOUTH) + return SOUTH|WEST|NORTH + if(EAST) + return EAST|WEST|SOUTH + if(WEST) + return WEST|NORTH|EAST + +// Trinary get_node_connect_dirs() logic in a separate proc so it can be referenced from "trinary-ish" places like T-Valves +/proc/get_node_connect_dirs_trinary(var/dir, var/mirrored = FALSE, var/tee = FALSE) + var/node1_connect + var/node2_connect + var/node3_connect + + if(tee) + node1_connect = turn(dir, -90) + node2_connect = turn(dir, 90) + node3_connect = dir + else if(mirrored) + node1_connect = turn(dir, 180) + node2_connect = turn(dir, 90) + node3_connect = dir + else + node1_connect = turn(dir, 180) + node2_connect = turn(dir, -90) + node3_connect = dir + return list(node1_connect, node2_connect, node3_connect) diff --git a/code/ATMOSPHERICS/components/tvalve.dm b/code/ATMOSPHERICS/components/tvalve.dm index 6c2264321e8..bb735448831 100644 --- a/code/ATMOSPHERICS/components/tvalve.dm +++ b/code/ATMOSPHERICS/components/tvalve.dm @@ -11,6 +11,8 @@ var/state = 0 // 0 = go straight, 1 = go to side + var/mirrored = FALSE + // like a trinary component, node1 is input, node2 is side output, node3 is straight output var/obj/machinery/atmospherics/node3 @@ -24,9 +26,9 @@ /obj/machinery/atmospherics/tvalve/update_icon(animation) if(animation) - flick("tvalve[src.state][!src.state]",src) + flick("tvalve[mirrored ? "m" : ""][src.state][!src.state]",src) else - icon_state = "tvalve[state]" + icon_state = "tvalve[mirrored ? "m" : ""][state]" /obj/machinery/atmospherics/tvalve/update_underlays() if(..()) @@ -43,15 +45,7 @@ update_underlays() /obj/machinery/atmospherics/tvalve/init_dir() - switch(dir) - if(NORTH) - initialize_directions = SOUTH|NORTH|EAST - if(SOUTH) - initialize_directions = NORTH|SOUTH|WEST - if(EAST) - initialize_directions = WEST|EAST|SOUTH - if(WEST) - initialize_directions = EAST|WEST|NORTH + initialize_directions = get_initialize_directions_trinary(dir, mirrored) /obj/machinery/atmospherics/tvalve/network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference) if(reference == node1) @@ -176,10 +170,7 @@ 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) + return get_node_connect_dirs_trinary(dir, mirrored) /obj/machinery/atmospherics/tvalve/atmos_init() if(node1 && node2 && node3) @@ -293,7 +284,7 @@ /obj/machinery/atmospherics/tvalve/digital/update_icon() ..() if(!powered()) - icon_state = "tvalvenopower" + icon_state = "tvalve[mirrored ? "m" : ""]nopower" /obj/machinery/atmospherics/tvalve/digital/attack_ai(mob/user as mob) return src.attack_hand(user) @@ -362,34 +353,12 @@ /obj/machinery/atmospherics/tvalve/mirrored icon_state = "map_tvalvem0" + mirrored = TRUE /obj/machinery/atmospherics/tvalve/mirrored/bypass icon_state = "map_tvalvem1" state = 1 -/obj/machinery/atmospherics/tvalve/mirrored/init_dir() - switch(dir) - if(NORTH) - initialize_directions = SOUTH|NORTH|WEST - if(SOUTH) - initialize_directions = NORTH|SOUTH|EAST - if(EAST) - initialize_directions = WEST|EAST|NORTH - if(WEST) - initialize_directions = EAST|WEST|SOUTH - -/obj/machinery/atmospherics/tvalve/mirrored/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/mirrored/update_icon(animation) - if(animation) - flick("tvalvem[src.state][!src.state]",src) - else - icon_state = "tvalvem[state]" - /obj/machinery/atmospherics/tvalve/mirrored/digital // can be controlled by AI name = "digital switching valve" desc = "A digitally controlled valve." From ba36595263c03ef7222ecc9627ffab405a0d035e Mon Sep 17 00:00:00 2001 From: Leshana Date: Thu, 22 Feb 2018 14:49:04 -0500 Subject: [PATCH 3/3] Consolidated digital t-valves type paths. - Because mirroring is now *much* easier to setup than digital remote control, we reverse the order of inheritance to de-duplicate all the radio code from digital t-valves! - This requires changing the following type paths: /obj/machinery/atmospherics/tvalve/mirrored/digital -> /obj/machinery/atmospherics/tvalve/digital/mirrored /obj/machinery/atmospherics/tvalve/mirrored/digital/bypass -> /obj/machinery/atmospherics/tvalve/digital/mirrored/bypass - Change made on all maps. - We can eliminate any overriden methods at all on flipped trinary devices by making a `mirrored` and `tee` variable! This allows us to do things like flip them without delete/spawning. - T-Valves are also basically trinary. Sadly they are not a subtype, so to share code with them I have to put it into an outside proc. But still worth it. --- code/ATMOSPHERICS/components/tvalve.dm | 71 ++---------------------- code/game/machinery/pipe/construction.dm | 4 +- maps/northern_star/polaris-1.dmm | 4 +- 3 files changed, 8 insertions(+), 71 deletions(-) diff --git a/code/ATMOSPHERICS/components/tvalve.dm b/code/ATMOSPHERICS/components/tvalve.dm index bb735448831..2b64d6f5bb4 100644 --- a/code/ATMOSPHERICS/components/tvalve.dm +++ b/code/ATMOSPHERICS/components/tvalve.dm @@ -359,73 +359,10 @@ icon_state = "map_tvalvem1" state = 1 -/obj/machinery/atmospherics/tvalve/mirrored/digital // can be controlled by AI - name = "digital switching valve" - desc = "A digitally controlled valve." - icon = 'icons/atmos/digital_tvalve.dmi' +/obj/machinery/atmospherics/tvalve/digital/mirrored + icon_state = "map_tvalvem0" + mirrored = TRUE - var/frequency = 0 - var/id = null - var/datum/radio_frequency/radio_connection - -/obj/machinery/atmospherics/tvalve/mirrored/digital/Destroy() - unregister_radio(src, frequency) - . = ..() - -/obj/machinery/atmospherics/tvalve/mirrored/digital/bypass +/obj/machinery/atmospherics/tvalve/digital/mirrored/bypass icon_state = "map_tvalvem1" state = 1 - -/obj/machinery/atmospherics/tvalve/mirrored/digital/power_change() - var/old_stat = stat - ..() - if(old_stat != stat) - update_icon() - -/obj/machinery/atmospherics/tvalve/mirrored/digital/update_icon() - ..() - if(!powered()) - icon_state = "tvalvemnopower" - -/obj/machinery/atmospherics/tvalve/mirrored/digital/attack_ai(mob/user as mob) - return src.attack_hand(user) - -/obj/machinery/atmospherics/tvalve/mirrored/digital/attack_hand(mob/user as mob) - if(!powered()) - return - if(!src.allowed(user)) - to_chat(user, "Access denied.") - return - ..() - -//Radio remote control -eh? - -/obj/machinery/atmospherics/tvalve/mirrored/digital/proc/set_frequency(new_frequency) - radio_controller.remove_object(src, frequency) - frequency = new_frequency - if(frequency) - radio_connection = radio_controller.add_object(src, frequency, RADIO_ATMOSIA) - -/obj/machinery/atmospherics/tvalve/mirrored/digital/initialize() - . = ..() - if(frequency) - set_frequency(frequency) - -/obj/machinery/atmospherics/tvalve/mirrored/digital/receive_signal(datum/signal/signal) - if(!signal.data["tag"] || (signal.data["tag"] != id)) - return 0 - - switch(signal.data["command"]) - if("valve_open") - if(!state) - go_to_side() - - if("valve_close") - if(state) - go_straight() - - if("valve_toggle") - if(state) - go_straight() - else - go_to_side() diff --git a/code/game/machinery/pipe/construction.dm b/code/game/machinery/pipe/construction.dm index ec0f8a027c4..f03e56e6429 100644 --- a/code/game/machinery/pipe/construction.dm +++ b/code/game/machinery/pipe/construction.dm @@ -145,7 +145,7 @@ Buildable meters src.pipe_type = PIPE_PASSIVE_GATE else if(istype(make_from, /obj/machinery/atmospherics/unary/heat_exchanger)) src.pipe_type = PIPE_HEAT_EXCHANGE - else if(istype(make_from, /obj/machinery/atmospherics/tvalve/mirrored/digital)) + else if(istype(make_from, /obj/machinery/atmospherics/tvalve/digital/mirrored)) src.pipe_type = PIPE_DTVALVEM else if(istype(make_from, /obj/machinery/atmospherics/tvalve/mirrored)) src.pipe_type = PIPE_MTVALVEM @@ -1105,7 +1105,7 @@ Buildable meters V.node3.build_network() if(PIPE_DTVALVEM) //mirrored digital t-valve - var/obj/machinery/atmospherics/tvalve/mirrored/digital/V = new(src.loc) + var/obj/machinery/atmospherics/tvalve/digital/mirrored/V = new(src.loc) if(src.req_access) V.req_access = src.req_access if(src.req_one_access) diff --git a/maps/northern_star/polaris-1.dmm b/maps/northern_star/polaris-1.dmm index 16836b3912b..3f1213a0508 100644 --- a/maps/northern_star/polaris-1.dmm +++ b/maps/northern_star/polaris-1.dmm @@ -2643,7 +2643,7 @@ "aYQ" = (/obj/structure/grille,/obj/structure/window/reinforced{dir = 8},/obj/structure/window/reinforced{dir = 4},/obj/structure/window/reinforced{dir = 1},/obj/machinery/door/firedoor/border_only,/obj/machinery/atmospherics/pipe/simple/hidden/red{tag = "icon-intact (EAST)"; icon_state = "intact"; dir = 4},/turf/simulated/floor/plating,/area/maintenance/engineering/pumpstation) "aYR" = (/obj/machinery/atmospherics/pipe/simple/visible/red{tag = "icon-intact (EAST)"; icon_state = "intact"; dir = 4},/turf/simulated/floor/tiled,/area/maintenance/engineering/pumpstation) "aYS" = (/obj/machinery/atmospherics/pipe/simple/hidden/supply,/obj/machinery/atmospherics/pipe/simple/visible/red{tag = "icon-intact (EAST)"; icon_state = "intact"; dir = 4},/turf/simulated/floor/tiled,/area/maintenance/engineering/pumpstation) -"aYT" = (/obj/machinery/atmospherics/tvalve/mirrored/digital/bypass{dir = 4},/obj/machinery/camera/network/engineering{c_tag = "ENG - Pump Station"; dir = 1},/obj/structure/extinguisher_cabinet{pixel_x = 5; pixel_y = -32},/turf/simulated/floor/tiled,/area/maintenance/engineering/pumpstation) +"aYT" = (/obj/machinery/atmospherics/tvalve/digital/mirrored/bypass{dir = 4},/obj/machinery/camera/network/engineering{c_tag = "ENG - Pump Station"; dir = 1},/obj/structure/extinguisher_cabinet{pixel_x = 5; pixel_y = -32},/turf/simulated/floor/tiled,/area/maintenance/engineering/pumpstation) "aYU" = (/obj/machinery/atmospherics/binary/pump{dir = 4},/turf/simulated/floor/tiled,/area/maintenance/engineering/pumpstation) "aYV" = (/obj/machinery/atmospherics/pipe/manifold/visible/red,/turf/simulated/floor/tiled,/area/maintenance/engineering/pumpstation) "aYW" = (/obj/random/maintenance/research,/obj/random/maintenance/research,/obj/random/junk,/turf/simulated/floor,/area/maintenance/research_shuttle) @@ -8600,7 +8600,7 @@ "djt" = (/obj/machinery/atmospherics/pipe/manifold/visible/green{dir = 8},/turf/simulated/floor/tiled,/area/engineering/atmos) "dju" = (/obj/machinery/atmospherics/pipe/simple/visible/red,/obj/machinery/atmospherics/binary/pump{dir = 4; name = "N2 to Mixing"},/turf/simulated/floor/tiled,/area/engineering/atmos) "djv" = (/obj/machinery/atmospherics/pipe/manifold/visible/green{tag = "icon-map (EAST)"; icon_state = "map"; dir = 4},/turf/simulated/floor/tiled,/area/engineering/atmos) -"djw" = (/obj/machinery/atmospherics/tvalve/mirrored/digital{name = "Waste to Space"},/obj/structure/cable{d1 = 1; d2 = 2; icon_state = "1-2"},/turf/simulated/floor/tiled,/area/engineering/atmos) +"djw" = (/obj/machinery/atmospherics/tvalve/digital/mirrored{name = "Waste to Space"},/obj/structure/cable{d1 = 1; d2 = 2; icon_state = "1-2"},/turf/simulated/floor/tiled,/area/engineering/atmos) "djx" = (/obj/machinery/atmospherics/pipe/simple/visible/red{tag = "icon-intact (SOUTHWEST)"; icon_state = "intact"; dir = 10},/obj/machinery/meter,/turf/simulated/floor/tiled,/area/engineering/atmos) "djy" = (/obj/machinery/atmospherics/pipe/simple/visible/red,/turf/simulated/floor/tiled,/area/engineering/atmos) "djz" = (/obj/machinery/atmospherics/valve/digital,/turf/simulated/floor/tiled,/area/engineering/atmos)