Clean up several functions.
This commit is contained in:
parent
e6f482c9d5
commit
42916c4666
5 changed files with 159 additions and 103 deletions
70
decogen.lua
70
decogen.lua
|
@ -30,19 +30,19 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
local biomemap = minetest.get_mapgen_object("biomemap")
|
||||
local map_max = {x = csize.x, y = csize.y + 2, z = csize.z}
|
||||
local map_min = {x = minp.x, y = minp.y - 1, z = minp.z}
|
||||
--local noise_area = VoxelArea:new({MinEdge={x=0,y=-1,z=0}, MaxEdge={x=csize.x,y=csize.y+1,z=csize.z}})
|
||||
|
||||
local biome_n = minetest.get_perlin_map(biome_noise, map_max):get3dMap_flat(map_min)
|
||||
local plant_n = minetest.get_perlin_map(plant_noise, {x=csize.x, y=csize.z}):get2dMap_flat({x=minp.x, y=minp.z})
|
||||
|
||||
local math_random = math.random
|
||||
local dis_map = {}
|
||||
if underzone and underzone.name == 'Dis' then
|
||||
for i = 0, 10, 2 do
|
||||
dis_map[i] = {}
|
||||
for j = 0, 10, 2 do
|
||||
dis_map[i][j] = math.random(6)
|
||||
dis_map[i][j] = math_random(6)
|
||||
if dis_map[i][j] == 6 then
|
||||
dis_map[i][j] = 5 + math.random(10)
|
||||
dis_map[i][j] = 5 + math_random(10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -55,10 +55,14 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
|
||||
local index = 0
|
||||
local index3d = 0
|
||||
local pos = {x=0, y=0, z=0}
|
||||
local math_floor = math.floor
|
||||
local math_max = math.max
|
||||
local math_min = math.min
|
||||
local math_log = math.log
|
||||
for z = minp.z, maxp.z do
|
||||
for x = minp.x, maxp.x do
|
||||
index = index + 1
|
||||
--index3d = noise_area:index(x - minp.x, -1, z - minp.z)
|
||||
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
|
||||
local ivm = area:index(x, minp.y, z)
|
||||
|
||||
|
@ -84,7 +88,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
|
||||
-- Compress biomes at the surface to avoid fluids.
|
||||
if y > fluid_compression then
|
||||
biome_val = biome_val / math.max(1, math.log(y - fluid_compression))
|
||||
biome_val = biome_val / math_max(1, math_log(y - fluid_compression))
|
||||
end
|
||||
|
||||
for _, bi in pairs(fun_caves.cave_biomes) do
|
||||
|
@ -117,7 +121,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
end
|
||||
|
||||
if data[ivm] == node["default:stone"] then
|
||||
if node_above == node["air"] and biome and biome.dirt and math.random(biome.dirt_chance) == 1 then
|
||||
if node_above == node["air"] and biome and biome.dirt and math_random(biome.dirt_chance) == 1 then
|
||||
data[ivm] = node[biome.dirt]
|
||||
write = true
|
||||
break
|
||||
|
@ -131,7 +135,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
end
|
||||
|
||||
if air_above then
|
||||
if biome and biome.deco and math.random(biome.deco_chance) == 1 then
|
||||
if biome and biome.deco and math_random(biome.deco_chance) == 1 then
|
||||
data[ivm] = node[biome.deco]
|
||||
write = true
|
||||
break
|
||||
|
@ -156,7 +160,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
end
|
||||
|
||||
if air_below then
|
||||
if biome and biome.deco and math.random(biome.deco_chance) == 1 then
|
||||
if biome and biome.deco and math_random(biome.deco_chance) == 1 then
|
||||
data[ivm] = node[biome.deco]
|
||||
write = true
|
||||
break
|
||||
|
@ -169,7 +173,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
end
|
||||
|
||||
-- smallest city generator ever
|
||||
if underzone and underzone.name == 'Dis' and data[ivm] == node['air'] and math.floor((x - minp.x) / 8) % 2 == 0 and math.floor((z - minp.z) / 8) % 2 == 0 and y - underzone.floor < dis_map[math.floor((x - minp.x) / 8)][math.floor((z - minp.z) / 8)] * 4 + 1 and y - underzone.floor >= 0 then
|
||||
if underzone and underzone.name == 'Dis' and data[ivm] == node['air'] and math_floor((x - minp.x) / 8) % 2 == 0 and math_floor((z - minp.z) / 8) % 2 == 0 and y - underzone.floor < dis_map[math_floor((x - minp.x) / 8)][math_floor((z - minp.z) / 8)] * 4 + 1 and y - underzone.floor >= 0 then
|
||||
local dx = (x - minp.x) % 16
|
||||
local dy = y - underzone.floor + 1
|
||||
local dz = (z - minp.z) % 16
|
||||
|
@ -189,22 +193,22 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
if data[ivm] == node["air"] and y < maxp.y then
|
||||
-- hanging down
|
||||
-- stone hasn't yet been changed
|
||||
if biome and biome.stalactite and node_above == node["default:stone"] and math.random(biome.stalactite_chance) == 1 then
|
||||
if biome and biome.stalactite and node_above == node["default:stone"] and math_random(biome.stalactite_chance) == 1 then
|
||||
data[ivm] = node[biome.stalactite]
|
||||
write = true
|
||||
break
|
||||
end
|
||||
|
||||
-- fluids
|
||||
if y > minp.y and biome and biome.fluid and node_below == node[biome.floor_node] and math.random(biome.fluid_chance) == 1 then
|
||||
if y > minp.y and biome and biome.fluid and node_below == node[biome.floor_node] and math_random(biome.fluid_chance) == 1 then
|
||||
data[ivm] = node[biome.fluid]
|
||||
write = true
|
||||
break
|
||||
|
||||
-- standing up
|
||||
elseif node_below == node[biome.floor_node] and biome and biome.stalagmite and math.random(biome.stalagmite_chance) == 1 then
|
||||
elseif node_below == node[biome.floor_node] and biome and biome.stalagmite and math_random(biome.stalagmite_chance) == 1 then
|
||||
if type(biome.stalagmite) == 'table' then
|
||||
data[ivm] = node[biome.stalagmite[math.random(#biome.stalagmite)]]
|
||||
data[ivm] = node[biome.stalagmite[math_random(#biome.stalagmite)]]
|
||||
else
|
||||
data[ivm] = node[biome.stalagmite]
|
||||
end
|
||||
|
@ -213,11 +217,11 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
|
||||
-- vegetation
|
||||
elseif node_below == node["fun_caves:polluted_dirt"] then
|
||||
if math.random(10) == 1 then
|
||||
if math_random(10) == 1 then
|
||||
data[ivm] = node["default:dry_shrub"]
|
||||
write = true
|
||||
break
|
||||
elseif math.random(50) == 1 then
|
||||
elseif math_random(50) == 1 then
|
||||
local air_count = 0
|
||||
local j
|
||||
for i = 1, 9 do
|
||||
|
@ -227,23 +231,26 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
end
|
||||
end
|
||||
if air_count > 6 then
|
||||
fun_caves.place_schematic(minp, maxp, data, p2data, area, node, {x=x,y=y,z=z}, fun_caves.schematics['decaying_tree'], true)
|
||||
pos.x = x
|
||||
pos.y = y
|
||||
pos.z = z
|
||||
fun_caves.place_schematic(minp, maxp, data, p2data, area, node, pos, fun_caves.schematics['decaying_tree'], true)
|
||||
end
|
||||
end
|
||||
elseif node_below == node["default:dirt"] and biome and biome.fungi then
|
||||
if math.random(10) == 1 then
|
||||
if math_random(10) == 1 then
|
||||
data[ivm] = node["flowers:mushroom_red"]
|
||||
write = true
|
||||
break
|
||||
elseif math.random(10) == 1 then
|
||||
elseif math_random(10) == 1 then
|
||||
data[ivm] = node["flowers:mushroom_brown"]
|
||||
write = true
|
||||
break
|
||||
elseif node_above == node["air"] and math.random(10) == 1 then
|
||||
elseif node_above == node["air"] and math_random(10) == 1 then
|
||||
data[ivm] = node["fun_caves:giant_mushroom_stem"]
|
||||
write = true
|
||||
break
|
||||
elseif math.random(30) == 1 then
|
||||
elseif math_random(30) == 1 then
|
||||
local air_count = 0
|
||||
local j
|
||||
for i = 1, 12 do
|
||||
|
@ -253,7 +260,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
end
|
||||
end
|
||||
if air_count > 5 then
|
||||
fun_caves.make_fungal_tree(data, area, ivm, math.random(2, math.min(air_count, 12)))
|
||||
fun_caves.make_fungal_tree(data, area, ivm, math_random(2, math_min(air_count, 12)))
|
||||
end
|
||||
end
|
||||
elseif node_below == node["fun_caves:giant_mushroom_stem"] and data[ivm - area.ystride * 2] == node["fun_caves:giant_mushroom_stem"] then
|
||||
|
@ -261,7 +268,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
write = true
|
||||
break
|
||||
elseif node_below == node["fun_caves:giant_mushroom_stem"] then
|
||||
if node_above == node["air"] and math.random(3) == 1 then
|
||||
if node_above == node["air"] and math_random(3) == 1 then
|
||||
data[ivm] = node["fun_caves:giant_mushroom_stem"]
|
||||
write = true
|
||||
break
|
||||
|
@ -299,20 +306,20 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
local node_below = data[ivm - area.ystride]
|
||||
local node_above = data[ivm + area.ystride]
|
||||
|
||||
if y < water_level and data[ivm] == node["default:sand"] and node_above == node["default:water_source"] and data[ivm + area.ystride * 2] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math.random(5) == 1 and fun_caves.surround(node, data, area, ivm) then
|
||||
if math.random(100) == 1 then
|
||||
if y < water_level and data[ivm] == node["default:sand"] and node_above == node["default:water_source"] and data[ivm + area.ystride * 2] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math_random(5) == 1 and fun_caves.surround(node, data, area, ivm) then
|
||||
if math_random(100) == 1 then
|
||||
data[ivm] = node["fun_caves:precious_coral_water_sand"]
|
||||
else
|
||||
data[ivm] = node["fun_caves:staghorn_coral_water_sand"]
|
||||
end
|
||||
write = true
|
||||
break
|
||||
elseif y < water_level and node_below == node["default:sand"] and node_above == node["default:water_source"] and data[ivm] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math.random(5) < 3 then
|
||||
if math.random(15) == 1 then
|
||||
elseif y < water_level and node_below == node["default:sand"] and node_above == node["default:water_source"] and data[ivm] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math_random(5) < 3 then
|
||||
if math_random(15) == 1 then
|
||||
data[ivm] = node["fun_caves:brain_coral"]
|
||||
write = true
|
||||
break
|
||||
elseif math.random(15) == 1 then
|
||||
elseif math_random(15) == 1 then
|
||||
data[ivm] = node["fun_caves:dragon_eye"]
|
||||
write = true
|
||||
break
|
||||
|
@ -340,7 +347,10 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
-- against a given node (or nodes). However, it's slow.
|
||||
-- To speed it up, we cache the results for each plant
|
||||
-- on each node, and avoid calling find_nodes every time.
|
||||
local posm, count = minetest.find_nodes_in_area({x=x, y=y, z=z}, {x=x, y=y, z=z}, desc.place_on)
|
||||
pos.x = x
|
||||
pos.y = y
|
||||
pos.z = z
|
||||
local posm, count = minetest.find_nodes_in_area(pos, pos, desc.place_on)
|
||||
if #posm > 0 then
|
||||
node_match_cache[desc.content_id][data[ivm]] = "good"
|
||||
else
|
||||
|
@ -348,14 +358,14 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
|
|||
end
|
||||
end
|
||||
|
||||
if node_match_cache[desc.content_id][data[ivm]] == "good" and desc.fill_ratio and (not desc.biomes or (biome and desc.biomes and table.contains(desc.biomes, biome))) and math.random() <= desc.fill_ratio then
|
||||
if node_match_cache[desc.content_id][data[ivm]] == "good" and desc.fill_ratio and (not desc.biomes or (biome and desc.biomes and table.contains(desc.biomes, biome))) and math_random() <= desc.fill_ratio then
|
||||
data[ivm] = desc.content_id
|
||||
write = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif y > minp.y and node_below == node["default:river_water_source"] and data[ivm] == node["air"] and water_lily_biomes[biome] and pn > 0.5 and math.random(water_lily_ratio) == 1 then
|
||||
elseif y > minp.y and node_below == node["default:river_water_source"] and data[ivm] == node["air"] and water_lily_biomes[biome] and pn > 0.5 and math_random(water_lily_ratio) == 1 then
|
||||
-- on top of the water
|
||||
-- I haven't figured out what the decoration manager is
|
||||
-- doing with the noise functions, but this works ok.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue