2018-05-23 23:34:47 +02:00
|
|
|
local perlin = require 'map_gen.shared.perlin_noise'
|
|
|
|
local Event = require 'utils.event'
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2018-05-23 23:34:47 +02:00
|
|
|
local random_ores = {'iron-ore', 'coal', 'copper-ore', 'stone', 'uranium-ore'}
|
2018-08-21 14:11:06 +02:00
|
|
|
local random_dense = {1.6, 0.8, 1, 0.6, 0.5} --ore density reference
|
2017-07-14 20:12:28 +02:00
|
|
|
|
2018-05-10 21:42:24 +02:00
|
|
|
local function run_ores_module_setup()
|
2018-08-21 14:11:06 +02:00
|
|
|
local seed = game.surfaces[1].map_gen_settings.seed
|
2018-05-23 23:34:47 +02:00
|
|
|
if not global.ores_seed_A then
|
2018-08-21 14:11:06 +02:00
|
|
|
global.ores_seed_A = seed
|
2018-05-23 23:34:47 +02:00
|
|
|
end
|
|
|
|
if not global.ores_seed_B then
|
2018-08-21 14:11:06 +02:00
|
|
|
global.ores_seed_B = seed * 2
|
2018-05-23 23:34:47 +02:00
|
|
|
end
|
2017-07-14 20:12:28 +02:00
|
|
|
end
|
|
|
|
|
2018-05-10 21:42:24 +02:00
|
|
|
Event.on_init(run_ores_module_setup)
|
2017-07-14 20:12:28 +02:00
|
|
|
|
2018-05-23 23:34:47 +02:00
|
|
|
return function(x, y, world)
|
2018-10-02 21:58:22 +02:00
|
|
|
local d_sq = world.x * world.x + world.y * world.y
|
|
|
|
if d_sq < 9216 then
|
2018-08-21 14:11:06 +02:00
|
|
|
return
|
2018-05-23 23:34:47 +02:00
|
|
|
end
|
|
|
|
|
2018-08-21 14:11:06 +02:00
|
|
|
local distance_bonus = 100 + 0.4 * d ^ 1.2
|
2018-05-23 23:34:47 +02:00
|
|
|
|
2018-06-12 17:57:39 +02:00
|
|
|
local wiggle = 100 + perlin.noise((x * 0.005), (y * 0.005), global.ores_seed_A + 41) * 60
|
|
|
|
local Ores_A = perlin.noise((x * 0.01), (y * 0.01), global.ores_seed_B + 57) * wiggle
|
2018-05-23 23:34:47 +02:00
|
|
|
|
|
|
|
if Ores_A > 35 then --we place ores
|
2018-06-12 17:57:39 +02:00
|
|
|
local Ores_B = perlin.noise((x * 0.02), (y * 0.02), global.ores_seed_B + 13) * wiggle
|
2018-05-23 23:34:47 +02:00
|
|
|
local a = 5
|
|
|
|
--
|
|
|
|
if Ores_A < 76 then
|
|
|
|
a = math.floor(Ores_A * 0.75 + Ores_B * 0.5) % 4 + 1
|
|
|
|
end --if its not super high we place normal ores
|
|
|
|
--
|
|
|
|
local res_amount = distance_bonus
|
|
|
|
res_amount = math.floor(res_amount * random_dense[a])
|
|
|
|
--
|
|
|
|
|
|
|
|
return {name = random_ores[a], amount = res_amount}
|
|
|
|
elseif Ores_A < -60 then
|
|
|
|
if math.random(1, 200) == 1 then
|
2018-08-21 14:11:06 +02:00
|
|
|
return {name = 'crude-oil', amount = 5000 + math.floor(distance_bonus) * 500}
|
2018-05-23 23:34:47 +02:00
|
|
|
end
|
|
|
|
end
|
2017-07-18 21:26:12 +02:00
|
|
|
end
|