2018-07-19 11:48:34 +02:00
|
|
|
mmgen_levels = {}
|
|
|
|
|
|
|
|
-- levels 0.2.6
|
|
|
|
-- bugfixes: rename luxoff to luxore, remove 'local' from nobj_s
|
|
|
|
|
|
|
|
-- Parameters
|
|
|
|
|
|
|
|
local TERSCA = 96
|
|
|
|
local TSPIKE = 1.2
|
|
|
|
local SPIKEAMP = 2000
|
|
|
|
local TSTONE = 0.04
|
|
|
|
local STABLE = 2
|
|
|
|
|
|
|
|
local FLOATPER = 512
|
|
|
|
local FLOATFAC = 2
|
|
|
|
local FLOATOFF = -0.2
|
|
|
|
|
|
|
|
local YSURFMAX = 256
|
|
|
|
local YSAND = 4
|
|
|
|
local YWATER = 1
|
|
|
|
local YSURFCEN = 0
|
|
|
|
local YSURFMIN = -256
|
|
|
|
|
|
|
|
local YUNDERCEN = -512
|
|
|
|
local YLAVA = -528
|
|
|
|
local UNDERFAC = 0.0001
|
|
|
|
local UNDEROFF = -0.2
|
|
|
|
local LUXCHA = 1 / 9 ^ 3
|
|
|
|
|
|
|
|
-- Stuff
|
|
|
|
|
|
|
|
local floatper = math.pi / FLOATPER
|
|
|
|
|
2018-08-03 12:28:11 +02:00
|
|
|
-- Generate function
|
2018-07-19 11:48:34 +02:00
|
|
|
|
2022-03-25 23:59:40 +01:00
|
|
|
function mmgen_levels.generate(current_layer, vm, area, data, minp, maxp, offset_minp, offset_maxp, param,seed)
|
2018-07-19 11:48:34 +02:00
|
|
|
|
2018-08-03 12:28:11 +02:00
|
|
|
if not params then params = {} end
|
2018-07-19 11:48:34 +02:00
|
|
|
|
|
|
|
local x1 = maxp.x
|
|
|
|
local y1 = maxp.y
|
|
|
|
local z1 = maxp.z
|
|
|
|
local x0 = minp.x
|
|
|
|
local y0 = minp.y
|
|
|
|
local z0 = minp.z
|
|
|
|
local oy1 = offset_maxp.y
|
|
|
|
local oy0 = offset_minp.y
|
|
|
|
|
2022-03-24 22:01:05 +01:00
|
|
|
local c_stone = minetest.get_content_id("mcl_core:stone")
|
|
|
|
local c_sand = minetest.get_content_id("mcl_core:sand")
|
|
|
|
local c_water = minetest.get_content_id("mcl_core:water_source")
|
|
|
|
local c_lava = minetest.get_content_id("mcl_core:lava_source")
|
2018-07-19 11:48:34 +02:00
|
|
|
|
2022-03-24 22:01:05 +01:00
|
|
|
local c_grass = minetest.get_content_id("mcl_core:dirt_with_grass")
|
|
|
|
local c_dirt = minetest.get_content_id("mcl_core:dirt")
|
|
|
|
local c_luxore = minetest.get_content_id("mcl_core:stone_with_diamond")
|
2018-07-19 11:48:34 +02:00
|
|
|
|
|
|
|
local sidelen = x1 - x0 + 1
|
|
|
|
local ystride = sidelen + 32
|
|
|
|
--local zstride = ystride ^ 2
|
|
|
|
local chulens3d = {x=sidelen, y=sidelen+17, z=sidelen}
|
|
|
|
local chulens2d = {x=sidelen, y=sidelen, z=1}
|
|
|
|
local minpos3d = {x=x0, y=y0-16, z=z0}
|
|
|
|
local minpos2d = {x=x0, y=z0}
|
|
|
|
|
2018-08-03 12:28:11 +02:00
|
|
|
local nvals_terrain = multi_map.get_global_3dmap_flat("terrain", chulens3d, minpos3d)
|
|
|
|
local nvals_spike = multi_map.get_global_2dmap_flat("spike", chulens2d, minpos2d)
|
2018-07-19 11:48:34 +02:00
|
|
|
|
|
|
|
local ni3d = 1
|
|
|
|
local ni2d = 1
|
|
|
|
local stable = {}
|
|
|
|
local under = {}
|
|
|
|
for z = z0, z1 do
|
|
|
|
for x = x0, x1 do
|
|
|
|
local si = x - x0 + 1
|
|
|
|
stable[si] = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local relative_y = oy0 - 16
|
|
|
|
|
|
|
|
for y = y0 - 16, y1 + 1 do
|
|
|
|
local vi = area:index(x0, y, z)
|
|
|
|
for x = x0, x1 do
|
|
|
|
local si = x - x0 + 1
|
|
|
|
local viu = vi - ystride
|
|
|
|
|
|
|
|
local n_terrain = nvals_terrain[ni3d]
|
|
|
|
local n_spike = nvals_spike[ni2d]
|
|
|
|
local spikeoff = 0
|
2018-08-03 12:28:11 +02:00
|
|
|
if n_spike > (params.tspike or TSPIKE) then
|
|
|
|
spikeoff = (n_spike - (params.tspike or TSPIKE)) ^ 4 * (params.spikeamp or SPIKEAMP)
|
2018-07-19 11:48:34 +02:00
|
|
|
end
|
2018-08-03 12:28:11 +02:00
|
|
|
local grad = ((params.ysurfcen or YSURFCEN) - relative_y) / (params.tersca or TERSCA) + spikeoff
|
|
|
|
if relative_y > (params.ysurfmax or YSURFMAX) then
|
2018-07-19 11:48:34 +02:00
|
|
|
grad = math.max(
|
2018-08-03 12:28:11 +02:00
|
|
|
(-1 * (params.floatfac or FLOATFAC)) * math.abs(math.cos((relative_y - (params.ysurfmax or YSURFMAX)) * floatper)),
|
2018-07-19 11:48:34 +02:00
|
|
|
grad
|
|
|
|
)
|
2018-08-03 12:28:11 +02:00
|
|
|
elseif relative_y < (params.ysurfmin or YSURFMIN) then
|
2018-07-19 11:48:34 +02:00
|
|
|
grad = math.min(
|
2018-08-03 12:28:11 +02:00
|
|
|
(params.underfac or UNDERFAC) * (relative_y - (params.yundercen or YUNDERCEN)) ^ 2 + (params.underoff or UNDEROFF),
|
2018-07-19 11:48:34 +02:00
|
|
|
grad
|
|
|
|
)
|
|
|
|
end
|
|
|
|
local density = n_terrain + grad
|
|
|
|
|
|
|
|
if y < y0 then
|
2018-08-03 12:28:11 +02:00
|
|
|
if density >= (params.tstone or TSTONE) then
|
2018-07-19 11:48:34 +02:00
|
|
|
stable[si] = stable[si] + 1
|
|
|
|
elseif density <= 0 then
|
|
|
|
stable[si] = 0
|
|
|
|
end
|
|
|
|
if y == y0 - 1 then
|
|
|
|
local nodid = data[vi]
|
|
|
|
if nodid == c_stone
|
|
|
|
or nodid == c_sand
|
|
|
|
or nodid == c_grass
|
|
|
|
or nodid == c_dirt
|
|
|
|
or nodid == c_luxore then
|
|
|
|
stable[si] = STABLE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif y >= y0 and y <= y1 then
|
2018-08-03 12:28:11 +02:00
|
|
|
if density >= (params.tstone or TSTONE) then
|
|
|
|
if math.random() < (params.luxcha or LUXCHA) and relative_y < (params.ysurfmin or YSURFMIN)
|
2018-07-19 11:48:34 +02:00
|
|
|
and density < 0.01 and data[viu] == c_stone then
|
|
|
|
data[vi] = c_luxore
|
|
|
|
else
|
|
|
|
data[vi] = c_stone
|
|
|
|
end
|
|
|
|
stable[si] = stable[si] + 1
|
|
|
|
under[si] = 0
|
2018-08-03 12:28:11 +02:00
|
|
|
elseif density > 0 and density < (params.tstone or TSTONE)
|
|
|
|
and stable[si] >= (params.stable or STABLE) and relative_y > (params.ysurfmin or YSURFMIN) then
|
|
|
|
if relative_y <= (params.ysand or YSAND) then
|
2018-07-19 11:48:34 +02:00
|
|
|
data[vi] = c_sand
|
|
|
|
under[si] = 0
|
|
|
|
else
|
2022-03-25 23:59:40 +01:00
|
|
|
--data[vi] = c_dirt
|
2018-07-19 11:48:34 +02:00
|
|
|
under[si] = 1
|
|
|
|
end
|
2018-08-03 12:28:11 +02:00
|
|
|
elseif relative_y > (params.ysurfmin or YSURFMIN) and relative_y <= (params.ywater or YWATER) then
|
2018-07-19 11:48:34 +02:00
|
|
|
data[vi] = c_water
|
|
|
|
stable[si] = 0
|
|
|
|
under[si] = 0
|
2018-08-03 12:28:11 +02:00
|
|
|
elseif relative_y <= (params.ylava or YLAVA) then
|
2018-07-19 11:48:34 +02:00
|
|
|
data[vi] = c_lava
|
|
|
|
stable[si] = 0
|
|
|
|
under[si] = 0
|
|
|
|
else -- air, possibly just above surface
|
|
|
|
if under[si] == 1 then
|
2022-03-25 23:59:40 +01:00
|
|
|
--data[viu] = c_grass
|
2018-07-19 11:48:34 +02:00
|
|
|
end
|
|
|
|
stable[si] = 0
|
|
|
|
under[si] = 0
|
|
|
|
end
|
|
|
|
elseif y == y1 + 1 then
|
2018-08-03 12:28:11 +02:00
|
|
|
if density <= 0 and relative_y > (params.ywater or YWATER) then -- air, possibly just above surface
|
2018-07-19 11:48:34 +02:00
|
|
|
if under[si] == 1 then
|
2022-03-25 23:59:40 +01:00
|
|
|
--data[viu] = c_grass
|
2018-07-19 11:48:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ni3d = ni3d + 1
|
|
|
|
ni2d = ni2d + 1
|
|
|
|
vi = vi + 1
|
|
|
|
end
|
|
|
|
ni2d = ni2d - sidelen
|
|
|
|
relative_y = relative_y + 1
|
|
|
|
end
|
|
|
|
ni2d = ni2d + sidelen
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|