2016-03-31 16:11:15 -07:00
|
|
|
local node = loud_walking.node
|
|
|
|
|
2016-04-01 10:55:51 -07:00
|
|
|
local bevel = 40
|
2016-04-08 13:01:33 -07:00
|
|
|
local cloud_i = 0.5
|
|
|
|
local glass = {"loud_walking:sky_scrith", "loud_walking:cloud_scrith", "loud_walking:transparent_scrith"}
|
2016-04-01 10:55:51 -07:00
|
|
|
|
2016-03-31 16:11:15 -07:00
|
|
|
|
|
|
|
local data = {}
|
|
|
|
local p2data = {} -- vm rotation data buffer
|
|
|
|
local lightmap = {}
|
|
|
|
local vm, emin, emax, a, csize, heightmap, biomemap
|
|
|
|
local div_sz_x, div_sz_z, minp, maxp, terrain, cave
|
2016-04-09 17:10:29 -07:00
|
|
|
local cloud
|
2016-03-31 16:11:15 -07:00
|
|
|
|
2016-04-01 10:55:51 -07:00
|
|
|
local terrain_noise = {offset = 0,
|
2016-03-31 16:11:15 -07:00
|
|
|
scale = 20, seed = 8829, spread = {x = 40, y = 40, z = 40},
|
|
|
|
octaves = 6, persist = 0.4, lacunarity = 2}
|
|
|
|
|
|
|
|
local cave_noise = {offset = 0, scale = 1,
|
|
|
|
seed = -3977, spread = {x = 30, y = 30, z = 30}, octaves = 3,
|
|
|
|
persist = 0.8, lacunarity = 2}
|
|
|
|
|
2016-04-08 13:01:33 -07:00
|
|
|
local cloud_noise = {offset = 0, scale = 1,
|
|
|
|
seed = -7874, spread = {x = 30, y = 30, z = 30}, octaves = 3,
|
|
|
|
persist = 0.8, lacunarity = 2}
|
|
|
|
|
2016-04-03 00:08:13 -07:00
|
|
|
loud_walking.biomes = {}
|
|
|
|
local biomes = loud_walking.biomes
|
2016-04-01 10:55:51 -07:00
|
|
|
local biome_names = {}
|
|
|
|
biome_names["common"] = {}
|
|
|
|
biome_names["uncommon"] = {}
|
|
|
|
do
|
|
|
|
local biome_terrain_scale = {}
|
|
|
|
biome_terrain_scale["coniferous_forest"] = 0.75
|
|
|
|
biome_terrain_scale["rainforest"] = 0.33
|
|
|
|
biome_terrain_scale["underground"] = 1.5
|
|
|
|
|
|
|
|
local tree_biomes = {}
|
|
|
|
tree_biomes["deciduous_forest"] = {"deciduous_trees"}
|
|
|
|
tree_biomes["coniferous_forest"] = {"conifer_trees"}
|
|
|
|
tree_biomes["taiga"] = {"conifer_trees"}
|
|
|
|
tree_biomes["rainforest"] = {"jungle_trees"}
|
|
|
|
tree_biomes["rainforest_swamp"] = {"jungle_trees"}
|
|
|
|
tree_biomes["coniferous_forest"] = {"conifer_trees"}
|
2016-04-05 00:17:41 -07:00
|
|
|
tree_biomes["savanna"] = {"acacia_trees"}
|
2016-04-01 10:55:51 -07:00
|
|
|
|
|
|
|
for i, obiome in pairs(minetest.registered_biomes) do
|
|
|
|
local biome = table.copy(obiome)
|
2016-04-05 00:17:41 -07:00
|
|
|
biome.special_tree_prob = 2
|
|
|
|
if biome.name == "savanna" then
|
|
|
|
biome.special_tree_prob = 30
|
|
|
|
end
|
2016-04-01 10:55:51 -07:00
|
|
|
local rarity = "common"
|
|
|
|
biome.terrain_scale = biome_terrain_scale[biome] or 0.5
|
|
|
|
if string.find(biome.name, "ocean") then
|
|
|
|
biome.terrain_scale = 1
|
|
|
|
rarity = "uncommon"
|
|
|
|
end
|
|
|
|
if string.find(biome.name, "swamp") then
|
|
|
|
biome.terrain_scale = 0.25
|
|
|
|
rarity = "uncommon"
|
|
|
|
end
|
|
|
|
if string.find(biome.name, "beach") then
|
|
|
|
biome.terrain_scale = 0.25
|
|
|
|
rarity = "uncommon"
|
|
|
|
end
|
|
|
|
if string.find(biome.name, "^underground$") then
|
|
|
|
biome.node_top = "default:stone"
|
|
|
|
rarity = "uncommon"
|
|
|
|
end
|
|
|
|
biome.special_trees = tree_biomes[biome.name]
|
|
|
|
biomes[biome.name] = biome
|
|
|
|
biome_names[rarity][#biome_names[rarity]+1] = biome.name
|
|
|
|
end
|
|
|
|
end
|
2016-04-08 21:35:14 -07:00
|
|
|
biomes["control"] = {}
|
2016-03-31 16:11:15 -07:00
|
|
|
|
2016-04-04 21:47:42 -07:00
|
|
|
local cave_stones = {
|
|
|
|
"loud_walking:stone_with_moss",
|
|
|
|
"loud_walking:stone_with_lichen",
|
|
|
|
"loud_walking:stone_with_algae",
|
|
|
|
"loud_walking:stone_with_salt",
|
|
|
|
}
|
|
|
|
local mushroom_stones = {}
|
|
|
|
mushroom_stones[node("default:stone")] = true
|
|
|
|
mushroom_stones[node("loud_walking:stone_with_algae")] = true
|
|
|
|
mushroom_stones[node("loud_walking:stone_with_lichen")] = true
|
|
|
|
|
2016-03-31 16:11:15 -07:00
|
|
|
local function place_schematic(pos, schem, center)
|
2016-04-05 00:17:41 -07:00
|
|
|
local rot = math.random(4) - 1
|
2016-03-31 16:11:15 -07:00
|
|
|
local yslice = {}
|
|
|
|
if schem.yslice_prob then
|
|
|
|
for _, ys in pairs(schem.yslice_prob) do
|
|
|
|
yslice[ys.ypos] = ys.prob
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if center then
|
|
|
|
pos.x = pos.x - math.floor(schem.size.x / 2)
|
|
|
|
pos.z = pos.z - math.floor(schem.size.z / 2)
|
|
|
|
end
|
|
|
|
|
2016-04-05 00:17:41 -07:00
|
|
|
for z1 = 0, schem.size.z - 1 do
|
|
|
|
for x1 = 0, schem.size.x - 1 do
|
|
|
|
local x, z
|
|
|
|
if rot == 0 then
|
|
|
|
x, z = x1, z1
|
|
|
|
elseif rot == 1 then
|
|
|
|
x, z = schem.size.z - z1 - 1, x1
|
|
|
|
elseif rot == 2 then
|
|
|
|
x, z = schem.size.x - x1 - 1, schem.size.z - z1 - 1
|
|
|
|
elseif rot == 3 then
|
|
|
|
x, z = z1, schem.size.x - x1 - 1
|
|
|
|
end
|
|
|
|
local dz = pos.z - minp.z + z
|
2016-04-01 10:55:51 -07:00
|
|
|
local dx = pos.x - minp.x + x
|
|
|
|
if pos.x + x > minp.x and pos.x + x < maxp.x and pos.z + z > minp.z and pos.z + z < maxp.z then
|
|
|
|
local ivm = a:index(pos.x + x, pos.y, pos.z + z)
|
2016-04-05 00:17:41 -07:00
|
|
|
local isch = z1 * schem.size.y * schem.size.x + x1 + 1
|
2016-04-01 10:55:51 -07:00
|
|
|
for y = 0, schem.size.y - 1 do
|
|
|
|
local dy = pos.y - minp.y + y
|
|
|
|
if math.min(dx, csize.x - dx) + math.min(dy, csize.y - dy) + math.min(dz, csize.z - dz) > bevel then
|
|
|
|
if yslice[y] or 255 >= math.random(255) then
|
|
|
|
local prob = schem.data[isch].prob or schem.data[isch].param1 or 255
|
|
|
|
if prob >= math.random(255) and schem.data[isch].name ~= "air" then
|
|
|
|
data[ivm] = node(schem.data[isch].name)
|
|
|
|
end
|
|
|
|
local param2 = schem.data[isch].param2 or 0
|
|
|
|
p2data[ivm] = param2
|
|
|
|
end
|
2016-03-31 16:11:15 -07:00
|
|
|
end
|
2016-04-01 10:55:51 -07:00
|
|
|
|
|
|
|
ivm = ivm + a.ystride
|
|
|
|
isch = isch + schem.size.x
|
2016-03-31 16:11:15 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function is_pod(x, y, z)
|
|
|
|
local min_x = math.floor((x + 32) / csize.x)
|
|
|
|
local min_y = math.floor((y + 32) / csize.y)
|
|
|
|
local min_z = math.floor((z + 32) / csize.z)
|
|
|
|
|
|
|
|
if min_x % 2 == 0 and min_y % 2 == 0 and min_z % 2 == 0 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
--if min_x % 2 == 1 and min_y % 4 == 0 and min_z % 2 == 1 then
|
|
|
|
-- return true
|
|
|
|
--elseif min_x % 2 == 0 and min_y % 4 == 2 and min_z % 2 == 0 then
|
|
|
|
-- return true
|
|
|
|
--end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function connection(x, y, z)
|
|
|
|
local min_x = math.floor((x + 32) / csize.x)
|
|
|
|
local min_y = math.floor((y + 32) / csize.y)
|
|
|
|
local min_z = math.floor((z + 32) / csize.z)
|
|
|
|
|
|
|
|
--local seed_noise = minetest.get_perlin({offset = 0, scale = 32768,
|
|
|
|
--seed = 5202, spread = {x = 80, y = 80, z = 80}, octaves = 2,
|
|
|
|
--persist = 0.4, lacunarity = 2})
|
|
|
|
--math.randomseed(seed_noise:get2d({x=minp.x, y=minp.z}))
|
|
|
|
|
|
|
|
local ct = min_x % 2 + min_y % 2 + min_z % 2
|
|
|
|
local r = min_x % 2 + 2 * (min_y % 2) + 4 * (min_z % 2)
|
|
|
|
if ct == 1 then
|
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2016-04-01 10:55:51 -07:00
|
|
|
local function get_height(dx, dz, terrain_scale, ocean, index)
|
2016-03-31 16:11:15 -07:00
|
|
|
local terr
|
2016-04-01 10:55:51 -07:00
|
|
|
local half = math.floor(csize.y / 2 + 0.5)
|
2016-04-08 21:35:14 -07:00
|
|
|
terrain_scale = terrain_scale or 1
|
2016-04-01 10:55:51 -07:00
|
|
|
|
|
|
|
--if index == true then
|
|
|
|
-- terr = minetest.get_perlin(terrain_noise):get2d({x=dx, y=dz})
|
|
|
|
-- -- Still need csize here...
|
|
|
|
-- dx = (dx + 32) % 80
|
|
|
|
-- dz = (dz + 32) % 80
|
|
|
|
if not index then
|
2016-03-31 16:11:15 -07:00
|
|
|
index = dz * csize.x + dx + 1
|
2016-04-01 10:55:51 -07:00
|
|
|
terr = terrain[index]
|
2016-03-31 16:11:15 -07:00
|
|
|
else
|
2016-04-01 10:55:51 -07:00
|
|
|
terr = terrain[index]
|
2016-03-31 16:11:15 -07:00
|
|
|
end
|
|
|
|
|
2016-04-01 10:55:51 -07:00
|
|
|
terr = math.floor(terr * terrain_scale + 0.5)
|
|
|
|
|
|
|
|
local d = half - 2 - math.abs(math.abs(dx - (half - 0.5)) - math.abs(dz - (half - 0.5)))
|
2016-03-31 16:11:15 -07:00
|
|
|
if math.abs(terr) > d then
|
|
|
|
if terr > 0 then
|
|
|
|
terr = math.floor(d + 0.5)
|
2016-04-01 10:55:51 -07:00
|
|
|
elseif not ocean then
|
2016-03-31 16:11:15 -07:00
|
|
|
terr = math.floor(0.5 - d)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return terr
|
|
|
|
end
|
|
|
|
|
|
|
|
local function get_biome(px, pz)
|
2016-04-08 21:35:14 -07:00
|
|
|
if px % 10 == 6 and pz % 10 == 6 then
|
|
|
|
return "control"
|
|
|
|
else
|
|
|
|
local sr = math.random(5)
|
|
|
|
local rarity = "common"
|
|
|
|
if sr > 4 then
|
|
|
|
rarity = "uncommon"
|
|
|
|
end
|
|
|
|
local biome = biome_names[rarity][math.random(#biome_names[rarity])]
|
|
|
|
return biome
|
2016-04-01 10:55:51 -07:00
|
|
|
end
|
2016-03-31 16:11:15 -07:00
|
|
|
end
|
|
|
|
|
2016-03-31 17:06:06 -07:00
|
|
|
local function get_decoration(biome)
|
2016-04-03 00:08:13 -07:00
|
|
|
for i, deco in pairs(loud_walking.decorations) do
|
|
|
|
if not deco.biomes or deco.biomes[biome] then
|
|
|
|
local range = 1000
|
|
|
|
if deco.deco_type == "simple" then
|
|
|
|
if deco.fill_ratio and math.random(range) - 1 < deco.fill_ratio * 1000 then
|
|
|
|
return deco.decoration
|
2016-03-31 17:06:06 -07:00
|
|
|
end
|
2016-04-03 00:08:13 -07:00
|
|
|
else
|
|
|
|
-- nop
|
2016-03-31 17:06:06 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-31 16:11:15 -07:00
|
|
|
|
|
|
|
function loud_walking.generate(p_minp, p_maxp, seed)
|
|
|
|
minp, maxp = p_minp, p_maxp
|
|
|
|
vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
|
|
|
vm:get_data(data)
|
|
|
|
--p2data = vm:get_param2_data()
|
|
|
|
a = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
|
|
|
csize = vector.add(vector.subtract(maxp, minp), 1)
|
|
|
|
|
|
|
|
-- Deal with memory issues. This, of course, is supposed to be automatic.
|
|
|
|
local mem = math.floor(collectgarbage("count")/1024)
|
|
|
|
if mem > 300 then
|
2016-04-01 10:55:51 -07:00
|
|
|
print("Loud Walking: Manually collecting garbage...")
|
2016-03-31 16:11:15 -07:00
|
|
|
collectgarbage("collect")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- use the same seed (based on perlin noise).
|
|
|
|
local seed_noise = minetest.get_perlin({offset = 0, scale = 32768,
|
|
|
|
seed = 5202, spread = {x = 80, y = 80, z = 80}, octaves = 2,
|
|
|
|
persist = 0.4, lacunarity = 2})
|
|
|
|
math.randomseed(seed_noise:get2d({x=minp.x, y=minp.z}))
|
|
|
|
|
2016-04-01 10:55:51 -07:00
|
|
|
-- Keep this first after seeding!
|
|
|
|
local px = math.floor((minp.x + 32) / csize.x)
|
|
|
|
local pz = math.floor((minp.z + 32) / csize.z)
|
2016-04-01 15:16:27 -07:00
|
|
|
local biome = get_biome(px, pz)
|
2016-04-04 21:47:42 -07:00
|
|
|
local cave_lining = cave_stones[math.random(#cave_stones)]
|
|
|
|
if math.random(3) == 1 then
|
|
|
|
cave_lining = nil
|
|
|
|
end
|
2016-04-01 15:16:27 -07:00
|
|
|
|
2016-04-08 21:35:14 -07:00
|
|
|
vm:set_lighting({day = 15, night = (biome == "control" and 15 or 0)}, minp, maxp)
|
|
|
|
lightmap = vm:get_light_data()
|
|
|
|
|
2016-04-03 00:08:13 -07:00
|
|
|
local node_top = biomes[biome].node_top or "default:dirt_with_grass"
|
2016-04-01 12:48:13 -07:00
|
|
|
local node_filler = biomes[biome].node_filler or "default:dirt"
|
2016-04-03 00:08:13 -07:00
|
|
|
local node_water_top = biomes[biome].node_water_top or "default:water_source"
|
|
|
|
local node_water = biomes[biome].node_water or "default:water_source"
|
2016-04-01 10:55:51 -07:00
|
|
|
local depth_top = biomes[biome].depth_top or 1
|
2016-04-03 00:08:13 -07:00
|
|
|
local depth_water_top = biomes[biome].node_water_top or 1
|
2016-04-01 10:55:51 -07:00
|
|
|
local depth_filler = biomes[biome].depth_filler or 1
|
|
|
|
local node_stone = biomes[biome].node_stone or "default:stone"
|
|
|
|
local ocean = string.find(biome, "ocean") and true or false
|
|
|
|
local swamp = string.find(biome, "swamp") and true or false
|
|
|
|
local beach = string.find(biome, "beach") and true or false
|
2016-04-01 12:48:13 -07:00
|
|
|
local dunes = string.find(biome, "dunes") and true or false
|
2016-04-01 10:55:51 -07:00
|
|
|
local half = math.floor(csize.y / 2 + 0.5)
|
|
|
|
local ground = half
|
|
|
|
|
2016-04-01 12:48:13 -07:00
|
|
|
beach = beach or dunes
|
2016-04-01 10:55:51 -07:00
|
|
|
if ocean then
|
|
|
|
ground = ground - 15
|
|
|
|
elseif swamp or beach then
|
|
|
|
ground = ground - 3
|
|
|
|
end
|
|
|
|
|
2016-03-31 16:11:15 -07:00
|
|
|
terrain = minetest.get_perlin_map(terrain_noise, csize):get2dMap_flat(minp)
|
|
|
|
cave = minetest.get_perlin_map(cave_noise, csize):get3dMap_flat(minp)
|
2016-04-08 13:01:33 -07:00
|
|
|
cloud = minetest.get_perlin_map(cloud_noise, csize):get2dMap_flat(minp)
|
2016-03-31 16:11:15 -07:00
|
|
|
|
|
|
|
local pod = is_pod(minp.x, minp.y, minp.z)
|
|
|
|
local connection = connection(minp.x, minp.y, minp.z)
|
|
|
|
|
|
|
|
local index = 0
|
|
|
|
local index3d = 0
|
|
|
|
for z = minp.z, maxp.z do
|
|
|
|
local dz = z - minp.z
|
|
|
|
for x = minp.x, maxp.x do
|
|
|
|
index = index + 1
|
|
|
|
local dx = x - minp.x
|
|
|
|
index3d = dz * csize.y * csize.x + dx + 1
|
|
|
|
local ivm = a:index(x, minp.y, z)
|
|
|
|
|
2016-04-01 10:55:51 -07:00
|
|
|
local terr = get_height(dx, dz, biomes[biome].terrain_scale, ocean, index)
|
2016-03-31 16:11:15 -07:00
|
|
|
local in_cave = false
|
2016-04-04 00:34:05 -07:00
|
|
|
if biome == "underground" then
|
|
|
|
terr = half - 5
|
|
|
|
end
|
2016-03-31 16:11:15 -07:00
|
|
|
|
2016-04-04 00:34:05 -07:00
|
|
|
local cave_height = 0
|
2016-03-31 16:11:15 -07:00
|
|
|
for y = minp.y, maxp.y do
|
|
|
|
local dy = y - minp.y
|
|
|
|
if pod then
|
2016-04-08 21:35:14 -07:00
|
|
|
if biome == "control" and math.abs(dx - half) < 3 and math.abs(dz - half) < 3 then
|
|
|
|
data[ivm] = node("loud_walking:air_ladder")
|
|
|
|
elseif math.min(dx, csize.x - dx) + math.min(dy, csize.y - dy) + math.min(dz, csize.z - dz) < bevel then
|
2016-03-31 16:11:15 -07:00
|
|
|
data[ivm] = node("air")
|
2016-04-01 10:55:51 -07:00
|
|
|
lightmap[ivm] = 0
|
2016-03-31 16:11:15 -07:00
|
|
|
in_cave = false
|
2016-04-08 19:34:41 -07:00
|
|
|
elseif (dx == 0 or dx == csize.x - 1) or (dz == 0 or dz == csize.z - 1) or (dy == 0 or dy == csize.y - 1) or math.min(dx, csize.x - dx) + math.min(dy, csize.y - dy) + math.min(dz, csize.z - dz) < bevel + 1 then
|
2016-04-01 10:55:51 -07:00
|
|
|
if math.abs(dy - half - 2) < 2 and (dz == half or dx == half) then
|
2016-03-31 16:11:15 -07:00
|
|
|
data[ivm] = node("air")
|
|
|
|
else
|
2016-04-08 21:35:14 -07:00
|
|
|
if biome == "control" then
|
|
|
|
data[ivm] = node(glass[3])
|
2016-04-09 03:25:47 -07:00
|
|
|
elseif dy < half then
|
|
|
|
data[ivm] = node("loud_walking:scrith")
|
|
|
|
lightmap[ivm] = 0
|
|
|
|
elseif biome == "underground" then
|
2016-03-31 16:11:15 -07:00
|
|
|
data[ivm] = node("loud_walking:scrith")
|
|
|
|
lightmap[ivm] = 0
|
2016-04-08 13:01:33 -07:00
|
|
|
elseif dy == csize.y - 1 then
|
|
|
|
data[ivm] = node(glass[cloud[index] < cloud_i and 1 or 2])
|
2016-03-31 16:11:15 -07:00
|
|
|
else
|
2016-04-08 13:01:33 -07:00
|
|
|
data[ivm] = node(glass[1])
|
2016-03-31 16:11:15 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
in_cave = false
|
2016-04-08 21:35:14 -07:00
|
|
|
elseif biome == "control" and dy % 5 == 0 then
|
2016-04-09 16:42:00 -07:00
|
|
|
data[ivm] = node("loud_walking:control_floor")
|
2016-04-08 21:35:14 -07:00
|
|
|
elseif biome == "control" and (math.abs(dx - half) < 3 or math.abs(dz - half) < 3) then
|
|
|
|
data[ivm] = node("air")
|
|
|
|
elseif biome == "control" and ((math.abs(dx - half) % 20 == 3 and (math.abs(dz - half) - 12) % 20 > 3) or (math.abs(dz - half) % 20 == 3 and (math.abs(dx - half) - 12) % 20 > 3)) then
|
2016-04-09 16:42:00 -07:00
|
|
|
data[ivm] = node("loud_walking:control_wall")
|
2016-04-08 21:35:14 -07:00
|
|
|
elseif biome == "control" then
|
|
|
|
--
|
2016-04-01 15:16:27 -07:00
|
|
|
elseif (((dx == 35 or dx == 45) and dz >= 35 and dz <= 45) or ((dz == 35 or dz == 45) and dx >= 35 and dx <= 45)) and dx ~= 40 and dz ~= 40 and dy == csize.y - 2 then
|
|
|
|
data[ivm] = node("loud_walking:controls")
|
|
|
|
elseif (((dx == 35 or dx == 45) and dz >= 35 and dz <= 45) or ((dz == 35 or dz == 45) and dx >= 35 and dx <= 45)) and dx ~= 40 and dz ~= 40 and dy > csize.y - 5 then
|
2016-04-08 13:01:33 -07:00
|
|
|
data[ivm] = node(glass[3])
|
2016-04-01 15:16:27 -07:00
|
|
|
elseif dz >= 35 and dz <= 45 and dx >= 35 and dx <= 45 and dy == csize.y - 5 then
|
2016-04-08 13:01:33 -07:00
|
|
|
data[ivm] = node(glass[3])
|
2016-04-03 00:08:13 -07:00
|
|
|
elseif not in_cave and (ocean or swamp or beach) and dy > terr + ground and dy <= half and dy == terr + ground + 1 then
|
2016-04-01 12:48:13 -07:00
|
|
|
-- ** water decorations **
|
|
|
|
--local deco = get_decoration(biome)
|
|
|
|
--if deco then
|
|
|
|
-- data[ivm] = node(deco)
|
|
|
|
--end
|
2016-04-03 00:08:13 -07:00
|
|
|
elseif not in_cave and dy == terr + ground + 1 then
|
|
|
|
local deco = get_decoration(biome)
|
|
|
|
if deco then
|
|
|
|
data[ivm] = node(deco)
|
|
|
|
end
|
|
|
|
elseif (ocean or swamp or beach) and dy > terr + ground and dy <= half and dy >= half - depth_water_top then
|
|
|
|
data[ivm] = node(node_water_top)
|
|
|
|
in_cave = false
|
2016-04-01 10:55:51 -07:00
|
|
|
elseif (ocean or swamp or beach) and dy > terr + ground and dy <= half then
|
2016-04-03 00:08:13 -07:00
|
|
|
data[ivm] = node(node_water)
|
2016-04-01 10:55:51 -07:00
|
|
|
in_cave = false
|
|
|
|
elseif dy > terr + ground then
|
2016-03-31 16:11:15 -07:00
|
|
|
data[ivm] = node("air")
|
|
|
|
in_cave = false
|
2016-04-04 00:34:05 -07:00
|
|
|
elseif cave[index3d] ^ 2 > (biome == "underground" and 0.5 or 1.3 - math.sin(dy / (half * 0.2))) then
|
2016-04-04 21:47:42 -07:00
|
|
|
cave_height = cave_height + 1
|
2016-04-01 10:55:51 -07:00
|
|
|
if terr + ground >= dy and not in_cave and dy > terr + ground - 10 then
|
2016-04-03 00:08:13 -07:00
|
|
|
data[ivm] = node(node_top)
|
2016-04-01 12:48:13 -07:00
|
|
|
elseif dy == 1 then
|
2016-04-04 21:47:42 -07:00
|
|
|
if not cave_lining and not ocean and not swamp and not beach and biome ~= "glacier" and math.random(6) == 1 then
|
2016-04-01 12:48:13 -07:00
|
|
|
data[ivm] = node("default:lava_source")
|
|
|
|
elseif ocean or swamp or beach then
|
|
|
|
data[ivm] = node(node_filler)
|
|
|
|
end
|
2016-04-04 00:34:05 -07:00
|
|
|
elseif (ocean or swamp or beach) and not in_cave and node_stone == "default:stone" and dy < half and math.random(20) == 1 then
|
|
|
|
data[ivm] = node("loud_walking:glowing_fungal_stone")
|
|
|
|
elseif (ocean or swamp or beach) and dy < half then
|
2016-04-03 00:08:13 -07:00
|
|
|
data[ivm] = node(node_water)
|
2016-04-04 21:47:42 -07:00
|
|
|
elseif cave_height == 3 and node_filler == "default:dirt" and mushroom_stones[data[ivm - 3 * a.ystride]] and math.random(40) == 1 then
|
2016-04-04 00:34:05 -07:00
|
|
|
data[ivm] = node("loud_walking:giant_mushroom_cap")
|
|
|
|
data[ivm - a.ystride] = node("loud_walking:giant_mushroom_stem")
|
|
|
|
data[ivm - 2 * a.ystride] = node("loud_walking:giant_mushroom_stem")
|
|
|
|
data[ivm - 3 * a.ystride] = node(node_filler)
|
2016-04-04 21:47:42 -07:00
|
|
|
elseif cave_height == 2 and node_filler == "default:dirt" and mushroom_stones[data[ivm - 2 * a.ystride]] and math.random(20) == 1 then
|
2016-04-04 00:34:05 -07:00
|
|
|
data[ivm] = node("loud_walking:huge_mushroom_cap")
|
|
|
|
data[ivm - a.ystride] = node("loud_walking:giant_mushroom_stem")
|
|
|
|
data[ivm - 2 * a.ystride] = node(node_filler)
|
2016-04-04 21:47:42 -07:00
|
|
|
elseif not in_cave and node_stone == "default:stone" and not cave_lining and math.random(10) == 1 then
|
2016-04-04 00:34:05 -07:00
|
|
|
data[ivm] = node("loud_walking:stalagmite")
|
|
|
|
elseif not in_cave and node_stone == "default:ice" and math.random(10) == 1 then
|
|
|
|
data[ivm] = node("loud_walking:icicle_up")
|
2016-03-31 16:11:15 -07:00
|
|
|
else
|
|
|
|
data[ivm] = node("air")
|
|
|
|
end
|
|
|
|
in_cave = true
|
|
|
|
lightmap[ivm] = 0
|
2016-04-04 21:47:42 -07:00
|
|
|
elseif cave_lining and cave[index3d] ^ 2 > (biome == "underground" and 0.4 or 1.2 - math.sin(dy / (half * 0.2))) then
|
|
|
|
data[ivm] = node(cave_lining)
|
|
|
|
lightmap[ivm] = 0
|
2016-04-01 10:55:51 -07:00
|
|
|
elseif dy > terr + ground - depth_top then
|
2016-04-03 00:08:13 -07:00
|
|
|
data[ivm] = node(node_top)
|
2016-03-31 16:11:15 -07:00
|
|
|
lightmap[ivm] = 0
|
|
|
|
in_cave = false
|
2016-04-01 10:55:51 -07:00
|
|
|
elseif dy > terr + ground - depth_filler - depth_top then
|
2016-04-03 00:08:13 -07:00
|
|
|
data[ivm] = node(node_filler)
|
2016-03-31 16:11:15 -07:00
|
|
|
lightmap[ivm] = 0
|
|
|
|
in_cave = false
|
|
|
|
else
|
2016-04-01 10:55:51 -07:00
|
|
|
data[ivm] = node(node_stone)
|
2016-04-04 00:34:05 -07:00
|
|
|
if in_cave and node_stone == "default:stone" and math.random(20) == 1 then
|
|
|
|
data[ivm] = node("loud_walking:glowing_fungal_stone")
|
2016-04-04 21:47:42 -07:00
|
|
|
elseif in_cave and not (ocean or swamp or beach) and node_stone == "default:stone" and not cave_lining and math.random(10) == 1 then
|
2016-04-04 00:34:05 -07:00
|
|
|
data[ivm - a.ystride] = node("loud_walking:stalactite")
|
|
|
|
elseif in_cave and not (ocean or swamp or beach) and node_stone == "default:ice" and math.random(10) == 1 then
|
|
|
|
data[ivm - a.ystride] = node("loud_walking:icicle_down")
|
|
|
|
end
|
2016-03-31 16:11:15 -07:00
|
|
|
lightmap[ivm] = 0
|
|
|
|
in_cave = false
|
|
|
|
end
|
2016-04-08 21:35:14 -07:00
|
|
|
elseif biome == "control" and math.abs(dx - half) < 3 and math.abs(dz - half) < 3 then
|
|
|
|
data[ivm] = node("loud_walking:air_ladder")
|
2016-04-01 10:55:51 -07:00
|
|
|
elseif connection and dy == half and ((dx == half and connection % 4 == 0) or (dz == half and connection % 2 == 1)) then
|
|
|
|
data[ivm] = node("loud_walking:scrith")
|
2016-03-31 16:11:15 -07:00
|
|
|
lightmap[ivm] = 0
|
|
|
|
end
|
|
|
|
|
2016-04-04 21:47:42 -07:00
|
|
|
if not in_cave then
|
2016-04-04 00:34:05 -07:00
|
|
|
cave_height = 0
|
|
|
|
end
|
2016-03-31 16:11:15 -07:00
|
|
|
ivm = ivm + a.ystride
|
|
|
|
index3d = index3d + csize.x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if pod then
|
|
|
|
for dz = 0, 75, 5 do
|
|
|
|
for dx = 0, 75, 5 do
|
2016-04-05 00:17:41 -07:00
|
|
|
if biomes[biome].special_tree_prob and math.random(biomes[biome].special_tree_prob) == 1 then
|
2016-04-04 00:34:05 -07:00
|
|
|
local x = minp.x + dx + math.random(5) - 1
|
|
|
|
local z = minp.z + dz + math.random(5) - 1
|
2016-04-01 10:55:51 -07:00
|
|
|
local y = minp.y + get_height(x - minp.x, z - minp.z, biomes[biome].terrain_scale, ocean) + ground
|
2016-03-31 16:11:15 -07:00
|
|
|
|
|
|
|
local ivm = a:index(x, y, z)
|
2016-04-05 00:17:41 -07:00
|
|
|
if (swamp or data[ivm + a.ystride] ~= node("default:water_source")) and (data[ivm] == node(node_top)) then
|
2016-04-01 10:55:51 -07:00
|
|
|
if biomes[biome].special_trees then
|
|
|
|
local tree_type = biomes[biome].special_trees[math.random(#biomes[biome].special_trees)]
|
|
|
|
if tree_type then
|
|
|
|
local schem = loud_walking.schematics[tree_type][math.random(#loud_walking.schematics[tree_type])]
|
|
|
|
local pos = {x=x, y=y, z=z}
|
|
|
|
-- The minetest schematic functions don't seem very accurate.
|
|
|
|
place_schematic(pos, schem, true)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- regular schematics?
|
2016-03-31 16:11:15 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-09 16:42:00 -07:00
|
|
|
if pod and biome == "control" then
|
|
|
|
for dy = 0, 15 do
|
|
|
|
for dz = 0, 1 do
|
|
|
|
for dx = 0, 1 do
|
|
|
|
local x1 = minp.x + dx * 26 + 17
|
|
|
|
local z1 = minp.z + dz * 26 + 17
|
|
|
|
local y1 = minp.y + dy * 5
|
|
|
|
|
|
|
|
local sr = math.random(6)
|
|
|
|
for z = 0, 20 do
|
|
|
|
local ivm = a:index(x1, y1, z1 + z)
|
|
|
|
for x = 0, 20 do
|
|
|
|
if sr == 1 then
|
|
|
|
if dy > 0 then
|
|
|
|
if data[ivm] == node("loud_walking:control_floor_alert_down") then
|
|
|
|
data[ivm] = node("loud_walking:control_floor_alert_both")
|
|
|
|
else
|
|
|
|
data[ivm] = node("loud_walking:control_floor_alert_up")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if dy < 15 then
|
|
|
|
data[ivm + a.ystride * 5] = node("loud_walking:control_floor_alert_down")
|
|
|
|
end
|
|
|
|
elseif sr == 2 then
|
|
|
|
if x > 1 and x < 19 and z > 1 and z < 19 and (z - 2) % 4 ~= 0 and (x - 2) % 4 ~= 0 then
|
|
|
|
for y = 1, 4 do
|
|
|
|
data[ivm + y * a.ystride] = node("loud_walking:air_ladder")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif sr == 3 then
|
|
|
|
if dy > 0 and data[ivm] ~= node("loud_walking:control_floor_alert_down") and x > 0 and z > 0 and x < 20 and z < 20 then
|
|
|
|
data[ivm] = node("loud_walking:control_floor_growth")
|
|
|
|
local sr2 = math.random(20)
|
|
|
|
if sr2 == 1 then
|
|
|
|
data[ivm + a.ystride] = node("loud_walking:control_plant_1")
|
|
|
|
elseif sr2 == 2 then
|
|
|
|
data[ivm + a.ystride] = node("loud_walking:control_plant_2")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif sr == 4 then
|
|
|
|
if dy < 15 and (x > 0 and x < 20 and z > 0 and z < 20) and (((x == 1 or x == 19) and math.abs(z - 10) > 3) or ((z == 1 or z == 19) and math.abs(x - 10) > 3)) then
|
|
|
|
data[ivm + 3 * a.ystride] = node("loud_walking:controls")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ivm = ivm + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-08 13:01:33 -07:00
|
|
|
vm:set_data(data)
|
|
|
|
minetest.generate_ores(vm, minp, maxp)
|
2016-04-09 21:41:24 -07:00
|
|
|
--minetest.generate_decorations(vm, minp, maxp)
|
2016-04-08 13:01:33 -07:00
|
|
|
--vm:set_param2_data(p2data)
|
|
|
|
--vm:set_lighting({day = 15, night = 0})
|
|
|
|
if pod then
|
2016-04-04 00:40:06 -07:00
|
|
|
vm:set_light_data(lightmap)
|
2016-03-31 16:11:15 -07:00
|
|
|
end
|
2016-04-08 13:01:33 -07:00
|
|
|
vm:update_liquids()
|
|
|
|
vm:calc_lighting(minp, maxp, false)
|
|
|
|
vm:write_to_map()
|
2016-03-31 16:11:15 -07:00
|
|
|
|
|
|
|
vm, a, heightmap, biomemap = nil, nil, nil, nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function loud_walking.respawn(player)
|
2016-09-27 18:55:13 -07:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
if not player_name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if beds and beds.spawn and beds.spawn[player_name] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-04-01 15:16:27 -07:00
|
|
|
while true do
|
2016-04-01 10:55:51 -07:00
|
|
|
local px = math.random(-10, 10) * 2 - 1
|
2016-03-31 16:11:15 -07:00
|
|
|
local pz = math.random(-10, 10) * 2
|
2016-04-01 10:55:51 -07:00
|
|
|
local x = 80 * px + 8
|
|
|
|
local z = 80 * pz + 8
|
|
|
|
local y = 9
|
2016-03-31 16:11:15 -07:00
|
|
|
|
|
|
|
local pos = {x=x,y=y,z=z}
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if node.name ~= "air" then
|
|
|
|
player:setpos(pos)
|
2016-04-01 15:16:27 -07:00
|
|
|
return true
|
2016-03-31 16:11:15 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|