1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-12-27 11:45:18 +01:00

[riesenpilz] Update

- For #352
This commit is contained in:
LeMagnesium
2015-12-31 13:43:25 +01:00
parent 8eebd39db8
commit ee352dbc60
57 changed files with 314 additions and 206 deletions

View File

@@ -1,3 +1,5 @@
local minetest = minetest --Should make things a bit faster.
local c
local function define_contents()
c = {
@@ -74,15 +76,25 @@ local function say_info(info)
minetest.chat_send_all(info)
end
local riesenpilz_rarity = riesenpilz.mapgen_rarity
local riesenpilz_size = riesenpilz.mapgen_size
local smooth_trans_size = riesenpilz.smooth_trans_size
-- perlin noise "hills" are not peaks but looking like sinus curve
local function upper_rarity(rarity)
return math.sign(rarity)*math.sin(math.abs(rarity)*math.pi/2)
end
local nosmooth_rarity = 1-riesenpilz_rarity/50
local perlin_scale = riesenpilz_size*100/riesenpilz_rarity
local smooth_rarity_max = nosmooth_rarity+smooth_trans_size*2/perlin_scale
local smooth_rarity_min = nosmooth_rarity-smooth_trans_size/perlin_scale
local smooth_rarity_dif = smooth_rarity_max-smooth_rarity_min
local rarity = riesenpilz.mapgen_rarity
local riesenpilz_size = riesenpilz.mapgen_size
local nosmooth_rarity = 1-rarity/50
local perlin_scale = riesenpilz_size*100/rarity
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
local smooth = riesenpilz.smooth
if smooth then
local smooth_trans_size = riesenpilz.smooth_trans_size
smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
smooth_rarity_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale)
smooth_rarity_dif = smooth_rarity_max-smooth_rarity_min
end
nosmooth_rarity = upper_rarity(nosmooth_rarity)
--local USUAL_STUFF = {"default:leaves","default:apple","default:tree","default:cactus","default:papyrus"}
@@ -94,8 +106,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
local x0,z0,x1,z1 = minp.x,minp.z,maxp.x,maxp.z -- Assume X and Z lengths are equal
local env = minetest.env --Should make things a bit faster.
local perlin1 = env:get_perlin(51,3, 0.5, perlin_scale) --Get map specific perlin
local perlin1 = minetest.get_perlin(51,3, 0.5, perlin_scale) --Get map specific perlin
if not riesenpilz.always_generate then
local biome_allowed
@@ -115,23 +126,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
end
--[[if not (perlin1:get2d({x=x0, y=z0}) > 0.53) and not (perlin1:get2d({x=x1, y=z1}) > 0.53)
and not (perlin1:get2d({x=x0, y=z1}) > 0.53) and not (perlin1:get2d({x=x1, y=z0}) > 0.53)
and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > 0.53) then
if not riesenpilz.always_generate
and not ( perlin1:get2d( {x=x0, y=z0} ) > nosmooth_rarity ) --top left
and not ( perlin1:get2d( { x = x0 + ( (x1-x0)/2), y=z0 } ) > nosmooth_rarity )--top middle
and not (perlin1:get2d({x=x1, y=z1}) > nosmooth_rarity) --bottom right
and not (perlin1:get2d({x=x1, y=z0+((z1-z0)/2)}) > nosmooth_rarity) --right middle
and not (perlin1:get2d({x=x0, y=z1}) > nosmooth_rarity) --bottom left
and not (perlin1:get2d({x=x1, y=z0}) > nosmooth_rarity) --top right
and not (perlin1:get2d({x=x0+((x1-x0)/2), y=z1}) > nosmooth_rarity) --left middle
and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > nosmooth_rarity) --middle
and not (perlin1:get2d({x=x0, y=z1+((z1-z0)/2)}) > nosmooth_rarity) then --bottom middle
return
end]]
local t1 = os.clock()
riesenpilz.inform("tries to generate a giant mushroom biome at: x=["..minp.x.."; "..maxp.x.."]; y=["..minp.y.."; "..maxp.y.."]; z=["..minp.z.."; "..maxp.z.."]", 2)
@@ -145,6 +139,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
local tab = {}
pr = PseudoRandom(seed+68)
local heightmap = minetest.get_mapgen_object("heightmap")
local hmi = 1
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
data = vm:get_data()
area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
@@ -158,14 +155,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
end
end
--[[remove usual stuff
local trees = env:find_nodes_in_area(minp, maxp, USUAL_STUFF)
for i,v in pairs(trees) do
env:remove_node(v)
end]]
local smooth = riesenpilz.smooth
for j=0,divs do
for i=0,divs do
@@ -185,31 +174,43 @@ minetest.register_on_generated(function(minp, maxp, seed)
) then
in_biome = true
end
elseif (not smooth)
and test > nosmooth_rarity then
elseif test > nosmooth_rarity then
in_biome = true
end
if in_biome then
local ground_y = nil --Definition des Bodens:
-- for y=maxp.y,0,-1 do
for y=maxp.y,1,-1 do
local p_pos = area:index(x, y, z)
local d_p_pos = data[p_pos]
for _,nam in pairs(c.USUAL_STUFF) do --remove usual stuff
if d_p_pos == nam then
data[p_pos] = c.air
p_pos = nil
break
end
end
if p_pos --else search ground_y
and find_ground(d_p_pos, c.GROUND) then
ground_y = y
local ymin = math.max(heightmap[hmi]-5, minp.y) -- -1
-- skip the air part
local ground
for y = math.min(heightmap[hmi]+20, maxp.y),ymin,-1 do
if data[area:index(x, y, z)] ~= c.air then
ground = y
break
end
end
local ground_y
if ground then
for y = ground,ymin,-1 do
local p_pos = area:index(x, y, z)
local d_p_pos = data[p_pos]
for _,nam in pairs(c.USUAL_STUFF) do --remove usual stuff
if d_p_pos == nam then
data[p_pos] = c.air
p_pos = nil
break
end
end
if p_pos --else search ground_y
and find_ground(d_p_pos, c.GROUND) then
ground_y = y
break
end
end
end
if ground_y then
data[area:index(x, ground_y, z)] = c.ground
for i = -1,-5,-1 do
@@ -220,6 +221,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
break
end
end
local bigtype
local boden = {x=x,y=ground_y+1,z=z}
if pr:next(1,15) == 1 then
data[area:index(x, ground_y+1, z)] = c.dry_shrub
@@ -231,28 +233,32 @@ minetest.register_on_generated(function(minp, maxp, seed)
riesenpilz_circle(c.riesenpilz_red, boden, pr:next(4,5), 3)
elseif pr:next(1,100) == 1 then
riesenpilz_circle(c.riesenpilz_fly_agaric, boden, 4, 3)
elseif pr:next(1,340) == 10 then
bigtype = 2
elseif pr:next(1,380) == 1 then
bigtype = 1
elseif pr:next(1,390) == 20 then
bigtype = 3
elseif pr:next(1,800) == 7 then
bigtype = 5
elseif pr:next(1,4000) == 1 then
riesenpilz_circle(c.riesenpilz_lavashroom, boden, pr:next(5,6), 3)
elseif pr:next(1,5000) == 1 then
riesenpilz_circle(c.riesenpilz_glowshroom, boden, 3, 3)
elseif pr:next(1,380) == 1 then
tab[num] = {1, boden}
num = num+1
elseif pr:next(1,340) == 10 then
tab[num] = {2, boden}
num = num+1
elseif pr:next(1,390) == 20 then
tab[num] = {3, boden}
num = num+1
elseif pr:next(1,6000) == 2 and pr:next(1,200) == 15 then
tab[num] = {4, boden}
num = num+1
elseif pr:next(1,800) == 7 then
tab[num] = {5, boden}
elseif pr:next(1,6000) == 2 then
if pr:next(1,200) == 15 then
bigtype = 4
elseif pr:next(1,2000) == 54 then
bigtype = 6
end
end
if bigtype then
tab[num] = {bigtype, boden}
num = num+1
end
end
end
hmi = hmi+1
end
end
riesenpilz.inform("ground finished", 2, t1)
@@ -276,6 +282,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
riesenpilz.lavashroom(p, data, area)
elseif m == 5 then
riesenpilz.parasol(p, data, area)
elseif m == 6 then
riesenpilz.red45(p, data, area)
end
end
riesenpilz.inform("giant shrooms generated", 2, t2)
@@ -289,49 +297,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
vm:set_lighting({day=0, night=0})
vm:calc_lighting()
vm:write_to_map()
data = nil
area = nil
riesenpilz.inform("data set", 2, t2)
riesenpilz.inform("done", 1, t1)
end)
--[[ if maxp.y < -10 then
local x0,z0,x1,z1 = minp.x,minp.z,maxp.x,maxp.z -- Assume X and Z lengths are equal
local env = minetest.env --Should make things a bit faster.
local perlin1 = env:get_perlin(11,3, 0.5, 200) --Get map specific perlin
--[if not (perlin1:get2d({x=x0, y=z0}) > 0.53) and not (perlin1:get2d({x=x1, y=z1}) > 0.53)
and not (perlin1:get2d({x=x0, y=z1}) > 0.53) and not (perlin1:get2d({x=x1, y=z0}) > 0.53)
and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > 0.53) then]
if not ( perlin1:get2d( {x=x0, y=z0} ) > 0.53 ) --top left
and not ( perlin1:get2d( { x = x0 + ( (x1-x0)/2), y=z0 } ) > 0.53 )--top middle
and not (perlin1:get2d({x=x1, y=z1}) > 0.53) --bottom right
and not (perlin1:get2d({x=x1, y=z0+((z1-z0)/2)}) > 0.53) --right middle
and not (perlin1:get2d({x=x0, y=z1}) > 0.53) --bottom left
and not (perlin1:get2d({x=x1, y=z0}) > 0.53) --top right
and not (perlin1:get2d({x=x0+((x1-x0)/2), y=z1}) > 0.53) --left middle
and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > 0.53) --middle
and not (perlin1:get2d({x=x0, y=z1+((z1-z0)/2)}) > 0.53) then --bottom middle
print("abortriesenpilz")
return
end
local divs = (maxp.x-minp.x);
local pr = PseudoRandom(seed+68)
for j=0,divs do
for i=0,divs do
local x,z = x0+i,z0+j
for y=minp.y,maxp.y,1 do
local pos = {x=x, y=y, z=z}
if env:get_node(pos).name == "air"
and env:get_node({x=x, y=y-1, z=z}).name == "default:stone"
and pr:next(1,40) == 33
and env:find_node_near(pos, 4, "group:igniter")
and not env:find_node_near(pos, 3, "group:igniter") then
env:add_node(pos, {name="riesenpilz:lavashroom"})
end
end
end
end
end
end)]]