2021-06-06 13:25:43 +02:00
|
|
|
local mtsettings = minetest.settings
|
|
|
|
local mgrsettings = Settings(minetest.get_worldpath() .. '/mapgen_rivers.conf')
|
2021-07-24 13:21:06 +02:00
|
|
|
|
2022-01-18 17:58:51 +01:00
|
|
|
mapgen_rivers.version = "1.0.2-dev1"
|
2021-07-24 13:21:06 +02:00
|
|
|
|
|
|
|
local previous_version_mt = mtsettings:get("mapgen_rivers_version") or "0.0"
|
|
|
|
local previous_version_mgr = mgrsettings:get("version") or "0.0"
|
|
|
|
|
|
|
|
if mapgen_rivers.version ~= previous_version_mt or mapgen_rivers.version ~= previous_version_mgr then
|
2021-07-24 18:55:13 +02:00
|
|
|
local compat_mt, compat_mgr = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/compatibility.lua")
|
|
|
|
if mapgen_rivers.version ~= previous_version_mt then
|
|
|
|
compat_mt(mtsettings)
|
|
|
|
end
|
|
|
|
if mapgen_rivers.version ~= previous_version_mgr then
|
|
|
|
compat_mgr(mgrsettings)
|
|
|
|
end
|
2021-07-24 13:21:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
mtsettings:set("mapgen_rivers_version", mapgen_rivers.version)
|
|
|
|
mgrsettings:set("version", mapgen_rivers.version)
|
|
|
|
|
2022-01-18 14:25:37 +01:00
|
|
|
local defaults
|
|
|
|
do
|
|
|
|
local f = io.open(mapgen_rivers.modpath .. "/settings_default.json")
|
|
|
|
defaults = minetest.parse_json(f:read("*all"))
|
|
|
|
f:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Convert strings to numbers in noise params because Minetest API is not able to do it cleanly...
|
|
|
|
local function clean_np(np)
|
|
|
|
for field, value in pairs(np) do
|
|
|
|
if field ~= 'flags' and type(value) == 'string' then
|
|
|
|
np[field] = tonumber(value) or value
|
|
|
|
elseif field == 'spread' then
|
|
|
|
for dir, v in pairs(value) do
|
|
|
|
value[dir] = tonumber(v) or v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-06 13:25:43 +02:00
|
|
|
function mapgen_rivers.define_setting(name, dtype, default)
|
|
|
|
if dtype == "number" or dtype == "string" then
|
|
|
|
local v = mgrsettings:get(name)
|
|
|
|
if v == nil then
|
|
|
|
v = mtsettings:get('mapgen_rivers_' .. name)
|
|
|
|
if v == nil then
|
2022-01-18 14:25:37 +01:00
|
|
|
v = defaults[name]
|
2021-06-06 13:25:43 +02:00
|
|
|
end
|
|
|
|
mgrsettings:set(name, v)
|
2020-04-14 17:53:36 +02:00
|
|
|
end
|
2021-06-06 13:25:43 +02:00
|
|
|
if dtype == "number" then
|
|
|
|
return tonumber(v)
|
2020-11-17 20:56:02 +01:00
|
|
|
else
|
2021-06-06 13:25:43 +02:00
|
|
|
return v
|
|
|
|
end
|
|
|
|
elseif dtype == "bool" then
|
|
|
|
local v = mgrsettings:get_bool(name)
|
|
|
|
if v == nil then
|
|
|
|
v = mtsettings:get_bool('mapgen_rivers_' .. name)
|
|
|
|
if v == nil then
|
2022-01-18 14:25:37 +01:00
|
|
|
v = defaults[name]
|
2020-11-17 20:56:02 +01:00
|
|
|
end
|
2021-06-06 13:25:43 +02:00
|
|
|
mgrsettings:set_bool(name, v)
|
2020-04-14 17:53:36 +02:00
|
|
|
end
|
2021-06-06 13:25:43 +02:00
|
|
|
return v
|
|
|
|
elseif dtype == "noise" then
|
|
|
|
local v = mgrsettings:get_np_group(name)
|
|
|
|
if v == nil then
|
|
|
|
v = mtsettings:get_np_group('mapgen_rivers_' .. name)
|
|
|
|
if v == nil then
|
2022-01-18 14:25:37 +01:00
|
|
|
v = defaults[name]
|
2021-06-06 13:25:43 +02:00
|
|
|
end
|
|
|
|
mgrsettings:set_np_group(name, v)
|
2020-04-14 17:53:36 +02:00
|
|
|
end
|
2022-01-18 14:25:37 +01:00
|
|
|
clean_np(v)
|
2021-06-06 13:25:43 +02:00
|
|
|
return v
|
2020-04-14 17:53:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-06 13:25:43 +02:00
|
|
|
local def_setting = mapgen_rivers.define_setting
|
|
|
|
|
|
|
|
mapgen_rivers.settings = {
|
2022-01-18 14:25:37 +01:00
|
|
|
center = def_setting('center', 'bool'),
|
|
|
|
blocksize = def_setting('blocksize', 'number'),
|
2021-06-06 13:25:43 +02:00
|
|
|
sea_level = tonumber(minetest.get_mapgen_setting('water_level')),
|
2022-01-18 14:25:37 +01:00
|
|
|
min_catchment = def_setting('min_catchment', 'number'),
|
|
|
|
river_widening_power = def_setting('river_widening_power', 'number'),
|
|
|
|
riverbed_slope = def_setting('riverbed_slope', 'number'),
|
|
|
|
distort = def_setting('distort', 'bool'),
|
|
|
|
biomes = def_setting('biomes', 'bool'),
|
|
|
|
glaciers = def_setting('glaciers', 'bool'),
|
|
|
|
glacier_factor = def_setting('glacier_factor', 'number'),
|
|
|
|
elevation_chill = def_setting('elevation_chill', 'number'),
|
|
|
|
|
2022-01-18 17:58:51 +01:00
|
|
|
map_x_size = def_setting('map_x_size', 'number'),
|
|
|
|
map_z_size = def_setting('map_z_size', 'number'),
|
2022-01-03 15:45:27 +01:00
|
|
|
margin = def_setting('margin', 'bool'),
|
|
|
|
margin_width = def_setting('margin_width', 'number'),
|
|
|
|
margin_elev = def_setting('margin_elev', 'number'),
|
2021-06-06 13:25:43 +02:00
|
|
|
evol_params = {
|
2022-01-18 14:25:37 +01:00
|
|
|
K = def_setting('river_erosion_coef', 'number'),
|
|
|
|
m = def_setting('river_erosion_power', 'number'),
|
|
|
|
d = def_setting('diffusive_erosion', 'number'),
|
|
|
|
compensation_radius = def_setting('compensation_radius', 'number'),
|
2021-06-06 13:25:43 +02:00
|
|
|
},
|
2022-01-18 14:25:37 +01:00
|
|
|
tectonic_speed = def_setting('tectonic_speed', 'number'),
|
|
|
|
evol_time = def_setting('evol_time', 'number'),
|
|
|
|
evol_time_step = def_setting('evol_time_step', 'number'),
|
2021-06-26 13:13:41 +02:00
|
|
|
|
2021-07-24 18:55:13 +02:00
|
|
|
load_all = mtsettings:get_bool('mapgen_rivers_load_all')
|
2021-06-06 13:25:43 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 14:25:37 +01:00
|
|
|
mapgen_rivers.noise_params = {
|
|
|
|
base = def_setting("np_base", "noise"),
|
|
|
|
distort_x = def_setting("np_distort_x", "noise"),
|
|
|
|
distort_z = def_setting("np_distort_z", "noise"),
|
|
|
|
distort_amplitude = def_setting("np_distort_amplitude", "noise"),
|
|
|
|
|
|
|
|
heat = minetest.get_mapgen_setting_noiseparams('mg_biome_np_heat'),
|
|
|
|
heat_blend = minetest.get_mapgen_setting_noiseparams('mg_biome_np_heat_blend'),
|
|
|
|
}
|
|
|
|
|
|
|
|
mapgen_rivers.noise_params.heat.offset = mapgen_rivers.noise_params.heat.offset +
|
|
|
|
mapgen_rivers.settings.sea_level * mapgen_rivers.settings.elevation_chill
|
|
|
|
|
2021-06-06 13:25:43 +02:00
|
|
|
local function write_settings()
|
|
|
|
mgrsettings:write()
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_mods_loaded(write_settings)
|
|
|
|
minetest.register_on_shutdown(write_settings)
|