Many smart pipe fixes (#60981)

* Smart pipes now actually go over smart pipes

This was ostensibly the main feature of smart pipes, so should be
fairly important

Parentheses are technically not required around the |, but I think
it's important to emphasise the importance of parentheses around
bitwise operators as this was apparently broken since 3e8407c471

Also purge var/connections and var/connection_num, since it's
literally only used for a `machine.connection_num < 3` check
which is completely redundant, and we already build a bitfield
tracking active directions.

* Smart pipes bridge over straight pipe types

This improves bridging to now go over most devices where possible,
letting you, for example, bridge over a perpindicular layer adapter.

* Pipe construction: Better documentation

Cleans up smart pipe documentation to match what's actually happening.

No functional changes.

* Skip pipes on different layers earlier

This prevents a pipe being made into a bridge perpindicular to a pipe
on a completely different layer, then failing to turn into a bridge
perpindicular to a relevant pipe.

* Pop superfluous parentheses

* Prevent creation of stub pipes

Setting the RPD to create a smart pipe that can only connect in one
direction would cause it to create invisible pipes that would still
block the placement of other pipes.

* The RPD can now reprogram smart pipes

The RPD can only affect smart pipes in directions that they are not
currently connected to.

This makes it easier to adjust designs after the fact, including
prevening round-start pipes from eagerly linking to a grey layer
adapter.

* Even smarter pipes

No more turning into bridge pipes. We now only try to be smart if
placement would fail, and we do our best to find a solution
whenever there is at least one smart pipe involved, regardless
of whether we're currently placing a smart pipe or not.

We never reconfigure any directions that a smart pipe is currently
connected, and we never reconfigure a smart pipe to have one or less
usable directions.

* Smartly go across perpindicular layer adapters

Also works when we're placing a layer adapter perpindicular to a
promiscuous smart pipe

* Pipes: Factor out loops and some bitfiddling

Create and use helpers with documented purposes over inline bitfiddling,
when it makes sense.

Many loops and switch statements were recreating information that was
already there.

Some relationships between pipe bitfield states were already assumed.
This centralises the functionality that relies upon these assumptions,
places them where the bits are defined, and documents them.

Rewrite some bitwise operations to be more idiomatic.

* Smart pipes: Debugging output

I normally clean history before pushing changes to any project,
but I feel like this should be saved.

* Revert "Smart pipes: Debugging output"

This reverts commit bb3aa76cf6d08e4d0951113a26fc9d48b6bc1735.

* Add trailing comma

The lack of this was making the linter sad
This commit is contained in:
esainane
2021-08-30 00:42:53 +12:00
committed by GitHub
parent b66ec7de43
commit d0e8bf35de
7 changed files with 181 additions and 105 deletions
@@ -58,9 +58,6 @@
///The bitflag that's being checked on ventcrawling. Default is to allow ventcrawling and seeing pipes.
var/vent_movement = VENTCRAWL_ALLOWED | VENTCRAWL_CAN_SEE
///Store the smart pipes connections, used for pipe construction
var/connection_num = 0
/obj/machinery/atmospherics/LateInitialize()
. = ..()
update_name()
@@ -93,32 +93,16 @@
/obj/machinery/atmospherics/pipe/proc/update_pipe_icon()
icon = 'icons/obj/atmospherics/pipes/pipes_bitmask.dmi'
var/connections = NONE
var/bitfield = NONE
for(var/i in 1 to device_type)
if(!nodes[i])
continue
var/obj/machinery/atmospherics/node = nodes[i]
var/connected_dir = get_dir(src, node)
switch(connected_dir)
if(NORTH)
bitfield |= NORTH_FULLPIPE
if(SOUTH)
bitfield |= SOUTH_FULLPIPE
if(EAST)
bitfield |= EAST_FULLPIPE
if(WEST)
bitfield |= WEST_FULLPIPE
for(var/cardinal in GLOB.cardinals)
if(initialize_directions & cardinal && !(bitfield & cardinal))
switch(cardinal)
if(NORTH)
bitfield |= NORTH_SHORTPIPE
if(SOUTH)
bitfield |= SOUTH_SHORTPIPE
if(EAST)
bitfield |= EAST_SHORTPIPE
if(WEST)
bitfield |= WEST_SHORTPIPE
connections |= connected_dir
bitfield = CARDINAL_TO_FULLPIPES(connections)
bitfield |= CARDINAL_TO_SHORTPIPES(initialize_directions & ~connections)
icon_state = "[bitfield]_[piping_layer]"
/obj/machinery/atmospherics/pipe/update_icon()
@@ -10,72 +10,45 @@ GLOBAL_LIST_INIT(atmos_components, typecacheof(list(/obj/machinery/atmospherics)
device_type = QUATERNARY
construction_type = /obj/item/pipe/quaternary
pipe_state = "manifold4w"
connection_num = 0
var/connections
var/connections = NONE
/obj/machinery/atmospherics/pipe/smart/update_pipe_icon()
icon = 'icons/obj/atmospherics/pipes/pipes_bitmask.dmi'
var/bitfield = NONE
var/bits = 0
connections = NONE
connection_num = 0
for(var/i in 1 to device_type)
if(!nodes[i])
continue
var/obj/machinery/atmospherics/node = nodes[i]
var/connected_dir = get_dir(src, node)
connections |= connected_dir
connection_num += 1
bits++
switch(connected_dir)
if(NORTH)
bitfield |= NORTH_FULLPIPE
if(SOUTH)
bitfield |= SOUTH_FULLPIPE
if(EAST)
bitfield |= EAST_FULLPIPE
if(WEST)
bitfield |= WEST_FULLPIPE
//If we dont have enough bits to make a proper sprite, add some shortpipe bits
if(bits < 2)
var/list/bits_to_add = list()
var/list/iterate_list = list()
if(bits == 1)
iterate_list += REVERSE_DIR(bitfield)
iterate_list += GLOB.cardinals
for(var/cardinal in iterate_list)
if(!(bitfield & cardinal) && !(cardinal in bits_to_add) && initialize_directions & cardinal)
bits_to_add += cardinal
bits++
if(bits >= 2)
break
for(var/direction in bits_to_add)
switch(direction)
if(NORTH)
bitfield |= NORTH_SHORTPIPE
if(SOUTH)
bitfield |= SOUTH_SHORTPIPE
if(EAST)
bitfield |= EAST_SHORTPIPE
if(WEST)
bitfield |= WEST_SHORTPIPE
bitfield = CARDINAL_TO_FULLPIPES(connections)
dir = check_binary_direction(connections)
// If we dont have enough bits to make a proper sprite, add some shortpipe bits
// Smart pipe icons differ from classic pipe icons in that we stop adding
// short pipe directions as soon as we find a valid sprite, rather than
// adding in all connectable directions.
// This prevents a lot of visual clutter, though it does make it harder to
// notice completely disconnected pipes.
if(ISSTUB(connections))
var/bits_to_add = NONE
if(connections != NONE)
bits_to_add |= REVERSE_DIR(connections) & initialize_directions
var/candidates = initialize_directions
var/shift = 0
// Note that candidates "should" never reach 0, as stub pipes are not allowed and break things
while (ISSTUB(connections | bits_to_add) && (candidates >> shift) != 0)
bits_to_add |= candidates & (1 << shift)
shift += 1
bitfield |= CARDINAL_TO_SHORTPIPES(bits_to_add)
icon_state = "[bitfield]_[piping_layer]"
switch(connection_num)
if(0)
dir = SOUTH
if(1)
dir = connections
if(2)
dir = check_binary_direction(connections)
if(3)
dir = connections
if(4)
dir = NORTH | SOUTH | EAST | WEST
/obj/machinery/atmospherics/pipe/smart/SetInitDirections(init_dir)
if(init_dir)
initialize_directions = init_dir
initialize_directions = init_dir
else
initialize_directions = ALL_CARDINALS