Compare commits

..

No commits in common. "daaf22b72681613c97a58610c7eb5c65c75aa444" and "feaa3e7ba61af800c2c9af3c93aabafb745f7e94" have entirely different histories.

6 changed files with 19 additions and 31 deletions

View File

@ -1,14 +1,4 @@
---------------------------------------------------------------------------------------------------
Version: 2.0.1
Date: 04.11.2024
Bugfixes:
- Prevent crash on new saves
---------------------------------------------------------------------------------------------------
Version: 2.0.0
Date: 20.10.2024
Major Features:
- Update to 2.0
---------------------------------------------------------------------------------------------------
Version: 1.0.2
Date: 20.09.2024
Changes:

View File

@ -10,19 +10,17 @@ require("teardown.on_resource_depleted")
require("teardown.on_tick")
script.on_init(function()
storage.active = {}
storage.active.mining_drills = {} -- [Tick:Entity]
storage.passive = {}
storage.passive.mining_drills = {} -- [Entity.unit_number:Entity]
recompute_max_mining_drill_radius()
global.active = {}
global.active.mining_drills = {} -- [Tick:Entity]
global.passive = {}
global.passive.mining_drills = {} -- [Entity.unit_number:Entity]
end)
script.on_load(function()
if next(storage.active.mining_drills) ~= nil then
if next(global.active.mining_drills) ~= nil then
script.on_nth_tick(active_tick, on_active_tick)
end
if next(storage.passive.mining_drills) ~= nil then
if next(global.passive.mining_drills) ~= nil then
script.on_nth_tick(passive_tick, on_passive_tick)
end
end)

View File

@ -1,12 +1,12 @@
{
"name": "Teardown",
"version": "2.0.1",
"version": "1.0.2",
"title": "Teardown",
"description": "Automate the removal of depleted miners",
"author": "David Skrundz",
"contact": "david@skrundz.ca",
"homepage": "https://git.skrundz.dev/skrundztorio/Teardown",
"factorio_version": "2.0",
"factorio_version": "1.1",
"dependencies": [
"fmsl"
]

View File

@ -1,8 +1,8 @@
-- Populate storage.max_mining_drill_radius with [Category:double]
-- Populate global.max_mining_drill_radius with [Category:double]
function recompute_max_mining_drill_radius()
local max_radius = {}
local prototypes = prototypes.get_entity_filtered({{filter = "type", type = "mining-drill"}})
local prototypes = game.get_filtered_entity_prototypes({{filter = "type", type = "mining-drill"}})
for _, prototype in pairs(prototypes) do
local categories = prototype.resource_categories or {}
for category, _ in pairs(categories) do
@ -10,5 +10,5 @@ function recompute_max_mining_drill_radius()
end
end
storage.max_mining_drill_radius = max_radius
global.max_mining_drill_radius = max_radius
end

View File

@ -10,10 +10,10 @@ function on_resource_depleted(event)
local position = entity.position
local category = entity.prototype.resource_category
local radius = storage.max_mining_drill_radius[category]
local radius = global.max_mining_drill_radius[category]
if radius == nil then
log("max_mining_drill_radius: " .. serpent.block(storage.max_mining_drill_radius))
log("max_mining_drill_radius: " .. serpent.block(global.max_mining_drill_radius))
error("max_mining_drill_radius is not set for category: " .. category)
return
end
@ -28,10 +28,10 @@ function on_resource_depleted(event)
local target_tick = event.tick + 2
local add_table = false
local active_miners = table.remove_key(storage.active.mining_drills, target_tick) or {}
local active_miners = table.remove_key(global.active.mining_drills, target_tick) or {}
for _, miner in pairs(miners) do
if miner.has_flag("not-deconstructable") then
if miner.has_flag("hidden") then
goto miner_continue
end
@ -42,7 +42,7 @@ function on_resource_depleted(event)
end
if add_table then
storage.active.mining_drills[target_tick] = active_miners
global.active.mining_drills[target_tick] = active_miners
script.on_nth_tick(active_tick, on_active_tick)
end
end

View File

@ -1,8 +1,8 @@
local next = next
function on_active_tick(event)
local active_mining_drills = storage.active.mining_drills
local passive_mining_drills = storage.passive.mining_drills
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
@ -24,7 +24,7 @@ function on_active_tick(event)
end
function on_passive_tick(event)
local passive_mining_drills = storage.passive.mining_drills
local passive_mining_drills = global.passive.mining_drills
for id, miner in pairs(passive_mining_drills) do
if miner.valid then