Teardown/teardown/on_tick.lua

48 lines
1.4 KiB
Lua
Raw Normal View History

2024-09-15 08:10:53 +00:00
local next = next
function on_active_tick(event)
local active_mining_drills = global.active.mining_drills
local passive_mining_drills = global.passive.mining_drills
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)
local passive_mining_drills = global.passive.mining_drills
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