Mapgen improvement

This commit is contained in:
Unknown 2017-03-02 10:08:14 +01:00
parent 754e7a16da
commit 15eafe7030

View File

@ -9,9 +9,12 @@ local c_sand = minetest.get_content_id("default:sand")
local c_dirt = minetest.get_content_id("default:dirt")
local c_lawn = minetest.get_content_id("default:dirt_with_grass")
local stone_and_air_assoc = {[c_stone]=true,[c_air]=true} --associative array
--Makes a stratus of rocks
--name of the rock to generate
--c_wherein id of node to replace, for example minetest.get_content_id("default:stone")
--ca_ceilin associative array
--minp, maxp the corners of the map to be generated
--seed random seed
--stratus_chance inverse probability in a given radius 1:2, 1:3 etc
@ -38,7 +41,7 @@ local function generate_stratus(data, area, name, c_wherein, ca_ceilin, minp, ma
if blocks == 0 then
blocks = 1
end
minetest.log("info", string.format(" blocks: %d in vol: %d (%d,%d,%d)",
minetest.log("info", string.format(" blocks: %d in vol: %d (%d,%d,%d)",
blocks, volume, maxp.x-minp.x+1, y_max-y_min+1, maxp.z-minp.z+1))
for i = 1,blocks do
if pr:next(1,stratus_chance) == 1 then
@ -63,15 +66,8 @@ local function generate_stratus(data, area, name, c_wherein, ca_ceilin, minp, ma
end
local n = data[area:index(x0, y0, z0)]
local i = 0
--print(" upper node "..n)
local x
for _,v in ipairs(ca_ceilin) do
if n == v then
x = true
break
end
end
if x then
if ca_ceilin[n] then
-- search for the node to replace
--print(" Searching nodes to replace from "..dump(y0-1).." to "..dump(y_min))
local vi = area:index(x0, y0-1, z0)
@ -108,7 +104,7 @@ local function generate_stratus(data, area, name, c_wherein, ca_ceilin, minp, ma
--print("generate_ore done")
end
local function generate_claylike(data, varea, name, minp, maxp, seed, chance, minh, maxh, dirt)
local function generate_claylike(data, varea, name, minp, maxp, seed, chance, minh, maxh, needs_dirt)
if maxp.y >= maxh+1 and minp.y <= minh-1 then
local c_ore = minetest.get_content_id(name)
local pr = PseudoRandom(seed)
@ -124,8 +120,7 @@ local function generate_claylike(data, varea, name, minp, maxp, seed, chance, mi
local cz = minp.z + math.floor((divz+0.5)*divlen)
local up = data[varea:index(cx,yy,cz)]
local down = data[varea:index(cx,yy-1,cz)]
if ( up == c_water or up == c_air ) and ( down == c_sand or (dirt == 1 and (down == c_dirt or down == c_lawn ))) then
local is_shallow = true
if ( up == c_water or up == c_air ) and ( down == c_sand or (needs_dirt and (down == c_dirt or down == c_lawn ))) then
local num_water_around = 0
if data[varea:index(cx-divlen*2,yy,cz)] == c_water then
num_water_around = num_water_around + 1
@ -139,16 +134,13 @@ local function generate_claylike(data, varea, name, minp, maxp, seed, chance, mi
if data[varea:index(cx,yy,cz+divlen*2)] == c_water then
num_water_around = num_water_around + 1
end
if num_water_around >= 3 then
is_shallow = false
end
if is_shallow then
if num_water_around < 3 then
for x1=-divlen,divlen do
for z1=-divlen,divlen do
local p={x=cx+x1,y=yy-1,z=cz+z1}
down = data[varea:indexp(p)]
if down == c_sand or (dirt == 1 and (down == c_dirt or down == c_lawn)) then
data[varea:indexp(p)] = c_ore
local i = varea:index(cx+x1,yy-1,cz+z1)
local down = data[i]
if down == c_sand or (needs_dirt and (down == c_dirt or down == c_lawn)) then
data[i] = c_ore
end
end
end
@ -199,7 +191,7 @@ minetest.register_ore({
minetest.register_ore({
ore_type = "sheet",
ore = "darkage:tuff",
wherein = {"default:stone", "default:dirt", "default:gravel", "default:stone_with_coal"},
wherein = {"default:stone", "default:needs_dirt", "default:gravel", "default:stone_with_coal"},
column_height_max = 20,
column_height_min = 15,
y_min = -200,
@ -218,7 +210,7 @@ minetest.register_ore({
minetest.register_ore({
ore_type = "sheet",
ore = "darkage:rhyolitic_tuff",
wherein = {"default:stone", "default:dirt", "default:gravel", "default:stone_with_coal"},
wherein = {"default:stone", "default:needs_dirt", "default:gravel", "default:stone_with_coal"},
column_height_max = 20,
column_height_min = 15,
y_min = -2000,
@ -258,7 +250,7 @@ minetest.register_ore({
-- Generate strati
local dbuf --for mapgen
local function generate_strati(minp, maxp, seed)
local t1 = os.clock()
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
@ -266,43 +258,43 @@ local function generate_strati(minp, maxp, seed)
local data = vm:get_data(dbuf)
generate_claylike(data, area, "darkage:mud", minp, maxp, seed+1, 4, 0, 2, 0)
generate_claylike(data, area, "darkage:silt", minp, maxp, seed+2, 4, -1, 1, 1)
generate_claylike(data, area, "darkage:mud", minp, maxp, seed+1, 4, 0, 2, false)
generate_claylike(data, area, "darkage:silt", minp, maxp, seed+2, 4, -1, 1, true)
-- TODO: Maybe realize the following stuff with register ore. somehow.
generate_stratus(data, area, "darkage:shale",
c_stone,
{c_stone, c_air},
c_stone,
stone_and_air_assoc,
minp, maxp, seed+5, 4, 23, 7, 50, -50, 20)
generate_stratus(data, area, "darkage:slate",
c_stone,
{c_stone, c_air},
generate_stratus(data, area, "darkage:slate",
c_stone,
stone_and_air_assoc,
minp, maxp, seed+6, 6, 23, 5, 50, -500, 0)
generate_stratus(data, area, "darkage:schist",
c_stone,
{c_stone, c_air},
generate_stratus(data, area, "darkage:schist",
c_stone,
stone_and_air_assoc,
minp, maxp, seed+7, 6, 19, 6, 50, -31000, -10)
generate_stratus(data, area, "darkage:basalt",
c_stone,
{c_stone, c_air},
generate_stratus(data, area, "darkage:basalt",
c_stone,
stone_and_air_assoc,
minp, maxp, seed+8, 5, 20, 5, 20, -31000, -50)
generate_stratus(data, area, "darkage:marble",
generate_stratus(data, area, "darkage:marble",
c_stone,
{c_stone, c_air},
stone_and_air_assoc,
minp, maxp, seed+9, 4, 25, 6, 50, -31000, -75)
generate_stratus(data, area, "darkage:serpentine",
generate_stratus(data, area, "darkage:serpentine",
c_stone,
{c_stone, c_air},
stone_and_air_assoc,
minp, maxp, seed+10, 4, 28, 8, 50, -31000, -350)
generate_stratus(data, area, "darkage:gneiss",
c_stone,
{c_stone, c_air},
generate_stratus(data, area, "darkage:gneiss",
c_stone,
stone_and_air_assoc,
minp, maxp, seed+11, 4, 15, 5, 50, -31000, -250)
vm:set_data(data)