1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/modules/scramble_ores.lua

41 lines
1.8 KiB
Lua
Raw Normal View History

2021-03-24 21:14:55 +02:00
local Event = require 'utils.event'
2019-03-13 18:09:06 +02:00
2021-03-24 21:14:55 +02:00
local diversity = 0.20
local exempt_area = 200 --This is the radius of the starting area that can't be affected.
local stone_byproduct = false --Delete patches of stone. Stone only appears as a byproduct.
local stone_ratio = 0.25 --If math.random() is between diversity and this, it's stone.
2019-03-13 18:09:06 +02:00
--Build a table of potential ores to pick from. Uranium is exempt from popping up randomly.
local function init()
2021-03-24 17:46:00 +02:00
global.diverse_ores = {}
for k, v in pairs(game.entity_prototypes) do
if v.type == 'resource' and v.resource_category == 'basic-solid' and v.mineable_properties.required_fluid == nil then
table.insert(global.diverse_ores, v.name)
end
end
2019-03-13 18:09:06 +02:00
end
local function scramble(event)
2021-03-24 17:46:00 +02:00
local ores = event.surface.find_entities_filtered {type = 'resource', area = event.area}
for k, v in pairs(ores) do
2021-03-24 21:14:55 +02:00
if math.abs(v.position.x) > exempt_area or math.abs(v.position.y) > exempt_area then
2021-03-24 17:46:00 +02:00
if v.prototype.resource_category == 'basic-solid' then
local random = math.random()
2021-03-24 21:14:55 +02:00
if v.name == 'stone' and stone_byproduct then
2021-03-24 17:46:00 +02:00
v.destroy()
2021-03-24 21:14:55 +02:00
elseif random < diversity then --Replace!
2021-03-24 17:46:00 +02:00
local refugee = global.diverse_ores[math.random(#global.diverse_ores)]
event.surface.create_entity {name = refugee, position = v.position, amount = v.amount}
v.destroy()
2021-03-24 21:14:55 +02:00
elseif stone_byproduct and random < stone_ratio then --Replace with stone!
2021-03-24 17:46:00 +02:00
event.surface.create_entity {name = 'stone', position = v.position, amount = v.amount}
v.destroy()
end
end
end
end
2019-03-13 18:09:06 +02:00
end
2021-03-24 21:14:55 +02:00
Event.on_init(init)
Event.add(defines.events.on_chunk_generated, scramble)