// Title: Turf Borders
// Credit to: Hiead
// Contributed by: Hiead
/*
This snippet was written to show an example of how one
can apply imaginary "borders" to turfs, disallowing movable
atoms from entering or exiting from specific directions.
For example, a turf with NORTH and EAST borders:
borders = NORTH|EAST
will not allow movable atoms to enter from a NORTH, EAST,
or NORTHEAST direction, and it will prevent movable atoms
from exiting in a NORTH, EAST, or NORTHEAST direction.
*/
turf/var/borders = 0 // bit-flagged value determining directional
atom/movable/Move(nLoc, nDir)
if(nDir)
// We need to split the dir into segments because otherwise,
// if we just flagged against the original dir,
// it would block movement when traveling NORTHEAST even if
// NORTH and EAST were not included as borders
var/d1 = nDir
var/d2 = 0
if(d1 & NORTH && d1 != NORTH)
d2 = d1 ^ NORTH
d1 = NORTH
else if(d1 & SOUTH && d1 != SOUTH)
d2 = d1 ^ SOUTH
d1 = SOUTH
if(isturf(loc)) // If not a turf, it won't have our borders!
var/turf/currLoc = loc
if(currLoc.borders & d1 && (d2 ? currLoc.borders & d2 : TRUE))
return FALSE
if(isturf(nLoc))
var/turf/newLoc = nLoc
if(newLoc.borders & turn(d1, 180) \
&& (d2 ? newLoc.borders & turn(d2, 180) : TRUE))
return FALSE
. = ..()
///*
// Testing Code/Sample Implementation:
turf/limited_exit/borders = EAST|NORTH|WEST
//*/
Hiead
e.g.
This way, you'll avoid extra checks each time you move... =)