Initial commit
This commit is contained in:
commit
bf398c7ff5
|
@ -0,0 +1 @@
|
||||||
|
*.zip
|
|
@ -0,0 +1,33 @@
|
||||||
|
column_limit: 100
|
||||||
|
indent_width: 2
|
||||||
|
use_tab: false
|
||||||
|
tab_width: 4
|
||||||
|
continuation_indent_width: 4
|
||||||
|
keep_simple_control_block_one_line: false
|
||||||
|
keep_simple_function_one_line: false
|
||||||
|
align_args: true
|
||||||
|
break_after_functioncall_lp: false
|
||||||
|
break_before_functioncall_rp: false
|
||||||
|
align_parameter: true
|
||||||
|
chop_down_parameter: true
|
||||||
|
break_after_functiondef_lp: true
|
||||||
|
break_before_functiondef_rp: true
|
||||||
|
align_table_field: true
|
||||||
|
break_after_table_lb: true
|
||||||
|
break_before_table_rb: true
|
||||||
|
chop_down_table: false
|
||||||
|
chop_down_kv_table: true
|
||||||
|
column_table_limit: 100
|
||||||
|
column_table_limit_kv: 100
|
||||||
|
table_sep: ","
|
||||||
|
extra_sep_at_table_end: true
|
||||||
|
break_after_operator: false
|
||||||
|
single_quote_to_double_quote: true
|
||||||
|
double_quote_to_single_quote: false
|
||||||
|
spaces_before_call: 1
|
||||||
|
spaces_inside_functiondef_parens: false
|
||||||
|
spaces_inside_functioncall_parens: false
|
||||||
|
spaces_inside_table_braces: false
|
||||||
|
spaces_around_equals_in_field: true
|
||||||
|
line_breaks_after_function_body: 1
|
||||||
|
line_separator: input
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"koihik.vscode-lua-format",
|
||||||
|
],
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"editor.detectIndentation": false,
|
||||||
|
"editor.tabSize": 4,
|
||||||
|
"editor.insertSpaces": false,
|
||||||
|
"[lua]": {
|
||||||
|
"editor.detectIndentation": false,
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"editor.insertSpaces": true,
|
||||||
|
},
|
||||||
|
"vscode-lua-format.configPath": ".vscode/.lua-format"
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
How to Contribute
|
||||||
|
=================
|
||||||
|
|
||||||
|
We'd love to accept your patches and contributions to this project.
|
||||||
|
We just need you to follow the Contributor License Agreement outlined
|
||||||
|
in the latest v0.0.x of https://github.com/Skrunix/license
|
|
@ -0,0 +1,7 @@
|
||||||
|
Skrunix Software License
|
||||||
|
========================
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software is
|
||||||
|
outlined in the latest v0.0.x of https://github.com/Skrunix/license
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS"
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Teardown
|
||||||
|
|
||||||
|
Automate the removal of depleted miners
|
||||||
|
|
||||||
|
---
|
|
@ -0,0 +1,5 @@
|
||||||
|
---------------------------------------------------------------------------------------------------
|
||||||
|
Version: 0.0.1
|
||||||
|
Date: 15.09.2024
|
||||||
|
Features:
|
||||||
|
- Initial release
|
|
@ -0,0 +1,30 @@
|
||||||
|
fmsl = require("__fmsl__.fmsl")
|
||||||
|
|
||||||
|
local next = next
|
||||||
|
|
||||||
|
active_tick = 1
|
||||||
|
passive_tick = 31
|
||||||
|
|
||||||
|
require("teardown.mining_drill")
|
||||||
|
require("teardown.on_resource_depleted")
|
||||||
|
require("teardown.on_tick")
|
||||||
|
|
||||||
|
script.on_init(function()
|
||||||
|
global.active = {}
|
||||||
|
global.active.mining_drills = {} -- [Tick:Entity]
|
||||||
|
global.passive = {}
|
||||||
|
global.passive.mining_drills = {} -- [Entity:true]
|
||||||
|
|
||||||
|
recompute_max_mining_drill_radius()
|
||||||
|
end)
|
||||||
|
|
||||||
|
script.on_load(function()
|
||||||
|
if next(global.active.mining_drills) ~= nil then
|
||||||
|
script.on_nth_tick(active_tick, on_active_tick)
|
||||||
|
end
|
||||||
|
if next(global.passive.mining_drills) ~= nil then
|
||||||
|
script.on_nth_tick(passive_tick, on_passive_tick)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
script.on_event(defines.events.on_resource_depleted, on_resource_depleted)
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"name": "Teardown",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"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": "1.1",
|
||||||
|
"dependencies": [
|
||||||
|
"fmsl"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
|
modFiles = [
|
||||||
|
"info.json",
|
||||||
|
"changelog.txt",
|
||||||
|
"thumbnail.png",
|
||||||
|
|
||||||
|
"control.lua",
|
||||||
|
]
|
||||||
|
modFolders = [
|
||||||
|
"teardown",
|
||||||
|
]
|
||||||
|
|
||||||
|
with open("info.json") as file:
|
||||||
|
modInfo = json.load(file)
|
||||||
|
|
||||||
|
mod_name = modInfo["name"]
|
||||||
|
mod_version = modInfo["version"]
|
||||||
|
zipName = f"{mod_name}_{mod_version}"
|
||||||
|
|
||||||
|
with ZipFile(f"{zipName}.zip", 'w') as modZip:
|
||||||
|
for file in modFiles:
|
||||||
|
modZip.write(file, arcname=f"{zipName}/{file}")
|
||||||
|
for folder in modFolders:
|
||||||
|
for root, dirs, files in os.walk(folder):
|
||||||
|
for file in files:
|
||||||
|
filePath = os.path.join(root, file)
|
||||||
|
archivePath = os.path.relpath(filePath, os.path.join(folder, '..'))
|
||||||
|
modZip.write(filePath, arcname=f"{zipName}/{archivePath}")
|
|
@ -0,0 +1,14 @@
|
||||||
|
-- Populate global.max_mining_drill_radius with [Category:double]
|
||||||
|
function recompute_max_mining_drill_radius()
|
||||||
|
local max_radius = {}
|
||||||
|
|
||||||
|
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
|
||||||
|
max_radius[category] = math.max(max_radius[category] or 0, prototype.mining_drill_radius or 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
global.max_mining_drill_radius = max_radius
|
||||||
|
end
|
|
@ -0,0 +1,48 @@
|
||||||
|
function on_resource_depleted(event)
|
||||||
|
local entity = event.entity
|
||||||
|
|
||||||
|
if entity.initial_amount ~= nil then
|
||||||
|
-- Infinite Resource
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local surface = entity.surface
|
||||||
|
local position = entity.position
|
||||||
|
|
||||||
|
local category = entity.prototype.resource_category
|
||||||
|
local radius = global.max_mining_drill_radius[category]
|
||||||
|
|
||||||
|
if radius == nil then
|
||||||
|
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
|
||||||
|
|
||||||
|
local miners = surface.find_entities_filtered({
|
||||||
|
area = fmsl.box.center_radius(position, radius),
|
||||||
|
type = "mining-drill",
|
||||||
|
to_be_deconstructed = false,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- two tick delay for dropping product and finding a new resource node
|
||||||
|
local target_tick = event.tick + 2
|
||||||
|
|
||||||
|
local add_table = false
|
||||||
|
local active_miners = table.remove_key(global.active.mining_drills, target_tick) or {}
|
||||||
|
|
||||||
|
for _, miner in pairs(miners) do
|
||||||
|
if miner.has_flag("hidden") then
|
||||||
|
goto miner_continue
|
||||||
|
end
|
||||||
|
|
||||||
|
add_table = true
|
||||||
|
table.insert(active_miners, miner)
|
||||||
|
|
||||||
|
::miner_continue::
|
||||||
|
end
|
||||||
|
|
||||||
|
if add_table then
|
||||||
|
global.active.mining_drills[target_tick] = active_miners
|
||||||
|
script.on_nth_tick(active_tick, on_active_tick)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,47 @@
|
||||||
|
local next = next
|
||||||
|
|
||||||
|
function on_active_tick(event)
|
||||||
|
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
|
||||||
|
if miner.valid then
|
||||||
|
local status = miner.status
|
||||||
|
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
|
||||||
|
script.on_nth_tick(passive_tick, on_passive_tick)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if next(active_mining_drills) == nil then
|
||||||
|
script.on_nth_tick(active_tick, nil)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_passive_tick(event)
|
||||||
|
local passive_mining_drills = global.passive.mining_drills
|
||||||
|
|
||||||
|
for 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
|
||||||
|
elseif status == defines.entity_status.working then
|
||||||
|
passive_mining_drills[miner] = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
passive_mining_drills[miner] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if next(passive_mining_drills) == nil then
|
||||||
|
script.on_nth_tick(passive_tick, nil)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
Loading…
Reference in New Issue