This is a super simple auto join technique I discovered and I can't believe I didn't think of it earlier. (duhh)
It will append a code to the object's icon_state in the format of NSEW (North, South, East, West). Add this code to the states in your .dmi file and you're done.
atom/proc/AutoJoin()
icon_state = "" // Remove the icon_state used for placing it on the map
var/north = locate(type) in get_step(src,NORTH)
var/south = locate(type) in get_step(src,SOUTH)
var/east = locate(type) in get_step(src,EAST)
var/west = locate(type) in get_step(src,WEST)
icon_state += north ? "N" : ""
icon_state += south ? "S" : ""
icon_state += east ? "E" : ""
icon_state += west ? "W" : ""
If you're really optimization heavy, this works just the same twice as fast.
atom/proc/AutoJoin()
icon_state = "[(locate(type) in get_step(src,NORTH)) ? "N" : ""][(locate(type) in get_step(src,SOUTH)) ? "S" : ""][(locate(type) in get_step(src,EAST)) ? "E" : ""][(locate(type) in get_step(src,WEST)) ? "W" : ""]"
Nope. I tested it. That's fairly consistent with my experimentation with bitwise operations. On the whole they're pretty slow on BYOND.