Add large craters.

This commit is contained in:
Duane 2016-07-21 03:07:36 -05:00
parent 212511b754
commit e9765fabfc
3 changed files with 54 additions and 6 deletions

View file

@ -43,14 +43,19 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
local write = false
local index = 0
local index3d = 0
local cave_width = fun_caves.cave_width
local styx_sea_level = fun_caves.underzones['Styx'].sealevel
local crater
if not underzone and math.random(10) == 1 then
crater = {
x = minp.x + math.random(math.floor(csize.x / 2)) + math.floor(csize.x / 4),
y = 15,
z = minp.z + math.random(math.floor(csize.z / 2)) + math.floor(csize.z / 4),
}
end
local crater_min = 33000
for z = minp.z, maxp.z do
for x = minp.x, maxp.x do
index = index + 1
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
local ivm = area:index(x, minp.y-1, z)
local height = heightmap[index]
if height and height < maxp.y - 1 and height > minp.y then
@ -68,6 +73,30 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
heightmap[index] = height
end
if crater then
local dist = crater.y - math.sqrt((x - crater.x) ^ 2 + (z - crater.z) ^ 2)
if dist > 0 and (height > maxp.y or height < minp.y + crater.y) then
crater = nil
end
if crater and dist > 0 and dist <= 1 and crater_min > height then
crater_min = height
end
end
end
end
index = 0
local index3d = 0
local cave_width = fun_caves.cave_width
local styx_sea_level = fun_caves.underzones['Styx'].sealevel
for z = minp.z, maxp.z do
for x = minp.x, maxp.x do
index = index + 1
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
local ivm = area:index(x, minp.y-1, z)
local height = heightmap[index]
local column = 0
if underzone then
if cave_3[index] < 30 then
@ -77,7 +106,21 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
end
end
local dist
if crater then
dist = crater.y - math.sqrt((x - crater.x) ^ 2 + (z - crater.z) ^ 2)
end
for y = minp.y-1, maxp.y+1 do
if crater and dist and dist > 0 then
if y > crater_min - 1.5 * dist and y < maxp.y - 1.5 * dist then
data[ivm] = data[ivm + (math.floor((height - crater_min) * dist / crater.y) + math.ceil(dist / 2)) * area.ystride]
end
if y > crater_min - dist and ground_nodes[data[ivm]] and math.random(300) == 1 then
data[ivm] = node['fun_caves:stone_with_meteoritic_iron']
end
end
if underzone and underzone.regular_columns and (x - minp.x) < 8 and (z - minp.z) < 8 then
data[ivm] = node[underzone.column_node]
write = true