onedreamer
Dragon
Distances for UHV conditions in RAND are calculated on one axis only. The highest distance on the x or y axis will be taken into account as the distance between two cities (normally a city and the current capital). If you found a city 7 tiles east, 4 north from Moscow, distance will be 7 and it will not count towards the UHV condition. This is RAND's formula:
But there is already a function in Civ4 to calculate plot distances that does take into account both the x and y axis. Two diagonal moves will count 3, the first will count 1 and the second will count 2, just like in Dungeons&Dragons. Here's the formula:
In the example above, distance would be 9 (7+ 4/2). plotDistance is used to calculate Trade Routes base values.
What do you think about using the second formula?
Code:
def calculateDistance(self, x1, y1, x2, y2):
dx = abs(x2-x1)
dy = abs(y2-y1)
return max(dx, dy)
But there is already a function in Civ4 to calculate plot distances that does take into account both the x and y axis. Two diagonal moves will count 3, the first will count 1 and the second will count 2, just like in Dungeons&Dragons. Here's the formula:
Code:
inline int plotDistance(int iX1, int iY1, int iX2, int iY2)
{
iDX = xDistance(iX1, iX2);
iDY = yDistance(iY1, iY2);
return (std::max(iDX, iDY) + (std::min(iDX, iDY) / 2));
}
In the example above, distance would be 9 (7+ 4/2). plotDistance is used to calculate Trade Routes base values.
What do you think about using the second formula?