.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Dominions 3: The Awakening (http://forum.shrapnelgames.com/forumdisplay.php?f=138)
-   -   Diagonal Distance/Range (http://forum.shrapnelgames.com/showthread.php?t=43095)

Illuminated One May 12th, 2009 01:20 AM

Diagonal Distance/Range
 
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

Re: Diagonal Distance/Range
 
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

Re: Diagonal Distance/Range
 
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

Re: Diagonal Distance/Range
 
Quote:

Originally Posted by lch (Post 691551)
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

Re: Diagonal Distance/Range
 
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

Re: Diagonal Distance/Range
 
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

Re: Diagonal Distance/Range
 
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

Re: Diagonal Distance/Range
 
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

Re: Diagonal Distance/Range
 
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

Re: Diagonal Distance/Range
 
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.


All times are GMT -4. The time now is 08:42 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.