//Title: Cone of Effect
//Credit to: Lummox JR
//Contributed by: Jtgibson
//Special thanks to: Foomer (for suggesting its creation)
//This proc returns a "cone" in a given direction -- that is,
// when you use the cone proc, it'll return a list of all objects
// within a certain distance inside a cone leading from the source
// out to that distance.
//For example:
// cone(usr, NORTH)
// would produce a cone like so:
// X X X X X X X X X | X = included space
// X X X X X X X | O = user's space (also included)
// X X X X X |
// X X X |
// O |
//You can tweak the cone's acceptable list as desired. For
// example:
// cone(usr, NORTH, range(usr))
// would make a cone from all objects within range().
//The default is view().
//To make a cone out three spaces, just use:
// cone(usr, NORTH, list = view(3))
//And so on and so forth.
//Lummox JR's Very Efficient Version
//But still even more efficient! See the Hyper-Efficient version.
proc/Cone(atom/center = usr, dir = NORTH, list/L = view(center))
. = list()
var/atom/A
if(dir & (dir-1))
for(A in L)
if(get_dir(center, A) & dir) . += A
else
for(A in L)
var/d = get_dir(center, A)
if(d == dir) . += A
else if(d & dir)
var/dx = abs(A.x - center.x)
var/dy = abs(A.y - center.y)
if(dx == dy) . += A
else if(dy > dx)
if(dir & 3) . += A
else
if(dir & 12) . += A
ID:195139
Nov 21 2006, 7:21 am
|
|