2021-06-03 23:30:04 +02:00
|
|
|
local EvolutionModel = dofile(mapgen_rivers.modpath .. '/terrainlib_lua/erosion.lua')
|
|
|
|
local twist = dofile(mapgen_rivers.modpath .. '/terrainlib_lua/twist.lua')
|
2021-06-03 20:08:57 +02:00
|
|
|
|
|
|
|
local size = {x=1000, y=1000}
|
|
|
|
local blocksize = 12
|
2021-06-03 23:30:04 +02:00
|
|
|
local variation_speed = 70
|
2021-06-03 20:08:57 +02:00
|
|
|
|
|
|
|
local np_base = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 200,
|
|
|
|
seed = 2469,
|
|
|
|
octaves = 8,
|
2021-06-03 23:30:04 +02:00
|
|
|
spread = {x=4000/blocksize, y=4000/blocksize, z=4000/blocksize},
|
2021-06-03 20:08:57 +02:00
|
|
|
persist = 0.6,
|
|
|
|
lacunarity = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
local time = 10
|
|
|
|
local time_step = 1
|
|
|
|
local niter = math.ceil(time/time_step)
|
|
|
|
time_step = time / niter
|
|
|
|
|
|
|
|
local function generate()
|
2021-06-03 23:30:04 +02:00
|
|
|
local seed = tonumber(minetest.get_mapgen_setting("seed"))
|
|
|
|
np_base.seed = (np_base.seed or 0) + seed
|
2021-06-03 20:08:57 +02:00
|
|
|
|
2021-06-03 23:30:04 +02:00
|
|
|
local nobj_base = PerlinNoiseMap(np_base, {x=size.x, y=1, z=size.y})
|
|
|
|
--nobj_base:calc_3d_map({x=0, y=0, z=0})
|
|
|
|
|
|
|
|
--local dem = nobj_base:get_map_slice({z=1}, {z=1})
|
|
|
|
local dem = nobj_base:get_3d_map_flat({x=0, y=0, z=0})
|
2021-06-03 20:08:57 +02:00
|
|
|
dem.X = size.x
|
|
|
|
dem.Y = size.y
|
|
|
|
|
|
|
|
local model = EvolutionModel()
|
|
|
|
model.dem = dem
|
|
|
|
local ref_dem = model:define_isostasy(dem)
|
|
|
|
|
2021-06-03 23:30:04 +02:00
|
|
|
local variation_step = variation_speed * time_step
|
2021-06-03 20:08:57 +02:00
|
|
|
for i=1, niter do
|
2021-06-03 23:30:04 +02:00
|
|
|
--nobj_base:get_map_slice({z=i+1}, {z=1}, ref_dem)
|
|
|
|
nobj_base:get_3d_map_flat({x=0, y=variation_step*i, z=0}, ref_dem)
|
2021-06-03 20:08:57 +02:00
|
|
|
|
|
|
|
model:diffuse(time_step)
|
|
|
|
model:flow()
|
|
|
|
model:erode(time_step)
|
|
|
|
model:isostasy()
|
|
|
|
end
|
|
|
|
model:flow()
|
|
|
|
|
|
|
|
local mfloor = math.floor
|
|
|
|
local mmin, mmax = math.min, math.max
|
|
|
|
local offset_x, offset_y = twist(model.dirs, model.rivers, 5)
|
2021-06-03 23:30:04 +02:00
|
|
|
for i=1, size.x*size.y do
|
2021-06-03 20:08:57 +02:00
|
|
|
offset_x[i] = mmin(mmax(offset_x[i]*256, -128), 127)
|
|
|
|
offset_y[i] = mmin(mmax(offset_y[i]*256, -128), 127)
|
|
|
|
end
|
|
|
|
|
|
|
|
mapgen_rivers.write_map('dem', model.dem, 2)
|
|
|
|
mapgen_rivers.write_map('lakes', model.lakes, 2)
|
|
|
|
mapgen_rivers.write_map('dirs', model.dirs, 1)
|
|
|
|
mapgen_rivers.write_map('rivers', model.rivers, 4)
|
|
|
|
mapgen_rivers.write_map('offset_x', offset_x, 1)
|
|
|
|
mapgen_rivers.write_map('offset_y', offset_y, 1)
|
|
|
|
local sfile = io.open(mapgen_rivers.world_data_path .. 'size', "w")
|
2021-06-03 23:30:04 +02:00
|
|
|
sfile:write(size.x..'\n'..size.y)
|
2021-06-03 20:08:57 +02:00
|
|
|
sfile:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
return generate
|