2014-08-11 15:17:58 +02:00
|
|
|
local c
|
|
|
|
local function define_contents()
|
|
|
|
c = {
|
2015-05-27 12:18:16 +02:00
|
|
|
ignore = minetest.get_content_id("ignore"),
|
2014-08-11 15:17:58 +02:00
|
|
|
air = minetest.get_content_id("air"),
|
2015-05-27 12:18:16 +02:00
|
|
|
|
2014-08-11 15:17:58 +02:00
|
|
|
stone = minetest.get_content_id("default:stone"),
|
|
|
|
dirt = minetest.get_content_id("default:dirt"),
|
|
|
|
desert_sand = minetest.get_content_id("default:desert_sand"),
|
2013-08-23 17:34:54 +02:00
|
|
|
|
2014-08-11 15:17:58 +02:00
|
|
|
dry_shrub = minetest.get_content_id("default:dry_shrub"),
|
2013-08-23 17:34:54 +02:00
|
|
|
|
2014-08-11 15:17:58 +02:00
|
|
|
ground = minetest.get_content_id("riesenpilz:ground"),
|
|
|
|
riesenpilz_brown = minetest.get_content_id("riesenpilz:brown"),
|
|
|
|
riesenpilz_red = minetest.get_content_id("riesenpilz:red"),
|
|
|
|
riesenpilz_fly_agaric = minetest.get_content_id("riesenpilz:fly_agaric"),
|
|
|
|
riesenpilz_lavashroom = minetest.get_content_id("riesenpilz:lavashroom"),
|
|
|
|
riesenpilz_glowshroom = minetest.get_content_id("riesenpilz:glowshroom"),
|
|
|
|
riesenpilz_parasol = minetest.get_content_id("riesenpilz:parasol"),
|
|
|
|
|
|
|
|
GROUND = {},
|
|
|
|
TREE_STUFF = {
|
|
|
|
minetest.get_content_id("default:tree"),
|
|
|
|
minetest.get_content_id("default:leaves"),
|
|
|
|
minetest.get_content_id("default:apple"),
|
|
|
|
minetest.get_content_id("default:jungletree"),
|
|
|
|
minetest.get_content_id("default:jungleleaves"),
|
|
|
|
minetest.get_content_id("default:junglegrass"),
|
|
|
|
},
|
|
|
|
USUAL_STUFF = {
|
|
|
|
minetest.get_content_id("default:cactus"),
|
|
|
|
minetest.get_content_id("default:papyrus"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for name,data in pairs(minetest.registered_nodes) do
|
|
|
|
local groups = data.groups
|
|
|
|
if groups then
|
|
|
|
if groups.crumbly == 3
|
|
|
|
or groups.soil == 1 then
|
|
|
|
table.insert(c.GROUND, minetest.get_content_id(name))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-08-23 17:34:54 +02:00
|
|
|
|
|
|
|
|
2014-12-05 23:52:55 +01:00
|
|
|
local function find_ground(a,list)
|
2015-05-27 12:18:16 +02:00
|
|
|
for i = 1,#list do
|
|
|
|
if a == list[i] then
|
2013-08-23 17:34:54 +02:00
|
|
|
return true
|
2013-05-10 20:08:50 +02:00
|
|
|
end
|
|
|
|
end
|
2013-08-23 17:34:54 +02:00
|
|
|
return false
|
2013-05-10 20:08:50 +02:00
|
|
|
end
|
2013-06-11 19:25:16 +02:00
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
|
2014-12-14 13:59:35 +01:00
|
|
|
local data, area
|
2013-06-11 19:25:16 +02:00
|
|
|
function riesenpilz_circle(nam, pos, radius, chance)
|
2014-12-05 23:52:55 +01:00
|
|
|
for _,p in pairs(vector.circle(radius)) do
|
|
|
|
if pr:next(1,chance) == 1 then
|
|
|
|
local p = vector.add(pos, p)
|
|
|
|
local p_p = area:indexp(p)
|
2015-05-27 12:18:16 +02:00
|
|
|
if (data[p_p] == c.air or data[p_p] == c.ignore)
|
|
|
|
and find_ground(data[area:index(p.x, p.y-1, p.z)], c.GROUND) then
|
2014-12-05 23:52:55 +01:00
|
|
|
data[p_p] = nam
|
2013-06-11 19:25:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
local function say_info(info)
|
|
|
|
local info = "[riesenpilz] "..info
|
|
|
|
print(info)
|
|
|
|
minetest.chat_send_all(info)
|
2013-04-24 20:53:20 +02:00
|
|
|
end
|
|
|
|
|
2015-06-21 10:41:11 +02:00
|
|
|
-- 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 rarity = riesenpilz.mapgen_rarity
|
2013-10-11 13:36:24 +02:00
|
|
|
local riesenpilz_size = riesenpilz.mapgen_size
|
|
|
|
|
2015-06-21 10:41:11 +02:00
|
|
|
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)
|
2013-08-23 17:34:54 +02:00
|
|
|
|
|
|
|
--local USUAL_STUFF = {"default:leaves","default:apple","default:tree","default:cactus","default:papyrus"}
|
2014-08-11 15:17:58 +02:00
|
|
|
|
|
|
|
local contents_defined
|
2013-04-24 20:53:20 +02:00
|
|
|
minetest.register_on_generated(function(minp, maxp, seed)
|
2013-08-23 17:34:54 +02:00
|
|
|
if maxp.y <= 0
|
|
|
|
or minp.y >= 150 then --avoid generation in the sky
|
|
|
|
return
|
|
|
|
end
|
2014-08-11 15:17:58 +02:00
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
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.
|
2013-10-11 13:36:24 +02:00
|
|
|
local perlin1 = env:get_perlin(51,3, 0.5, perlin_scale) --Get map specific perlin
|
2013-04-24 20:53:20 +02:00
|
|
|
|
2014-12-14 13:59:35 +01:00
|
|
|
if not riesenpilz.always_generate then
|
|
|
|
local biome_allowed
|
|
|
|
for x = x0, x1, 16 do
|
|
|
|
for z = z0, z1, 16 do
|
|
|
|
if perlin1:get2d({x=x, y=z}) > nosmooth_rarity then
|
|
|
|
biome_allowed = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2015-05-28 10:52:47 +02:00
|
|
|
if biome_allowed then
|
|
|
|
break
|
|
|
|
end
|
2014-12-14 13:59:35 +01:00
|
|
|
end
|
|
|
|
if not biome_allowed then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-11 15:17:58 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
if not contents_defined then
|
|
|
|
define_contents()
|
|
|
|
contents_defined = true
|
2013-08-23 17:34:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local divs = (maxp.x-minp.x);
|
|
|
|
local num = 1
|
|
|
|
local tab = {}
|
|
|
|
pr = PseudoRandom(seed+68)
|
|
|
|
|
2015-07-17 20:21:56 +02:00
|
|
|
local heightmap = minetest.get_mapgen_object("heightmap")
|
|
|
|
local hmi = 1
|
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
|
|
|
data = vm:get_data()
|
|
|
|
area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
2013-04-24 20:53:20 +02:00
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
for p_pos in area:iterp(minp, maxp) do --remove tree stuff
|
|
|
|
local d_p_pos = data[p_pos]
|
2015-05-29 12:09:22 +02:00
|
|
|
for _,nam in ipairs(c.TREE_STUFF) do
|
2013-08-23 17:34:54 +02:00
|
|
|
if d_p_pos == nam then
|
2014-08-11 15:17:58 +02:00
|
|
|
data[p_pos] = c.air
|
2013-08-23 17:34:54 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--[[remove usual stuff
|
2013-04-24 20:53:20 +02:00
|
|
|
local trees = env:find_nodes_in_area(minp, maxp, USUAL_STUFF)
|
|
|
|
for i,v in pairs(trees) do
|
|
|
|
env:remove_node(v)
|
2013-08-23 17:34:54 +02:00
|
|
|
end]]
|
2013-04-24 20:53:20 +02:00
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
for j=0,divs do
|
|
|
|
for i=0,divs do
|
|
|
|
local x,z = x0+i,z0+j
|
2013-04-24 20:53:20 +02:00
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
--Check if we are in a "riesenpilz biome"
|
|
|
|
local in_biome = false
|
|
|
|
local test = perlin1:get2d({x=x, y=z})
|
|
|
|
--smooth mapgen
|
|
|
|
if riesenpilz.always_generate then
|
|
|
|
in_biome = true
|
2014-05-12 20:05:55 +02:00
|
|
|
elseif smooth then
|
|
|
|
if test >= smooth_rarity_max
|
2013-10-11 13:36:24 +02:00
|
|
|
or (
|
2014-05-12 20:05:55 +02:00
|
|
|
test > smooth_rarity_min
|
|
|
|
and pr:next(1, 1000) <= ((test-smooth_rarity_min)/smooth_rarity_dif)*1000
|
|
|
|
) then
|
|
|
|
in_biome = true
|
|
|
|
end
|
2015-06-21 10:41:11 +02:00
|
|
|
elseif test > nosmooth_rarity then
|
2013-08-23 17:34:54 +02:00
|
|
|
in_biome = true
|
|
|
|
end
|
2013-04-24 20:53:20 +02:00
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
if in_biome then
|
2013-04-24 20:53:20 +02:00
|
|
|
|
2015-07-17 20:21:56 +02:00
|
|
|
local ymin = math.max(heightmap[hmi]-5, minp.y) -- -1
|
2015-06-21 10:41:11 +02:00
|
|
|
|
|
|
|
-- skip the air part
|
|
|
|
local ground
|
2015-07-17 20:21:56 +02:00
|
|
|
for y = math.min(heightmap[hmi]+20, maxp.y),ymin,-1 do
|
2015-06-21 10:41:11 +02:00
|
|
|
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
|
2013-04-24 20:53:20 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2013-08-23 17:34:54 +02:00
|
|
|
end
|
2015-07-05 21:01:34 +02:00
|
|
|
|
2013-08-23 17:34:54 +02:00
|
|
|
if ground_y then
|
2015-05-27 12:18:16 +02:00
|
|
|
data[area:index(x, ground_y, z)] = c.ground
|
2013-08-23 17:34:54 +02:00
|
|
|
for i = -1,-5,-1 do
|
|
|
|
local p_pos = area:index(x, ground_y+i, z)
|
2015-05-27 12:18:16 +02:00
|
|
|
if data[p_pos] == c.desert_sand then
|
2014-08-11 15:17:58 +02:00
|
|
|
data[p_pos] = c.dirt
|
2013-08-23 17:34:54 +02:00
|
|
|
else
|
|
|
|
break
|
2013-04-24 20:53:20 +02:00
|
|
|
end
|
|
|
|
end
|
2015-07-23 18:43:47 +02:00
|
|
|
local bigtype
|
2013-08-23 17:34:54 +02:00
|
|
|
local boden = {x=x,y=ground_y+1,z=z}
|
|
|
|
if pr:next(1,15) == 1 then
|
2015-05-27 12:18:16 +02:00
|
|
|
data[area:index(x, ground_y+1, z)] = c.dry_shrub
|
2013-08-23 17:34:54 +02:00
|
|
|
elseif pr:next(1,80) == 1 then
|
2014-08-11 15:17:58 +02:00
|
|
|
riesenpilz_circle(c.riesenpilz_brown, boden, pr:next(3,4), 3)
|
2013-10-11 13:36:24 +02:00
|
|
|
elseif pr:next(1,85) == 1 then
|
2014-08-11 15:17:58 +02:00
|
|
|
riesenpilz_circle(c.riesenpilz_parasol, boden, pr:next(3,5), 3)
|
2013-08-23 17:34:54 +02:00
|
|
|
elseif pr:next(1,90) == 1 then
|
2014-08-11 15:17:58 +02:00
|
|
|
riesenpilz_circle(c.riesenpilz_red, boden, pr:next(4,5), 3)
|
2013-08-23 17:34:54 +02:00
|
|
|
elseif pr:next(1,100) == 1 then
|
2014-08-11 15:17:58 +02:00
|
|
|
riesenpilz_circle(c.riesenpilz_fly_agaric, boden, 4, 3)
|
2015-07-23 18:43:47 +02:00
|
|
|
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
|
2013-08-23 17:34:54 +02:00
|
|
|
elseif pr:next(1,4000) == 1 then
|
2014-08-11 15:17:58 +02:00
|
|
|
riesenpilz_circle(c.riesenpilz_lavashroom, boden, pr:next(5,6), 3)
|
2013-08-23 17:34:54 +02:00
|
|
|
elseif pr:next(1,5000) == 1 then
|
2014-08-11 15:17:58 +02:00
|
|
|
riesenpilz_circle(c.riesenpilz_glowshroom, boden, 3, 3)
|
2015-07-23 18:43:47 +02:00
|
|
|
elseif pr:next(1,6000) == 2 then
|
|
|
|
local raretype = pr:next(1,200)
|
|
|
|
if raretype == 15 then
|
|
|
|
bigtype = 4
|
|
|
|
elseif raretype == 54 then
|
|
|
|
bigtype = 6
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if bigtype then
|
|
|
|
tab[num] = {bigtype, boden}
|
2013-11-10 11:06:24 +01:00
|
|
|
num = num+1
|
2013-08-23 17:34:54 +02:00
|
|
|
end
|
2013-04-24 20:53:20 +02:00
|
|
|
end
|
|
|
|
end
|
2015-07-17 20:21:56 +02:00
|
|
|
hmi = hmi+1
|
2013-04-24 20:53:20 +02:00
|
|
|
end
|
|
|
|
end
|
2014-08-11 15:17:58 +02:00
|
|
|
riesenpilz.inform("ground finished", 2, t1)
|
2014-12-14 13:59:35 +01:00
|
|
|
|
2015-05-27 12:18:16 +02:00
|
|
|
local param2s
|
|
|
|
if num ~= 1 then
|
|
|
|
local t2 = os.clock()
|
|
|
|
for _,v in pairs(tab) do
|
|
|
|
local p = v[2]
|
|
|
|
local m = v[1]
|
|
|
|
if m == 1 then
|
|
|
|
riesenpilz.red(p, data, area)
|
|
|
|
elseif m == 2 then
|
|
|
|
riesenpilz.brown(p, data, area)
|
|
|
|
elseif m == 3 then
|
|
|
|
if not param2s then
|
|
|
|
param2s = vm:get_param2_data()
|
|
|
|
end
|
|
|
|
riesenpilz.fly_agaric(p, data, area, param2s)
|
|
|
|
elseif m == 4 then
|
|
|
|
riesenpilz.lavashroom(p, data, area)
|
|
|
|
elseif m == 5 then
|
|
|
|
riesenpilz.parasol(p, data, area)
|
2015-07-23 18:43:47 +02:00
|
|
|
elseif m == 6 then
|
|
|
|
riesenpilz.red45(p, data, area)
|
2015-05-27 12:18:16 +02:00
|
|
|
end
|
2013-08-23 17:34:54 +02:00
|
|
|
end
|
2015-05-27 12:18:16 +02:00
|
|
|
riesenpilz.inform("giant shrooms generated", 2, t2)
|
2013-08-23 17:34:54 +02:00
|
|
|
end
|
2015-05-27 12:18:16 +02:00
|
|
|
|
|
|
|
local t2 = os.clock()
|
|
|
|
vm:set_data(data)
|
|
|
|
if param2s then
|
|
|
|
vm:set_param2_data(param2s)
|
2014-12-14 13:59:35 +01:00
|
|
|
end
|
2015-05-27 12:18:16 +02:00
|
|
|
vm:set_lighting({day=0, night=0})
|
|
|
|
vm:calc_lighting()
|
|
|
|
vm:write_to_map()
|
2015-06-21 10:41:11 +02:00
|
|
|
data = nil
|
|
|
|
area = nil
|
2015-05-27 12:18:16 +02:00
|
|
|
riesenpilz.inform("data set", 2, t2)
|
2014-12-14 13:59:35 +01:00
|
|
|
|
2014-08-11 15:17:58 +02:00
|
|
|
riesenpilz.inform("done", 1, t1)
|
2013-08-23 17:34:54 +02:00
|
|
|
end)
|