GetDistanceToXY without source token

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

GetDistanceToXY without source token

Post by xavram »

I'm trying to write a macro that will calculate the distance between two cells on a map. It needs to use the "One_Two_One" metric to calculate this distance, so I thought I would use the GetDistanceToXY macro...but that assumes you are measuring from a token to a point on the map. I'm not; this is, effectively, always measuring from 0,0 to some determined set of coordinates.

Is there a way to do this that I'm not thinking of? That still keeps the "One_Two_One" metric I need?

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: GetDistanceToXY without source token

Post by aliasmask »

Calculate the differences in X and Y direction, then take the smaller value, divide by 2 and add that to bigger distance. So, dX = 5, dY=2 total distance is 6 (dX + dY/2). Round down.

Not complete code, but guts of it.

Code: Select all

<!-- gridDistance(point1, point2, isGrid) -->
[H: x1 = json.get(point1,"x")]
[H: y1 = json.get([point1,"y")]
[H: x2 = json.get(point2,"x")]
[H: y2 = json.get(point2,"y")]

[H: dArray = "[]"] 
[H: dArray = json.append(dArray,abs(x1 - x2))]
[H: dArray = json.append(dArray,abs(y1 - y2))]
[H: dArray = json.sort(dArray,"d")]

[H: distance = json.get(dArray,0) + floor(json.get(dArray,1)/2)]


xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: GetDistanceToXY without source token

Post by xavram »

OMG, Alias, you da man! I'll give this a shot!

Post Reply

Return to “Macros”