1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Distances in RAND

Discussion in 'Rhye's and Fall RAND' started by onedreamer, Aug 7, 2010.

  1. onedreamer

    onedreamer Dragon

    Joined:
    Oct 21, 2004
    Messages:
    6,561
    Location:
    Torino - Italia
    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:

    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?
     
  2. Wessel V1

    Wessel V1 Chieftain

    Joined:
    Sep 10, 2007
    Messages:
    1,411
    Location:
    Nijmegen
    It's better but not perfect either. As you know, the actual distance would be (7^2 + 2^2)/2 = 7.3 (I believe, without a calculator), which is quite far from 9. So, the distance is shaped like a 45 degrees tilted square, in stead of a circle. It is easier for the player though.
     
  3. sercer88

    sercer88 Chieftain

    Joined:
    Oct 1, 2006
    Messages:
    1,443
    Location:
    MO, USA
    um, sorry to be nit-picking, but it's the square root of 7^2 + 4^2, which is just over 8... still not nine, but nine is actually closer...

    maybe the code could read:

    Code:
    inline int plotDistance(int iX1, int iY1, int iX2, int iY2)										
    {
    	iDX = xDistance(iX1, iX2);
    	iDY = yDistance(iY1, iY2);
    	[U]return (std::max(iDX, iDY) + (std::min(iDX, iDY) / 3));[/U]
    }
    instead... or does the code need to return a number ending in x.0 or x.5?
    If not, then we could actually use the REAL formula for distance, rather than some rough calculation.

    In this example, the distance returned would be 8.3
     
  4. Wessel V1

    Wessel V1 Chieftain

    Joined:
    Sep 10, 2007
    Messages:
    1,411
    Location:
    Nijmegen
    Of course you are right, just missed the number. Square root, that was the term I was looking for, thanks.:)
     
  5. Rhye

    Rhye 's and Fall creator

    Joined:
    May 23, 2001
    Messages:
    9,468
    Location:
    Japan / South America
    the meaning of that function is plot distance. You can reach the city in 7 moves. I don't need any other value
     
  6. onedreamer

    onedreamer Dragon

    Joined:
    Oct 21, 2004
    Messages:
    6,561
    Location:
    Torino - Italia
    plotDistance is different, what is currently in use is movement distance.
    In terms of distances between cities for calculations of trade routes values and maintenance, plotdistance is used, not movement distance. So I thought it should be used for the UHV conditions as well.
     

Share This Page