434 lines
17 KiB
Lua
Raw Normal View History

2015-04-11 10:59:45 +02:00
-- Mapgen 2.0
-- Thursday April 23, 2015
2015-03-07 09:33:01 +01:00
vmg.noises = {
-- Noise 1 : Base Ground Height 2D
2015-03-09 09:04:05 +01:00
{offset = -10, scale = 50, seed = 5202, spread = {x = 1024, y = 1024, z = 1024}, octaves = 6, persist = 0.4, lacunarity = 2},
2015-03-07 09:33:01 +01:00
-- Noise 2 : Valleys (River where around zero) 2D
2015-03-09 09:04:05 +01:00
{offset = 0, scale = 1, seed = -6050, spread = {x = 256, y = 256, z = 256}, octaves = 5, persist = 0.6, lacunarity = 2},
2015-03-07 09:33:01 +01:00
-- Noise 3 : Valleys Depth 2D
2015-03-09 09:04:05 +01:00
{offset = 5, scale = 4, seed = -1914, spread = {x = 512, y = 512, z = 512}, octaves = 1, persist = 1, lacunarity = 2},
2015-03-07 09:33:01 +01:00
-- Noise 4 : Valleys Profile (Higher values = Larger valleys) 2D
2015-03-14 10:34:35 +01:00
{offset = 0.6, scale = 0.5, seed = 777, spread = {x = 512, y = 512, z = 512}, octaves = 1, persist = 1, lacunarity = 2},
2015-03-07 09:33:01 +01:00
-- Noise 5 : Inter-valleys slopes 2D
2015-03-09 09:04:05 +01:00
{offset = 0.5, scale = 0.5, seed = 746, spread = {x = 128, y = 128, z = 128}, octaves = 1, persist = 1, lacunarity = 2},
2015-03-07 09:33:01 +01:00
-- Noise 6 : Inter-valleys filling 3D
2015-03-09 09:04:05 +01:00
{offset = 0, scale = 1, seed = 1993, spread = {x = 256, y = 512, z = 256}, octaves = 6, persist = 0.8, lacunarity = 2},
2015-03-07 09:33:01 +01:00
-- Noise 7 : Dirt thickness 2D
2015-03-14 10:54:08 +01:00
{offset = 3, scale = 1.75, seed = 1605, spread = {x = 256, y = 256, z = 256}, octaves = 3, persist = 0.5, lacunarity = 2},
2015-03-07 09:33:01 +01:00
2015-03-14 10:34:35 +01:00
-- Noise 8 : Caves I 3D
2015-03-09 09:04:05 +01:00
{offset = 0, scale = 1, seed = -4640, spread = {x = 32, y = 32, z = 32}, octaves = 4, persist = 0.5, lacunarity = 2},
2015-03-08 10:40:37 +01:00
2015-03-14 10:34:35 +01:00
-- Noise 9 : Caves II 3D
2015-03-09 09:04:05 +01:00
{offset = 0, scale = 1, seed = 8804, spread = {x = 32, y = 32, z = 32}, octaves = 4, persist = 0.5, lacunarity = 2},
2015-03-08 10:40:37 +01:00
2015-03-14 10:34:35 +01:00
-- Noise 10 : Caves III 3D
2015-03-09 09:04:05 +01:00
{offset = 0, scale = 1, seed = -4780, spread = {x = 32, y = 32, z = 32}, octaves = 4, persist = 0.5, lacunarity = 2},
2015-03-08 10:40:37 +01:00
2015-03-16 09:04:15 +01:00
-- Noise 11 : Caves IV and Lava I 3D
2015-03-09 09:04:05 +01:00
{offset = 0, scale = 1, seed = -9969, spread = {x = 32, y = 32, z = 32}, octaves = 4, persist = 0.5, lacunarity = 2},
2015-03-08 10:40:37 +01:00
2015-04-17 21:27:21 +02:00
-- Noise 12 : Lava II (Geologic heat) 3D
2015-03-16 09:04:15 +01:00
{offset = 0, scale = 1, seed = 3314, spread = {x = 64, y = 64, z = 64}, octaves = 4, persist = 0.5, lacunarity = 2},
2015-04-04 22:32:37 +02:00
-- Noise 13 : Clayey dirt noise 2D
{offset = 0, scale = 1, seed = 2835, spread = {x = 256, y = 256, z = 256}, octaves = 5, persist = 0.5, lacunarity = 4},
2015-04-04 22:32:37 +02:00
-- Noise 14 : Silty dirt noise 2D
{offset = 0, scale = 1, seed = 6674, spread = {x = 256, y = 256, z = 256}, octaves = 5, persist = 0.5, lacunarity = 4},
2015-04-04 22:32:37 +02:00
-- Noise 15 : Sandy dirt noise 2D
{offset = 0, scale = 1, seed = 6940, spread = {x = 256, y = 256, z = 256}, octaves = 5, persist = 0.5, lacunarity = 4},
2015-04-04 22:32:37 +02:00
2015-04-06 10:43:33 +02:00
-- Noise 16 : Beaches 2D
{offset = 2, scale = 8, seed = 2349, spread = {x = 256, y = 256, z = 256}, octaves = 3, persist = 0.5, lacunarity = 2},
2015-04-17 21:27:21 +02:00
-- Noise 17 : Temperature (not in maps) 3D
{offset = 2, scale = 1, seed = -1805, spread = {x = 768, y = 256, z = 768}, octaves = 4, persist = 0.5, lacunarity = 4},
-- Noise 18 : Humidity (not in maps) 2D
{offset = 0, scale = 1, seed = -5787, spread = {x = 243, y = 243, z = 243}, octaves = 4, persist = 0.5, lacunarity = 3},
2015-03-07 09:33:01 +01:00
}
2015-03-15 19:37:00 +01:00
function vmg.noisemap(i, minp, chulens)
local obj = minetest.get_perlin_map(vmg.noises[i], chulens)
if minp.z then
return obj:get3dMap_flat(minp)
else
return obj:get2dMap_flat(minp)
end
end
2015-03-09 09:04:05 +01:00
for i, n in ipairs(vmg.noises) do
vmg.noises[i] = vmg.define("noise_" .. i, n)
2015-03-09 09:04:05 +01:00
end
2015-05-01 22:36:01 +02:00
vmg.after_mapgen = {}
function vmg.register_after_mapgen(f, ...)
table.insert(vmg.after_mapgen, {f = f, ...})
end
function vmg.execute_after_mapgen()
for i, params in ipairs(vmg.after_mapgen) do
params.f(unpack(params))
end
vmg.after_mapgen = {}
end
2015-03-14 10:54:08 +01:00
local average_stone_level = vmg.define("average_stone_level", 180)
2015-03-11 19:10:35 +01:00
local dirt_thickness = math.sqrt(average_stone_level) / (vmg.noises[7].offset + 0.5)
2015-03-13 20:11:48 +01:00
local river_size = vmg.define("river_size", 5) / 100
local caves_size = vmg.define("caves_size", 7) / 100
2015-03-16 09:04:15 +01:00
local lava_depth = vmg.define("lava_depth", 2000)
2015-04-11 11:23:52 +02:00
local lava_max_height = vmg.define("lava_max_height", -1)
2015-04-17 22:15:00 +02:00
local altitude_chill = vmg.define("altitude_chill", 90)
2015-03-13 20:11:48 +01:00
2015-03-14 10:47:15 +01:00
local player_max_distance = vmg.define("player_max_distance", 450)
2015-04-05 17:05:22 +02:00
local clay_threshold = vmg.define("clay_threshold", 1)
local silt_threshold = vmg.define("silt_threshold", 1)
local sand_threshold = vmg.define("sand_threshold", 0.75)
local dirt_threshold = vmg.define("dirt_threshold", 0.5)
2015-04-06 11:32:47 +02:00
local water_level = vmg.define("water_level", 1)
2015-03-07 09:33:01 +01:00
function vmg.generate(minp, maxp, seed)
local minps, maxps = minetest.pos_to_string(minp), minetest.pos_to_string(maxp)
if vmg.loglevel >= 2 then
print("[Valleys Mapgen] Preparing to generate map from " .. minps .. " to " .. maxps .. " ...")
elseif vmg.loglevel == 1 then
print("[Valleys Mapgen] Generating map from " .. minps .. " to " .. maxps .. " ...")
end
local t0 = os.clock()
2015-03-07 09:33:01 +01:00
local c_stone = minetest.get_content_id("default:stone")
2015-04-04 22:32:37 +02:00
local c_dirt = minetest.get_content_id("default:dirt")
2015-03-07 09:33:01 +01:00
local c_lawn = minetest.get_content_id("default:dirt_with_grass")
2015-04-04 22:32:37 +02:00
local c_dirt_clay = minetest.get_content_id("valleys_mapgen:dirt_clayey")
local c_lawn_clay = minetest.get_content_id("valleys_mapgen:dirt_clayey_with_grass")
local c_dirt_silt = minetest.get_content_id("valleys_mapgen:dirt_silty")
local c_lawn_silt = minetest.get_content_id("valleys_mapgen:dirt_silty_with_grass")
local c_dirt_sand = minetest.get_content_id("valleys_mapgen:dirt_sandy")
local c_lawn_sand = minetest.get_content_id("valleys_mapgen:dirt_sandy_with_grass")
local c_desert_sand = minetest.get_content_id("default:desert_sand")
2015-04-06 10:43:33 +02:00
local c_sand = minetest.get_content_id("default:sand")
2015-04-04 22:32:37 +02:00
local c_gravel = minetest.get_content_id("default:gravel")
local c_silt = minetest.get_content_id("valleys_mapgen:silt")
2015-04-05 16:21:51 +02:00
local c_clay = minetest.get_content_id("valleys_mapgen:red_clay")
2015-03-07 09:33:01 +01:00
local c_water = minetest.get_content_id("default:water_source")
2015-03-16 09:04:15 +01:00
local c_lava = minetest.get_content_id("default:lava_source")
2015-04-24 16:15:08 +02:00
local c_tree = minetest.get_content_id("default:tree")
local c_leaves = minetest.get_content_id("default:leaves")
local c_apple = minetest.get_content_id("default:apple")
2015-05-01 22:36:01 +02:00
local c_jungletree = minetest.get_content_id("default:jungletree")
local c_jungleleaves = minetest.get_content_id("default:jungleleaves")
2015-04-24 16:15:08 +02:00
2015-03-07 09:33:01 +01:00
local c_air = minetest.get_content_id("air")
2015-04-24 16:15:08 +02:00
local c_ignore = minetest.get_content_id("ignore")
2015-03-07 09:33:01 +01:00
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local data = vm:get_data()
local a = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local chulens = vector.add(vector.subtract(maxp, minp), 1)
local chulens_sup = {x = chulens.x, y = chulens.y + 6, z = chulens.z}
local minp2d = pos2d(minp)
local t1 = os.clock()
if vmg.loglevel >= 2 then
print("[Valleys Mapgen] Mapgen preparation finished in " .. t1 - t0 .. " s")
print("[Valleys Mapgen] Calculating noises ...")
end
2015-03-15 19:37:00 +01:00
local n1 = vmg.noisemap(1, minp2d, chulens)
local n2 = vmg.noisemap(2, minp2d, chulens)
local n3 = vmg.noisemap(3, minp2d, chulens)
local n4 = vmg.noisemap(4, minp2d, chulens)
local n5 = vmg.noisemap(5, minp2d, chulens)
local n6 = vmg.noisemap(6, minp, chulens_sup)
local n7 = vmg.noisemap(7, minp2d, chulens)
local n8 = vmg.noisemap(8, minp, chulens)
local n9 = vmg.noisemap(9, minp, chulens)
local n10 = vmg.noisemap(10, minp, chulens)
local n11 = vmg.noisemap(11, minp, chulens)
2015-03-16 09:04:15 +01:00
local n12 = vmg.noisemap(12, minp, chulens)
2015-04-04 22:32:37 +02:00
local n13 = vmg.noisemap(13, minp2d, chulens)
local n14 = vmg.noisemap(14, minp2d, chulens)
local n15 = vmg.noisemap(15, minp2d, chulens)
2015-04-06 10:43:33 +02:00
local n16 = vmg.noisemap(16, minp2d, chulens)
2015-03-07 09:33:01 +01:00
local t2 = os.clock()
if vmg.loglevel >= 2 then
print("[Valleys Mapgen] Noises calculation finished in " .. t2 - t1 .. " s")
print("[Valleys Mapgen] Collecting data ...")
end
2015-03-07 09:33:01 +01:00
local i2d = 1 -- index for 2D noises
local i3d_sup = 1 -- index for noise 6 which has a special size
local i3d = 1 -- index for 3D noises
-- Calculate increments
local i2d_incrZ = chulens.z
local i2d_decrX = chulens.x * chulens.z - 1
local i3d_incrY = chulens.y
local i3d_sup_incrZ = 6 * chulens.y
local i3d_decrX = chulens.x * chulens.y * chulens.z - 1
local i3d_sup_decrX = chulens.x * (chulens.y + 6) * chulens.z - 1
for x = minp.x, maxp.x do -- for each YZ plane
for z = minp.z, maxp.z do -- for each vertical line in this plane
2015-04-06 10:43:33 +02:00
local v1, v2, v3, v4, v5, v7, v13, v14, v15, v16 = n1[i2d], n2[i2d], n3[i2d], n4[i2d], n5[i2d], n7[i2d], n13[i2d], n14[i2d], n15[i2d], n16[i2d] -- n for noise, v for value
2015-03-07 09:33:01 +01:00
v3 = v3 ^ 2 -- v3 must be > 0 and by the square there are high mountains but the median valleys depth is small.
local base_ground = v1 + v3 -- v3 is here because terrain is generally higher when valleys are deep (mountains)
2015-03-13 20:11:48 +01:00
local river = math.abs(v2) < river_size
local valleys = v3 * (1 - math.exp(- (v2 / v4) ^ 2)) -- use the curve of the function 1exp((x/a)²) to modelise valleys. Making "a" varying 0 < a ≤ 1 will change the shape of the valleys. Try it with a geometry software ! (here x = v2 and a = v4)
2015-03-07 09:33:01 +01:00
local mountain_ground = base_ground + valleys
local slopes = v5 * valleys
2015-04-04 22:32:37 +02:00
2015-03-07 09:33:01 +01:00
if river then
2015-04-06 11:32:47 +02:00
mountain_ground = math.min(math.max(base_ground - 3, water_level - 6), mountain_ground)
2015-03-07 09:33:01 +01:00
slopes = 0
end
2015-04-04 22:32:37 +02:00
-- Choose biome
2015-04-04 22:32:37 +02:00
local dirt = c_dirt
local lawn = c_lawn
local max = math.max(v13, v14, v15) -- the biome is the maximal of these 3 values, if bigger than 0.5. Else, make normal dirt.
2015-04-05 17:05:22 +02:00
if max > dirt_threshold then
2015-04-04 22:32:37 +02:00
if v13 == max then
2015-04-05 17:05:22 +02:00
if v13 > clay_threshold then
2015-04-04 22:32:37 +02:00
dirt = c_clay
lawn = c_clay
else
dirt = c_dirt_clay
lawn = c_lawn_clay
end
elseif v14 == max then
2015-04-05 17:05:22 +02:00
if v14 > silt_threshold then
2015-04-04 22:32:37 +02:00
dirt = c_silt
lawn = c_silt
else
dirt = c_dirt_silt
lawn = c_lawn_silt
end
else
2015-04-05 17:05:22 +02:00
if v15 > sand_threshold then
2015-04-04 22:32:37 +02:00
dirt = c_desert_sand
lawn = c_desert_sand
else
dirt = c_dirt_sand
lawn = c_lawn_sand
end
end
end
2015-04-06 10:43:33 +02:00
local is_beach = v15 > 0 and v16 > 0
local beach = v15 * v16 + water_level -- the y coordinate below which dirt is replaced by beach sand
2015-04-04 22:32:37 +02:00
for y = minp.y, maxp.y do -- for each node in vertical line
2015-03-07 09:33:01 +01:00
local ivm = a:index(x, y, z)
local v6, v8, v9, v10, v11, v12 = n6[i3d_sup], n8[i3d], n9[i3d], n10[i3d], n11[i3d], n12[i3d]
2015-03-13 20:11:48 +01:00
local is_cave = v8 ^ 2 + v9 ^ 2 + v10 ^ 2 + v11 ^ 2 < caves_size
2015-03-07 09:33:01 +01:00
if v6 * slopes > y - mountain_ground then -- if pos is in the ground
2015-03-08 10:40:37 +01:00
if not is_cave then
2015-03-11 19:10:35 +01:00
local above = math.ceil(
v7 + math.random() - math.sqrt(math.abs(y)) / dirt_thickness -- The following code will look for air at this many nodes up. If any, make dirt, else, make stone. So, it's the dirt layer thickness.
2015-03-11 19:10:35 +01:00
)
2015-03-08 10:40:37 +01:00
if above <= 0 then
data[ivm] = c_stone
elseif y >= water_level and n6[i3d_sup+i3d_incrY] * slopes <= y + 1 - mountain_ground and not river then
2015-04-06 10:43:33 +02:00
if is_beach and y < beach then
data[ivm] = c_sand
else
data[ivm] = lawn -- if node above is not in the ground, place lawn
2015-05-08 10:37:22 +02:00
if math.random(20) == 1 then -- make a tree
2015-04-24 16:15:08 +02:00
y = y + 1
local pos = {x = x, y = y, z = z}
local v17 = vmg.get_noise(pos, 17)
local v18 = vmg.get_noise(pos, 18)
local temp -- calculate_temperature
if y > 0 then
temp = v17 * 0.5 ^ (y / altitude_chill)
else
temp = v17 * 0.5 ^ (-y / altitude_chill) + 20 * (v12 + 1) * (1 - 2 ^ (y / lava_depth))
end
local humidity -- calculate humidity
local hraw = 2 ^ (v13 - v15 + v18 * 2)
local sea_water = 0.5 ^ math.max((y - water_level) / 6, 0)
local river_water = 0.5 ^ math.max((y - base_ground) / 3, 0)
local water = sea_water + (1 - sea_water) * river_water
humidity = hraw + water
-- choose a tree from climatic and geological conditions
2015-05-08 10:37:22 +02:00
if v15 < 0.6 and temp >= 0.5 and temp < 2.3 and humidity < 3 and v16 < 0 and v14 > -0.5 and v13 < 0.8 then
2015-04-24 16:15:08 +02:00
local rand = math.random()
local height = math.floor(4 + 2.5 * rand)
local radius = 3 + rand
if math.random(1, 4) == 1 then
vmg.grow_apple_tree(pos, data, a, height, radius, c_tree, c_leaves, c_apple, c_air, c_ignore)
else
vmg.grow_tree(pos, data, a, height, radius, c_tree, c_leaves, c_air, c_ignore)
end
2015-05-01 22:36:01 +02:00
elseif v15 < 0.7 and temp >= 2.5 and humidity > 2 and v16 > -0.1 then
local rand = math.random()
local height = math.floor(8 + 4 * rand)
local radius = 5 + 3 * rand
vmg.grow_jungle_tree(pos, data, a, height, radius, c_jungletree, c_jungleleaves, c_air, c_ignore)
2015-04-24 16:15:08 +02:00
end
y = y - 1
end
2015-04-06 10:43:33 +02:00
end
elseif n6[i3d_sup+above*i3d_incrY] * slopes <= y + above - mountain_ground then -- if node at "above" nodes up is not in the ground, make dirt
2015-04-06 10:43:33 +02:00
if is_beach and y < beach then
data[ivm] = c_sand
else
data[ivm] = dirt
end
2015-03-08 10:40:37 +01:00
else
data[ivm] = c_stone
end
2015-04-11 11:23:52 +02:00
elseif v11 + v12 > 2 ^ (y / lava_depth) and y <= lava_max_height then
2015-03-16 09:04:15 +01:00
data[ivm] = c_lava
2015-03-07 09:33:01 +01:00
end
elseif y <= water_level or river and y - 2 <= mountain_ground then -- if pos is not in the ground, and below water_level, it's an ocean
2015-03-07 09:33:01 +01:00
data[ivm] = c_water
end
i3d = i3d + i3d_incrY -- increment i3d by one line
i3d_sup = i3d_sup + i3d_incrY -- idem
2015-03-07 09:33:01 +01:00
end
i2d = i2d + i2d_incrZ -- increment i2d by one Z
-- useless to increment i3d, because increment would be 0 !
i3d_sup = i3d_sup + i3d_sup_incrZ -- for i3d_sup, just avoid the 6 supplemental lines
2015-03-07 09:33:01 +01:00
end
i2d = i2d - i2d_decrX -- decrement the Z line previously incremented and increment by one X (1)
i3d = i3d - i3d_decrX -- decrement the YZ plane previously incremented and increment by one X (1)
i3d_sup = i3d_sup - i3d_sup_decrX -- idem, including the supplemental lines
2015-03-07 09:33:01 +01:00
end
vmg.execute_after_mapgen() -- needed for jungletree roots
2015-03-07 09:33:01 +01:00
local t3 = os.clock()
if vmg.loglevel >= 2 then
print("[Valleys Mapgen] Data collecting finished in " .. t3 - t2 .. " s")
print("[Valleys Mapgen] Writing data ...")
end
2015-03-07 09:33:01 +01:00
-- execute voxelmanip boring stuff to write to the map
vm:set_data(data)
2015-03-13 21:21:32 +01:00
minetest.generate_ores(vm, minp, maxp)
2015-03-08 10:40:37 +01:00
vm:set_lighting({day = 0, night = 0})
2015-03-07 09:33:01 +01:00
vm:calc_lighting()
vm:update_liquids()
2015-03-08 10:59:09 +01:00
vm:write_to_map()
local t4 = os.clock()
if vmg.loglevel >= 2 then
print("[Valleys Mapgen] Data writing finished in " .. t4 - t2 .. " s")
end
if vmg.loglevel >= 1 then
print("[Valleys Mapgen] Mapgen finished in " .. t4 - t0 .. " s")
end
2015-03-07 09:33:01 +01:00
end
dofile(vmg.path .. "/trees.lua")
2015-04-17 21:27:21 +02:00
function vmg.get_humidity_raw(pos)
local v13 = vmg.get_noise(pos, 13)
local v15 = vmg.get_noise(pos, 15)
local v18 = vmg.get_noise(pos, 18)
return 2 ^ (v13 - v15 + v18 * 2)
end
function vmg.get_humidity(pos)
local y = pos.y
local flatpos = pos2d(pos)
local hraw = vmg.get_humidity_raw(flatpos)
local v1 = vmg.get_noise(flatpos, 1)
local v3 = vmg.get_noise(flatpos, 3) ^ 2
local base_ground = v1 + v3
local sea_water = 0.5 ^ math.max((y - water_level) / 6, 0)
local river_water = 0.5 ^ math.max((y - base_ground) / 3, 0)
local water = sea_water + (1 - sea_water) * river_water
return hraw + water
end
function vmg.get_temperature(pos)
local v12 = vmg.get_noise(pos, 12) + 1
local v17 = vmg.get_noise(pos, 17)
local y = pos.y
if y > 0 then
2015-04-17 22:15:00 +02:00
return v17 * 0.5 ^ (y / altitude_chill)
2015-04-17 21:27:21 +02:00
else
2015-04-17 22:15:00 +02:00
return v17 * 0.5 ^ (-y / altitude_chill) + 20 * v12 * (1 - 2 ^ (y / lava_depth))
2015-04-17 21:27:21 +02:00
end
end
2015-03-07 09:33:01 +01:00
function vmg.get_noise(pos, i)
local n = vmg.noises[i]
local noise = minetest.get_perlin(n.seed, n.octaves, n.persist, 1)
if not pos.z then
return noise:get2d({x = pos.x / n.spread.x, y = pos.y / n.spread.y}) * n.scale + n.offset
else
return noise:get3d({x = pos.x / n.spread.x, y = pos.y / n.spread.y, z = pos.z / n.spread.z}) * n.scale + n.offset
end
end
local function round(n)
return math.floor(n + 0.5)
end
function vmg.get_elevation(pos)
local v1 = vmg.get_noise(pos, 1)
local v2 = vmg.get_noise(pos, 2)
local v3 = vmg.get_noise(pos, 3) ^ 2
local v4 = vmg.get_noise(pos, 4)
local v5 = vmg.get_noise(pos, 5)
local base_ground = v1 + v3
local valleys = v3 * (1 - math.exp(- (v2 / v4) ^ 2))
local mountain_ground = base_ground + valleys
local pos = pos3d(pos, round(mountain_ground))
local slopes = v5 * valleys
if vmg.get_noise(pos, 6) * slopes > pos.y - mountain_ground then
pos.y = pos.y + 1
while vmg.get_noise(pos, 6) * slopes > pos.y - mountain_ground do
pos.y = pos.y + 1
end
return pos.y
else
pos.y = pos.y - 1
while vmg.get_noise(pos, 6) * slopes <= pos.y - mountain_ground do
pos.y = pos.y - 1
end
return pos.y
end
end
function vmg.spawnplayer(player)
local angle = math.random() * math.pi * 2
2015-03-14 10:47:15 +01:00
local distance = math.random() * player_max_distance
2015-03-07 09:33:01 +01:00
local p_angle = {x = math.cos(angle), y = math.sin(angle)}
2015-03-14 10:47:15 +01:00
local pos = {x = -p_angle.x * distance, y = -p_angle.y * distance}
2015-03-07 09:33:01 +01:00
local elevation = vmg.get_elevation(pos)
2015-04-06 11:32:47 +02:00
while elevation < water_level + 2 or math.abs(vmg.get_noise(pos, 2)) < river_size do
2015-03-07 09:33:01 +01:00
pos.x = pos.x + p_angle.x
pos.y = pos.y + p_angle.y
elevation = vmg.get_elevation({x = round(pos.x), y = round(pos.y)})
end
pos = {x = round(pos.x), y = round(elevation + 1), z = round(pos.y)}
player:setpos(pos)
end