2014-03-05 11:41:34 +01:00
|
|
|
-- watershed 0.2.6 by paramat
|
2014-02-15 10:50:29 +01:00
|
|
|
-- For latest stable Minetest and back to 0.4.8
|
|
|
|
-- Depends default
|
|
|
|
-- License: code WTFPL
|
|
|
|
|
2014-03-05 11:41:34 +01:00
|
|
|
-- darkcloud node def was missing
|
|
|
|
-- ores and sandstone as strata with gentle sloping
|
|
|
|
-- TODO
|
|
|
|
-- more strata: gravel, sand, desert stone ...
|
|
|
|
-- clay
|
2014-02-20 08:18:40 +01:00
|
|
|
|
2014-02-15 10:50:29 +01:00
|
|
|
-- Parameters
|
|
|
|
|
2014-02-20 08:18:40 +01:00
|
|
|
local YMIN = 6000 -- Approximate base of realm stone
|
|
|
|
local YMAX = 8000 -- Approximate top of atmosphere / mountains / floatlands
|
2014-02-20 13:24:02 +01:00
|
|
|
local TERCEN = 6960 -- Terrain 'centre'. Approximate average seabed level
|
2014-02-19 23:28:36 +01:00
|
|
|
local YWAT = 7024 -- Sea level
|
2014-02-24 12:56:37 +01:00
|
|
|
local YCLOUD = 7152 -- Cloud level
|
2014-02-20 13:24:02 +01:00
|
|
|
|
2014-02-19 23:28:36 +01:00
|
|
|
local TERSCA = 384 -- Vertical terrain scale
|
2014-02-19 09:19:17 +01:00
|
|
|
local XLSAMP = 0 -- Extra large scale height variation amplitude
|
2014-02-24 12:56:37 +01:00
|
|
|
local BASAMP = 0.4 -- Base terrain amplitude
|
|
|
|
local CANAMP = 0.6 -- Canyon terrain amplitude
|
2014-02-19 02:16:19 +01:00
|
|
|
local CANEXP = 1.33 -- Canyon shape exponent
|
2014-02-24 12:56:37 +01:00
|
|
|
local ATANAMP = 1.2 -- Arctan function amplitude, controls size and number of floatlands / caves
|
2014-02-20 13:24:02 +01:00
|
|
|
|
2014-03-05 11:41:34 +01:00
|
|
|
local TSTONE = 0.02 -- 0.02 -- Density threshold for stone, depth of soil at TERCEN
|
2014-02-24 12:56:37 +01:00
|
|
|
local TRIV = -0.015 -- Maximum densitybase threshold for river water
|
|
|
|
local TSAND = -0.018 -- Maximum densitybase threshold for river sand
|
|
|
|
local FIST = 0 -- Fissure threshold at surface, controls size of fissure entrances at surface
|
2014-02-19 23:28:36 +01:00
|
|
|
local FISEXP = 0.02 -- Fissure expansion rate under surface
|
2014-03-05 11:41:34 +01:00
|
|
|
local ORECHA = 2 -- Ore 1/x chance per vein node
|
|
|
|
local ORETHI = 0.003 -- Ore vein thickness tuner
|
2014-02-25 19:14:54 +01:00
|
|
|
local TCLOUD = 0.5 -- Cloud threshold
|
|
|
|
|
|
|
|
local HITET = 0.5 -- --
|
|
|
|
local LOTET = -0.5 -- --
|
|
|
|
local ICETET = -0.8 -- --
|
|
|
|
local HIHUT = 0.5 -- --
|
|
|
|
local MIDHUT = 0 -- --
|
|
|
|
local LOHUT = -0.5 -- --
|
2014-03-05 11:41:34 +01:00
|
|
|
local CLOHUT = 0 -- --
|
|
|
|
local DCLOHUT = 1 -- --
|
2014-02-19 02:16:19 +01:00
|
|
|
|
2014-02-19 23:28:36 +01:00
|
|
|
local PINCHA = 47 -- Pine tree 1/x chance per node
|
|
|
|
local APTCHA = 47 -- Appletree
|
|
|
|
local FLOCHA = 36 -- Flower
|
|
|
|
local FOGCHA = 9 -- Forest grass
|
2014-02-20 08:18:40 +01:00
|
|
|
local GRACHA = 3 -- Grassland grasses
|
2014-02-19 23:28:36 +01:00
|
|
|
local JUTCHA = 16 -- Jungletree
|
|
|
|
local JUGCHA = 9 -- Junglegrass
|
2014-02-20 13:24:02 +01:00
|
|
|
local CACCHA = 841 -- Cactus
|
|
|
|
local DRYCHA = 169 -- Dry shrub
|
2014-02-20 08:18:40 +01:00
|
|
|
local PAPCHA = 3 -- Papyrus
|
2014-02-20 13:24:02 +01:00
|
|
|
local ACACHA = 841 -- Acacia tree
|
|
|
|
local GOGCHA = 3 -- Golden grass
|
2014-02-15 10:50:29 +01:00
|
|
|
|
|
|
|
-- 3D noise for rough terrain
|
|
|
|
|
2014-02-17 15:43:35 +01:00
|
|
|
local np_rough = {
|
2014-02-15 10:50:29 +01:00
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
2014-02-17 15:43:35 +01:00
|
|
|
spread = {x=512, y=512, z=512},
|
|
|
|
seed = 593,
|
2014-02-15 10:50:29 +01:00
|
|
|
octaves = 6,
|
2014-03-05 11:41:34 +01:00
|
|
|
persist = 0.67
|
2014-02-15 10:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
-- 3D noise for smooth terrain
|
|
|
|
|
2014-02-17 15:43:35 +01:00
|
|
|
local np_smooth = {
|
2014-02-15 10:50:29 +01:00
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
2014-02-17 15:43:35 +01:00
|
|
|
spread = {x=512, y=512, z=512},
|
|
|
|
seed = 593,
|
2014-02-24 12:56:37 +01:00
|
|
|
octaves = 5,
|
2014-02-15 10:50:29 +01:00
|
|
|
persist = 0.4
|
|
|
|
}
|
|
|
|
|
2014-02-19 23:28:36 +01:00
|
|
|
-- 3D noise for fissures
|
2014-02-19 09:19:17 +01:00
|
|
|
|
2014-02-19 23:28:36 +01:00
|
|
|
local np_fissure = {
|
2014-02-19 09:19:17 +01:00
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
2014-02-19 23:28:36 +01:00
|
|
|
spread = {x=256, y=512, z=256},
|
|
|
|
seed = 20099,
|
|
|
|
octaves = 5,
|
|
|
|
persist = 0.5
|
2014-02-19 09:19:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-25 19:14:54 +01:00
|
|
|
-- 3D noise for temperature
|
2014-02-24 12:56:37 +01:00
|
|
|
|
2014-02-25 19:14:54 +01:00
|
|
|
local np_temp = {
|
2014-02-24 12:56:37 +01:00
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
2014-02-25 19:14:54 +01:00
|
|
|
spread = {x=512, y=512, z=512},
|
|
|
|
seed = 9130,
|
|
|
|
octaves = 2,
|
|
|
|
persist = 0.5
|
|
|
|
}
|
|
|
|
|
|
|
|
-- 3D noise for humidity
|
|
|
|
|
|
|
|
local np_humid = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=512, y=512, z=512},
|
|
|
|
seed = -55500,
|
2014-02-24 12:56:37 +01:00
|
|
|
octaves = 2,
|
|
|
|
persist = 0.5
|
|
|
|
}
|
|
|
|
|
2014-03-05 11:41:34 +01:00
|
|
|
-- 3D noise for strata variation
|
|
|
|
|
|
|
|
local np_stratavar = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=128, y=32, z=128},
|
|
|
|
seed = -992221,
|
|
|
|
octaves = 2,
|
|
|
|
persist = 0.5
|
|
|
|
}
|
|
|
|
|
2014-02-19 02:16:19 +01:00
|
|
|
-- 2D noise for base terrain / riverbed height / mountain ranges, terrain blend, river and river sand depth
|
2014-02-15 10:50:29 +01:00
|
|
|
|
2014-02-17 15:43:35 +01:00
|
|
|
local np_base = {
|
2014-02-15 10:50:29 +01:00
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
2014-02-17 15:43:35 +01:00
|
|
|
spread = {x=4096, y=4096, z=4096},
|
|
|
|
seed = 8890,
|
2014-02-19 02:16:19 +01:00
|
|
|
octaves = 4,
|
|
|
|
persist = 0.4
|
2014-02-15 10:50:29 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 09:19:17 +01:00
|
|
|
-- 2D noise for extra large scale height variation
|
|
|
|
|
|
|
|
local np_xlscale = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=8192, y=8192, z=8192},
|
|
|
|
seed = -72,
|
|
|
|
octaves = 3,
|
|
|
|
persist = 0.4
|
|
|
|
}
|
|
|
|
|
2014-02-20 08:18:40 +01:00
|
|
|
-- 2D noise for clouds
|
|
|
|
|
|
|
|
local np_cloud = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
2014-02-24 12:56:37 +01:00
|
|
|
spread = {x=207, y=207, z=207},
|
2014-02-20 08:18:40 +01:00
|
|
|
seed = 2113,
|
2014-02-24 12:56:37 +01:00
|
|
|
octaves = 4,
|
2014-02-25 19:14:54 +01:00
|
|
|
persist = 0.7
|
2014-02-20 08:18:40 +01:00
|
|
|
}
|
|
|
|
|
2014-03-05 11:41:34 +01:00
|
|
|
-- 2D noise for strata
|
|
|
|
|
|
|
|
local np_strata = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=128, y=128, z=128},
|
|
|
|
seed = 23,
|
|
|
|
octaves = 2,
|
|
|
|
persist = 0.5
|
|
|
|
}
|
|
|
|
|
2014-02-15 10:50:29 +01:00
|
|
|
-- Stuff
|
|
|
|
|
|
|
|
watershed = {}
|
|
|
|
|
2014-02-19 02:16:19 +01:00
|
|
|
dofile(minetest.get_modpath("watershed").."/nodes.lua")
|
|
|
|
dofile(minetest.get_modpath("watershed").."/functions.lua")
|
2014-02-15 10:50:29 +01:00
|
|
|
|
|
|
|
-- On generated function
|
|
|
|
|
|
|
|
minetest.register_on_generated(function(minp, maxp, seed)
|
|
|
|
if minp.y < YMIN or maxp.y > YMAX then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local t1 = os.clock()
|
|
|
|
local x1 = maxp.x
|
|
|
|
local y1 = maxp.y
|
|
|
|
local z1 = maxp.z
|
|
|
|
local x0 = minp.x
|
|
|
|
local y0 = minp.y
|
|
|
|
local z0 = minp.z
|
|
|
|
|
|
|
|
print ("[watershed] chunk minp ("..x0.." "..y0.." "..z0..")")
|
|
|
|
|
|
|
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
|
|
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
|
|
|
local data = vm:get_data()
|
|
|
|
|
|
|
|
local c_air = minetest.get_content_id("air")
|
2014-02-17 15:43:35 +01:00
|
|
|
local c_water = minetest.get_content_id("default:water_source")
|
2014-02-15 10:50:29 +01:00
|
|
|
local c_sand = minetest.get_content_id("default:sand")
|
2014-02-17 15:43:35 +01:00
|
|
|
local c_desand = minetest.get_content_id("default:desert_sand")
|
|
|
|
local c_snowblock = minetest.get_content_id("default:snowblock")
|
2014-02-20 08:18:40 +01:00
|
|
|
local c_ice = minetest.get_content_id("default:ice")
|
2014-02-19 02:16:19 +01:00
|
|
|
local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
|
|
|
|
local c_jungrass = minetest.get_content_id("default:junglegrass")
|
2014-02-20 08:18:40 +01:00
|
|
|
local c_dryshrub = minetest.get_content_id("default:dry_shrub")
|
2014-02-19 23:28:36 +01:00
|
|
|
local c_stodiam = minetest.get_content_id("default:stone_with_diamond")
|
|
|
|
local c_stomese = minetest.get_content_id("default:stone_with_mese")
|
|
|
|
local c_stogold = minetest.get_content_id("default:stone_with_gold")
|
|
|
|
local c_stocopp = minetest.get_content_id("default:stone_with_copper")
|
|
|
|
local c_stoiron = minetest.get_content_id("default:stone_with_iron")
|
|
|
|
local c_stocoal = minetest.get_content_id("default:stone_with_coal")
|
2014-03-05 11:41:34 +01:00
|
|
|
local c_sandstone = minetest.get_content_id("default:sandstone")
|
2014-02-17 15:43:35 +01:00
|
|
|
|
2014-02-15 10:50:29 +01:00
|
|
|
local c_wswater = minetest.get_content_id("watershed:water")
|
2014-02-17 15:43:35 +01:00
|
|
|
local c_wsstone = minetest.get_content_id("watershed:stone")
|
|
|
|
local c_wsredstone = minetest.get_content_id("watershed:redstone")
|
|
|
|
local c_wsgrass = minetest.get_content_id("watershed:grass")
|
2014-02-20 13:24:02 +01:00
|
|
|
local c_wsdrygrass = minetest.get_content_id("watershed:drygrass")
|
|
|
|
local c_wsgoldgrass = minetest.get_content_id("watershed:goldengrass")
|
2014-02-19 09:19:17 +01:00
|
|
|
local c_wsdirt = minetest.get_content_id("watershed:dirt")
|
2014-02-20 08:18:40 +01:00
|
|
|
local c_wscloud = minetest.get_content_id("watershed:cloud")
|
2014-02-25 19:14:54 +01:00
|
|
|
local c_wsdarkcloud = minetest.get_content_id("watershed:darkcloud")
|
|
|
|
local c_wspermafrost = minetest.get_content_id("watershed:permafrost")
|
2014-02-15 10:50:29 +01:00
|
|
|
|
|
|
|
local sidelen = x1 - x0 + 1
|
|
|
|
local chulens = {x=sidelen, y=sidelen, z=sidelen}
|
|
|
|
local minposxyz = {x=x0, y=y0, z=z0}
|
|
|
|
local minposxz = {x=x0, y=z0}
|
2014-03-05 11:41:34 +01:00
|
|
|
local minposy = {x=y0, y=0}
|
2014-02-15 10:50:29 +01:00
|
|
|
|
2014-02-17 15:43:35 +01:00
|
|
|
local nvals_rough = minetest.get_perlin_map(np_rough, chulens):get3dMap_flat(minposxyz)
|
|
|
|
local nvals_smooth = minetest.get_perlin_map(np_smooth, chulens):get3dMap_flat(minposxyz)
|
2014-02-19 23:28:36 +01:00
|
|
|
local nvals_fissure = minetest.get_perlin_map(np_fissure, chulens):get3dMap_flat(minposxyz)
|
2014-02-25 19:14:54 +01:00
|
|
|
local nvals_temp = minetest.get_perlin_map(np_temp, chulens):get3dMap_flat(minposxyz)
|
|
|
|
local nvals_humid = minetest.get_perlin_map(np_humid, chulens):get3dMap_flat(minposxyz)
|
2014-03-05 11:41:34 +01:00
|
|
|
local nvals_stratavar = minetest.get_perlin_map(np_stratavar, chulens):get3dMap_flat(minposxyz)
|
2014-02-15 10:50:29 +01:00
|
|
|
|
2014-02-17 15:43:35 +01:00
|
|
|
local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat(minposxz)
|
2014-02-19 09:19:17 +01:00
|
|
|
local nvals_xlscale = minetest.get_perlin_map(np_xlscale, chulens):get2dMap_flat(minposxz)
|
2014-02-20 08:18:40 +01:00
|
|
|
local nvals_cloud = minetest.get_perlin_map(np_cloud, chulens):get2dMap_flat(minposxz)
|
2014-02-15 10:50:29 +01:00
|
|
|
|
2014-03-05 11:41:34 +01:00
|
|
|
local nvals_strata = minetest.get_perlin_map(np_strata, chulens):get2dMap_flat(minposy)
|
|
|
|
|
2014-02-15 10:50:29 +01:00
|
|
|
local nixyz = 1
|
|
|
|
local nixz = 1
|
|
|
|
local stable = {}
|
2014-02-19 02:16:19 +01:00
|
|
|
local under = {}
|
2014-02-24 12:56:37 +01:00
|
|
|
local soil = {}
|
2014-02-15 10:50:29 +01:00
|
|
|
for z = z0, z1 do -- for each xy plane progressing northwards
|
|
|
|
for x = x0, x1 do
|
|
|
|
local si = x - x0 + 1
|
2014-02-19 02:16:19 +01:00
|
|
|
under[si] = 0
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = 0
|
2014-02-15 10:50:29 +01:00
|
|
|
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)
|
2014-02-19 02:16:19 +01:00
|
|
|
local viu = area:index(x0, y-1, z)
|
2014-02-15 10:50:29 +01:00
|
|
|
for x = x0, x1 do -- for each node do
|
|
|
|
local si = x - x0 + 1
|
2014-02-20 13:24:02 +01:00
|
|
|
local grad = math.atan((TERCEN - y) / TERSCA) * ATANAMP
|
2014-02-17 15:43:35 +01:00
|
|
|
local n_base = nvals_base[nixz]
|
2014-02-24 12:56:37 +01:00
|
|
|
local terblen = math.max(1 - math.abs(n_base), 0)
|
|
|
|
local densitybase = (1 - math.abs(n_base)) * BASAMP + nvals_xlscale[nixz] * XLSAMP + grad
|
|
|
|
local altprop = (y - YWAT) / (TERCEN + TERSCA - YWAT)
|
|
|
|
local triv = TRIV * (1 - altprop * 1.1)
|
|
|
|
local tsand = TSAND * (1 - altprop * 1.1)
|
2014-03-05 11:41:34 +01:00
|
|
|
local tstone = TSTONE * (1 - math.atan(altprop) * 0.6) -- 1 to 0.05
|
2014-02-19 23:28:36 +01:00
|
|
|
local density = densitybase
|
2014-02-24 12:56:37 +01:00
|
|
|
+ math.abs(nvals_rough[nixyz] * terblen
|
|
|
|
+ nvals_smooth[nixyz] * (1 - terblen)) ^ CANEXP * CANAMP
|
2014-02-19 23:28:36 +01:00
|
|
|
|
|
|
|
local nofis = false
|
|
|
|
if density >= 0 then -- if terrain set fissure flag
|
|
|
|
if math.abs(nvals_fissure[nixyz]) > FIST + math.sqrt(density) * FISEXP then
|
|
|
|
nofis = true
|
|
|
|
end
|
|
|
|
end
|
2014-02-17 15:43:35 +01:00
|
|
|
|
2014-02-25 19:14:54 +01:00
|
|
|
local n_temp = nvals_temp[nixyz] -- get raw temp and humid noise for use with node
|
|
|
|
local n_humid = nvals_humid[nixyz]
|
|
|
|
local biome = false -- select biome for node
|
|
|
|
if n_temp < LOTET then
|
|
|
|
if n_humid < MIDHUT then
|
|
|
|
biome = 1 -- tundra
|
|
|
|
else
|
|
|
|
biome = 2 -- taiga
|
|
|
|
end
|
|
|
|
elseif n_temp > HITET then
|
|
|
|
if n_humid < LOHUT then
|
|
|
|
biome = 6 -- desert
|
|
|
|
elseif n_humid > HIHUT then
|
|
|
|
biome = 8 -- rainforest
|
|
|
|
else
|
|
|
|
biome = 7 -- savanna
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if n_humid < LOHUT then
|
|
|
|
biome = 3 -- dry grassland
|
|
|
|
elseif n_humid > HIHUT then
|
|
|
|
biome = 5 -- deciduous forest
|
|
|
|
else
|
|
|
|
biome = 4 -- grassland
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-19 23:28:36 +01:00
|
|
|
if density >= tstone and nofis -- stone cut by fissures
|
2014-03-05 11:41:34 +01:00
|
|
|
or (density >= tstone and density < TSTONE * 3 and y <= YWAT) -- stone around water
|
|
|
|
or (density >= tstone and density < TSTONE * 3 and densitybase >= triv ) then -- stone around river
|
|
|
|
local niy = y - y0 + 1
|
|
|
|
local n_strata = nvals_strata[niy] + nvals_stratavar[nixyz] / 4
|
|
|
|
if biome == 6 then
|
2014-02-25 19:14:54 +01:00
|
|
|
data[vi] = c_wsredstone
|
2014-03-05 11:41:34 +01:00
|
|
|
elseif n_strata >= 0 and n_strata <= ORETHI * 8 then
|
|
|
|
data[vi] = c_sandstone
|
|
|
|
elseif n_strata >= 1 and n_strata <= 1 + ORETHI then
|
|
|
|
data[vi] = c_stodiam
|
|
|
|
elseif n_strata >= 0.6 and n_strata <= 0.6 + ORETHI then
|
|
|
|
data[vi] = c_stomese
|
|
|
|
elseif n_strata >= 0.2 and n_strata <= 0.2 + ORETHI then
|
|
|
|
data[vi] = c_stogold
|
|
|
|
elseif n_strata >= -0.2 and n_strata <= -0.2 + ORETHI * 2 then
|
|
|
|
data[vi] = c_stocopp
|
|
|
|
elseif n_strata >= -0.6 and n_strata <= -0.6 + ORETHI * 2 then
|
|
|
|
data[vi] = c_stoiron
|
|
|
|
elseif n_strata >= -1 and n_strata <= -1 + ORETHI * 4 then
|
|
|
|
data[vi] = c_stocoal
|
2014-02-17 15:43:35 +01:00
|
|
|
else
|
|
|
|
data[vi] = c_wsstone
|
|
|
|
end
|
2014-02-15 10:50:29 +01:00
|
|
|
stable[si] = stable[si] + 1
|
2014-02-20 13:24:02 +01:00
|
|
|
under[si] = 0
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = 0
|
2014-02-17 15:43:35 +01:00
|
|
|
elseif density >= 0 and density < tstone and stable[si] >= 2 then -- fine materials
|
2014-03-05 11:41:34 +01:00
|
|
|
if densitybase >= tsand + math.random() * 0.003
|
|
|
|
or y <= YWAT + 1 + math.random(2) then
|
2014-02-24 12:56:37 +01:00
|
|
|
data[vi] = c_sand -- river / seabed sand not cut by fissures
|
2014-02-19 23:28:36 +01:00
|
|
|
elseif nofis then -- fine materials cut by fissures
|
2014-02-25 19:14:54 +01:00
|
|
|
if biome == 6 then
|
2014-02-17 15:43:35 +01:00
|
|
|
data[vi] = c_desand
|
2014-02-20 13:24:02 +01:00
|
|
|
under[si] = 6 -- desert
|
2014-02-25 19:14:54 +01:00
|
|
|
elseif biome == 7 then
|
2014-02-20 13:24:02 +01:00
|
|
|
data[vi] = c_wsdirt
|
2014-02-25 19:14:54 +01:00
|
|
|
under[si] = 7 -- savanna
|
|
|
|
soil[si] = soil[si] + 1 -- increment soil if trees within biome
|
|
|
|
elseif biome == 8 then
|
2014-02-19 09:19:17 +01:00
|
|
|
data[vi] = c_wsdirt
|
2014-02-25 19:14:54 +01:00
|
|
|
under[si] = 8 -- rainforest
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = soil[si] + 1
|
2014-02-25 19:14:54 +01:00
|
|
|
elseif biome == 3 then
|
2014-02-19 09:19:17 +01:00
|
|
|
data[vi] = c_wsdirt
|
2014-02-25 19:14:54 +01:00
|
|
|
under[si] = 3 -- dry grassland
|
|
|
|
elseif biome == 4 then
|
2014-02-19 09:19:17 +01:00
|
|
|
data[vi] = c_wsdirt
|
2014-02-25 19:14:54 +01:00
|
|
|
under[si] = 4 -- grassland
|
|
|
|
elseif biome == 5 then
|
|
|
|
data[vi] = c_wsdirt
|
|
|
|
under[si] = 5 -- forest
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = soil[si] + 1
|
2014-02-25 19:14:54 +01:00
|
|
|
elseif biome == 1 then
|
|
|
|
data[vi] = c_wspermafrost
|
|
|
|
under[si] = 1 -- tundra
|
|
|
|
elseif biome == 2 then
|
2014-02-19 09:19:17 +01:00
|
|
|
data[vi] = c_wsdirt
|
2014-02-25 19:14:54 +01:00
|
|
|
under[si] = 2 -- taiga
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = soil[si] + 1
|
2014-02-17 15:43:35 +01:00
|
|
|
end
|
2014-02-19 23:28:36 +01:00
|
|
|
else -- fissure
|
|
|
|
stable[si] = 0
|
|
|
|
under[si] = 0
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = 0
|
2014-02-17 15:43:35 +01:00
|
|
|
end
|
2014-02-19 23:28:36 +01:00
|
|
|
elseif y <= YWAT and density < tstone then -- sea water, not in fissures
|
2014-02-25 19:14:54 +01:00
|
|
|
if y == YWAT and n_temp < ICETET then
|
2014-02-20 08:18:40 +01:00
|
|
|
data[vi] = c_ice
|
|
|
|
else
|
|
|
|
data[vi] = c_water
|
2014-02-25 19:14:54 +01:00
|
|
|
if y == YWAT and biome >= 6 and stable[si] >= 1
|
2014-02-20 08:18:40 +01:00
|
|
|
and math.random(PAPCHA) == 2 then -- papyrus in desert and rainforest
|
|
|
|
watershed_papyrus(x, y, z, area, data)
|
|
|
|
end
|
|
|
|
end
|
2014-02-15 10:50:29 +01:00
|
|
|
stable[si] = 0
|
2014-02-19 02:16:19 +01:00
|
|
|
under[si] = 0
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = 0
|
2014-02-19 23:28:36 +01:00
|
|
|
elseif densitybase >= triv and density < tstone then -- river water, not in fissures
|
2014-02-25 19:14:54 +01:00
|
|
|
if n_temp < ICETET then
|
2014-02-20 08:18:40 +01:00
|
|
|
data[vi] = c_ice
|
|
|
|
else
|
|
|
|
data[vi] = c_wswater
|
|
|
|
end
|
|
|
|
stable[si] = 0
|
|
|
|
under[si] = 0
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = 0
|
|
|
|
elseif y == YCLOUD then -- clouds
|
2014-02-20 08:18:40 +01:00
|
|
|
local xrq = 16 * math.floor((x - x0) / 16)
|
|
|
|
local zrq = 16 * math.floor((z - z0) / 16)
|
2014-02-24 12:56:37 +01:00
|
|
|
local qixz = zrq * 80 + xrq + 1
|
2014-03-05 11:41:34 +01:00
|
|
|
if nvals_cloud[qixz] > TCLOUD then
|
|
|
|
local yrq = 16 * math.floor((y - y0) / 16)
|
|
|
|
local qixyz = zrq * 6400 + yrq * 80 + xrq + 1
|
|
|
|
if nvals_humid[qixyz] > DCLOHUT then
|
|
|
|
data[vi] = c_wsdarkcloud
|
|
|
|
elseif nvals_humid[qixyz] > CLOHUT then
|
|
|
|
data[vi] = c_wscloud
|
|
|
|
end
|
2014-02-20 08:18:40 +01:00
|
|
|
end
|
2014-02-15 10:50:29 +01:00
|
|
|
stable[si] = 0
|
2014-02-19 02:16:19 +01:00
|
|
|
under[si] = 0
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = 0
|
2014-02-19 02:16:19 +01:00
|
|
|
else -- possible above surface air node
|
|
|
|
if y >= YWAT and under[si] ~= 0 then
|
|
|
|
if under[si] == 1 then
|
2014-02-25 19:14:54 +01:00
|
|
|
if math.random(121) == 2 then
|
|
|
|
data[viu] = c_dirtsnow
|
|
|
|
elseif math.random(121) == 2 then
|
|
|
|
data[viu] = c_ice
|
|
|
|
else
|
|
|
|
data[viu] = c_wsdrygrass
|
|
|
|
if math.random(DRYCHA) == 2 then
|
|
|
|
data[vi] = c_dryshrub
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif under[si] == 2 then
|
|
|
|
if n_humid > HIHUT and math.random(PINCHA) == 2
|
2014-02-24 12:56:37 +01:00
|
|
|
and soil[si] >= 4 then
|
2014-02-19 02:16:19 +01:00
|
|
|
watershed_pinetree(x, y, z, area, data)
|
|
|
|
else
|
|
|
|
data[viu] = c_dirtsnow
|
|
|
|
data[vi] = c_snowblock
|
|
|
|
end
|
2014-02-25 19:14:54 +01:00
|
|
|
elseif under[si] == 5 then
|
2014-02-24 12:56:37 +01:00
|
|
|
if math.random(APTCHA) == 2 and soil[si] >= 2 then
|
2014-02-19 02:16:19 +01:00
|
|
|
watershed_appletree(x, y, z, area, data)
|
2014-02-19 09:19:17 +01:00
|
|
|
else
|
2014-02-19 02:16:19 +01:00
|
|
|
data[viu] = c_wsgrass
|
2014-02-19 09:19:17 +01:00
|
|
|
if math.random(FLOCHA) == 2 then
|
|
|
|
data[viu] = c_wsgrass
|
|
|
|
watershed_flower(data, vi)
|
|
|
|
elseif math.random(FOGCHA) == 2 then
|
|
|
|
data[viu] = c_wsgrass
|
|
|
|
watershed_grass(data, vi)
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
elseif under[si] == 3 then
|
2014-02-25 19:14:54 +01:00
|
|
|
data[viu] = c_wsdrygrass
|
2014-02-19 02:16:19 +01:00
|
|
|
if math.random(GRACHA) == 2 then
|
2014-02-25 19:14:54 +01:00
|
|
|
if math.random(5) == 2 then
|
|
|
|
data[vi] = c_wsgoldgrass
|
2014-02-19 02:16:19 +01:00
|
|
|
else
|
2014-02-25 19:14:54 +01:00
|
|
|
data[vi] = c_dryshrub
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif under[si] == 4 then
|
2014-02-25 19:14:54 +01:00
|
|
|
data[viu] = c_wsgrass
|
|
|
|
if math.random(FLOCHA) == 2 then
|
|
|
|
watershed_flower(data, vi)
|
|
|
|
elseif math.random(GRACHA) == 2 then
|
|
|
|
if math.random(11) == 2 then
|
|
|
|
data[vi] = c_wsgoldgrass
|
|
|
|
else
|
|
|
|
watershed_grass(data, vi)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif under[si] == 8 then
|
2014-02-24 12:56:37 +01:00
|
|
|
if math.random(JUTCHA) == 2 and soil[si] >= 5 then
|
2014-02-19 02:16:19 +01:00
|
|
|
watershed_jungletree(x, y, z, area, data)
|
|
|
|
else
|
|
|
|
data[viu] = c_wsgrass
|
|
|
|
if math.random(JUGCHA) == 2 then
|
|
|
|
data[vi] = c_jungrass
|
|
|
|
end
|
|
|
|
end
|
2014-02-25 19:14:54 +01:00
|
|
|
elseif under[si] == 7 then
|
2014-02-24 12:56:37 +01:00
|
|
|
if math.random(ACACHA) == 2 and soil[si] >= 3 then
|
2014-02-20 13:24:02 +01:00
|
|
|
watershed_acaciatree(x, y, z, area, data)
|
|
|
|
else
|
|
|
|
data[viu] = c_wsdrygrass
|
|
|
|
if math.random(GOGCHA) == 2 then
|
|
|
|
data[vi] = c_wsgoldgrass
|
|
|
|
end
|
|
|
|
end
|
2014-02-25 19:14:54 +01:00
|
|
|
elseif under[si] == 6 and n_temp < HITET + 0.1 then
|
2014-02-20 13:24:02 +01:00
|
|
|
if math.random(CACCHA) == 2 then
|
2014-02-20 08:18:40 +01:00
|
|
|
watershed_cactus(x, y, z, area, data)
|
2014-02-20 13:24:02 +01:00
|
|
|
elseif math.random(DRYCHA) == 2 then
|
2014-02-20 08:18:40 +01:00
|
|
|
data[vi] = c_dryshrub
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
2014-02-15 10:50:29 +01:00
|
|
|
stable[si] = 0
|
2014-02-19 02:16:19 +01:00
|
|
|
under[si] = 0
|
2014-02-24 12:56:37 +01:00
|
|
|
soil[si] = 0
|
2014-02-15 10:50:29 +01:00
|
|
|
end
|
2014-02-19 09:19:17 +01:00
|
|
|
nixyz = nixyz + 1
|
|
|
|
nixz = nixz + 1
|
2014-02-15 10:50:29 +01:00
|
|
|
vi = vi + 1
|
2014-02-19 02:16:19 +01:00
|
|
|
viu = viu + 1
|
2014-02-15 10:50:29 +01:00
|
|
|
end
|
2014-02-19 09:19:17 +01:00
|
|
|
nixz = nixz - 80
|
2014-02-15 10:50:29 +01:00
|
|
|
end
|
2014-02-19 09:19:17 +01:00
|
|
|
nixz = nixz + 80
|
2014-02-15 10:50:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:set_lighting({day=0, night=0})
|
|
|
|
vm:calc_lighting()
|
|
|
|
vm:write_to_map(data)
|
|
|
|
local chugent = math.ceil((os.clock() - t1) * 1000)
|
2014-02-17 15:43:35 +01:00
|
|
|
print ("[watershed] "..chugent.." ms")
|
2014-02-15 10:50:29 +01:00
|
|
|
end)
|