Optionally center the map around x=0 z=0

This commit is contained in:
Gael-de-Sailly 2020-12-20 22:28:54 +01:00
parent 53f88d337d
commit d5cf4a6267
3 changed files with 23 additions and 0 deletions

View File

@ -59,6 +59,12 @@ end
local blocksize = mapgen_rivers.blocksize local blocksize = mapgen_rivers.blocksize
local min_catchment = mapgen_rivers.min_catchment local min_catchment = mapgen_rivers.min_catchment
local max_catchment = mapgen_rivers.max_catchment local max_catchment = mapgen_rivers.max_catchment
local map_offset, map_offset_blocks
local center = mapgen_rivers.center
if center then
map_offset = {x=math.floor(X/2), z=math.floor(Z/2)}
map_offset_blocks = {x=map_offset.x/blocksize, z=map_offset.z/blocksize}
end
-- Width coefficients: coefficients solving -- Width coefficients: coefficients solving
-- wfactor * min_catchment ^ wpower = 1/(2*blocksize) -- wfactor * min_catchment ^ wpower = 1/(2*blocksize)
@ -89,6 +95,12 @@ local init = false
-- On map generation, determine into which polygon every point (in 2D) will fall. -- On map generation, determine into which polygon every point (in 2D) will fall.
-- Also store polygon-specific data -- Also store polygon-specific data
local function make_polygons(minp, maxp) local function make_polygons(minp, maxp)
if center then
minp = {x=minp.x+map_offset.x, z=minp.z+map_offset.z}
maxp = {x=maxp.x+map_offset.x, z=maxp.z+map_offset.z}
map_offset_x_blocks = map_offset.x / blocksize
end
if not init then if not init then
if glaciers then if glaciers then
noise_heat = minetest.get_perlin(mapgen_rivers.noise_params.heat) noise_heat = minetest.get_perlin(mapgen_rivers.noise_params.heat)
@ -164,6 +176,13 @@ local function make_polygons(minp, maxp)
polygon.dem = poly_dem polygon.dem = poly_dem
polygon.lake = math.min(lakes[iA], lakes[iB], lakes[iC], lakes[iD]) polygon.lake = math.min(lakes[iA], lakes[iB], lakes[iC], lakes[iD])
if center then
for i=1, 4 do
poly_x[i] = poly_x[i] - map_offset_blocks.x
poly_z[i] = poly_z[i] - map_offset_blocks.z
end
end
-- Now, rivers. -- Now, rivers.
-- Load river flux values for the 4 corners -- Load river flux values for the 4 corners
local riverA = river_width(rivers[iA]) local riverA = river_width(rivers[iA])

View File

@ -45,6 +45,7 @@ local function get_settings(key, dtype, default)
end end
end end
mapgen_rivers.center = get_settings('center', 'bool', false)
mapgen_rivers.blocksize = get_settings('blocksize', 'int', 12) mapgen_rivers.blocksize = get_settings('blocksize', 'int', 12)
mapgen_rivers.sea_level = get_settings('sea_level', 'int', 1) mapgen_rivers.sea_level = get_settings('sea_level', 'int', 1)
mapgen_rivers.min_catchment = get_settings('min_catchment', 'float', 25) mapgen_rivers.min_catchment = get_settings('min_catchment', 'float', 25)

View File

@ -1,5 +1,8 @@
# File containing all settings for 'mapgen_rivers' mod. # File containing all settings for 'mapgen_rivers' mod.
# Whether the map should be centered at x=0, z=0.
mapgen_rivers_center (Center map) bool false
# Represents horizontal map scale. Every cell of the grid will be upscaled to # Represents horizontal map scale. Every cell of the grid will be upscaled to
# a square of this size. # a square of this size.
# For example if the grid size is 1000x1000 and block size is 12, # For example if the grid size is 1000x1000 and block size is 12,