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 Version: 1.0.1
Date: 18.09.2024 Date: 18.09.2024
Bugfixes: Bugfixes:

View File

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

View File

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

View File

@ -11,7 +11,7 @@ function on_active_tick(event)
if status == defines.entity_status.no_minable_resources then if status == defines.entity_status.no_minable_resources then
miner.order_deconstruction(miner.force, nil) miner.order_deconstruction(miner.force, nil)
elseif status ~= defines.entity_status.working then 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) script.on_nth_tick(passive_tick, on_passive_tick)
end end
end end
@ -26,17 +26,17 @@ end
function on_passive_tick(event) function on_passive_tick(event)
local passive_mining_drills = global.passive.mining_drills 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 if miner.valid then
local status = miner.status local status = miner.status
if status == defines.entity_status.no_minable_resources then if status == defines.entity_status.no_minable_resources then
miner.order_deconstruction(miner.force, nil) miner.order_deconstruction(miner.force, nil)
passive_mining_drills[miner] = nil passive_mining_drills[id] = nil
elseif status == defines.entity_status.working then elseif status == defines.entity_status.working then
passive_mining_drills[miner] = nil passive_mining_drills[id] = nil
end end
else else
passive_mining_drills[miner] = nil passive_mining_drills[id] = nil
end end
end end