2018-06-07 17:41:43 +02:00
|
|
|
local b = require 'map_gen.shared.builders'
|
2018-06-11 21:01:38 +02:00
|
|
|
local perlin = require 'map_gen.shared.perlin_noise'
|
2018-09-15 14:45:32 +02:00
|
|
|
local Global = require 'utils.global'
|
2018-11-06 13:55:52 +02:00
|
|
|
local math = require 'utils.math'
|
2019-01-16 20:44:55 +02:00
|
|
|
local RS = require 'map_gen.shared.redmew_surface'
|
2019-01-16 22:33:32 +02:00
|
|
|
local MGSP = require 'resources.map_gen_settings'
|
2019-01-15 15:27:48 +02:00
|
|
|
local table = require 'utils.table'
|
2018-06-07 17:41:43 +02:00
|
|
|
|
2018-06-23 18:59:39 +02:00
|
|
|
local sand_width = 512
|
2018-11-06 13:55:52 +02:00
|
|
|
local sand_width_inv = math.tau / sand_width
|
2018-06-23 18:59:39 +02:00
|
|
|
local water_width = 233
|
2018-11-06 13:55:52 +02:00
|
|
|
local water_width_inv = math.tau / water_width
|
2018-06-07 17:41:43 +02:00
|
|
|
|
2018-06-11 21:01:38 +02:00
|
|
|
--perlin options
|
2018-06-23 18:59:39 +02:00
|
|
|
local noise_variance = 0.025 --The lower this number the smoother the curve is gonna be
|
|
|
|
local noise_level = 15 --Factor for the magnitude of the curve
|
2018-06-11 21:01:38 +02:00
|
|
|
|
2018-12-22 01:38:11 +02:00
|
|
|
local sand_noise_level = noise_level * 0.9
|
2018-06-23 18:59:39 +02:00
|
|
|
local water_noise_level = noise_level * 1.35
|
2018-06-11 21:01:38 +02:00
|
|
|
|
2018-09-15 14:45:32 +02:00
|
|
|
-- Leave nil and they will be set based on the map seed.
|
|
|
|
local perlin_seed_1 = nil
|
|
|
|
local perlin_seed_2 = nil
|
|
|
|
|
2019-01-16 22:33:32 +02:00
|
|
|
RS.set_map_gen_settings(
|
|
|
|
{
|
|
|
|
MGSP.ore_oil_none,
|
|
|
|
MGSP.cliff_none
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-09-15 14:45:32 +02:00
|
|
|
Global.register_init(
|
|
|
|
{},
|
|
|
|
function(tbl)
|
2019-01-16 20:44:55 +02:00
|
|
|
local seed = RS.get_surface().map_gen_settings.seed
|
2018-09-15 14:45:32 +02:00
|
|
|
tbl.perlin_seed_1 = perlin_seed_1 or seed
|
|
|
|
tbl.perlin_seed_2 = perlin_seed_2 or seed * 2
|
|
|
|
end,
|
|
|
|
function(tbl)
|
|
|
|
perlin_seed_1 = tbl.perlin_seed_1
|
|
|
|
perlin_seed_2 = tbl.perlin_seed_2
|
|
|
|
end
|
|
|
|
)
|
2018-06-11 21:01:38 +02:00
|
|
|
|
2018-06-07 17:41:43 +02:00
|
|
|
local function sand_shape(x, y)
|
2018-12-22 01:38:11 +02:00
|
|
|
local p = perlin.noise(x * noise_variance, y * noise_variance, perlin_seed_1) * sand_noise_level
|
2018-06-23 18:59:39 +02:00
|
|
|
p = p + math.sin(x * sand_width_inv) * 15
|
|
|
|
return p > y
|
|
|
|
end
|
|
|
|
|
|
|
|
local function water_shape(x, y)
|
|
|
|
local p = perlin.noise(x * noise_variance, y * noise_variance, perlin_seed_2) * water_noise_level
|
|
|
|
p = p + math.sin(x * water_width_inv + 179) * 15
|
|
|
|
return p > y
|
2018-06-07 17:41:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
sand_shape = b.change_tile(sand_shape, true, 'sand-1')
|
|
|
|
|
|
|
|
local value = b.manhattan_value
|
|
|
|
|
|
|
|
local ores = {
|
2018-06-08 00:14:03 +02:00
|
|
|
{b.resource(b.full_shape, 'iron-ore', value(125, 0.5)), 6},
|
|
|
|
{b.resource(b.full_shape, 'copper-ore', value(125, 0.5)), 4},
|
2018-06-08 01:24:24 +02:00
|
|
|
{b.resource(b.full_shape, 'stone', value(125, 0.25)), 1},
|
|
|
|
{b.resource(b.full_shape, 'coal', value(250, 0.25)), 1}
|
2018-06-07 17:41:43 +02:00
|
|
|
}
|
|
|
|
|
2018-09-15 14:45:32 +02:00
|
|
|
local start_coal = b.resource(b.full_shape, 'coal', value(500, 0.25))
|
|
|
|
|
2018-12-22 01:38:11 +02:00
|
|
|
local uranium_ore = b.resource(b.full_shape, 'uranium-ore', value(50, 0.25))
|
2018-06-07 17:41:43 +02:00
|
|
|
|
|
|
|
local total_weights = {}
|
|
|
|
local t = 0
|
|
|
|
for _, v in ipairs(ores) do
|
|
|
|
t = t + v[2]
|
|
|
|
table.insert(total_weights, t)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function do_ores(x, y, world)
|
2018-06-23 18:59:39 +02:00
|
|
|
if x > -4 and x < 5 then
|
2018-09-15 14:45:32 +02:00
|
|
|
return start_coal(x, y, world)
|
2018-06-23 18:59:39 +02:00
|
|
|
end
|
|
|
|
|
2018-06-07 17:41:43 +02:00
|
|
|
if (x > 512 or x < -512) and (math.floor(x / 32) % 16 == 0) then
|
|
|
|
return uranium_ore(x, y, world)
|
|
|
|
else
|
|
|
|
local i = math.random(t)
|
|
|
|
|
|
|
|
local index = table.binary_search(total_weights, i)
|
|
|
|
if (index < 0) then
|
|
|
|
index = bit32.bnot(index)
|
|
|
|
end
|
|
|
|
|
|
|
|
local ore = ores[index][1]
|
|
|
|
|
|
|
|
return ore(x, y, world)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sand_shape = b.apply_entity(sand_shape, do_ores)
|
|
|
|
|
|
|
|
water_shape = b.change_tile(water_shape, true, 'water')
|
|
|
|
|
2018-10-06 14:46:32 +02:00
|
|
|
local oil = b.resource(b.full_shape, 'crude-oil', value(300000, 2000))
|
2018-06-07 17:41:43 +02:00
|
|
|
local function do_oil(x, y, world)
|
|
|
|
if math.random(16384) == 1 then
|
|
|
|
local e = oil(x, y, world)
|
|
|
|
e.always_place = true
|
|
|
|
return e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
water_shape = b.apply_entity(water_shape, do_oil)
|
|
|
|
|
2018-12-22 01:38:11 +02:00
|
|
|
local grass = b.tile('grass-1')
|
2018-06-07 17:41:43 +02:00
|
|
|
|
2018-06-23 18:59:39 +02:00
|
|
|
local bounds = b.line_x(384)
|
|
|
|
|
|
|
|
local map = b.any {b.translate(water_shape, 64, -48), sand_shape, grass}
|
2018-06-07 17:41:43 +02:00
|
|
|
|
2018-06-23 18:59:39 +02:00
|
|
|
map = b.fish(map, 0.0025)
|
2018-06-07 17:41:43 +02:00
|
|
|
|
|
|
|
map = b.choose(bounds, map, b.empty_shape)
|
|
|
|
|
2018-06-07 18:26:52 +02:00
|
|
|
map = b.translate(map, 0, -64)
|
|
|
|
|
2018-06-07 17:41:43 +02:00
|
|
|
return map
|