2014-12-29 20:16:14 +01:00
|
|
|
--
|
|
|
|
-- layer generator
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_generated(function(minp, maxp, seed)
|
2015-02-08 16:58:57 +01:00
|
|
|
stone_ctx= minetest.get_content_id("default:stone")
|
|
|
|
air_ctx= minetest.get_content_id("air")
|
2014-12-29 20:16:14 +01:00
|
|
|
local timebefore=os.clock();
|
|
|
|
local manipulator, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
|
|
|
local nodes = manipulator:get_data()
|
|
|
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
2015-02-08 16:58:57 +01:00
|
|
|
local side_length = (maxp.x - minp.x) + 1
|
|
|
|
local map_lengths_xyz = {x=side_length, y=side_length, z=side_length}
|
|
|
|
|
|
|
|
-- sort out unused layers
|
|
|
|
-- generate noises
|
|
|
|
avl={}
|
|
|
|
for i,d in ipairs(rocks.layers) do
|
|
|
|
-- h je normaalna vyyska horného konca vrstvy
|
|
|
|
if (d.height+d.gain)>=minp.y then -- ak je to mimo zdola tak ju vyhodime
|
|
|
|
-- urobime sum pre vrstvu
|
|
|
|
local np=rocks.noiseparams_layers
|
|
|
|
np.seed=d.seed
|
|
|
|
np.scale=d.gain
|
|
|
|
np.offset=d.height
|
|
|
|
d.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z})
|
|
|
|
-- contene_id kamenov
|
|
|
|
d.rock.ctx=d.rock.ctx or minetest.get_content_id(d.rock.node)
|
2015-02-08 21:20:07 +01:00
|
|
|
-- veiny
|
|
|
|
local veinstodo={}
|
|
|
|
for veinname,vd in pairs(d.veins) do
|
|
|
|
-- todo: do not generate noise for blocks outside the layer
|
|
|
|
veinstodo[veinname]=vd
|
|
|
|
end
|
|
|
|
for veinname,vd in pairs(veinstodo) do
|
|
|
|
-- noise pre vein
|
|
|
|
np=vd.np
|
|
|
|
vd.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get3dMap_flat(minp)
|
2015-02-08 21:32:25 +01:00
|
|
|
vd.prng=PseudoRandom(np.seed)
|
2015-02-08 21:20:07 +01:00
|
|
|
vd.sum=0
|
|
|
|
for i,ore in pairs(vd.ores) do
|
|
|
|
-- contntid pre rudu
|
|
|
|
ore.ctx=ore.ctx or minetest.get_content_id(ore.node)
|
|
|
|
-- sum sanci pre vein
|
|
|
|
vd.sum=vd.sum+ore.chance
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(avl,d) -- pridame vrstvu
|
2015-02-08 16:58:57 +01:00
|
|
|
if (d.height-d.gain)>maxp.y then break end -- ak je mimo zhora tak uz dalsie nehladaj
|
|
|
|
else
|
2015-02-08 17:14:01 +01:00
|
|
|
--print(" no higher "..d.height.." than "..minp.y)
|
2015-02-08 16:58:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-29 20:16:14 +01:00
|
|
|
--
|
2015-02-08 21:20:07 +01:00
|
|
|
print("[rocks] gen2 "..os.clock()-timebefore.." #layers="..#avl.." minp.y="..minp.y.." maxp.y"..maxp.y)
|
2015-02-08 16:58:57 +01:00
|
|
|
for lh,ld in ipairs(avl) do
|
2015-02-08 21:20:07 +01:00
|
|
|
print(" "..lh.."->"..ld.name.." top="..ld.height)
|
|
|
|
for vn,vd in pairs(ld.veins) do
|
|
|
|
print(" "..vn.."->"..#vd.ores)
|
|
|
|
end
|
2015-02-08 16:58:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local noise2d_ix = 1
|
|
|
|
local noise3d_ix = 1
|
|
|
|
|
2015-02-08 21:20:07 +01:00
|
|
|
for z=minp.z,maxp.z,1 do
|
|
|
|
for y=minp.y,maxp.y,1 do
|
|
|
|
for x=minp.x,maxp.x,1 do
|
2014-12-29 21:47:55 +01:00
|
|
|
local p_pos = area:index(x, y, z)
|
2015-02-08 21:20:07 +01:00
|
|
|
local layer,vein
|
|
|
|
local rock
|
2014-12-29 21:47:55 +01:00
|
|
|
|
2014-12-29 20:16:14 +01:00
|
|
|
--* select layer
|
2015-02-08 16:58:57 +01:00
|
|
|
for lh,ld in ipairs(avl) do
|
2015-02-08 21:20:07 +01:00
|
|
|
if (y<ld.nmap[noise2d_ix])and(ld.nmap[noise2d_ix]<ld.limit) then
|
2014-12-29 20:16:14 +01:00
|
|
|
layer=ld
|
2015-02-08 16:58:57 +01:00
|
|
|
rock=layer.rock
|
|
|
|
break
|
2014-12-29 20:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-08 21:20:07 +01:00
|
|
|
if layer then
|
|
|
|
--* select vein
|
|
|
|
for veinname,vd in pairs(layer.veins) do
|
|
|
|
if vd.nmap[noise3d_ix]>vd.treshold then
|
|
|
|
vein=vd
|
|
|
|
--rock not changed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if vein then
|
|
|
|
--* select ore
|
2015-02-08 21:32:25 +01:00
|
|
|
local chance=vein.prng:next(0,vein.sum)
|
2015-02-08 21:20:07 +01:00
|
|
|
for i,ore in pairs(vein.ores) do
|
2015-02-08 21:32:25 +01:00
|
|
|
chance=chance-ore.chance
|
|
|
|
if chance<=0 then
|
|
|
|
rock=ore
|
|
|
|
break
|
|
|
|
end
|
2015-02-08 21:20:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-29 20:16:14 +01:00
|
|
|
--* place rocks
|
2014-12-29 21:47:55 +01:00
|
|
|
if (rock) and(nodes[p_pos]==stone_ctx) then
|
2014-12-29 20:16:14 +01:00
|
|
|
nodes[p_pos] = rock.ctx
|
|
|
|
end
|
2014-12-29 21:47:55 +01:00
|
|
|
|
2015-02-08 16:58:57 +01:00
|
|
|
noise3d_ix =noise3d_ix+1
|
2015-02-08 21:20:07 +01:00
|
|
|
noise2d_ix = noise2d_ix+1
|
2015-02-08 16:58:57 +01:00
|
|
|
end
|
2015-02-08 21:20:07 +01:00
|
|
|
noise2d_ix = noise2d_ix-side_length
|
2014-12-29 20:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
manipulator:set_data(nodes)
|
2015-02-08 21:32:25 +01:00
|
|
|
--manipulator:calc_lighting()
|
|
|
|
--manipulator:set_lighting({day=15,night=15})
|
|
|
|
--manipulator:update_liquids()
|
2014-12-29 20:16:14 +01:00
|
|
|
manipulator:write_to_map()
|
2015-02-08 21:20:07 +01:00
|
|
|
print("[rocks] gen0 "..os.clock()-timebefore)
|
2014-12-29 20:16:14 +01:00
|
|
|
end)
|
2015-01-10 16:05:32 +01:00
|
|
|
|