ID:195069
 
//Title: Cone of Effect
//Credit to: Foomer
//Contributed by: Foomer

/*
I needed a way to generate a cone shape from a specific
point, but I didn't have any handy grid-based geometric
know-how to aid me in my quest for coneness, and since all
of the existing cone procs posted on these forums didn't
work so good when projected diagonally, I built this one as
a substitute.

Example:
@ = mob
# = turf
#
####### ##### ##
##### ##### ###
### ##### @###
@ @#### ###
##
#
(North) (Northeast) (East)

NOTE:
Requires AbyssDragon's BasicMath</a> library, since it uses the get_steps() proc:

-- http://developer.byond.com/hub/AbyssDragon/BasicMath --

*/


// Returns a list containing all turfs within a cone
// from the origin in the specified direction.

proc/cone(atom/origin, dir, dist=3)
if(!origin || !dir) return

var/list/L = list()
var/turf/current_step = isturf(origin) ? origin : origin.loc

// Calculate the forward line
for(var/x=dist, x>0, x--)
if(!current_step) break // fail check
L += current_step

// Calculate the branches from the forward line
for(var/i=x-1, i>0, i--)
L += get_steps(current_step, turn(dir, 45), i)
L += get_steps(current_step, turn(dir, -45), i)

current_step = get_step(current_step, dir)

return L