mirror of
https://github.com/adrido/darkage.git
synced 2025-01-09 17:30:19 +01:00
Mapgen improvement
This commit is contained in:
parent
754e7a16da
commit
15eafe7030
54
mapgen.lua
54
mapgen.lua
@ -9,9 +9,12 @@ local c_sand = minetest.get_content_id("default:sand")
|
|||||||
local c_dirt = minetest.get_content_id("default:dirt")
|
local c_dirt = minetest.get_content_id("default:dirt")
|
||||||
local c_lawn = minetest.get_content_id("default:dirt_with_grass")
|
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
|
--Makes a stratus of rocks
|
||||||
--name of the rock to generate
|
--name of the rock to generate
|
||||||
--c_wherein id of node to replace, for example minetest.get_content_id("default:stone")
|
--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
|
--minp, maxp the corners of the map to be generated
|
||||||
--seed random seed
|
--seed random seed
|
||||||
--stratus_chance inverse probability in a given radius 1:2, 1:3 etc
|
--stratus_chance inverse probability in a given radius 1:2, 1:3 etc
|
||||||
@ -63,15 +66,8 @@ local function generate_stratus(data, area, name, c_wherein, ca_ceilin, minp, ma
|
|||||||
end
|
end
|
||||||
local n = data[area:index(x0, y0, z0)]
|
local n = data[area:index(x0, y0, z0)]
|
||||||
local i = 0
|
local i = 0
|
||||||
--print(" upper node "..n)
|
|
||||||
local x
|
if ca_ceilin[n] then
|
||||||
for _,v in ipairs(ca_ceilin) do
|
|
||||||
if n == v then
|
|
||||||
x = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if x then
|
|
||||||
-- search for the node to replace
|
-- search for the node to replace
|
||||||
--print(" Searching nodes to replace from "..dump(y0-1).." to "..dump(y_min))
|
--print(" Searching nodes to replace from "..dump(y0-1).." to "..dump(y_min))
|
||||||
local vi = area:index(x0, y0-1, z0)
|
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")
|
--print("generate_ore done")
|
||||||
end
|
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
|
if maxp.y >= maxh+1 and minp.y <= minh-1 then
|
||||||
local c_ore = minetest.get_content_id(name)
|
local c_ore = minetest.get_content_id(name)
|
||||||
local pr = PseudoRandom(seed)
|
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 cz = minp.z + math.floor((divz+0.5)*divlen)
|
||||||
local up = data[varea:index(cx,yy,cz)]
|
local up = data[varea:index(cx,yy,cz)]
|
||||||
local down = data[varea:index(cx,yy-1,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
|
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 is_shallow = true
|
|
||||||
local num_water_around = 0
|
local num_water_around = 0
|
||||||
if data[varea:index(cx-divlen*2,yy,cz)] == c_water then
|
if data[varea:index(cx-divlen*2,yy,cz)] == c_water then
|
||||||
num_water_around = num_water_around + 1
|
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
|
if data[varea:index(cx,yy,cz+divlen*2)] == c_water then
|
||||||
num_water_around = num_water_around + 1
|
num_water_around = num_water_around + 1
|
||||||
end
|
end
|
||||||
if num_water_around >= 3 then
|
if num_water_around < 3 then
|
||||||
is_shallow = false
|
|
||||||
end
|
|
||||||
if is_shallow then
|
|
||||||
for x1=-divlen,divlen do
|
for x1=-divlen,divlen do
|
||||||
for z1=-divlen,divlen do
|
for z1=-divlen,divlen do
|
||||||
local p={x=cx+x1,y=yy-1,z=cz+z1}
|
local i = varea:index(cx+x1,yy-1,cz+z1)
|
||||||
down = data[varea:indexp(p)]
|
local down = data[i]
|
||||||
if down == c_sand or (dirt == 1 and (down == c_dirt or down == c_lawn)) then
|
if down == c_sand or (needs_dirt and (down == c_dirt or down == c_lawn)) then
|
||||||
data[varea:indexp(p)] = c_ore
|
data[i] = c_ore
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -199,7 +191,7 @@ minetest.register_ore({
|
|||||||
minetest.register_ore({
|
minetest.register_ore({
|
||||||
ore_type = "sheet",
|
ore_type = "sheet",
|
||||||
ore = "darkage:tuff",
|
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_max = 20,
|
||||||
column_height_min = 15,
|
column_height_min = 15,
|
||||||
y_min = -200,
|
y_min = -200,
|
||||||
@ -218,7 +210,7 @@ minetest.register_ore({
|
|||||||
minetest.register_ore({
|
minetest.register_ore({
|
||||||
ore_type = "sheet",
|
ore_type = "sheet",
|
||||||
ore = "darkage:rhyolitic_tuff",
|
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_max = 20,
|
||||||
column_height_min = 15,
|
column_height_min = 15,
|
||||||
y_min = -2000,
|
y_min = -2000,
|
||||||
@ -266,43 +258,43 @@ local function generate_strati(minp, maxp, seed)
|
|||||||
local data = vm:get_data(dbuf)
|
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:mud", minp, maxp, seed+1, 4, 0, 2, false)
|
||||||
generate_claylike(data, area, "darkage:silt", minp, maxp, seed+2, 4, -1, 1, 1)
|
generate_claylike(data, area, "darkage:silt", minp, maxp, seed+2, 4, -1, 1, true)
|
||||||
|
|
||||||
-- TODO: Maybe realize the following stuff with register ore. somehow.
|
-- TODO: Maybe realize the following stuff with register ore. somehow.
|
||||||
generate_stratus(data, area, "darkage:shale",
|
generate_stratus(data, area, "darkage:shale",
|
||||||
c_stone,
|
c_stone,
|
||||||
{c_stone, c_air},
|
stone_and_air_assoc,
|
||||||
minp, maxp, seed+5, 4, 23, 7, 50, -50, 20)
|
minp, maxp, seed+5, 4, 23, 7, 50, -50, 20)
|
||||||
|
|
||||||
generate_stratus(data, area, "darkage:slate",
|
generate_stratus(data, area, "darkage:slate",
|
||||||
c_stone,
|
c_stone,
|
||||||
{c_stone, c_air},
|
stone_and_air_assoc,
|
||||||
minp, maxp, seed+6, 6, 23, 5, 50, -500, 0)
|
minp, maxp, seed+6, 6, 23, 5, 50, -500, 0)
|
||||||
|
|
||||||
generate_stratus(data, area, "darkage:schist",
|
generate_stratus(data, area, "darkage:schist",
|
||||||
c_stone,
|
c_stone,
|
||||||
{c_stone, c_air},
|
stone_and_air_assoc,
|
||||||
minp, maxp, seed+7, 6, 19, 6, 50, -31000, -10)
|
minp, maxp, seed+7, 6, 19, 6, 50, -31000, -10)
|
||||||
|
|
||||||
generate_stratus(data, area, "darkage:basalt",
|
generate_stratus(data, area, "darkage:basalt",
|
||||||
c_stone,
|
c_stone,
|
||||||
{c_stone, c_air},
|
stone_and_air_assoc,
|
||||||
minp, maxp, seed+8, 5, 20, 5, 20, -31000, -50)
|
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_stone, c_air},
|
stone_and_air_assoc,
|
||||||
minp, maxp, seed+9, 4, 25, 6, 50, -31000, -75)
|
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_stone, c_air},
|
stone_and_air_assoc,
|
||||||
minp, maxp, seed+10, 4, 28, 8, 50, -31000, -350)
|
minp, maxp, seed+10, 4, 28, 8, 50, -31000, -350)
|
||||||
|
|
||||||
generate_stratus(data, area, "darkage:gneiss",
|
generate_stratus(data, area, "darkage:gneiss",
|
||||||
c_stone,
|
c_stone,
|
||||||
{c_stone, c_air},
|
stone_and_air_assoc,
|
||||||
minp, maxp, seed+11, 4, 15, 5, 50, -31000, -250)
|
minp, maxp, seed+11, 4, 15, 5, 50, -31000, -250)
|
||||||
|
|
||||||
vm:set_data(data)
|
vm:set_data(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user