ID:932040
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Currently there is no way to determine a starting point or location based on pixels.

For instance if I wanted to create a projectile 8 pixels away from my character no matter what direction they were facing.

It just seems a bit of a drawn out process to do that and I've been told if you end up doing something repeatedly there should be a proc for it somewhere (hence my request).
Doing this with a single proc would be quite impossible without some kind of enhanced datum that contained the loc as well as the step offsets, because a proc has only one return value.

The calculations involved are quite easy to handle in soft code however.
// make these lists global
var/list/dx = list(0,0,0,1,1,1,0,-1,-1,-1)
var/list/dy = list(1,-1,0,0,1,-1,0,0,1,-1)

obj/projectile/New(newloc, mob/M)
owner = M
dir = M.dir
loc = M.loc
// center projectile on player and offset by step_size
step_x = M.step_x + M.bound_x - bound_x + (M.bound_width - bound_width) / 2 + dx[dir] * step_size
step_y = M.step_y + M.bound_y - bound_y + (M.bound_height - bound_height) / 2 + dy[dir] * step_size
walk(src, dir, 0)
In response to Lummox JR
I like your dir2offset. It's now going into my ProcLib, because it's ~2x faster than mine.
//  Lummox's:
var d2o = list(
list( 0, 0, 0, 1, 1, 1, 0, -1, -1, -1 ),
list( 1, -1, 0, 0, 1, -1, 0, 0, 1, -1 )
)
#define dir2offset(dir) new_vec2(d2o[1][dir], d2o[2][dir])

// Mine:
proc
dir2offset(dir)
. = new_vec2(0, 0)
if(dir & EAST ) .[1] = 1
if(dir & WEST ) .[1] = -1
if(dir & NORTH) .[2] = 1
if(dir & SOUTH) .[2] = -1
Doing this as a multidimensional list though is pretty pointless; you're adding an extra lookup operation to no effect and wasting a list. If this is for a library though, then I'd suggest prefixing the var names with something so there's no chance of them being used in the main project's code.