Avoid keying a table by LuaEntity

This commit is contained in:
David Skrundz 2024-09-20 00:35:21 -06:00
parent 44b4625518
commit feaa3e7ba6
Signed by: DavidSkrundz
GPG Key ID: D7006AAB6214A600
4 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 1.0.2
Date: 20.09.2024
Changes:
- Avoid keying a table by LuaEntity, use LuaEntity.unit_number instead
---------------------------------------------------------------------------------------------------
Version: 1.0.1
Date: 18.09.2024
Bugfixes:

View File

@ -13,7 +13,7 @@ script.on_init(function()
global.active = {}
global.active.mining_drills = {} -- [Tick:Entity]
global.passive = {}
global.passive.mining_drills = {} -- [Entity:true]
global.passive.mining_drills = {} -- [Entity.unit_number:Entity]
end)
script.on_load(function()

View File

@ -1,6 +1,6 @@
{
"name": "Teardown",
"version": "1.0.1",
"version": "1.0.2",
"title": "Teardown",
"description": "Automate the removal of depleted miners",
"author": "David Skrundz",

View File

@ -11,7 +11,7 @@ function on_active_tick(event)
if status == defines.entity_status.no_minable_resources then
miner.order_deconstruction(miner.force, nil)
elseif status ~= defines.entity_status.working then
passive_mining_drills[miner] = true
passive_mining_drills[miner.unit_number] = miner
script.on_nth_tick(passive_tick, on_passive_tick)
end
end
@ -26,17 +26,17 @@ end
function on_passive_tick(event)
local passive_mining_drills = global.passive.mining_drills
for miner, _ in pairs(passive_mining_drills) do
for id, miner in pairs(passive_mining_drills) do
if miner.valid then
local status = miner.status
if status == defines.entity_status.no_minable_resources then
miner.order_deconstruction(miner.force, nil)
passive_mining_drills[miner] = nil
passive_mining_drills[id] = nil
elseif status == defines.entity_status.working then
passive_mining_drills[miner] = nil
passive_mining_drills[id] = nil
end
else
passive_mining_drills[miner] = nil
passive_mining_drills[id] = nil
end
end