1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/map_gen/ores/fluffy_rainbows.lua

60 lines
2.2 KiB
Lua
Raw Normal View History

2018-01-23 17:50:28 +02:00
--Author: MewMew / (Threaded by Valansch)
2017-08-16 16:58:45 +02:00
2018-05-23 23:34:47 +02:00
local perlin = require 'map_gen.shared.perlin_noise'
local Event = require 'utils.event'
2018-01-23 17:50:28 +02:00
--SETTINGS:
local width_modifier = 0.8
2018-05-10 21:42:24 +02:00
local ore_base_amounts = {
2018-05-23 23:34:47 +02:00
['iron-ore'] = 700,
['coal'] = 400,
['copper-ore'] = 400,
['stone'] = 400,
['uranium-ore'] = 400
2018-01-23 17:50:28 +02:00
}
2018-05-10 21:42:24 +02:00
local function init()
2018-05-23 23:34:47 +02:00
global.perlin_noise_seed = math.random(1000, 1000000)
2018-01-23 17:50:28 +02:00
end
2018-05-10 21:42:24 +02:00
Event.on_init(init)
2018-01-23 17:50:28 +02:00
2018-05-10 21:42:24 +02:00
local function do_resource(name, x, y, world, noise_terrain, noise_band_high, noise_band_low, seed)
2018-05-23 23:34:47 +02:00
if noise_terrain > -noise_band_high * width_modifier and noise_terrain <= -noise_band_low * width_modifier then
local noise_resource_amount_modifier = perlin:noise(((x + seed) / 200), ((y + seed) / 200), 0)
local resource_amount =
1 +
((ore_base_amounts[name] + (ore_base_amounts[name] * noise_resource_amount_modifier * 0.2)) *
world.amount_distance_multiplicator)
return {name = name, amount = resource_amount}
end
2018-01-23 17:50:28 +02:00
end
2018-05-10 21:42:24 +02:00
return function(x, y, world)
2018-05-23 23:34:47 +02:00
if not world.amount_distance_multiplicator then
local distance = math.sqrt(world.x * world.x + world.y * world.y)
local amount_distance_multiplicator = (((distance + 1) / 75) / 75) + 1
world.amount_distance_multiplicator = amount_distance_multiplicator
end
local entities = world.surface.find_entities_filtered {position = {world.x + 0.5, world.y + 0.5}, type = 'resource'}
for _, e in ipairs(entities) do
if e.name ~= 'crude-oil' then
e.destroy()
end
2018-05-10 21:42:24 +02:00
end
2017-08-16 16:58:45 +02:00
2018-05-23 23:34:47 +02:00
local seed = global.perlin_noise_seed
2017-08-16 16:58:45 +02:00
2018-05-23 23:34:47 +02:00
local noise_terrain_1 = perlin:noise(((x + seed) / 350), ((y + seed) / 350), 0)
local noise_terrain_2 = perlin:noise(((x + seed) / 50), ((y + seed) / 50), 0)
local noise_terrain = noise_terrain_1 + (noise_terrain_2 * 0.01)
2018-01-23 17:50:28 +02:00
2018-05-23 23:34:47 +02:00
return do_resource('iron-ore', x, y, world, noise_terrain, 0.1, 0.075, seed) or
do_resource('copper-ore', x, y, world, noise_terrain, 0.075, 0.05, seed) or
do_resource('stone', x, y, world, noise_terrain, 0.05, 0.04, seed) or
do_resource('coal', x, y, world, noise_terrain, 0.04, 0.03, seed) or
2018-05-24 00:12:18 +02:00
do_resource('uranium-ore', x, y, world, noise_terrain, 0.02, 0.01, seed)
2017-08-16 16:58:45 +02:00
end