mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-02-21 14:30:32 +01:00
Use settings from minetest.conf
This commit is contained in:
parent
af7a7ce26d
commit
14163681cc
48
init.lua
48
init.lua
@ -66,28 +66,15 @@ local blocksize = 12
|
|||||||
local sea_level = 1
|
local sea_level = 1
|
||||||
local min_catchment = 25
|
local min_catchment = 25
|
||||||
local max_catchment = 40000
|
local max_catchment = 40000
|
||||||
|
local riverbed_slope = 0.4
|
||||||
|
|
||||||
local storage = minetest.get_mod_storage()
|
local get_settings = dofile(modpath .. 'settings.lua')
|
||||||
if storage:contains("blocksize") then
|
|
||||||
blocksize = storage:get_int("blocksize")
|
blocksize = get_settings('blocksize', 'int', blocksize)
|
||||||
else
|
sea_level = get_settings('sea_level', 'int', sea_level)
|
||||||
storage:set_int("blocksize", blocksize)
|
min_catchment = get_settings('min_catchment', 'float', min_catchment)
|
||||||
end
|
max_catchment = get_settings('max_catchment', 'float', max_catchment)
|
||||||
if storage:contains("sea_level") then
|
riverbed_slope = get_settings('riverbed_slope', 'float', riverbed_slope) * blocksize
|
||||||
sea_level = storage:get_int("sea_level")
|
|
||||||
else
|
|
||||||
storage:set_int("sea_level", sea_level)
|
|
||||||
end
|
|
||||||
if storage:contains("min_catchment") then
|
|
||||||
min_catchment = storage:get_float("min_catchment")
|
|
||||||
else
|
|
||||||
storage:set_float("min_catchment", min_catchment)
|
|
||||||
end
|
|
||||||
if storage:contains("max_catchment") then
|
|
||||||
max_catchment = storage:get_float("max_catchment")
|
|
||||||
else
|
|
||||||
storage:set_float("max_catchment", max_catchment)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Width coefficients: coefficients solving
|
-- Width coefficients: coefficients solving
|
||||||
-- wfactor * min_catchment ^ wpower = 1/(2*blocksize)
|
-- wfactor * min_catchment ^ wpower = 1/(2*blocksize)
|
||||||
@ -218,19 +205,24 @@ local function generate(minp, maxp, seed)
|
|||||||
local i00, i01, i11, i10 = unpack(poly.i)
|
local i00, i01, i11, i10 = unpack(poly.i)
|
||||||
|
|
||||||
local is_river = false
|
local is_river = false
|
||||||
|
local depth_factor = 0
|
||||||
local r_west, r_north, r_east, r_south = unpack(poly.rivers)
|
local r_west, r_north, r_east, r_south = unpack(poly.rivers)
|
||||||
if xf >= r_east then
|
if xf >= r_east then
|
||||||
is_river = true
|
is_river = true
|
||||||
|
depth_factor = xf-r_east
|
||||||
xf = 1
|
xf = 1
|
||||||
elseif xf <= r_west then
|
elseif xf <= r_west then
|
||||||
is_river = true
|
is_river = true
|
||||||
|
depth_factor = r_west-xf
|
||||||
xf = 0
|
xf = 0
|
||||||
end
|
end
|
||||||
if zf >= r_south then
|
if zf >= r_south then
|
||||||
is_river = true
|
is_river = true
|
||||||
|
depth_factor = zf-r_south
|
||||||
zf = 1
|
zf = 1
|
||||||
elseif zf <= r_north then
|
elseif zf <= r_north then
|
||||||
is_river = true
|
is_river = true
|
||||||
|
depth_factor = r_north-zf
|
||||||
zf = 0
|
zf = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -238,15 +230,19 @@ local function generate(minp, maxp, seed)
|
|||||||
local c_NW, c_NE, c_SE, c_SW = unpack(poly.river_corners)
|
local c_NW, c_NE, c_SE, c_SW = unpack(poly.river_corners)
|
||||||
if xf+zf <= c_NW then
|
if xf+zf <= c_NW then
|
||||||
is_river = true
|
is_river = true
|
||||||
|
depth_factor = c_NW-xf-zf
|
||||||
xf, zf = 0, 0
|
xf, zf = 0, 0
|
||||||
elseif 1-xf+zf <= c_NE then
|
elseif 1-xf+zf <= c_NE then
|
||||||
is_river = true
|
is_river = true
|
||||||
|
depth_factor = c_NE-1+xf-zf
|
||||||
xf, zf = 1, 0
|
xf, zf = 1, 0
|
||||||
elseif 2-xf-zf <= c_SE then
|
elseif 2-xf-zf <= c_SE then
|
||||||
is_river = true
|
is_river = true
|
||||||
|
depth_factor = c_SE-2+xf+zf
|
||||||
xf, zf = 1, 1
|
xf, zf = 1, 1
|
||||||
elseif xf+1-zf <= c_SW then
|
elseif xf+1-zf <= c_SW then
|
||||||
is_river = true
|
is_river = true
|
||||||
|
depth_factor = c_SW-xf-1+zf
|
||||||
xf, zf = 0, 1
|
xf, zf = 0, 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -265,19 +261,17 @@ local function generate(minp, maxp, seed)
|
|||||||
xf, zf
|
xf, zf
|
||||||
))
|
))
|
||||||
|
|
||||||
local lake_height = math.floor(poly.lake)
|
local lake_height = math.max(math.floor(poly.lake), terrain_height)
|
||||||
|
if is_river then
|
||||||
|
terrain_height = math.min(math.max(lake_height, sea_level) - math.floor(1+depth_factor*riverbed_slope), terrain_height)
|
||||||
|
end
|
||||||
local is_lake = lake_height > terrain_height
|
local is_lake = lake_height > terrain_height
|
||||||
|
|
||||||
local ivm = a:index(x, minp.y-1, z)
|
local ivm = a:index(x, minp.y-1, z)
|
||||||
|
|
||||||
if terrain_height >= minp.y then
|
if terrain_height >= minp.y then
|
||||||
for y=minp.y, math.min(maxp.y, terrain_height) do
|
for y=minp.y, math.min(maxp.y, terrain_height) do
|
||||||
if y == terrain_height then
|
if y == terrain_height then
|
||||||
if is_lake or y <= sea_level then
|
if is_lake or y <= sea_level then
|
||||||
data[ivm] = c_sand
|
data[ivm] = c_sand
|
||||||
elseif is_river then
|
|
||||||
data[ivm] = c_rwater
|
|
||||||
else
|
else
|
||||||
data[ivm] = c_lawn
|
data[ivm] = c_lawn
|
||||||
end
|
end
|
||||||
|
41
settings.lua
Normal file
41
settings.lua
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
local storage = minetest.get_mod_storage()
|
||||||
|
local settings = minetest.settings
|
||||||
|
|
||||||
|
local function get_settings(key, dtype, default)
|
||||||
|
if storage:contains(key) then
|
||||||
|
if dtype == "string" then
|
||||||
|
return storage:get_string(key)
|
||||||
|
elseif dtype == "int" then
|
||||||
|
return storage:get_int(key)
|
||||||
|
elseif dtype == "float" then
|
||||||
|
return storage:get_float(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local conf_val = settings:get('mapgen_rivers_' .. key)
|
||||||
|
if conf_val then
|
||||||
|
if dtype == "int" then
|
||||||
|
conf_val = tonumber(conf_val)
|
||||||
|
storage:set_int(key, conf_val)
|
||||||
|
elseif dtype == "float" then
|
||||||
|
conf_val = tonumber(conf_val)
|
||||||
|
storage:set_float(key, conf_val)
|
||||||
|
elseif dtype == "string" then
|
||||||
|
storage:set_string(key, conf_val)
|
||||||
|
end
|
||||||
|
|
||||||
|
return conf_val
|
||||||
|
else
|
||||||
|
if dtype == "int" then
|
||||||
|
storage:set_int(key, default)
|
||||||
|
elseif dtype == "float" then
|
||||||
|
storage:set_float(key, default)
|
||||||
|
elseif dtype == "string" then
|
||||||
|
storage:set_string(key, default)
|
||||||
|
end
|
||||||
|
|
||||||
|
return default
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return get_settings
|
Loading…
x
Reference in New Issue
Block a user