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.
This commit is contained in:
Leshana
2018-02-22 14:11:49 -05:00
parent b70451cda6
commit 1d3697c68a
4 changed files with 95 additions and 150 deletions

View File

@@ -59,7 +59,7 @@
. = ..() . = ..()
/obj/machinery/atmospherics/trinary/atmos_filter/update_icon() /obj/machinery/atmospherics/trinary/atmos_filter/update_icon()
if(istype(src, /obj/machinery/atmospherics/trinary/atmos_filter/m_filter)) if(mirrored)
icon_state = "m" icon_state = "m"
else else
icon_state = "" icon_state = ""
@@ -108,24 +108,6 @@
if(frequency) if(frequency)
set_frequency(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, "<span class='warning'>You cannot unwrench \the [src], it too exerted due to internal pressure.</span>")
add_fingerprint(user)
return 1
playsound(src, W.usesound, 50, 1)
to_chat(user, "<span class='notice'>You begin to unfasten \the [src]...</span>")
if (do_after(user, 40 * W.toolspeed))
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/trinary/atmos_filter/attack_hand(user as mob) // -- TLE /obj/machinery/atmospherics/trinary/atmos_filter/attack_hand(user as mob) // -- TLE
if(..()) if(..())
return return
@@ -210,25 +192,11 @@
*/ */
return return
//
// Mirrored Orientation - Flips the output dir to opposite side from normal.
//
/obj/machinery/atmospherics/trinary/atmos_filter/m_filter /obj/machinery/atmospherics/trinary/atmos_filter/m_filter
icon_state = "mmap" icon_state = "mmap"
dir = SOUTH dir = SOUTH
initialize_directions = SOUTH|NORTH|EAST initialize_directions = SOUTH|NORTH|EAST
mirrored = TRUE
/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)

View File

@@ -20,10 +20,10 @@
//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/update_icon(var/safety = 0) /obj/machinery/atmospherics/trinary/mixer/update_icon(var/safety = 0)
if(istype(src, /obj/machinery/atmospherics/trinary/mixer/m_mixer)) if(tee)
icon_state = "m"
else if(istype(src, /obj/machinery/atmospherics/trinary/mixer/t_mixer))
icon_state = "t" icon_state = "t"
else if(mirrored)
icon_state = "m"
else else
icon_state = "" icon_state = ""
@@ -75,23 +75,6 @@
return 1 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, "<span class='warning'>You cannot unwrench \the [src], it too exerted due to internal pressure.</span>")
add_fingerprint(user)
return 1
playsound(src, W.usesound, 50, 1)
to_chat(user, "<span class='notice'>You begin to unfasten \the [src]...</span>")
if (do_after(user, 40 * W.toolspeed))
user.visible_message( \
"<span class='notice'>\The [user] unfastens \the [src].</span>", \
"<span class='notice'>You have unfastened \the [src].</span>", \
"You hear ratchet.")
new /obj/item/pipe(loc, make_from=src)
qdel(src)
/obj/machinery/atmospherics/trinary/mixer/attack_hand(user as mob) /obj/machinery/atmospherics/trinary/mixer/attack_hand(user as mob)
if(..()) if(..())
return return
@@ -150,53 +133,15 @@
// //
obj/machinery/atmospherics/trinary/mixer/t_mixer obj/machinery/atmospherics/trinary/mixer/t_mixer
icon_state = "tmap" icon_state = "tmap"
dir = SOUTH dir = SOUTH
initialize_directions = SOUTH|EAST|WEST initialize_directions = SOUTH|EAST|WEST
tee = TRUE
//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)
// //
// Mirrored Orientation - Flips the output dir to opposite side from normal. // Mirrored Orientation - Flips the output dir to opposite side from normal.
// //
/obj/machinery/atmospherics/trinary/mixer/m_mixer /obj/machinery/atmospherics/trinary/mixer/m_mixer
icon_state = "mmap" icon_state = "mmap"
dir = SOUTH dir = SOUTH
initialize_directions = SOUTH|NORTH|EAST initialize_directions = SOUTH|NORTH|EAST
mirrored = TRUE
//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)

View File

@@ -3,6 +3,9 @@
initialize_directions = SOUTH|NORTH|WEST initialize_directions = SOUTH|NORTH|WEST
use_power = 0 use_power = 0
var/mirrored = FALSE
var/tee = FALSE
var/datum/gas_mixture/air1 var/datum/gas_mixture/air1
var/datum/gas_mixture/air2 var/datum/gas_mixture/air2
var/datum/gas_mixture/air3 var/datum/gas_mixture/air3
@@ -25,15 +28,7 @@
air3.volume = 200 air3.volume = 200
/obj/machinery/atmospherics/trinary/init_dir() /obj/machinery/atmospherics/trinary/init_dir()
switch(dir) initialize_directions = get_initialize_directions_trinary(dir, mirrored, tee)
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
/obj/machinery/atmospherics/trinary/update_underlays() /obj/machinery/atmospherics/trinary/update_underlays()
if(..()) if(..())
@@ -55,6 +50,23 @@
if(old_stat != stat) if(old_stat != stat)
update_icon() 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, "<span class='warning'>You cannot unwrench \the [src], it too exerted due to internal pressure.</span>")
add_fingerprint(user)
return 1
playsound(src, W.usesound, 50, 1)
to_chat(user, "<span class='notice'>You begin to unfasten \the [src]...</span>")
if (do_after(user, 40 * W.toolspeed))
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)
// 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)
@@ -93,10 +105,7 @@
// Get the direction each node is facing to connect. // 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. // 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() /obj/machinery/atmospherics/trinary/get_node_connect_dirs()
var/node1_connect = turn(dir, 180) return get_node_connect_dirs_trinary(dir, mirrored, tee)
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)
@@ -191,4 +200,58 @@
update_underlays() update_underlays()
return null 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)

View File

@@ -11,6 +11,8 @@
var/state = 0 // 0 = go straight, 1 = go to side 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 // like a trinary component, node1 is input, node2 is side output, node3 is straight output
var/obj/machinery/atmospherics/node3 var/obj/machinery/atmospherics/node3
@@ -24,9 +26,9 @@
/obj/machinery/atmospherics/tvalve/update_icon(animation) /obj/machinery/atmospherics/tvalve/update_icon(animation)
if(animation) if(animation)
flick("tvalve[src.state][!src.state]",src) flick("tvalve[mirrored ? "m" : ""][src.state][!src.state]",src)
else else
icon_state = "tvalve[state]" icon_state = "tvalve[mirrored ? "m" : ""][state]"
/obj/machinery/atmospherics/tvalve/update_underlays() /obj/machinery/atmospherics/tvalve/update_underlays()
if(..()) if(..())
@@ -43,15 +45,7 @@
update_underlays() update_underlays()
/obj/machinery/atmospherics/tvalve/init_dir() /obj/machinery/atmospherics/tvalve/init_dir()
switch(dir) initialize_directions = get_initialize_directions_trinary(dir, mirrored)
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
/obj/machinery/atmospherics/tvalve/network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference) /obj/machinery/atmospherics/tvalve/network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference)
if(reference == node1) if(reference == node1)
@@ -176,10 +170,7 @@
return return
/obj/machinery/atmospherics/tvalve/get_node_connect_dirs() /obj/machinery/atmospherics/tvalve/get_node_connect_dirs()
var/node1_connect = turn(dir, 180) return get_node_connect_dirs_trinary(dir, mirrored)
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()
if(node1 && node2 && node3) if(node1 && node2 && node3)
@@ -293,7 +284,7 @@
/obj/machinery/atmospherics/tvalve/digital/update_icon() /obj/machinery/atmospherics/tvalve/digital/update_icon()
..() ..()
if(!powered()) if(!powered())
icon_state = "tvalvenopower" icon_state = "tvalve[mirrored ? "m" : ""]nopower"
/obj/machinery/atmospherics/tvalve/digital/attack_ai(mob/user as mob) /obj/machinery/atmospherics/tvalve/digital/attack_ai(mob/user as mob)
return src.attack_hand(user) return src.attack_hand(user)
@@ -362,34 +353,12 @@
/obj/machinery/atmospherics/tvalve/mirrored /obj/machinery/atmospherics/tvalve/mirrored
icon_state = "map_tvalvem0" icon_state = "map_tvalvem0"
mirrored = TRUE
/obj/machinery/atmospherics/tvalve/mirrored/bypass /obj/machinery/atmospherics/tvalve/mirrored/bypass
icon_state = "map_tvalvem1" icon_state = "map_tvalvem1"
state = 1 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 /obj/machinery/atmospherics/tvalve/mirrored/digital // can be controlled by AI
name = "digital switching valve" name = "digital switching valve"
desc = "A digitally controlled valve." desc = "A digitally controlled valve."