short mapgen code

This commit is contained in:
HybridDog 2015-05-30 22:06:23 +02:00
parent 819f2d6cfb
commit f2b23a0a27

View File

@ -28,8 +28,7 @@ local biome_strings = {
}
local function biome_to_string(num,num2)
local biome = biome_strings[1][num] or "unknown "..num
local biome2 = biome_strings[2][num2] or "unknown "..num2
return biome, biome2
return biome
end
-- On generated function
@ -76,22 +75,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
-- Choose biomes
local pr = PseudoRandom(seed+57)
local biome
-- Land biomes
biome = pr:next(1, 5)
local biome = pr:next(1, 5)
local snowy = biome == 1 -- spawns alot of snow
local plain = biome == 2 -- spawns not much
local alpine = biome == 3 -- rocky terrain
-- Water biomes
local biome2 = pr:next(1, 5)
local cool = biome == 1 -- only spawns ice on edge of water
local icebergs = biome == 2
local icesheet = biome == 3
local icecave = biome == 4
local icehole = biome == 5 -- icesheet with holes
-- Misc biome settings
local icy = pr:next(1, 2) == 2 -- if enabled spawns ice in sand instead of snow blocks
local mossy = pr:next(1,2) == 1 -- spawns moss in snow
local shrubs = pr:next(1,2) == 1 -- spawns dry shrubs in snow
local pines = pr:next(1,2) == 1 -- spawns pines
-- Reseed random
@ -112,7 +101,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
if not in_biome then
if alpine == true and test > 0.43 then
if alpine and test > 0.43 then
local ground_y = nil
for y = maxp.y, minp.y, -1 do
local nodid = data[area:index(x, y, z)]
@ -133,7 +122,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
if id == c_leaves
or id == c_jungleleaves
or id == c_tree
or id == c_air
or id == c_apple then
data[vi] = c_air
else
@ -147,9 +135,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
elseif in_biome then
write_to_map = true
local icetype = nvals_ice[ni]
local cool = icetype > 0
local cool = icetype > 0 -- only spawns ice on edge of water
local icebergs = icetype > -0.2 and icetype <= 0
local icehole = icetype > -0.4 and icetype <= -0.2
local icehole = icetype > -0.4 and icetype <= -0.2 -- icesheet with holes
local icesheet = icetype > -0.6 and icetype <= -0.4
local icecave = icetype <= -0.6
@ -211,9 +199,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
else
data[abovenode] = c_snow
end
elseif ground_y and data[node] == c_junglegrass then
elseif ground_y
and data[node] == c_junglegrass then
data[node] = c_dry_shrub
elseif ground_y and data[node] == c_papyrus then
elseif ground_y
and data[node] == c_papyrus then
for y = ground_y, ground_y-4, -1 do
local vi = area:index(x, y, z)
if data[vi] == c_papyrus then
@ -222,41 +212,48 @@ minetest.register_on_generated(function(minp, maxp, seed)
data[vi] = c_snow_block
end
end
elseif ground_y and data[node] == c_water then
if not icesheet and not icecave and not icehole then
elseif ground_y
and data[node] == c_water then
if not icesheet
and not icecave
and not icehole then
local x1 = data[area:index(x+1, ground_y, z)]
local z1 = data[area:index(x, ground_y, z+1)]
local xz1 = data[area:index(x+1, ground_y, z+1)]
local xz2 = data[area:index(x-1, ground_y, z-1)]
local x2 = data[area:index(x-1, ground_y, z)]
local z2 = data[area:index(x, ground_y, z-1)]
local rand = (pr:next(1,4) == 1) and (cool or icebergs)
local ice
if rand then
for _,i in ipairs({x1,z1,xz1,xz2,x2,z2}) do
if i == c_ice then
ice = true
break
end
end
end
if not ice then
for _,i in ipairs({x1,z1,xz1,xz2,x2,z2}) do
if i ~= c_water
and i ~= c_ice
and i ~= c_air
and i ~= c_ignore then
ice = true
break
end
end
end
local y = data[area:index(x, ground_y-1, z)]
local rand = pr:next(1,4) == 1
if ((x1 and x1 ~= c_water and x1 ~= c_ice
and x1 ~= c_air and x1 ~= c_ignore)
or (rand and (cool or icebergs) and x1 == c_ice))
or ((z1 and z1 ~= c_water and z1 ~= c_ice
and z1 ~= c_air and z1 ~= c_ignore)
or (rand and (cool or icebergs) and z1 == c_ice))
or ((xz1 and xz1 ~= c_water and xz1 ~= c_ice
and xz1 ~= c_air and xz1 ~= c_ignore)
or (rand and (cool or icebergs) and xz1 == c_ice))
or ((xz2 and xz2 ~= c_water and xz2 ~= c_ice
and xz2 ~= c_air and xz2 ~= c_ignore)
or (rand and (cool or icebergs) and xz2 == c_ice))
or ((x2 and x2 ~= c_water and x2 ~= c_ice
and x2 ~= c_air and x2 ~= c_ignore)
or (rand and (cool or icebergs) and x2 == c_ice))
or ((z2 and z2 ~= c_water and z2 ~= c_ice
and z2 ~= c_air and z2 ~= c_ignore)
or (rand and (cool or icebergs) and z2 == c_ice))
if ice
or (y ~= c_water and y ~= c_ice) -- and y ~= "air") …I don't think y can be a string here ~HybridDog
or (icebergs and pr:next(1,6) == 1) then
data[node] = c_ice
end
else
if (icehole and pr:next(1,10) > 1)
or icecave or icesheet then
or icecave
or icesheet then
data[node] = c_ice
end
if icecave then
@ -284,9 +281,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
if write_to_map
and snow.debug then -- print if any column of mapchunk was snow biome
local biome_string,biome2_string = biome_to_string(biome,biome2)
local biome_string = biome_to_string(biome)
local chugent = math.ceil((os.clock() - t1) * 1000)
print("[snow] "..biome_string.." and "..biome2_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms")
print("[snow] "..biome_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms")
end
end)