//Title: General Direction Proc
//Credit to: Jtgibson
//Contributed by: Jtgibson
/*
This snippet was created to give better approximations than those of the
original get_dir proc (built into BYOND). This is because BYOND's get_dir works
in a special way:
9 9 9 9 9 1 5 5 5 5 5 1 = NORTH
9 9 9 9 9 1 5 5 5 5 5 2 = SOUTH
9 9 9 9 9 1 5 5 5 5 5 4 = EAST
9 9 9 9 9 1 5 5 5 5 5 8 = WEST
9 9 9 9 9 1 5 5 5 5 5 5 = NORTHEAST
8 8 8 8 8 X 4 4 4 4 4 6 = SOUTHEAST
10 10 10 10 10 2 6 6 6 6 6 9 = NORTHWEST
10 10 10 10 10 2 6 6 6 6 6 10 = SOUTHWEST
10 10 10 10 10 2 6 6 6 6 6 X = SOUTH (centre)
10 10 10 10 10 2 6 6 6 6 6
10 10 10 10 10 2 6 6 6 6 6
Notice how directions immediately to the NORTH, EAST, SOUTH, and WEST of the
source are reported as such. However, even if you're one micrometre off of the
vertical or horizontal, it will represent it instead as a diagonal direction:
NORTHEAST, SOUTHEAST, NORTHWEST, or SOUTHWEST.
This snippet returns a different result:
9 9 9 1 1 1 1 1 5 5 5
9 9 9 9 1 1 1 5 5 5 5
9 9 9 9 1 1 1 5 5 5 5
8 9 9 9 9 1 5 5 5 5 4
8 8 8 9 9 1 5 5 4 4 4
8 8 8 8 8 X 4 4 4 4 4
8 8 8 10 10 2 6 6 4 4 4
8 10 10 10 10 2 6 6 6 6 4
10 10 10 10 2 2 2 6 6 6 6
10 10 10 10 2 2 2 6 6 6 6
10 10 10 2 2 2 2 2 6 6 6
Now notice how all of the directions are constrained to more realistic angles.
This makes finding basic directions more accurate in BYOND, which (in some pro-
jects) provides for a much better feel.
Note well that get_dir() in its original form has many uses -- in fact, this
snippet alone depends on it. In no case should you ever think that this snippet
is more useful than the primary form -- both have their niches to fill.
*/
proc/get_general_dir(atom/Loc1, atom/Loc2)
var/dir = get_dir(Loc1, Loc2)
switch(dir)
if(NORTH, EAST, SOUTH, WEST)
return dir
if(NORTHEAST, SOUTHWEST)
var/abs_x = abs(Loc2.x - Loc1.x)
var/abs_y = abs(Loc2.y - Loc1.y)
if(abs_y > (2*abs_x))
return turn(dir,45)
else if(abs_x > (2*abs_y))
return turn(dir,-45)
else
return dir
if(NORTHWEST, SOUTHEAST)
var/abs_x = abs(Loc2.x - Loc1.x)
var/abs_y = abs(Loc2.y - Loc1.y)
if(abs_y > (2*abs_x))
return turn(dir,-45)
else if(abs_x > (2*abs_y))
return turn(dir,45)
else
return dir
ID:195152
Nov 21 2006, 6:53 am
|
|