Perlinmap overgen plus 'get node' scanning, lower sea level, remove soil table

This commit is contained in:
paramat 2014-03-29 00:57:57 +00:00
parent 608332334f
commit 72c1fab95d
2 changed files with 255 additions and 227 deletions

View File

@ -1,4 +1,4 @@
watershed 0.2.12 by paramat watershed 0.2.13 by paramat
For latest stable Minetest back to 0.4.8 For latest stable Minetest back to 0.4.8
Depends default Depends default
Licenses: code WTFPL Licenses: code WTFPL

108
init.lua
View File

@ -1,22 +1,23 @@
-- watershed 0.2.12 by paramat -- watershed 0.2.13 by paramat
-- For latest stable Minetest and back to 0.4.8 -- For latest stable Minetest and back to 0.4.8
-- Depends default -- Depends default
-- License: code WTFPL -- License: code WTFPL
-- 0.2.12 tune TERCEN, TERSCA and amplitudes -- lower sea level to 160 above TERCEN
-- fixed and added more sandstone strata -- removed soil table
-- vertical perlinmap overgeneration combined with 'get node' scanning
-- TODO -- TODO
-- fog -- fog
-- singlenode y = 0 realm option. on spawnplayer teleport to surface, how? -- singlenode y = 0 realm option, on spawnplayer teleport to surface
-- magma with it's own tapering conduit system ... creates vents at the surface -- magma
-- Parameters -- Parameters
local YMIN = 6000 -- Approximate base of realm stone local YMIN = 6000 -- Approximate base of realm stone
local YMAX = 8000 -- Approximate top of atmosphere / mountains / floatlands local YMAX = 8000 -- Approximate top of atmosphere / mountains / floatlands
local TERCEN = 6784 -- Terrain 'centre', average seabed level local TERCEN = 6856 -- Terrain 'centre', average seabed level
local YWAT = 7024 -- Sea level local YWAT = 7016 -- Sea level
local YCLOUD = 7152 -- Cloud level local YCLOUD = 7144 -- Cloud level
local TERSCA = 512 -- Vertical terrain scale local TERSCA = 512 -- Vertical terrain scale
local XLSAMP = 0.2 -- Extra large scale height variation amplitude local XLSAMP = 0.2 -- Extra large scale height variation amplitude
@ -253,7 +254,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
local c_sandstone = minetest.get_content_id("default:sandstone") local c_sandstone = minetest.get_content_id("default:sandstone")
local c_gravel = minetest.get_content_id("default:gravel") local c_gravel = minetest.get_content_id("default:gravel")
local c_clay = minetest.get_content_id("default:clay") local c_clay = minetest.get_content_id("default:clay")
local c_lava = minetest.get_content_id("default:lava_source")
local c_wswater = minetest.get_content_id("watershed:water") local c_wswater = minetest.get_content_id("watershed:water")
local c_wsstone = minetest.get_content_id("watershed:stone") local c_wsstone = minetest.get_content_id("watershed:stone")
@ -267,8 +267,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
local c_wspermafrost = minetest.get_content_id("watershed:permafrost") local c_wspermafrost = minetest.get_content_id("watershed:permafrost")
local sidelen = x1 - x0 + 1 local sidelen = x1 - x0 + 1
local chulens = {x=sidelen, y=sidelen, z=sidelen} local chulens = {x=sidelen, y=sidelen+2, z=sidelen}
local minposxyz = {x=x0, y=y0, z=z0} local minposxyz = {x=x0, y=y0-1, z=z0}
local minposxz = {x=x0, y=z0} local minposxz = {x=x0, y=z0}
local nvals_rough = minetest.get_perlin_map(np_rough, chulens):get3dMap_flat(minposxyz) local nvals_rough = minetest.get_perlin_map(np_rough, chulens):get3dMap_flat(minposxyz)
@ -284,25 +284,18 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nvals_xlscale = minetest.get_perlin_map(np_xlscale, chulens):get2dMap_flat(minposxz) local nvals_xlscale = minetest.get_perlin_map(np_xlscale, chulens):get2dMap_flat(minposxz)
local nvals_cloud = minetest.get_perlin_map(np_cloud, chulens):get2dMap_flat(minposxz) local nvals_cloud = minetest.get_perlin_map(np_cloud, chulens):get2dMap_flat(minposxz)
local ungen = false -- ungenerated chunk below?
if minetest.get_node({x=x0, y=y0-1, z=z0}).name == "ignore" then
ungen = true
print ("[watershed] ungen")
end
local nixyz = 1 local nixyz = 1
local nixz = 1 local nixz = 1
local stable = {} local stable = {}
local under = {} local under = {}
local soil = {}
for z = z0, z1 do -- for each xy plane progressing northwards for z = z0, z1 do -- for each xy plane progressing northwards
for x = x0, x1 do for y = y0 - 1, y1 + 1 do -- for each x row progressing upwards
local si = x - x0 + 1
under[si] = 0
soil[si] = 0
local nodename = minetest.get_node({x=x,y=y0-1,z=z}).name
if nodename == "air"
or nodename == "default:water_source" then
stable[si] = 0
else
stable[si] = 2
end
end
for y = y0, y1 do -- for each x row progressing upwards
local vi = area:index(x0, y, z) local vi = area:index(x0, y, z)
local viu = area:index(x0, y-1, z) local viu = area:index(x0, y-1, z)
for x = x0, x1 do -- for each node do for x = x0, x1 do -- for each node do
@ -332,6 +325,29 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
end end
if y == y0 - 1 then -- node layer below chunk
if ungen then
if density >= 0 then -- if node solid
stable[si] = 2
else
stable[si] = 0
end
else
local nodename = minetest.get_node({x=x,y=y,z=z}).name
if nodename == "watershed:stone"
or nodename == "watershed:redstone"
or nodename == "watershed:dirt"
or nodename == "watershed:permafrost"
or nodename == "default:sandstone"
or nodename == "default:sand"
or nodename == "default:desert_sand"
or nodename == "default:gravel" then
stable[si] = 2
else
stable[si] = 0
end
end
elseif y >= y0 and y <= y1 then -- chunk
local n_temp = nvals_temp[nixyz] -- get raw temp and humid noise for use with node local n_temp = nvals_temp[nixyz] -- get raw temp and humid noise for use with node
local n_humid = nvals_humid[nixyz] local n_humid = nvals_humid[nixyz]
local biome = false -- select biome for node local biome = false -- select biome for node
@ -402,7 +418,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
stable[si] = stable[si] + 1 stable[si] = stable[si] + 1
under[si] = 0 under[si] = 0
soil[si] = 0
elseif density >= 0 and density < tstone and stable[si] >= 2 then -- fine materials elseif density >= 0 and density < tstone and stable[si] >= 2 then -- fine materials
if y == YWAT - 2 and math.abs(n_temp) < 0.05 then -- clay if y == YWAT - 2 and math.abs(n_temp) < 0.05 then -- clay
data[vi] = c_clay data[vi] = c_clay
@ -416,11 +431,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
elseif biome == 7 then elseif biome == 7 then
data[vi] = c_wsdirt data[vi] = c_wsdirt
under[si] = 7 -- savanna under[si] = 7 -- savanna
soil[si] = soil[si] + 1 -- increment soil if trees within biome
elseif biome == 8 then elseif biome == 8 then
data[vi] = c_wsdirt data[vi] = c_wsdirt
under[si] = 8 -- rainforest under[si] = 8 -- rainforest
soil[si] = soil[si] + 1
elseif biome == 3 then elseif biome == 3 then
data[vi] = c_wsdirt data[vi] = c_wsdirt
under[si] = 3 -- dry grassland under[si] = 3 -- dry grassland
@ -430,19 +443,16 @@ minetest.register_on_generated(function(minp, maxp, seed)
elseif biome == 5 then elseif biome == 5 then
data[vi] = c_wsdirt data[vi] = c_wsdirt
under[si] = 5 -- forest under[si] = 5 -- forest
soil[si] = soil[si] + 1
elseif biome == 1 then elseif biome == 1 then
data[vi] = c_wspermafrost data[vi] = c_wspermafrost
under[si] = 1 -- tundra under[si] = 1 -- tundra
elseif biome == 2 then elseif biome == 2 then
data[vi] = c_wsdirt data[vi] = c_wsdirt
under[si] = 2 -- taiga under[si] = 2 -- taiga
soil[si] = soil[si] + 1
end end
else -- fissure else -- fissure
stable[si] = 0 stable[si] = 0
under[si] = 0 under[si] = 0
soil[si] = 0
end end
elseif y <= YWAT and density < tstone then -- sea water, not in fissures elseif y <= YWAT and density < tstone then -- sea water, not in fissures
if y == YWAT and n_temp < ICETET then if y == YWAT and n_temp < ICETET then
@ -456,7 +466,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
stable[si] = 0 stable[si] = 0
under[si] = 0 under[si] = 0
soil[si] = 0
elseif densitybase >= triv and density < tstone then -- river water, not in fissures elseif densitybase >= triv and density < tstone then -- river water, not in fissures
if n_temp < ICETET then if n_temp < ICETET then
data[vi] = c_ice data[vi] = c_ice
@ -465,7 +474,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
stable[si] = 0 stable[si] = 0
under[si] = 0 under[si] = 0
soil[si] = 0
elseif y == YCLOUD then -- clouds elseif y == YCLOUD then -- clouds
local xrq = 16 * math.floor((x - x0) / 16) -- quantise to 16x16 lattice local xrq = 16 * math.floor((x - x0) / 16) -- quantise to 16x16 lattice
local zrq = 16 * math.floor((z - z0) / 16) local zrq = 16 * math.floor((z - z0) / 16)
@ -481,7 +489,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
stable[si] = 0 stable[si] = 0
under[si] = 0 under[si] = 0
soil[si] = 0
else -- possible above surface air node else -- possible above surface air node
if y >= YWAT and under[si] ~= 0 then if y >= YWAT and under[si] ~= 0 then
local fnoise = nvals_fissure[nixyz] local fnoise = nvals_fissure[nixyz]
@ -497,15 +504,14 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
end end
elseif under[si] == 2 then elseif under[si] == 2 then
if n_humid > HIHUT and math.random(PINCHA) == 2 if n_humid > HIHUT and math.random(PINCHA) == 2 then
and soil[si] >= 4 then
watershed_pinetree(x, y, z, area, data) watershed_pinetree(x, y, z, area, data)
else else
data[viu] = c_dirtsnow data[viu] = c_dirtsnow
data[vi] = c_snowblock data[vi] = c_snowblock
end end
elseif under[si] == 5 then elseif under[si] == 5 then
if math.random(APTCHA) == 2 and soil[si] >= 2 then if math.random(APTCHA) == 2 then
watershed_appletree(x, y, z, area, data) watershed_appletree(x, y, z, area, data)
else else
data[viu] = c_wsgrass data[viu] = c_wsgrass
@ -534,7 +540,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
watershed_grass(data, vi) watershed_grass(data, vi)
end end
elseif under[si] == 8 then elseif under[si] == 8 then
if math.random(JUTCHA) == 2 and soil[si] >= 5 then if math.random(JUTCHA) == 2 then
watershed_jungletree(x, y, z, area, data) watershed_jungletree(x, y, z, area, data)
else else
data[viu] = c_wsgrass data[viu] = c_wsgrass
@ -543,7 +549,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
end end
elseif under[si] == 7 then elseif under[si] == 7 then
if math.random(ACACHA) == 2 and soil[si] >= 3 then if math.random(ACACHA) == 2 then
watershed_acaciatree(x, y, z, area, data) watershed_acaciatree(x, y, z, area, data)
else else
data[viu] = c_wsdrygrass data[viu] = c_wsdrygrass
@ -561,7 +567,29 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
stable[si] = 0 stable[si] = 0
under[si] = 0 under[si] = 0
soil[si] = 0 end
elseif y == y1 + 1 then -- plane of nodes above chunk
if density < 0 and y >= YWAT + 1 and under[si] ~= 0 then -- if air above fine materials
if under[si] == 1 then -- add surface nodes to chunk top layer
if math.random(121) == 2 then
data[viu] = c_dirtsnow
elseif math.random(121) == 2 then
data[viu] = c_ice
end
elseif under[si] == 2 then
data[viu] = c_dirtsnow
elseif under[si] == 5 then
data[viu] = c_wsgrass
elseif under[si] == 3 then
data[viu] = c_wsdrygrass
elseif under[si] == 4 then
data[viu] = c_wsgrass
elseif under[si] == 8 then
data[viu] = c_wsgrass
elseif under[si] == 7 then
data[viu] = c_wsdrygrass
end
end
end end
nixyz = nixyz + 1 nixyz = nixyz + 1
nixz = nixz + 1 nixz = nixz + 1