Refactor mcl_dungeons

This commit is contained in:
Wuzzy 2017-05-24 12:15:20 +02:00
parent 4625d2e8f8
commit 99a54319b1
1 changed files with 29 additions and 26 deletions

View File

@ -153,31 +153,34 @@ minetest.register_on_generated(function(minp, maxp)
end end
-- Check conditions. If okay, start generating -- Check conditions. If okay, start generating
-- But prepare random chest positions beforehand
-- We assign each position at the wall a number and each chest gets one of these numbers randomly
local totalChests = 2
local totalChestSlots = (dim.x-1) * (dim.z-1)
local chestSlots = {}
-- There is a small chance that both chests have the same slot.
-- In that case, we give a 2nd chance for the 2nd chest to get spawned.
-- If it failed again, tough luck! We stick with only 1 chest spawned.
local lastRandom
local secondChance = true -- second chance is still available
for i=1, totalChests do
local r = math.random(1, totalChestSlots)
if r == lastRandom and secondChance then
-- Oops! Same slot selected. Try again.
r = math.random(1, totalChestSlots)
secondChance = false
end
lastRandom = r
table.insert(chestSlots, r)
end
table.sort(chestSlots)
local currentChest = 1
if ceilingfloor_ok and openings >= 1 and openings <= 5 then if ceilingfloor_ok and openings >= 1 and openings <= 5 then
-- Okay! Spawning starts!
-- First prepare random chest positions.
-- Chests spawn at wall
-- We assign each position at the wall a number and each chest gets one of these numbers randomly
local totalChests = 2
local totalChestSlots = (dim.x-1) * (dim.z-1)
local chestSlots = {}
-- There is a small chance that both chests have the same slot.
-- In that case, we give a 2nd chance for the 2nd chest to get spawned.
-- If it failed again, tough luck! We stick with only 1 chest spawned.
local lastRandom
local secondChance = true -- second chance is still available
for i=1, totalChests do
local r = math.random(1, totalChestSlots)
if r == lastRandom and secondChance then
-- Oops! Same slot selected. Try again.
r = math.random(1, totalChestSlots)
secondChance = false
end
lastRandom = r
table.insert(chestSlots, r)
end
table.sort(chestSlots)
local currentChest = 1
-- Ceiling and floor -- Ceiling and floor
local maxx, maxy, maxz = x+dim.x+1, y+dim.y+1, z+dim.z+1 local maxx, maxy, maxz = x+dim.x+1, y+dim.y+1, z+dim.z+1
local chestSlotCounter = 1 local chestSlotCounter = 1