Using whoward's border and plot iterators in Civ 6

astog

Warlord
Joined
May 29, 2015
Messages
244
Location
Minneapolis
@whoward69 created an excellent plot iterator functions in Civ 5 (link). These functions allowed you to iterate over the plots without worrying about the back end of the civ coordinate system. But unfortunately the two function ( ToHexFromGrid() and ToGridFromHex() ) are missing in Civ 6.

Luckily I found this website that explains the various hex coordinate systems. Link: http://www.redblobgames.com/grids/hexagons/. And in there they have the functions that allow you to convert between the two coordinate systems. So I wrote the two required functions below. These are just one implementation where I tried to make them readable, but if you want you can change them around, or even write them in one line.

Code:
function ToHexFromGrid(grid)
    local hex = {
        x = grid.x - (grid.y - (grid.y % 2)) / 2;
        y = grid.y;
    }
    return hex
end

function ToGridFromHex(hex_x, hex_y)
    local grid = {
        x = hex_x + (hex_y - (hex_y % 2)) / 2;
        y = hex_y;
    }
    return grid.x, grid.y
end

So if you want to use the whoward's plot iterator functions (link) , just paste these two functions, and you should be able to use them. Happy modding!
 
Back
Top Bottom