PDA

View Full Version : Diagonal Distance/Range


Illuminated One
May 12th, 2009, 01:20 AM
Well, does anyone know how the distance on the battlefield is determined?

If your unit and your target are on a line in the grid, that's just counting.
But if say your mage starts in the middle of the field (0 on x axis, 0 on y) and an enemy SC starts in the upper left corner (20 on x axis, 10 on y), what effective range would be necessary to guarantee a hit before buffing?

Would you just add the difference on x and y (20 + 10)?
Pythagoras (sqr(20²+10²))?
Or maybe jump diagonal until you are on the same height and then straight to him (20)?

chrispedersen
May 12th, 2009, 09:48 AM
When moving, diagonal moves cost 3 ap, all others 2.

However, range caluculations for spells and missiles are not neccesarily done the same way. I don't know a way to confirm.
My suspician is that range is just calculated SR(a^2+b^2).

lch
May 18th, 2009, 03:47 AM
It's almost the Manhattan metric. The game calculates the distance between (x0,y0) and (x1,y1) by

dx = |x0-x1|
dy = |y0-y1|

r = dx+dy

if (dx > 0 and dy > 0) --r
if (dx > 3 and dy > 3) --r
if (dx > 6 and dy > 6) --r
if (dx > 9 and dy > 9) --r

chrispedersen
May 18th, 2009, 07:25 PM
It's almost the Manhattan metric. The game calculates the distance between (x0,y0) and (x1,y1) by

dx = |x0-x1|
dy = |y0-y1|

r = dx+dy

if (dx > 0 and dy > 0) --r
if (dx > 3 and dy > 3) --r
if (dx > 6 and dy > 6) --r
if (dx > 9 and dy > 9) --r

ok, I'll be the ignoramous.. I don't get the if (dx>0... etc
--r explain in english?

Jazzepi
May 18th, 2009, 07:59 PM
http://en.wikipedia.org/wiki/Manhattan_distance

I believe the simple explanation is that to move from point A to point B, you must follow a line that only turns 90 degrees at a time.

Jazzepi

Micah
May 18th, 2009, 08:40 PM
I think the "if (dx>0...)" bits subtract 1 from the range for each of those pairs that are true, so for a diagonal line you'd get range-length 1, 3, 5, 6, 8, 10, 11, 13, 15, 16. For straighter lines you'd be using the shorter coordinate to pass through each of those if gates, so if you have a differential of x=20 y=5 you would add them to get 25 and then subtract one for the first and second if statements, for a total of 23. Hopefully that's clear, and correct.

MaxWilson
May 18th, 2009, 09:05 PM
So displacing vertically on the battlefield is a LOT more effective at upping the range than I had previously thought.

chrispedersen
May 18th, 2009, 09:46 PM
oh, I get it. seems like

zx=min{dx,dy)
decrease = trunc(zx/3)
range=r-decrease or something like that is a little more elegant.. still .. interesting algorythmn.

Micah
May 18th, 2009, 10:09 PM
Looks mostly right chris, although you'd need to round "decrease" up to model the function, and it looks like you're truncating it. (Otherwise diagonals immediately next to a square would probably not count as melee range since they'd be range 2)

Lingchih
May 19th, 2009, 02:31 AM
Geez, I am so math challenged. I just stick them on the edges, and tell the to fire at whatever seems to be in range. Seems to work most of the time.

lch
May 19th, 2009, 05:10 AM
I think the "if (dx>0...)" bits subtract 1 from the range for each of those pairs that are true
Yeah. Normally, arrows would ignore diagonal movement and range would be determined as if they'd fly all the way to the front and then all the way to the side. That's the Manhattan metric, like a taxi cab that has to calculate distance by moving through the city blocks. If there is a greater amount of diagonal movement involved, though, then the game acknowledges that and allows for a little leeway by reducing the total distance a bit.

I'd think that this formula was chosen to speed up processing mostly.