2018-05-23 23:34:47 +02:00
|
|
|
local perlin = require 'map_gen.shared.perlin_noise'
|
2019-01-27 19:22:24 +02:00
|
|
|
local Global = require 'utils.global'
|
2017-08-10 00:05:11 +02:00
|
|
|
|
2019-01-27 19:22:24 +02:00
|
|
|
local seed
|
2017-08-10 00:05:11 +02:00
|
|
|
|
2019-01-27 19:22:24 +02:00
|
|
|
Global.register_init(
|
|
|
|
{},
|
|
|
|
function(tbl)
|
|
|
|
tbl.seed = math.random(10, 10000)
|
|
|
|
end,
|
|
|
|
function(tbl)
|
|
|
|
seed = tbl.seed
|
|
|
|
end
|
|
|
|
)
|
2017-08-10 00:05:11 +02:00
|
|
|
|
2019-01-19 18:34:29 +02:00
|
|
|
return function(x, y)
|
2019-01-27 19:22:24 +02:00
|
|
|
local wiggle = 50 + perlin.noise((x * 0.005), (y * 0.005), seed + 71) * 60
|
|
|
|
local terrain_A = perlin.noise((x * 0.005), (y * 0.005), seed + 19) * wiggle --For determining where water is
|
2018-05-23 23:34:47 +02:00
|
|
|
local terrain_sqr = terrain_A * terrain_A --we can use this again to mess with other layers as well
|
2017-08-10 00:05:11 +02:00
|
|
|
|
2018-05-23 23:34:47 +02:00
|
|
|
if terrain_sqr < 50 then --Main water areas
|
2019-01-27 19:22:24 +02:00
|
|
|
terrain_A = perlin.noise((x * 0.01), (y * 0.01), seed + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
|
2017-08-10 00:05:11 +02:00
|
|
|
|
2018-05-23 23:34:47 +02:00
|
|
|
if terrain_A * terrain_A > 40 then --creates random bridges over the water by overlapping with another noise layer
|
|
|
|
return 'water'
|
|
|
|
end
|
|
|
|
end
|
2017-08-10 00:05:11 +02:00
|
|
|
|
2018-05-23 23:34:47 +02:00
|
|
|
return true
|
2017-08-10 00:05:11 +02:00
|
|
|
end
|