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

65 lines
2.5 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
require "map_gen.shared.perlin_noise"
2018-01-27 17:49:55 +02:00
local Task = require "utils.Task"
2018-01-23 17:50:28 +02:00
--SETTINGS:
local width_modifier = 0.8
ore_base_amounts = {
["iron-ore"] = 700,
["coal"] = 400,
["copper-ore"] = 400,
["stone"] = 400,
["uranium-ore"] = 400
}
local function do_resource(name, x, y, noise_terrain, args, noise_band_high, noise_band_low, seed)
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)) * args.amount_distance_multiplicator)
if args.surface.can_place_entity {name=name, position={x,y}} then
args.surface.create_entity {name=name, position={x,y}, amount=resource_amount}
end
end
end
local function do_row(y, args)
local y = y + args.area.left_top.y
local seed = args.seed
for x= args.area.left_top.x, args.area.left_top.x + 31 do
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)
do_resource("iron-ore", x, y, noise_terrain, args, 0.1, 0.075, seed)
do_resource("copper-ore", x, y, noise_terrain, args, 0.075, 0.05, seed)
do_resource("stone", x, y, noise_terrain, args, 0.05, 0.04, seed)
do_resource("coal", x, y, noise_terrain, args, 0.04, 0.03, seed)
do_resource("uranium-ore", x, y, noise_terrain, args, 0.03, 0.02, seed)
end
end
function fluffy_rainbows_task(args)
do_row(args.y, args)
args.y = args.y + 1
return (args.y < 32)
end
2017-08-16 16:58:45 +02:00
function run_combined_module(event)
2018-01-23 17:50:28 +02:00
if not global.perlin_noise_seed then global.perlin_noise_seed = math.random(1000,1000000) end
local seed = global.perlin_noise_seed
2017-08-16 16:58:45 +02:00
local entities = event.surface.find_entities(event.area)
2018-01-23 17:50:28 +02:00
for _, entity in pairs(entities) do
2017-08-16 16:58:45 +02:00
if entity.type == "resource" and entity.name ~= "crude-oil" then
entity.destroy()
2018-01-23 17:50:28 +02:00
end
2017-08-16 16:58:45 +02:00
end
2018-01-23 17:50:28 +02:00
local distance = math.sqrt(event.area.left_top.x * event.area.left_top.x + event.area.left_top.y * event.area.left_top.y)
local amount_distance_multiplicator = (((distance + 1) / 75) / 75) + 1
2018-01-27 17:49:55 +02:00
Task.queue_task("fluffy_rainbows_task", {surface = event.surface, y = 0, area = event.area, amount_distance_multiplicator = amount_distance_multiplicator, seed = seed})
2017-08-16 16:58:45 +02:00
end