mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
Merge pull request #155 from Valansch/rainbow_threaded
threaded rainbow
This commit is contained in:
commit
8069c84c64
@ -1,98 +1,64 @@
|
||||
--Author: MewMew
|
||||
--Author: MewMew / (Threaded by Valansch)
|
||||
|
||||
require "map_gen.shared.perlin_noise"
|
||||
local Thread = require "utils.Thread"
|
||||
|
||||
--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
|
||||
|
||||
function run_combined_module(event)
|
||||
if not global.perlin_noise_seed then global.perlin_noise_seed = math.random(1000,1000000) end
|
||||
local seed = global.perlin_noise_seed
|
||||
if not global.perlin_noise_seed then global.perlin_noise_seed = math.random(1000,1000000) end
|
||||
local seed = global.perlin_noise_seed
|
||||
local entities = event.surface.find_entities(event.area)
|
||||
for _, entity in pairs(entities) do
|
||||
for _, entity in pairs(entities) do
|
||||
if entity.type == "resource" and entity.name ~= "crude-oil" then
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
|
||||
local width_modifier = 0.8
|
||||
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local pos_x = event.area.left_top.x + x
|
||||
local pos_y = event.area.left_top.y + y
|
||||
local noise_terrain_1 = perlin:noise(((pos_x+seed)/350),((pos_y+seed)/350),0)
|
||||
local noise_terrain_2 = perlin:noise(((pos_x+seed)/50),((pos_y+seed)/50),0)
|
||||
local noise_terrain = noise_terrain_1 + (noise_terrain_2 * 0.01)
|
||||
|
||||
if noise_terrain > -0.1 * width_modifier and noise_terrain <= -0.075 * width_modifier then
|
||||
local a = pos_x
|
||||
local b = pos_y
|
||||
local c = 1
|
||||
if event.area.right_bottom.x < 0 then a = event.area.right_bottom.x * -1 end
|
||||
if event.area.right_bottom.y < 0 then b = event.area.right_bottom.y * -1 end
|
||||
if a > b then c = a else c = b end
|
||||
local resource_amount_distance_multiplicator = (((c + 1) / 75) / 75) + 1
|
||||
local noise_resource_amount_modifier = perlin:noise(((pos_x+seed)/200),((pos_y+seed)/200),0)
|
||||
local resource_amount = 1 + ((700 + (700*noise_resource_amount_modifier*0.2)) * resource_amount_distance_multiplicator)
|
||||
if event.surface.can_place_entity {name="iron-ore", position={pos_x,pos_y}} then
|
||||
event.surface.create_entity {name="iron-ore", position={pos_x,pos_y}, amount=resource_amount}
|
||||
end
|
||||
end
|
||||
if noise_terrain > -0.075 * width_modifier and noise_terrain <= -0.05 * width_modifier then
|
||||
local a = pos_x
|
||||
local b = pos_y
|
||||
local c = 1
|
||||
if event.area.right_bottom.x < 0 then a = event.area.right_bottom.x * -1 end
|
||||
if event.area.right_bottom.y < 0 then b = event.area.right_bottom.y * -1 end
|
||||
if a > b then c = a else c = b end
|
||||
local resource_amount_distance_multiplicator = (((c + 1) / 75) / 75) + 1
|
||||
local noise_resource_amount_modifier = perlin:noise(((pos_x+seed)/200),((pos_y+seed)/200),0)
|
||||
local resource_amount = 1 + ((400 + (400*noise_resource_amount_modifier*0.2)) * resource_amount_distance_multiplicator)
|
||||
if event.surface.can_place_entity {name="copper-ore", position={pos_x,pos_y}} then
|
||||
event.surface.create_entity {name="copper-ore", position={pos_x,pos_y}, amount=resource_amount}
|
||||
end
|
||||
end
|
||||
if noise_terrain > -0.05 * width_modifier and noise_terrain <= -0.04 * width_modifier then
|
||||
local a = pos_x
|
||||
local b = pos_y
|
||||
local c = 1
|
||||
if event.area.right_bottom.x < 0 then a = event.area.right_bottom.x * -1 end
|
||||
if event.area.right_bottom.y < 0 then b = event.area.right_bottom.y * -1 end
|
||||
if a > b then c = a else c = b end
|
||||
local resource_amount_distance_multiplicator = (((c + 1) / 75) / 75) + 1
|
||||
local noise_resource_amount_modifier = perlin:noise(((pos_x+seed)/200),((pos_y+seed)/200),0)
|
||||
local resource_amount = 1 + ((400 + (400*noise_resource_amount_modifier*0.2)) * resource_amount_distance_multiplicator)
|
||||
if event.surface.can_place_entity {name="stone", position={pos_x,pos_y}} then
|
||||
event.surface.create_entity {name="stone", position={pos_x,pos_y}, amount=resource_amount}
|
||||
end
|
||||
end
|
||||
if noise_terrain > -0.04 * width_modifier and noise_terrain <= -0.03 * width_modifier then
|
||||
local a = pos_x
|
||||
local b = pos_y
|
||||
local c = 1
|
||||
if event.area.right_bottom.x < 0 then a = event.area.right_bottom.x * -1 end
|
||||
if event.area.right_bottom.y < 0 then b = event.area.right_bottom.y * -1 end
|
||||
if a > b then c = a else c = b end
|
||||
local resource_amount_distance_multiplicator = (((c + 1) / 75) / 75) + 1
|
||||
local noise_resource_amount_modifier = perlin:noise(((pos_x+seed)/200),((pos_y+seed)/200),0)
|
||||
local resource_amount = 1 + ((400 + (400*noise_resource_amount_modifier*0.2)) * resource_amount_distance_multiplicator)
|
||||
if event.surface.can_place_entity {name="coal", position={pos_x,pos_y}} then
|
||||
event.surface.create_entity {name="coal", position={pos_x,pos_y}, amount=resource_amount}
|
||||
end
|
||||
end
|
||||
if noise_terrain > -0.03 * width_modifier and noise_terrain <= -0.02 * width_modifier then
|
||||
local a = pos_x
|
||||
local b = pos_y
|
||||
local c = 1
|
||||
if event.area.right_bottom.x < 0 then a = event.area.right_bottom.x * -1 end
|
||||
if event.area.right_bottom.y < 0 then b = event.area.right_bottom.y * -1 end
|
||||
if a > b then c = a else c = b end
|
||||
local resource_amount_distance_multiplicator = (((c + 1) / 75) / 75) + 1
|
||||
local noise_resource_amount_modifier = perlin:noise(((pos_x+seed)/200),((pos_y+seed)/200),0)
|
||||
local resource_amount = 1 + ((400 + (400*noise_resource_amount_modifier*0.2)) * resource_amount_distance_multiplicator)
|
||||
if event.surface.can_place_entity {name="uranium-ore", position={pos_x,pos_y}} then
|
||||
event.surface.create_entity {name="uranium-ore", position={pos_x,pos_y}, amount=resource_amount}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
Thread.queue_action("fluffy_rainbows_task", {surface = event.surface, y = 0, area = event.area, amount_distance_multiplicator = amount_distance_multiplicator, seed = seed})
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user