2024-09-15 08:10:53 +00:00
|
|
|
local next = next
|
|
|
|
|
|
|
|
function on_active_tick(event)
|
2024-10-20 20:42:32 +00:00
|
|
|
local active_mining_drills = storage.active.mining_drills
|
|
|
|
local passive_mining_drills = storage.passive.mining_drills
|
2024-09-15 08:10:53 +00:00
|
|
|
|
|
|
|
local miners = table.remove_key(active_mining_drills, event.tick) or {}
|
|
|
|
for _, miner in pairs(miners) do
|
|
|
|
if miner.valid then
|
|
|
|
local status = miner.status
|
|
|
|
if status == defines.entity_status.no_minable_resources then
|
|
|
|
miner.order_deconstruction(miner.force, nil)
|
|
|
|
elseif status ~= defines.entity_status.working then
|
2024-09-20 06:35:21 +00:00
|
|
|
passive_mining_drills[miner.unit_number] = miner
|
2024-09-15 08:10:53 +00:00
|
|
|
script.on_nth_tick(passive_tick, on_passive_tick)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if next(active_mining_drills) == nil then
|
|
|
|
script.on_nth_tick(active_tick, nil)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function on_passive_tick(event)
|
2024-10-20 20:42:32 +00:00
|
|
|
local passive_mining_drills = storage.passive.mining_drills
|
2024-09-15 08:10:53 +00:00
|
|
|
|
2024-09-20 06:35:21 +00:00
|
|
|
for id, miner in pairs(passive_mining_drills) do
|
2024-09-15 08:10:53 +00:00
|
|
|
if miner.valid then
|
|
|
|
local status = miner.status
|
|
|
|
if status == defines.entity_status.no_minable_resources then
|
|
|
|
miner.order_deconstruction(miner.force, nil)
|
2024-09-20 06:35:21 +00:00
|
|
|
passive_mining_drills[id] = nil
|
2024-09-15 08:10:53 +00:00
|
|
|
elseif status == defines.entity_status.working then
|
2024-09-20 06:35:21 +00:00
|
|
|
passive_mining_drills[id] = nil
|
2024-09-15 08:10:53 +00:00
|
|
|
end
|
|
|
|
else
|
2024-09-20 06:35:21 +00:00
|
|
|
passive_mining_drills[id] = nil
|
2024-09-15 08:10:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if next(passive_mining_drills) == nil then
|
|
|
|
script.on_nth_tick(passive_tick, nil)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|