forked from mtcontrib/darkage
Minor speed improovements
This commit is contained in:
parent
a7040140dc
commit
03b6237d9f
85
mapgen.lua
85
mapgen.lua
@ -1,24 +1,19 @@
|
|||||||
--Makes a stratus of rocks
|
--Makes a stratus of rocks
|
||||||
--name of the rock to generate
|
--name of the rock to generate
|
||||||
--wherein kind of node to replace, for example default:stone
|
--c_wherein id of node to replace, for example minetest.get_content_id("default:stone")
|
||||||
--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
|
||||||
--radius horizontal radius of the stratus
|
--radius horizontal radius of the stratus
|
||||||
--radius_y vertical radius of the stratus
|
--radius_y vertical radius of the stratus
|
||||||
--deep how deep can be from the ground
|
--deep how deep can be from the ground
|
||||||
local function generate_stratus(data, area, name, wherein, ceilin, minp, maxp, seed, stratus_chance, radius, radius_y, deep, y_min, y_max)
|
local function generate_stratus(data, area, name, c_wherein, ca_ceilin, minp, maxp, seed, stratus_chance, radius, radius_y, deep, y_min, y_max)
|
||||||
if maxp.y < y_min
|
if maxp.y < y_min
|
||||||
or minp.y > y_max then
|
or minp.y > y_max then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
name = minetest.get_content_id(name)
|
local c_node = minetest.get_content_id(name)
|
||||||
wherein = minetest.get_content_id(wherein[1])
|
|
||||||
ceilin = table.copy(ceilin)
|
|
||||||
for n,i in pairs(ceilin) do
|
|
||||||
ceilin[n] = minetest.get_content_id(i)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- it will be only generate a stratus for every 100 m of area
|
-- it will be only generate a stratus for every 100 m of area
|
||||||
local stratus_per_volume=1
|
local stratus_per_volume=1
|
||||||
@ -28,11 +23,12 @@ if maxp.y < y_min
|
|||||||
local volume = ((maxp.x-minp.x+1)/area_size)*((y_max-y_min+1)/area_size)*((maxp.z-minp.z+1)/area_size)
|
local volume = ((maxp.x-minp.x+1)/area_size)*((y_max-y_min+1)/area_size)*((maxp.z-minp.z+1)/area_size)
|
||||||
local pr = PseudoRandom(seed)
|
local pr = PseudoRandom(seed)
|
||||||
local blocks = math.floor(stratus_per_volume*volume)
|
local blocks = math.floor(stratus_per_volume*volume)
|
||||||
minetest.log("info", " <<"..dump(name)..">>");
|
minetest.log("info", " <<"..name..">>");
|
||||||
if blocks == 0 then
|
if blocks == 0 then
|
||||||
blocks = 1
|
blocks = 1
|
||||||
end
|
end
|
||||||
minetest.log("info", " blocks: "..dump(blocks).." in vol: "..dump(volume).." ("..dump(maxp.x-minp.x+1)..","..dump(y_max-y_min+1)..","..dump(maxp.z-minp.z+1)..")")
|
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
|
for i = 1,blocks do
|
||||||
if pr:next(1,stratus_chance) == 1 then
|
if pr:next(1,stratus_chance) == 1 then
|
||||||
-- TODO deep
|
-- TODO deep
|
||||||
@ -58,7 +54,7 @@ if maxp.y < y_min
|
|||||||
local i = 0
|
local i = 0
|
||||||
--print(" upper node "..n)
|
--print(" upper node "..n)
|
||||||
local x
|
local x
|
||||||
for _,v in ipairs(ceilin) do
|
for _,v in ipairs(ca_ceilin) do
|
||||||
if n == v then
|
if n == v then
|
||||||
x = true
|
x = true
|
||||||
break
|
break
|
||||||
@ -68,7 +64,7 @@ if maxp.y < y_min
|
|||||||
-- 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))
|
||||||
for y1 = y0-1,y_min,-1 do
|
for y1 = y0-1,y_min,-1 do
|
||||||
if data[area:index(x0, y1, z0)] == wherein then
|
if data[area:index(x0, y1, z0)] == c_wherein then
|
||||||
y0 = y1-deep
|
y0 = y1-deep
|
||||||
if y0 < y_min then
|
if y0 < y_min then
|
||||||
y0 = y_min
|
y0 = y_min
|
||||||
@ -89,8 +85,8 @@ if maxp.y < y_min
|
|||||||
local ry0 = ry + pr:next(1,3)
|
local ry0 = ry + pr:next(1,3)
|
||||||
for y1 = pr:next(1,3),ry0 do
|
for y1 = pr:next(1,3),ry0 do
|
||||||
local p2 = area:index(x0+x1, y0+y1, z0+z1)
|
local p2 = area:index(x0+x1, y0+y1, z0+z1)
|
||||||
if data[p2] == wherein then
|
if data[p2] == c_wherein then
|
||||||
data[p2] = name
|
data[p2] = c_node
|
||||||
i = i +1
|
i = i +1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -104,17 +100,17 @@ if maxp.y < y_min
|
|||||||
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, dirt)
|
||||||
local c_ore = minetest.get_content_id(name)
|
|
||||||
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 c_water = minetest.get_content_id("default:water_source")
|
|
||||||
local c_air = minetest.get_content_id("air")
|
|
||||||
|
|
||||||
if maxp.y >= maxh+1 and minp.y <= minh-1 then
|
if maxp.y >= maxh+1 and minp.y <= minh-1 then
|
||||||
local pr = PseudoRandom(seed)
|
local c_ore = minetest.get_content_id(name)
|
||||||
local divlen = 4
|
local c_sand = minetest.get_content_id("default:sand")
|
||||||
local divs = (maxp.x-minp.x)/divlen+1;
|
local c_dirt = minetest.get_content_id("default:dirt")
|
||||||
|
local c_lawn = minetest.get_content_id("default:dirt_with_grass")
|
||||||
|
local c_water = minetest.get_content_id("default:water_source")
|
||||||
|
local c_air = minetest.get_content_id("air")
|
||||||
|
|
||||||
|
local pr = PseudoRandom(seed)
|
||||||
|
local divlen = 4
|
||||||
|
local divs = (maxp.x-minp.x)/divlen+1;
|
||||||
for yy=minh,maxh do
|
for yy=minh,maxh do
|
||||||
local x = pr:next(1,chance)
|
local x = pr:next(1,chance)
|
||||||
if x == 1 then
|
if x == 1 then
|
||||||
@ -201,48 +197,53 @@ local function generate_strati(minp, maxp, seed)
|
|||||||
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
|
|
||||||
|
local c_air = minetest.get_content_id("air")
|
||||||
|
local c_stone = minetest.get_content_id("default:stone")
|
||||||
|
local c_water = minetest.get_content_id("default:water_source")
|
||||||
|
|
||||||
|
|
||||||
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, 0)
|
||||||
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, 1)
|
||||||
|
|
||||||
-- 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:ors",
|
generate_stratus(data, area, "darkage:ors",
|
||||||
{"default:stone"},
|
c_stone,
|
||||||
{"default:stone","air","default:water_source"},
|
{c_stone, c_air, c_water},
|
||||||
minp, maxp, seed+4, 4, 25, 7, 50, -200, 500)
|
minp, maxp, seed+4, 4, 25, 7, 50, -200, 500)
|
||||||
|
|
||||||
generate_stratus(data, area, "darkage:shale",
|
generate_stratus(data, area, "darkage:shale",
|
||||||
{"default:stone"},
|
c_stone,
|
||||||
{"default:stone","air"},
|
{c_stone, c_air},
|
||||||
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",
|
||||||
{"default:stone"},
|
c_stone,
|
||||||
{"default:stone","air"},
|
{c_stone, c_air},
|
||||||
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",
|
||||||
{"default:stone"},
|
c_stone,
|
||||||
{"default:stone","air"},
|
{c_stone, c_air},
|
||||||
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",
|
||||||
{"default:stone"},
|
c_stone,
|
||||||
{"default:stone","air"},
|
{c_stone, c_air},
|
||||||
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",
|
||||||
{"default:stone"},
|
c_stone,
|
||||||
{"default:stone","air"},
|
{c_stone, c_air},
|
||||||
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",
|
||||||
{"default:stone"},
|
c_stone,
|
||||||
{"default:stone","air"},
|
{c_stone, c_air},
|
||||||
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",
|
||||||
{"default:stone"},
|
c_stone,
|
||||||
{"default:stone","air"},
|
{c_stone, c_air},
|
||||||
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