2024-09-15 08:10:53 +00:00
|
|
|
function on_resource_depleted(event)
|
|
|
|
local entity = event.entity
|
|
|
|
|
|
|
|
if entity.initial_amount ~= nil then
|
|
|
|
-- Infinite Resource
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local surface = entity.surface
|
|
|
|
local position = entity.position
|
|
|
|
|
|
|
|
local category = entity.prototype.resource_category
|
2024-09-19 02:31:42 +00:00
|
|
|
local radius = teardown.max_mining_drill_radius[category]
|
2024-09-15 08:10:53 +00:00
|
|
|
|
|
|
|
if radius == nil then
|
2024-09-19 02:31:42 +00:00
|
|
|
log("max_mining_drill_radius: " .. serpent.block(teardown.max_mining_drill_radius))
|
2024-09-15 08:10:53 +00:00
|
|
|
error("max_mining_drill_radius is not set for category: " .. category)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local miners = surface.find_entities_filtered({
|
|
|
|
area = fmsl.box.center_radius(position, radius),
|
|
|
|
type = "mining-drill",
|
|
|
|
to_be_deconstructed = false,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- two tick delay for dropping product and finding a new resource node
|
|
|
|
local target_tick = event.tick + 2
|
|
|
|
|
|
|
|
local add_table = false
|
|
|
|
local active_miners = table.remove_key(global.active.mining_drills, target_tick) or {}
|
|
|
|
|
|
|
|
for _, miner in pairs(miners) do
|
|
|
|
if miner.has_flag("hidden") then
|
|
|
|
goto miner_continue
|
|
|
|
end
|
|
|
|
|
|
|
|
add_table = true
|
|
|
|
table.insert(active_miners, miner)
|
|
|
|
|
|
|
|
::miner_continue::
|
|
|
|
end
|
|
|
|
|
|
|
|
if add_table then
|
|
|
|
global.active.mining_drills[target_tick] = active_miners
|
|
|
|
script.on_nth_tick(active_tick, on_active_tick)
|
|
|
|
end
|
|
|
|
end
|