ID:195154
 
//Title: Diagonal/Orthogonal Checking Procs
//Credit to: Jtgibson
//Contributed by: Jtgibson

/*
This is a handy and devastatingly fast pair of procs which determine whether
someone is diagonal to an object or orthogonally parallel to it. This is much
faster than checking to see if get_dir() returns a diagonal or an orthogonal
direction.

Note that get_diag returns false if you're standing in the same location as the
target, but get_ortho returns true if you're standing in the same location.
*/



proc/get_diag(atom/src, atom/trg)
return (src.x != trg.x && src.x != trg.y)

proc/get_ortho(atom/src, atom/trg)
return (src.x == trg.x || src.y == trg.y)


//The most common use I'd see for this would be in the form of the following:
// if(get_dist(src,trg)==1 && get_ortho(src,trg))
//This would be an excellent system to ensure that the user must be next to
// a computer/switch/whatever and not standing at an angle to it to be able to
// use it.
//You could also use this to prevent people from entering doors diagonally and
// other variations on the same theme.


///*
//Testing code/sample implementation:

//Because of the nature of the proc, it's difficult to include a sample, but
// here's one that you can use to determine if you're orthogonal to any nearby
// turf.

turf/verb/check_orthogonal()
set src in oview(1)
if(get_ortho(usr,src)) usr << "Orthogonal!"
else usr << "Not orthogonal!"
//*/