Unify dungeon API RNG
Avoid having to have each dungeon generation method manage its own RNG, which should save a lot of time on RNG seeding.
This commit is contained in:
parent
2e9d342110
commit
47d0b68dba
@ -24,9 +24,6 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
local mapperlin
|
||||
minetest.after(0, function() mapperlin = minetest.get_perlin(432, 1, 0, 1) end)
|
||||
|
||||
local function lootstack(pos, rng)
|
||||
local loot = nodecore.pickrand(loottable,
|
||||
function(t) return pos.y <= t.depth and t.prob or 0 end,
|
||||
@ -57,8 +54,7 @@ minetest.after(0, function()
|
||||
end
|
||||
end)
|
||||
|
||||
local function addloot(pos, height)
|
||||
local rng = nodecore.seeded_rng(mapperlin:get_3d(pos))
|
||||
local function addloot(pos, height, rng)
|
||||
if rng(1, 5) == 1 and #nodecore.find_nodes_around(pos, cobblist, {1, 0, 1}) > 0 then
|
||||
local max = nodecore.exporand(2, rng)
|
||||
if max < 1 then max = 1 elseif max > height then max = height end
|
||||
@ -77,27 +73,25 @@ end
|
||||
nodecore.register_dungeongen({
|
||||
label = "dungeon loot",
|
||||
priority = 100,
|
||||
func = function(pos)
|
||||
func = function(pos, _, rng)
|
||||
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
||||
if minetest.get_node(above).name ~= "air" then return end
|
||||
local rand = mapperlin:get_3d(pos)
|
||||
rand = rand - math_floor(rand)
|
||||
local prob = 0.1
|
||||
if pos.y < -128 then
|
||||
prob = prob * math_log(pos.y / -64) / math_log(2)
|
||||
end
|
||||
if rand > prob then return end
|
||||
if rng() > prob then return end
|
||||
for dy = 2, 8 do
|
||||
local p = {x = pos.x, y = pos.y + dy, z = pos.z}
|
||||
local nn = minetest.get_node(p).name
|
||||
if cobbles[nn] then
|
||||
return #nodecore.find_nodes_around(pos,
|
||||
{"air"}, {1, 0, 1}) > 0
|
||||
or addloot(above, dy - 2)
|
||||
or addloot(above, dy - 2, rng)
|
||||
end
|
||||
if nn ~= "air" then return end
|
||||
end
|
||||
if pos.y > -64 then return end
|
||||
addloot(above, 8)
|
||||
addloot(above, 8, rng)
|
||||
end
|
||||
})
|
||||
|
@ -5,9 +5,6 @@ local minetest, nodecore
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
|
||||
local mapperlin
|
||||
minetest.after(0, function() mapperlin = minetest.get_perlin(45821, 1, 0, 1) end)
|
||||
|
||||
function nodecore.dungeon_bricks()
|
||||
return {
|
||||
brick = modname .. ":bricks_stone",
|
||||
@ -18,8 +15,7 @@ end
|
||||
nodecore.register_dungeongen({
|
||||
label = "dungeon concrete/bricks",
|
||||
priority = -100,
|
||||
func = function(pos)
|
||||
local rng = nodecore.seeded_rng(mapperlin:get_3d(pos))
|
||||
func = function(pos, _, rng)
|
||||
local profile = nodecore.dungeon_bricks(pos, rng)
|
||||
if rng(1, 4) ~= 1 then
|
||||
return profile.fill and
|
||||
|
@ -41,10 +41,14 @@ function nodecore.register_dungeongen(def)
|
||||
table_insert(dungens, min, def)
|
||||
end
|
||||
|
||||
local mapperlin
|
||||
minetest.after(0, function() mapperlin = minetest.get_perlin(45821, 1, 0, 1) end)
|
||||
|
||||
local function dungeonprocess(pos, node)
|
||||
local rng = nodecore.seeded_rng(mapperlin:get_3d(pos))
|
||||
for _, def in ipairs(dungens) do
|
||||
if def.enabled ~= false then
|
||||
def.func(pos, node)
|
||||
def.func(pos, node, rng)
|
||||
if minetest.get_node(pos).name ~= node.name then return end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user