[1.0.0.194] Map.GetPlotDistance API Bug (Effects Tilted Axis, Start Locations, Etc.)

blackbutterfly

Emperor
Joined
May 9, 2016
Messages
1,813
Location
Leeds, UK
While developing the map scripts for Scrambled Arctic Ocean and AEP Earth, which are radial maps, I stumbled upon a bug with the Map API.

Map.GetPlotDistance() doesn't work correctly, so instead of producing nice circular ice shelves it was producing hexagonal ones.

Here's the correction/fix:

-- bugfix - remember Pythagoras?
function __GetPlotDistance(iX1, iY1, iX0, iY0)
return math.sqrt((iX1-iX0)^2 + (iY1-iY0)^2);
end

Minimal impact on Outback Tycoon scenario map (which is the template for all my map scripts).
 
Last edited:
This is what Map.GetPlotDistance will produce if used in map generation. A hex.
20220116232417_1.jpg

This is using Pythagoras:
20220116232149_1.jpg

Note: a vertical line will zig-zag on a hex grid, so a circle will be distorted.

The point is if Map.GetPlotDistance is used to find the distance between points A and B, it will be wrong. Use Pythagoras to calculate distance instead.
 
Map.GetPlotDistance() doesn't work correctly, so instead of producing nice circular ice shelves it was producing hexagonal ones.
Actually this function is working as designed: Map.GetPlotDistance() determines the number of plots from one point to another on a hex grid. You can use this to space out natrual wonders, for example, like in NaturalWonderGenerator.lua. FXS probably should have called this function Map.GetHexDistance() instead to be extra clear that this is intentionally not Pythagorean distance.

I agree that this is not a good function for drawing circles. Speaking of which, you can remove the zig-zag distortion by adjusting the Pythagorean distance on odd rows like so:
Code:
function GetPythagoreanDistance(x1, y1, x2, y2)  
    -- Shift x by half a plot on odd rows to account for hex grid.
    if ((y1 % 2) == 1) then
        x1 = x1 + 0.5;
    end
    if ((y2 % 2) == 1) then
        x2 = x2 + 0.5;
    end
    return math.sqrt((x1 - x2)^2 + (y1 - y2)^2);
end
 
FXS probably should have called this function Map.GetHexDistance() instead to be extra clear that this is intentionally not Pythagorean distance.

Exactly!

It is bad API programming.

I believe it may have even confused FXS own developers.

This is Tilted Axis map (released in 2019):
20220120093938_1.jpg
 
Exactly!

It is bad API programming.

I believe it may have even confused FXS own developers.

This is Tilted Axis map (released in 2019):View attachment 619054
Yeah, there's definitely some confusion going on with those hexagonal coastlines and latitude bands. And that diamond-shaped ice cap makes even less sense than a hexagon imo.

But what really confuses me about this map is that it doesn't even match the Tilted Axis map type from Civ 5. What Civ 6 calls "Tilted Axis" is really an Azimuthal projection (Wikipedia) of a world that spins with an Earth-like axis, as opposed to a world whose axis is tilted on its side with one pole always facing the sun which results in hot desert / fertile band on one half of the map and frozen wasteland on the other.
 
Yeah, there's definitely some confusion going on with those hexagonal coastlines and latitude bands. And that diamond-shaped ice cap makes even less sense than a hexagon imo.

Yeah, it seems like Tilted Axis was reimagined for Civ VI.
I concur it's trying to be an Azimuth projection.

Tilted Axis was a very flawed map, half developed.
I fixed it and uploaded it -> https://steamcommunity.com/sharedfiles/filedetails/?id=2730207061

Just FYI I posted this bug report back in 2017 (see date OP) almost two years before Tilted Axis shipped (in Sep 2019 update). ;)
 
Last edited:
Top Bottom