mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2024-12-28 03:40:39 +01:00
Added glaciers, and re-organized noise definitions
This commit is contained in:
parent
625768f967
commit
6f43430574
50
init.lua
50
init.lua
@ -7,6 +7,9 @@ dofile(modpath .. 'settings.lua')
|
||||
local blocksize = mapgen_rivers.blocksize
|
||||
local sea_level = mapgen_rivers.sea_level
|
||||
local riverbed_slope = mapgen_rivers.riverbed_slope
|
||||
local elevation_chill = mapgen_rivers.elevation_chill
|
||||
|
||||
dofile(modpath .. 'noises.lua')
|
||||
|
||||
local make_polygons = dofile(modpath .. 'polygons.lua')
|
||||
|
||||
@ -23,43 +26,6 @@ end
|
||||
|
||||
local data = {}
|
||||
|
||||
local noise_x_params = {
|
||||
offset = 0,
|
||||
scale = 1,
|
||||
seed = -4574,
|
||||
spread = {x=64, y=32, z=64},
|
||||
octaves = 3,
|
||||
persistence = 0.75,
|
||||
lacunarity = 2,
|
||||
}
|
||||
|
||||
local noise_z_params = {
|
||||
offset = 0,
|
||||
scale = 1,
|
||||
seed = -7940,
|
||||
spread = {x=64, y=32, z=64},
|
||||
octaves = 3,
|
||||
persistence = 0.75,
|
||||
lacunarity = 2,
|
||||
}
|
||||
|
||||
local noise_distort_params = {
|
||||
offset = 0,
|
||||
scale = 10,
|
||||
seed = 676,
|
||||
spread = {x=1024, y=1024, z=1024},
|
||||
octaves = 5,
|
||||
persistence = 0.5,
|
||||
lacunarity = 2,
|
||||
flags = "absvalue",
|
||||
}
|
||||
|
||||
local noise_heat_params = minetest.get_mapgen_setting_noiseparams('mg_biome_np_heat')
|
||||
local noise_heat_blend_params = minetest.get_mapgen_setting_noiseparams('mg_biome_np_heat_blend')
|
||||
|
||||
local elevation_chill = 0.25
|
||||
noise_heat_params.offset = noise_heat_params.offset + sea_level*elevation_chill
|
||||
|
||||
local noise_x_obj, noise_z_obj, noise_distort_obj, noise_heat_obj, noise_heat_blend_obj
|
||||
local noise_x_map = {}
|
||||
local noise_z_map = {}
|
||||
@ -82,11 +48,11 @@ local function generate(minp, maxp, seed)
|
||||
y = chulens.y+1,
|
||||
z = chulens.z,
|
||||
}
|
||||
noise_x_obj = minetest.get_perlin_map(noise_x_params, mapsize)
|
||||
noise_z_obj = minetest.get_perlin_map(noise_z_params, mapsize)
|
||||
noise_heat_obj = minetest.get_perlin_map(noise_heat_params, chulens)
|
||||
noise_heat_blend_obj = minetest.get_perlin_map(noise_heat_blend_params, chulens)
|
||||
noise_distort_obj = minetest.get_perlin_map(noise_distort_params, chulens)
|
||||
noise_x_obj = minetest.get_perlin_map(mapgen_rivers.noise_params.distort_x, mapsize)
|
||||
noise_z_obj = minetest.get_perlin_map(mapgen_rivers.noise_params.distort_z, mapsize)
|
||||
noise_heat_obj = minetest.get_perlin_map(mapgen_rivers.noise_params.heat, chulens)
|
||||
noise_heat_blend_obj = minetest.get_perlin_map(mapgen_rivers.noise_params.heat_blend, chulens)
|
||||
noise_distort_obj = minetest.get_perlin_map(mapgen_rivers.noise_params.distort_amplitude, chulens)
|
||||
init = true
|
||||
end
|
||||
|
||||
|
37
noises.lua
Normal file
37
noises.lua
Normal file
@ -0,0 +1,37 @@
|
||||
mapgen_rivers.noise_params = {
|
||||
distort_x = {
|
||||
offset = 0,
|
||||
scale = 1,
|
||||
seed = -4574,
|
||||
spread = {x=64, y=32, z=64},
|
||||
octaves = 3,
|
||||
persistence = 0.75,
|
||||
lacunarity = 2,
|
||||
},
|
||||
|
||||
distort_z = {
|
||||
offset = 0,
|
||||
scale = 1,
|
||||
seed = -7940,
|
||||
spread = {x=64, y=32, z=64},
|
||||
octaves = 3,
|
||||
persistence = 0.75,
|
||||
lacunarity = 2,
|
||||
},
|
||||
|
||||
distort_amplitude = {
|
||||
offset = 0,
|
||||
scale = 10,
|
||||
seed = 676,
|
||||
spread = {x=1024, y=1024, z=1024},
|
||||
octaves = 5,
|
||||
persistence = 0.5,
|
||||
lacunarity = 2,
|
||||
flags = "absvalue",
|
||||
},
|
||||
|
||||
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.sea_level*mapgen_rivers.elevation_chill
|
37
polygons.lua
37
polygons.lua
@ -74,9 +74,28 @@ local function river_width(flow)
|
||||
return math.min(wfactor * flow ^ wpower, 1)
|
||||
end
|
||||
|
||||
local noise_heat -- Need a large-scale noise here so no heat blend
|
||||
local elevation_chill = mapgen_rivers.elevation_chill
|
||||
local function get_temperature(x, y, z)
|
||||
local pos = {x=x, y=z}
|
||||
return noise_heat:get2d(pos) - y*elevation_chill
|
||||
end
|
||||
|
||||
local glaciers = mapgen_rivers.glaciers
|
||||
local glacier_factor = mapgen_rivers.glacier_factor
|
||||
|
||||
local init = false
|
||||
|
||||
-- On map generation, determine into which polygon every point (in 2D) will fall.
|
||||
-- Also store polygon-specific data
|
||||
local function make_polygons(minp, maxp)
|
||||
if not init then
|
||||
if glaciers then
|
||||
noise_heat = minetest.get_perlin(mapgen_rivers.noise_params.heat)
|
||||
end
|
||||
init = true
|
||||
end
|
||||
|
||||
local chulens = maxp.z - minp.z + 1
|
||||
|
||||
local polygons = {}
|
||||
@ -141,7 +160,8 @@ local function make_polygons(minp, maxp)
|
||||
end
|
||||
end
|
||||
|
||||
polygon.dem = {dem[iA], dem[iB], dem[iC], dem[iD]}
|
||||
local poly_dem = {dem[iA], dem[iB], dem[iC], dem[iD]}
|
||||
polygon.dem = poly_dem
|
||||
polygon.lake = math.min(lakes[iA], lakes[iB], lakes[iC], lakes[iD])
|
||||
|
||||
-- Now, rivers.
|
||||
@ -150,6 +170,21 @@ local function make_polygons(minp, maxp)
|
||||
local riverB = river_width(rivers[iB])
|
||||
local riverC = river_width(rivers[iC])
|
||||
local riverD = river_width(rivers[iD])
|
||||
if glaciers then -- Widen the river
|
||||
if get_temperature(poly_x[1]*blocksize, poly_dem[1], poly_z[1]*blocksize) < 0 then
|
||||
riverA = math.min(riverA*glacier_factor, 1)
|
||||
end
|
||||
if get_temperature(poly_x[2]*blocksize, poly_dem[2], poly_z[2]*blocksize) < 0 then
|
||||
riverB = math.min(riverB*glacier_factor, 1)
|
||||
end
|
||||
if get_temperature(poly_x[3]*blocksize, poly_dem[3], poly_z[3]*blocksize) < 0 then
|
||||
riverC = math.min(riverC*glacier_factor, 1)
|
||||
end
|
||||
if get_temperature(poly_x[4]*blocksize, poly_dem[4], poly_z[4]*blocksize) < 0 then
|
||||
riverD = math.min(riverD*glacier_factor, 1)
|
||||
end
|
||||
end
|
||||
|
||||
polygon.river_corners = {riverA, 1-riverB, 2-riverC, 1-riverD}
|
||||
|
||||
-- Flow directions
|
||||
|
10
settings.lua
10
settings.lua
@ -9,6 +9,8 @@ local function get_settings(key, dtype, default)
|
||||
return storage:get_int(key)
|
||||
elseif dtype == "float" then
|
||||
return storage:get_float(key)
|
||||
elseif dtype == "bool" then
|
||||
return storage:get_string(key) == 'true'
|
||||
end
|
||||
end
|
||||
|
||||
@ -20,7 +22,7 @@ local function get_settings(key, dtype, default)
|
||||
elseif dtype == "float" then
|
||||
conf_val = tonumber(conf_val)
|
||||
storage:set_float(key, conf_val)
|
||||
elseif dtype == "string" then
|
||||
elseif dtype == "string" or dtype == "bool" then
|
||||
storage:set_string(key, conf_val)
|
||||
end
|
||||
|
||||
@ -32,6 +34,8 @@ local function get_settings(key, dtype, default)
|
||||
storage:set_float(key, default)
|
||||
elseif dtype == "string" then
|
||||
storage:set_string(key, default)
|
||||
elseif dtype == "bool" then
|
||||
storage:set_string(key, tostring(default))
|
||||
end
|
||||
|
||||
return default
|
||||
@ -43,3 +47,7 @@ mapgen_rivers.sea_level = get_settings('sea_level', 'int', 1)
|
||||
mapgen_rivers.min_catchment = get_settings('min_catchment', 'float', 25)
|
||||
mapgen_rivers.max_catchment = get_settings('max_catchment', 'float', 40000)
|
||||
mapgen_rivers.riverbed_slope = get_settings('riverbed_slope', 'float', 0.4) * mapgen_rivers.blocksize
|
||||
--mapgen_rivers.distort = get_settings('distort', 'bool', true) To be implemented: should be possible to disable distorsion
|
||||
mapgen_rivers.glaciers = get_settings('glaciers', 'bool', true)
|
||||
mapgen_rivers.glacier_factor = get_settings('glacier_factor', 'float', 8)
|
||||
mapgen_rivers.elevation_chill = get_settings('elevation_chill', 'float', 0.25)
|
||||
|
Loading…
Reference in New Issue
Block a user