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 Version: 1.0.2
Date: 20.09.2024 Date: 20.09.2024
Changes: Changes:

View File

@ -10,19 +10,17 @@ require("teardown.on_resource_depleted")
require("teardown.on_tick") require("teardown.on_tick")
script.on_init(function() script.on_init(function()
storage.active = {} global.active = {}
storage.active.mining_drills = {} -- [Tick:Entity] global.active.mining_drills = {} -- [Tick:Entity]
storage.passive = {} global.passive = {}
storage.passive.mining_drills = {} -- [Entity.unit_number:Entity] global.passive.mining_drills = {} -- [Entity.unit_number:Entity]
recompute_max_mining_drill_radius()
end) end)
script.on_load(function() 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) script.on_nth_tick(active_tick, on_active_tick)
end 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) script.on_nth_tick(passive_tick, on_passive_tick)
end end
end) end)

View File

@ -1,12 +1,12 @@
{ {
"name": "Teardown", "name": "Teardown",
"version": "2.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",
"contact": "david@skrundz.ca", "contact": "david@skrundz.ca",
"homepage": "https://git.skrundz.dev/skrundztorio/Teardown", "homepage": "https://git.skrundz.dev/skrundztorio/Teardown",
"factorio_version": "2.0", "factorio_version": "1.1",
"dependencies": [ "dependencies": [
"fmsl" "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() function recompute_max_mining_drill_radius()
local max_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 for _, prototype in pairs(prototypes) do
local categories = prototype.resource_categories or {} local categories = prototype.resource_categories or {}
for category, _ in pairs(categories) do for category, _ in pairs(categories) do
@ -10,5 +10,5 @@ function recompute_max_mining_drill_radius()
end end
end end
storage.max_mining_drill_radius = max_radius global.max_mining_drill_radius = max_radius
end end

View File

@ -10,10 +10,10 @@ function on_resource_depleted(event)
local position = entity.position local position = entity.position
local category = entity.prototype.resource_category 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 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) error("max_mining_drill_radius is not set for category: " .. category)
return return
end end
@ -28,10 +28,10 @@ function on_resource_depleted(event)
local target_tick = event.tick + 2 local target_tick = event.tick + 2
local add_table = false 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 for _, miner in pairs(miners) do
if miner.has_flag("not-deconstructable") then if miner.has_flag("hidden") then
goto miner_continue goto miner_continue
end end
@ -42,7 +42,7 @@ function on_resource_depleted(event)
end end
if add_table then 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) script.on_nth_tick(active_tick, on_active_tick)
end end
end end

View File

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