Compare commits
2 Commits
feaa3e7ba6
...
daaf22b726
Author | SHA1 | Date |
---|---|---|
David Skrundz | daaf22b726 | |
David Skrundz | eb17157d4e |
|
@ -1,4 +1,14 @@
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
|
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:
|
||||||
|
|
14
control.lua
14
control.lua
|
@ -10,17 +10,19 @@ require("teardown.on_resource_depleted")
|
||||||
require("teardown.on_tick")
|
require("teardown.on_tick")
|
||||||
|
|
||||||
script.on_init(function()
|
script.on_init(function()
|
||||||
global.active = {}
|
storage.active = {}
|
||||||
global.active.mining_drills = {} -- [Tick:Entity]
|
storage.active.mining_drills = {} -- [Tick:Entity]
|
||||||
global.passive = {}
|
storage.passive = {}
|
||||||
global.passive.mining_drills = {} -- [Entity.unit_number:Entity]
|
storage.passive.mining_drills = {} -- [Entity.unit_number:Entity]
|
||||||
|
|
||||||
|
recompute_max_mining_drill_radius()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
script.on_load(function()
|
script.on_load(function()
|
||||||
if next(global.active.mining_drills) ~= nil then
|
if next(storage.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(global.passive.mining_drills) ~= nil then
|
if next(storage.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)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "Teardown",
|
"name": "Teardown",
|
||||||
"version": "1.0.2",
|
"version": "2.0.1",
|
||||||
"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": "1.1",
|
"factorio_version": "2.0",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"fmsl"
|
"fmsl"
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
-- Populate global.max_mining_drill_radius with [Category:double]
|
-- Populate storage.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 = game.get_filtered_entity_prototypes({{filter = "type", type = "mining-drill"}})
|
local prototypes = prototypes.get_entity_filtered({{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
|
||||||
|
|
||||||
global.max_mining_drill_radius = max_radius
|
storage.max_mining_drill_radius = max_radius
|
||||||
end
|
end
|
||||||
|
|
|
@ -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 = global.max_mining_drill_radius[category]
|
local radius = storage.max_mining_drill_radius[category]
|
||||||
|
|
||||||
if radius == nil then
|
if radius == nil then
|
||||||
log("max_mining_drill_radius: " .. serpent.block(global.max_mining_drill_radius))
|
log("max_mining_drill_radius: " .. serpent.block(storage.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(global.active.mining_drills, target_tick) or {}
|
local active_miners = table.remove_key(storage.active.mining_drills, target_tick) or {}
|
||||||
|
|
||||||
for _, miner in pairs(miners) do
|
for _, miner in pairs(miners) do
|
||||||
if miner.has_flag("hidden") then
|
if miner.has_flag("not-deconstructable") 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
|
||||||
global.active.mining_drills[target_tick] = active_miners
|
storage.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
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
local next = next
|
local next = next
|
||||||
|
|
||||||
function on_active_tick(event)
|
function on_active_tick(event)
|
||||||
local active_mining_drills = global.active.mining_drills
|
local active_mining_drills = storage.active.mining_drills
|
||||||
local passive_mining_drills = global.passive.mining_drills
|
local passive_mining_drills = storage.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 = global.passive.mining_drills
|
local passive_mining_drills = storage.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
|
||||||
|
|
Loading…
Reference in New Issue