Switch to subterrain base engine
Huge performance increase and error reduction. Also fixed stalagmite and stalactites spawning in midair. UNLIMITED vertical chunks.master
parent
86bbbd667c
commit
d5ef5993c9
|
@ -23,7 +23,7 @@ end
|
||||||
--generation settings
|
--generation settings
|
||||||
setting("number", "ymin", -33000) --bottom realm limit
|
setting("number", "ymin", -33000) --bottom realm limit
|
||||||
setting("number", "ymax", -700) --top realm limit
|
setting("number", "ymax", -700) --top realm limit
|
||||||
setting("number", "chuint", 4) --vertical chunk interval between caves
|
setting("number", "tcave", 0.5) --cave threshold
|
||||||
|
|
||||||
--falling icicles
|
--falling icicles
|
||||||
setting("bool", "falling_icicles", true) --enable/disable falling icicles
|
setting("bool", "falling_icicles", true) --enable/disable falling icicles
|
||||||
|
@ -40,6 +40,6 @@ setting("number", "h_clac", 13) --max height of glow crystal stalactites
|
||||||
setting("number", "gemcha", 0.03) --chance of small glow gems
|
setting("number", "gemcha", 0.03) --chance of small glow gems
|
||||||
setting("number", "mushcha", 0.04) --chance of mushrooms
|
setting("number", "mushcha", 0.04) --chance of mushrooms
|
||||||
setting("number", "myccha", 0.03) --chance of mycena mushrooms
|
setting("number", "myccha", 0.03) --chance of mycena mushrooms
|
||||||
setting("number", "wormcha", 0.03) --chance of glow worms
|
setting("number", "wormcha", 0.02) --chance of glow worms
|
||||||
setting("number", "giantcha", 0.001) --chance of giant mushrooms
|
setting("number", "giantcha", 0.001) --chance of giant mushrooms
|
||||||
setting("number", "icicha", 0.035) --chance of icicles
|
setting("number", "icicha", 0.035) --chance of icicles
|
||||||
|
|
|
@ -7,8 +7,32 @@ local H_LAC = caverealms.config.h_lac --20 --...stalactites
|
||||||
local H_CRY = caverealms.config.h_cry --9 --max height of glow crystals
|
local H_CRY = caverealms.config.h_cry --9 --max height of glow crystals
|
||||||
local H_CLAC = caverealms.config.h_clac --13 --max height of glow crystal stalactites
|
local H_CLAC = caverealms.config.h_clac --13 --max height of glow crystal stalactites
|
||||||
|
|
||||||
|
function caverealms:above_solid(x,y,z,area,data)
|
||||||
|
local c_air = minetest.get_content_id("air")
|
||||||
|
local ai = area:index(x,y+1,z-3)
|
||||||
|
if data[ai] == c_air then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function caverealms:below_solid(x,y,z,area,data)
|
||||||
|
local c_air = minetest.get_content_id("air")
|
||||||
|
local ai = area:index(x,y-1,z-3)
|
||||||
|
if data[ai] == c_air then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--stalagmite spawner
|
--stalagmite spawner
|
||||||
function caverealms:stalagmite(x,y,z, area, data)
|
function caverealms:stalagmite(x,y,z, area, data)
|
||||||
|
|
||||||
|
if not caverealms:below_solid(x,y,z,area,data) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
--contest ids
|
--contest ids
|
||||||
local c_stone = minetest.get_content_id("default:stone")
|
local c_stone = minetest.get_content_id("default:stone")
|
||||||
|
|
||||||
|
@ -42,6 +66,11 @@ end
|
||||||
|
|
||||||
--stalactite spawner
|
--stalactite spawner
|
||||||
function caverealms:stalactite(x,y,z, area, data)
|
function caverealms:stalactite(x,y,z, area, data)
|
||||||
|
|
||||||
|
if not caverealms:above_solid(x,y,z,area,data) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
--contest ids
|
--contest ids
|
||||||
local c_stone = minetest.get_content_id("default:stone")--("caverealms:limestone")
|
local c_stone = minetest.get_content_id("default:stone")--("caverealms:limestone")
|
||||||
|
|
||||||
|
@ -75,6 +104,11 @@ end
|
||||||
|
|
||||||
--glowing crystal stalagmite spawner
|
--glowing crystal stalagmite spawner
|
||||||
function caverealms:crystal_stalagmite(x,y,z, area, data, biome)
|
function caverealms:crystal_stalagmite(x,y,z, area, data, biome)
|
||||||
|
|
||||||
|
if not caverealms:below_solid(x,y,z,area,data) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
--contest ids
|
--contest ids
|
||||||
local c_stone = minetest.get_content_id("default:stone")
|
local c_stone = minetest.get_content_id("default:stone")
|
||||||
local c_crystal = minetest.get_content_id("caverealms:glow_crystal")
|
local c_crystal = minetest.get_content_id("caverealms:glow_crystal")
|
||||||
|
@ -162,6 +196,11 @@ end
|
||||||
|
|
||||||
--crystal stalactite spawner
|
--crystal stalactite spawner
|
||||||
function caverealms:crystal_stalactite(x,y,z, area, data, biome)
|
function caverealms:crystal_stalactite(x,y,z, area, data, biome)
|
||||||
|
|
||||||
|
if not caverealms:above_solid(x,y,z,area,data) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
--contest ids
|
--contest ids
|
||||||
local c_stone = minetest.get_content_id("default:stone")
|
local c_stone = minetest.get_content_id("default:stone")
|
||||||
local c_crystore = minetest.get_content_id("caverealms:glow_ore")
|
local c_crystore = minetest.get_content_id("caverealms:glow_ore")
|
||||||
|
@ -249,6 +288,11 @@ end
|
||||||
|
|
||||||
--function to create giant 'shrooms
|
--function to create giant 'shrooms
|
||||||
function caverealms:giant_shroom(x, y, z, area, data)
|
function caverealms:giant_shroom(x, y, z, area, data)
|
||||||
|
|
||||||
|
if not caverealms:below_solid(x,y,z,area,data) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
--as usual, grab the content ID's
|
--as usual, grab the content ID's
|
||||||
local c_stem = minetest.get_content_id("caverealms:mushroom_stem")
|
local c_stem = minetest.get_content_id("caverealms:mushroom_stem")
|
||||||
local c_cap = minetest.get_content_id("caverealms:mushroom_cap")
|
local c_cap = minetest.get_content_id("caverealms:mushroom_cap")
|
||||||
|
|
447
init.lua
447
init.lua
|
@ -1,8 +1,10 @@
|
||||||
-- caverealms 0.2.9 by HeroOfTheWinds
|
-- caverealms indev by HeroOfTheWinds
|
||||||
-- For latest stable Minetest and back to 0.4.8
|
-- original cave code modified from paramat's subterrain
|
||||||
|
-- For Minetest 0.4.8 stable
|
||||||
-- Depends default
|
-- Depends default
|
||||||
-- License: code WTFPL
|
-- License: code WTFPL
|
||||||
|
|
||||||
|
|
||||||
caverealms = {} --create a container for functions and constants
|
caverealms = {} --create a container for functions and constants
|
||||||
|
|
||||||
--grab a shorthand for the filepath of the mod
|
--grab a shorthand for the filepath of the mod
|
||||||
|
@ -15,26 +17,12 @@ dofile(modpath.."/falling_ice.lua") --complicated function for falling icicles
|
||||||
dofile(modpath.."/nodes.lua") --node definitions
|
dofile(modpath.."/nodes.lua") --node definitions
|
||||||
dofile(modpath.."/functions.lua") --function definitions
|
dofile(modpath.."/functions.lua") --function definitions
|
||||||
|
|
||||||
-- Parameters (see also config.lua)
|
-- Parameters
|
||||||
|
|
||||||
local YMIN = caverealms.config.ymin -- Approximate realm limits.
|
local YMIN = caverealms.config.ymin -- Approximate realm limits.
|
||||||
local YMAX = caverealms.config.ymax
|
local YMAX = caverealms.config.ymax
|
||||||
local XMIN = -33000
|
local TCAVE = caverealms.config.tcave --0.5 -- Cave threshold. 1 = small rare caves, 0.5 = 1/3rd ground volume, 0 = 1/2 ground volume
|
||||||
local XMAX = 33000
|
local BLEND = 128 -- Cave blend distance near YMIN, YMAX
|
||||||
local ZMIN = -33000
|
|
||||||
local ZMAX = 33000
|
|
||||||
|
|
||||||
local CHUINT = caverealms.config.chuint -- Chunk interval for cave realms
|
|
||||||
local CLUSAV = -0.5 --cave threshold, determines rarity of caves. -1 = small and rare, 0.5 = default, 0 = nearly half the volume.
|
|
||||||
local CLUSAM = 0.5 --cave size/density threshold. 0 is off, or little variation, 1 is max.
|
|
||||||
local WAVAMP = 24 -- Structure wave amplitude
|
|
||||||
local HISCAL = 32 -- Upper structure vertical scale
|
|
||||||
local LOSCAL = 32 -- Lower structure vertical scale
|
|
||||||
local HIEXP = 0.3 -- Upper structure density gradient exponent
|
|
||||||
local LOEXP = 0.3 -- Lower structure density gradient exponent
|
|
||||||
local DIRTHR = 0.04 -- Dirt density threshold
|
|
||||||
local STOTHR = 0.08 -- Stone density threshold
|
|
||||||
local STABLE = 2 -- Minimum number of stacked stone nodes in column for dirt / sand on top
|
|
||||||
|
|
||||||
local STAGCHA = caverealms.config.stagcha --0.002 --chance of stalagmites
|
local STAGCHA = caverealms.config.stagcha --0.002 --chance of stalagmites
|
||||||
local STALCHA = caverealms.config.stalcha --0.003 --chance of stalactites
|
local STALCHA = caverealms.config.stalcha --0.003 --chance of stalactites
|
||||||
|
@ -46,31 +34,18 @@ local WORMCHA = caverealms.config.wormcha --0.03 --chance of glow worms
|
||||||
local GIANTCHA = caverealms.config.giantcha --0.001 -- chance of giant mushrooms
|
local GIANTCHA = caverealms.config.giantcha --0.001 -- chance of giant mushrooms
|
||||||
local ICICHA = caverealms.config.icicha --0.035 -- chance of icicles
|
local ICICHA = caverealms.config.icicha --0.035 -- chance of icicles
|
||||||
|
|
||||||
|
-- 3D noise for caves
|
||||||
|
|
||||||
-- 3D noise for caverns
|
|
||||||
|
|
||||||
local np_cave = {
|
local np_cave = {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
scale = 1,
|
scale = 1,
|
||||||
spread = {x=512, y=256, z=512},
|
spread = {x=512, y=256, z=512}, -- squashed 2:1
|
||||||
seed = 277777979,
|
seed = 59033,
|
||||||
octaves = 6,
|
octaves = 6,
|
||||||
persist = 0.6
|
persist = 0.63
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 3D noise for large scale cavern size/density variation
|
-- 3D noise for wave
|
||||||
|
|
||||||
local np_cluster = {
|
|
||||||
offset = 0,
|
|
||||||
scale = 1,
|
|
||||||
spread = {x=2048, y=2048, z=2048},
|
|
||||||
seed = 23,
|
|
||||||
octaves = 1,
|
|
||||||
persist = 0.5
|
|
||||||
}
|
|
||||||
|
|
||||||
-- 2D noise for wave
|
|
||||||
|
|
||||||
local np_wave = {
|
local np_wave = {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
|
@ -78,7 +53,7 @@ local np_wave = {
|
||||||
spread = {x=256, y=256, z=256},
|
spread = {x=256, y=256, z=256},
|
||||||
seed = -400000000089,
|
seed = -400000000089,
|
||||||
octaves = 3,
|
octaves = 3,
|
||||||
persist = 0.5
|
persist = 0.67
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 2D noise for biome
|
-- 2D noise for biome
|
||||||
|
@ -92,21 +67,22 @@ local np_biome = {
|
||||||
persist = 0.5
|
persist = 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Stuff
|
||||||
|
|
||||||
|
subterrain = {}
|
||||||
|
|
||||||
|
local yblmin = YMIN + BLEND * 1.5
|
||||||
|
local yblmax = YMAX - BLEND * 1.5
|
||||||
|
|
||||||
-- On generated function
|
-- On generated function
|
||||||
|
|
||||||
minetest.register_on_generated(function(minp, maxp, seed)
|
minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
--only continue if within the bounds for creating cave realms
|
--if out of range of caverealms limits
|
||||||
if minp.x < XMIN or maxp.x > XMAX
|
if minp.y > YMAX or maxp.y < YMIN then
|
||||||
or minp.y < YMIN or maxp.y > YMAX
|
return --quit; otherwise, you'd have stalagmites all over the place
|
||||||
or minp.z < ZMIN or maxp.z > ZMAX then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--determine if there's enough spacing between layers to start a realm
|
--easy reference to commonly used values
|
||||||
local chulay = math.floor((minp.y + 32) / 80) -- chunk layer number, 0 = surface chunk
|
|
||||||
local tercen = (math.floor(chulay / CHUINT) * CHUINT + CHUINT / 2) * 80 - 32 -- terrain centre of this layer
|
|
||||||
|
|
||||||
--easy to reference variables for limits and time
|
|
||||||
local t1 = os.clock()
|
local t1 = os.clock()
|
||||||
local x1 = maxp.x
|
local x1 = maxp.x
|
||||||
local y1 = maxp.y
|
local y1 = maxp.y
|
||||||
|
@ -114,15 +90,13 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local x0 = minp.x
|
local x0 = minp.x
|
||||||
local y0 = minp.y
|
local y0 = minp.y
|
||||||
local z0 = minp.z
|
local z0 = minp.z
|
||||||
|
|
||||||
--let people know you're generating a realm
|
print ("[caverealms] chunk minp ("..x0.." "..y0.." "..z0..")") --tell people you are generating a chunk
|
||||||
print ("[caverealms] chunk minp ("..x0.." "..y0.." "..z0..")")
|
|
||||||
|
|
||||||
--fire up the LVM
|
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
|
|
||||||
--grab content IDs
|
--grab content IDs
|
||||||
local c_air = minetest.get_content_id("air")
|
local c_air = minetest.get_content_id("air")
|
||||||
local c_stone = minetest.get_content_id("default:stone")
|
local c_stone = minetest.get_content_id("default:stone")
|
||||||
|
@ -144,251 +118,174 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local c_worm = minetest.get_content_id("caverealms:glow_worm")
|
local c_worm = minetest.get_content_id("caverealms:glow_worm")
|
||||||
local c_iciu = minetest.get_content_id("caverealms:icicle_up")
|
local c_iciu = minetest.get_content_id("caverealms:icicle_up")
|
||||||
local c_icid = minetest.get_content_id("caverealms:icicle_down")
|
local c_icid = minetest.get_content_id("caverealms:icicle_down")
|
||||||
|
|
||||||
--some mandatory values
|
--mandatory values
|
||||||
local sidelen = x1 - x0 + 1 --usually equals 80 with default mapgen values. Always a multiple of 16.
|
local sidelen = x1 - x0 + 1 --length of a mapblock
|
||||||
local chulens = {x=sidelen, y=sidelen, z=sidelen} --position table to pass to get3dMap_flat
|
local chulens = {x=sidelen, y=sidelen, z=sidelen} --table of chunk edges
|
||||||
local minposxyz = {x=x0, y=y0, z=z0}
|
local minposxyz = {x=x0, y=y0, z=z0} --bottom corner
|
||||||
local minposxz = {x=x0, y=z0}
|
local minposxz = {x=x0, y=z0} --2D bottom corner
|
||||||
|
|
||||||
--generate the all important perlin that makes nice terrains
|
local nvals_cave = minetest.get_perlin_map(np_cave, chulens):get3dMap_flat(minposxyz) --cave noise for structure
|
||||||
local nvals_cave = minetest.get_perlin_map(np_cave, chulens):get3dMap_flat(minposxyz) --obviously for caves
|
local nvals_wave = minetest.get_perlin_map(np_wave, chulens):get3dMap_flat(minposxyz) --wavy structure of cavern ceilings and floors
|
||||||
local nvals_cluster = minetest.get_perlin_map(np_cluster, chulens):get3dMap_flat(minposxyz) --how large of clusters of caverns?
|
|
||||||
|
|
||||||
local nvals_wave = minetest.get_perlin_map(np_wave, chulens):get2dMap_flat(minposxz) --wavy structure of cavern ceilings and floors
|
|
||||||
local nvals_biome = minetest.get_perlin_map(np_biome, chulens):get2dMap_flat({x=x0+150, y=z0+50}) --2D noise for biomes (will be 3D humidity/temp later)
|
local nvals_biome = minetest.get_perlin_map(np_biome, chulens):get2dMap_flat({x=x0+150, y=z0+50}) --2D noise for biomes (will be 3D humidity/temp later)
|
||||||
|
|
||||||
--more values
|
local nixyz = 1 --3D node index
|
||||||
local nixyz = 1 --short for node index xyz
|
local nixz = 1 --2D node index
|
||||||
local nixz = 1 --node index xz
|
local nixyz2 = 1 --second 3D index for second loop
|
||||||
local stable = {} --stability for ground
|
|
||||||
local dirt = {} --table for ground surface
|
for z = z0, z1 do -- for each xy plane progressing northwards
|
||||||
local chumid = y0 + sidelen / 2 --middle of the current chunk
|
--structure loop
|
||||||
local roof = {}
|
for y = y0, y1 do -- for each x row progressing upwards
|
||||||
local nixyz2 = 1 --second 3d index for incrementation
|
local tcave --declare variable
|
||||||
local nixz2 = 1 --second 2d index
|
--determine the overal cave threshold
|
||||||
local stable2 = {} --second stability table
|
if y < yblmin then
|
||||||
|
tcave = TCAVE + ((yblmin - y) / BLEND) ^ 2
|
||||||
for z = z0, z1 do --for each xy plane progressing northwards
|
elseif y > yblmax then
|
||||||
for x = x0, x1 do
|
tcave = TCAVE + ((y - yblmax) / BLEND) ^ 2
|
||||||
local si = x - x0 + 1 --stability index
|
else
|
||||||
dirt[si] = 0 --no dirt here... yet
|
tcave = TCAVE
|
||||||
roof[si] = 0
|
end
|
||||||
local nodeid = area:index(x, y0-1, z) --grab the ID of the node just below
|
local vi = area:index(x0, y, z) --current node index
|
||||||
if nodeid == c_air
|
for x = x0, x1 do -- for each node do
|
||||||
or nodeid == c_water
|
if (nvals_cave[nixyz] + nvals_wave[nixyz])/2 > tcave then --if node falls within cave threshold
|
||||||
or nodeid == c_lava then --if a cave or any kind of lake
|
data[vi] = c_air --hollow it out to make the cave
|
||||||
stable[si] = 0 --this is not stable for plants or falling nodes above
|
end
|
||||||
stable2[si] = 0
|
--increment indices
|
||||||
else -- all else including ignore in ungenerated chunks
|
nixyz = nixyz + 1
|
||||||
stable[si] = STABLE --stuff can safely go above
|
vi = vi + 1
|
||||||
stable2[si] = STABLE
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for y = y1, y0, -1 do -- for each x row progressing downwards
|
|
||||||
local vi = area:index(x0, y, z) --grab the index of the node to edit
|
--decoration loop
|
||||||
for x = x0, x1 do -- for each node do
|
for y = y0, y1 do -- for each x row progressing upwards
|
||||||
--here's the good part
|
local tcave --same as above
|
||||||
local si = x - x0 + 1 --stability index
|
if y < yblmin then
|
||||||
local cavemid = tercen + nvals_wave[nixz] * WAVAMP --grab the middle of the cave's amplitude
|
tcave = TCAVE + ((yblmin - y) / BLEND) ^ 2
|
||||||
local grad
|
elseif y > yblmax then
|
||||||
if y > cavemid then
|
tcave = TCAVE + ((y - yblmax) / BLEND) ^ 2
|
||||||
grad = ((y - cavemid) / HISCAL) ^ HIEXP --for the ceiling
|
else
|
||||||
else
|
tcave = TCAVE
|
||||||
grad = ((cavemid - y) / LOSCAL) ^ LOEXP --for the floor
|
|
||||||
end
|
|
||||||
--local density = nvals_cave[nixyz] - grad --how dense is the emptiness?
|
|
||||||
local density = nvals_cave[nixyz] - grad - CLUSAV - nvals_cluster[nixyz] * CLUSAM
|
|
||||||
if density < 0 and density > -0.7 then -- if cavern "shell"
|
|
||||||
--local nodename = minetest.get_node({x=x,y=y,z=z}).name --grab the name of the node
|
|
||||||
data[vi] = c_air --make emptiness
|
|
||||||
if density < STOTHR and stable[si] <= STABLE then
|
|
||||||
dirt[si] = dirt[si] + 1
|
|
||||||
else
|
|
||||||
stable[si] = stable[si] + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif dirt[si] >= 1 then -- node above surface
|
|
||||||
--determine biome
|
|
||||||
local biome = false --preliminary declaration
|
|
||||||
n_biome = nvals_biome[nixz] --make an easier reference to the noise
|
|
||||||
--compare noise values to determine a biome
|
|
||||||
if n_biome >= 0 and n_biome < 0.5 then
|
|
||||||
biome = 1 --moss
|
|
||||||
elseif n_biome <= -0.5 then
|
|
||||||
biome = 2 --fungal
|
|
||||||
elseif n_biome >= 0.5 then
|
|
||||||
if n_biome >= 0.7 then
|
|
||||||
biome = 5 --deep glaciated
|
|
||||||
else
|
|
||||||
biome = 4 --glaciated
|
|
||||||
end
|
|
||||||
else
|
|
||||||
biome = 3 --algae
|
|
||||||
end
|
|
||||||
--place floor material, add plants/decorations
|
|
||||||
if biome == 1 then
|
|
||||||
data[vi] = c_moss
|
|
||||||
elseif biome == 2 then
|
|
||||||
data[vi] = c_lichen
|
|
||||||
elseif biome == 3 then
|
|
||||||
data[vi] = c_algae
|
|
||||||
elseif biome == 4 then
|
|
||||||
data[vi] = c_thinice
|
|
||||||
local bi = area:index(x,y-1,z)
|
|
||||||
data[bi] = c_thinice
|
|
||||||
elseif biome == 5 then
|
|
||||||
data[vi] = c_ice
|
|
||||||
local bi = area:index(x,y-1,z)
|
|
||||||
data[bi] = c_ice
|
|
||||||
end
|
|
||||||
--on random chance, place glow crystal formations
|
|
||||||
if math.random() <= CRYSTAL then
|
|
||||||
caverealms:crystal_stalagmite(x, y, z, area, data, biome)
|
|
||||||
end
|
|
||||||
--randomly place stalagmites
|
|
||||||
if math.random() <= STAGCHA then
|
|
||||||
caverealms:stalagmite(x, y, z, area, data, biome)
|
|
||||||
end
|
|
||||||
--randomly place glow gems
|
|
||||||
if math.random() < GEMCHA and biome == 1 then
|
|
||||||
-- of random size
|
|
||||||
local gems = { c_gem1, c_gem2, c_gem3, c_gem4, c_gem5 }
|
|
||||||
local gidx = math.random(1, 12)
|
|
||||||
if gidx > 5 then
|
|
||||||
gidx = 1
|
|
||||||
end
|
|
||||||
local gi = area:index(x,y+1,z)
|
|
||||||
data[gi] = gems[gidx]
|
|
||||||
end
|
|
||||||
if biome == 2 then --if fungus biome
|
|
||||||
if math.random() < MUSHCHA then --mushrooms
|
|
||||||
local gi = area:index(x,y+1,z)
|
|
||||||
data[gi] = c_fungus
|
|
||||||
end
|
|
||||||
if math.random() < MYCCHA then --mycena mushrooms
|
|
||||||
local gi = area:index(x,y+1,z)
|
|
||||||
data[gi] = c_mycena
|
|
||||||
end
|
|
||||||
if math.random() < GIANTCHA then --giant mushrooms
|
|
||||||
caverealms:giant_shroom(x, y, z, area, data)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if math.random() < ICICHA and (biome == 4 or biome == 5) then --if glaciated, place icicles
|
|
||||||
local gi = area:index(x,y+1,z)
|
|
||||||
data[gi] = c_iciu
|
|
||||||
end
|
|
||||||
dirt[si] = 0
|
|
||||||
else -- solid rock
|
|
||||||
stable[si] = 0
|
|
||||||
end
|
|
||||||
nixyz = nixyz + 1 --increment the 3D index
|
|
||||||
nixz = nixz + 1 --increment the 2D index
|
|
||||||
vi = vi + 1 --increment the area index
|
|
||||||
end
|
end
|
||||||
nixz = nixz - sidelen --shift the 2D index down a layer
|
local vi = area:index(x0, y, z)
|
||||||
end
|
|
||||||
nixz = nixz + sidelen --shift the 2D index up a layer
|
|
||||||
|
|
||||||
--second loop to obtain ceiling
|
|
||||||
for y = y0, y1 do -- for each x row progressing downwards
|
|
||||||
local vi = area:index(x0, y, z) --grab the index of the node to edit
|
|
||||||
for x = x0, x1 do -- for each node do
|
for x = x0, x1 do -- for each node do
|
||||||
--here's the good part
|
|
||||||
local si = x - x0 + 1 --stability index
|
--determine biome
|
||||||
local cavemid = tercen + nvals_wave[nixz2] * WAVAMP --grab the middle of the cave's amplitude
|
local biome = false --preliminary declaration
|
||||||
local grad
|
n_biome = nvals_biome[nixz] --make an easier reference to the noise
|
||||||
if y > cavemid then
|
--compare noise values to determine a biome
|
||||||
grad = ((y - cavemid) / HISCAL) ^ HIEXP --for the ceiling
|
if n_biome >= 0 and n_biome < 0.5 then
|
||||||
|
biome = 1 --moss
|
||||||
|
elseif n_biome <= -0.5 then
|
||||||
|
biome = 2 --fungal
|
||||||
|
elseif n_biome >= 0.5 then
|
||||||
|
if n_biome >= 0.7 then
|
||||||
|
biome = 5 --deep glaciated
|
||||||
|
else
|
||||||
|
biome = 4 --glaciated
|
||||||
|
end
|
||||||
else
|
else
|
||||||
grad = ((cavemid - y) / LOSCAL) ^ LOEXP --for the floor
|
biome = 3 --algae
|
||||||
end
|
end
|
||||||
--local density = nvals_cave[nixyz2] - grad --how dense is the emptiness?
|
|
||||||
local density = nvals_cave[nixyz2] - grad - CLUSAV - nvals_cluster[nixyz2] * CLUSAM
|
if math.floor(((nvals_cave[nixyz2] + nvals_wave[nixyz2])/2)*100) == math.floor(tcave*100) then
|
||||||
if density < 0 and density > -0.7 then -- if cavern "shell"
|
--ceiling
|
||||||
if density < STOTHR and stable2[si] <= STABLE then
|
local ai = area:index(x,y+1,z) --above index
|
||||||
roof[si] = roof[si] + 1
|
if data[ai] == c_stone and data[vi] == c_air then --ceiling
|
||||||
else
|
if math.random() < ICICHA and (biome == 4 or biome == 5) then
|
||||||
stable2[si] = stable2[si] + 1
|
local bi = area:index(x,y-1,z)
|
||||||
end
|
data[bi] = c_icid
|
||||||
|
|
||||||
elseif roof[si] >= 1 then --and stable2[si] >= 2 then -- node at roof
|
|
||||||
--determine biome
|
|
||||||
local biome = false --preliminary declaration
|
|
||||||
n_biome = nvals_biome[nixz2] --make an easier reference to the noise
|
|
||||||
if n_biome >= 0 and n_biome < 0.5 then
|
|
||||||
biome = 1 --moss
|
|
||||||
elseif n_biome <= -0.5 then
|
|
||||||
biome = 2 --fungal
|
|
||||||
elseif n_biome >= 0.5 then
|
|
||||||
if n_biome >= 0.7 then
|
|
||||||
biome = 5
|
|
||||||
else
|
|
||||||
biome = 4 --glaciated
|
|
||||||
end
|
end
|
||||||
else
|
if math.random() < WORMCHA then
|
||||||
biome = 3 --algae
|
|
||||||
end
|
|
||||||
--glow worm
|
|
||||||
if math.random() <= WORMCHA then
|
|
||||||
local ai = area:index(x,y+1,z)--index of node above
|
|
||||||
if data[ai] ~= c_air then
|
|
||||||
data[vi] = c_worm
|
data[vi] = c_worm
|
||||||
local bi = area:index(x,y-1,z) --below index 1
|
local bi = area:index(x,y-1,z)
|
||||||
data[bi] = c_worm
|
data[bi] = c_worm
|
||||||
if math.random(2) == 1 then
|
if math.random(2) == 1 then
|
||||||
local ci = area:index(x,y-2,z)
|
local bbi = area:index(x,y-2,z)
|
||||||
data[ci] = c_worm
|
data[bbi] = c_worm
|
||||||
if math.random(2) == 1 then
|
if math.random(2) ==1 then
|
||||||
local di = area:index(x,y-3,z)
|
local bbbi = area:index(x,y-3,z)
|
||||||
data[di] = c_worm
|
data[bbbi] = c_worm
|
||||||
if math.random(2) == 1 then
|
|
||||||
local ei = area:index(x,y-4,z)
|
|
||||||
data[ei] = c_worm
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if math.random() < STALCHA then
|
||||||
--self documenting...
|
caverealms:stalactite(x,y,z, area, data)
|
||||||
if math.random() < ICICHA and (biome == 4 or biome == 5) then
|
|
||||||
local ai = area:index(x,y+1,z)--index of node above
|
|
||||||
if data[ai] ~= c_air then
|
|
||||||
local gi = area:index(x,y-1,z)
|
|
||||||
data[gi] = c_icid
|
|
||||||
end
|
end
|
||||||
end
|
if math.random() < CRYSTAL then
|
||||||
if math.random() <= STALCHA then
|
|
||||||
local ai = area:index(x,y+1,z)
|
|
||||||
if data[ai] ~= c_air then
|
|
||||||
caverealms:stalactite(x, y, z, area, data, biome)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if math.random() <= CRYSTAL then
|
|
||||||
local ai = area:index(x,y+1,z)
|
|
||||||
if data[ai] ~= c_air then
|
|
||||||
caverealms:crystal_stalactite(x,y,z, area, data, biome)
|
caverealms:crystal_stalactite(x,y,z, area, data, biome)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
roof[si] = 0
|
--ground
|
||||||
else -- solid rock
|
local bi = area:index(x,y-1,z) --below index
|
||||||
stable2[si] = 0
|
if data[bi] == c_stone and data[vi] == c_air then --ground
|
||||||
|
local ai = area:index(x,y+1,z)
|
||||||
|
--place floor material, add plants/decorations
|
||||||
|
if biome == 1 then
|
||||||
|
data[vi] = c_moss
|
||||||
|
if math.random() < GEMCHA then
|
||||||
|
-- gems of random size
|
||||||
|
local gems = { c_gem1, c_gem2, c_gem3, c_gem4, c_gem5 }
|
||||||
|
local gidx = math.random(1, 12)
|
||||||
|
if gidx > 5 then
|
||||||
|
gidx = 1
|
||||||
|
end
|
||||||
|
data[ai] = gems[gidx]
|
||||||
|
end
|
||||||
|
elseif biome == 2 then
|
||||||
|
data[vi] = c_lichen
|
||||||
|
if math.random() < MUSHCHA then --mushrooms
|
||||||
|
data[ai] = c_fungus
|
||||||
|
end
|
||||||
|
if math.random() < MYCCHA then --mycena mushrooms
|
||||||
|
data[ai] = c_mycena
|
||||||
|
end
|
||||||
|
if math.random() < GIANTCHA then --giant mushrooms
|
||||||
|
caverealms:giant_shroom(x, y, z, area, data)
|
||||||
|
end
|
||||||
|
elseif biome == 3 then
|
||||||
|
data[vi] = c_algae
|
||||||
|
elseif biome == 4 then
|
||||||
|
data[vi] = c_thinice
|
||||||
|
local bi = area:index(x,y-1,z)
|
||||||
|
data[bi] = c_thinice
|
||||||
|
if math.random() < ICICHA then --if glaciated, place icicles
|
||||||
|
data[ai] = c_iciu
|
||||||
|
end
|
||||||
|
elseif biome == 5 then
|
||||||
|
data[vi] = c_ice
|
||||||
|
local bi = area:index(x,y-1,z)
|
||||||
|
data[bi] = c_ice
|
||||||
|
if math.random() < ICICHA then --if glaciated, place icicles
|
||||||
|
data[ai] = c_iciu
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if math.random() < STAGCHA then
|
||||||
|
caverealms:stalagmite(x,y,z, area, data)
|
||||||
|
end
|
||||||
|
if math.random() < CRYSTAL then
|
||||||
|
caverealms:crystal_stalagmite(x,y,z, area, data, biome)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
nixyz2 = nixyz2 + 1 --increment the 3D index
|
nixyz2 = nixyz2 + 1
|
||||||
nixz2 = nixz2 + 1 --increment the 2D index
|
nixz = nixz + 1
|
||||||
vi = vi + 1 --increment the area index
|
vi = vi + 1
|
||||||
end
|
end
|
||||||
nixz2 = nixz2 - sidelen --reverse the index a bit
|
nixz = nixz - sidelen
|
||||||
end
|
end
|
||||||
nixz2 = nixz2 + sidelen --increment the index
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--send data back to voxelmanip
|
||||||
--write these changes to the world
|
|
||||||
vm:set_data(data)
|
vm:set_data(data)
|
||||||
|
--calc lighting
|
||||||
vm:set_lighting({day=0, night=0})
|
vm:set_lighting({day=0, night=0})
|
||||||
vm:calc_lighting()
|
vm:calc_lighting()
|
||||||
|
--write it to world
|
||||||
vm:write_to_map(data)
|
vm:write_to_map(data)
|
||||||
local chugent = math.ceil((os.clock() - t1) * 1000) --grab how long this took
|
|
||||||
print ("[caverealms] "..chugent.." ms") --tell people how long it took
|
local chugent = math.ceil((os.clock() - t1) * 1000) --grab how long it took
|
||||||
|
print ("[subterrain] "..chugent.." ms") --tell people how long
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue