2018-01-19 23:33:54 +02:00
|
|
|
require "map_gen.shared.perlin_noise"
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
local random_ores = {"iron-ore","coal","copper-ore","stone","uranium-ore"}
|
|
|
|
local random_dense = {1.15,0.8,1,0.9, 0.5} --ore density reference
|
|
|
|
|
|
|
|
function run_ores_module_setup()
|
|
|
|
if not global.ores_seed_A then global.ores_seed_A = math.random(10,10000) end
|
|
|
|
if not global.ores_seed_B then global.ores_seed_B = math.random(10,10000) end
|
|
|
|
end
|
|
|
|
|
|
|
|
--generate ores for entire chunk
|
|
|
|
function run_ores_module(event)
|
|
|
|
--game.print("gen crazy ores")
|
|
|
|
run_ores_module_setup()
|
|
|
|
--if not global.ores_seed_A then global.ores_seed_A = math.random(10,10000) end
|
|
|
|
--if not global.ores_seed_B then global.ores_seed_B = math.random(10,10000) end
|
2017-07-18 21:26:12 +02:00
|
|
|
|
|
|
|
local area = event.area
|
2017-07-14 20:12:28 +02:00
|
|
|
local surface = event.surface
|
|
|
|
local tiles = {}
|
|
|
|
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
local entities = surface.find_entities(area)
|
2017-07-18 21:26:12 +02:00
|
|
|
for _, entity in pairs(entities) do
|
2017-07-14 20:12:28 +02:00
|
|
|
if entity.type == "resource" then
|
|
|
|
entity.destroy()
|
2017-07-18 21:26:12 +02:00
|
|
|
end
|
2017-07-14 20:12:28 +02:00
|
|
|
end
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
local top_left = area.left_top --make a more direct reference
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
local distance_bonus = 200 + math.sqrt(top_left.x*top_left.x + top_left.y*top_left.y) * 0.2
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
for x = top_left.x, top_left.x + 31 do
|
2017-07-18 21:26:12 +02:00
|
|
|
for y = top_left.y, top_left.y + 31 do
|
|
|
|
--table.insert(tiles, {name = "out-of-map", position = {x,y}})
|
2017-07-14 20:12:28 +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
|
2017-07-18 21:26:12 +02:00
|
|
|
|
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
if Ores_A > 35 then --we place ores
|
2017-07-18 21:26:12 +02:00
|
|
|
local Ores_B = perlin:noise((x*0.02),(y*0.02),global.ores_seed_B + 13) * wiggle
|
2017-07-14 20:12:28 +02:00
|
|
|
local a = 5
|
2017-07-18 21:26:12 +02:00
|
|
|
--
|
2017-07-14 20:12:28 +02:00
|
|
|
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
|
2017-07-18 21:26:12 +02:00
|
|
|
--
|
2017-07-14 20:12:28 +02:00
|
|
|
local res_amount = distance_bonus
|
|
|
|
res_amount = math.floor(res_amount * random_dense[a])
|
2017-07-18 21:26:12 +02:00
|
|
|
--
|
|
|
|
if surface.can_place_entity {name=random_ores[a], position={x,y}} then
|
2017-07-14 20:12:28 +02:00
|
|
|
surface.create_entity {name=random_ores[a], position={x,y}, amount=res_amount}
|
2017-07-18 21:26:12 +02:00
|
|
|
end
|
2017-07-14 20:12:28 +02:00
|
|
|
elseif Ores_A < -60 then
|
2017-07-18 21:26:12 +02:00
|
|
|
if math.random(1,200) == 1 and surface.can_place_entity {name="crude-oil", position={x,y}} then
|
2017-07-14 20:12:28 +02:00
|
|
|
surface.create_entity {name="crude-oil", position={x,y}, amount = math.random(5000,20000) +math.floor(distance_bonus)* 1500 }
|
|
|
|
end
|
|
|
|
end
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
end
|
|
|
|
end
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--used when terrain modual passes to it, can save extra calculations
|
|
|
|
function run_ores_module_tile(surface,x,y)
|
|
|
|
|
|
|
|
distance_bonus = 200 + math.sqrt(x*x + y*y) * 0.2
|
|
|
|
|
|
|
|
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
|
2017-07-18 21:26:12 +02:00
|
|
|
|
2017-07-14 20:12:28 +02:00
|
|
|
if Ores_A > 35 then --we place ores
|
2017-07-18 21:26:12 +02:00
|
|
|
local Ores_B = perlin:noise((x*0.02),(y*0.02),global.ores_seed_B + 13) * wiggle
|
2017-07-14 20:12:28 +02:00
|
|
|
local a = 5
|
2017-07-18 21:26:12 +02:00
|
|
|
--
|
2017-07-14 20:12:28 +02:00
|
|
|
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
|
2017-07-18 21:26:12 +02:00
|
|
|
--
|
2017-07-14 20:12:28 +02:00
|
|
|
local res_amount = distance_bonus
|
|
|
|
res_amount = math.floor(res_amount * random_dense[a])
|
2017-07-18 21:26:12 +02:00
|
|
|
--
|
|
|
|
--if surface.can_place_entity {name=random_ores[a], position={x,y}} then
|
2017-07-14 20:12:28 +02:00
|
|
|
--We assume it can be places because terrain gen told us to.
|
|
|
|
surface.create_entity {name=random_ores[a], position={x,y}, amount=res_amount}
|
2017-07-18 21:26:12 +02:00
|
|
|
--end
|
2017-07-14 20:12:28 +02:00
|
|
|
elseif Ores_A < -60 then
|
2017-07-18 21:26:12 +02:00
|
|
|
if math.random(1,200) == 1 then
|
2017-07-14 20:12:28 +02:00
|
|
|
surface.create_entity {name="crude-oil", position={x,y}, amount = math.random(5000,20000) +math.floor(distance_bonus)* 1500 }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-18 21:26:12 +02:00
|
|
|
end
|