From a9040ed1afa5f2b0355106b3266abe459d9f06b6 Mon Sep 17 00:00:00 2001 From: pajawojciech Date: Mon, 5 Jan 2026 20:48:16 +0100 Subject: [PATCH] Add --metal-only option to unforbid command --- changelog.txt | 1 + docs/unforbid.rst | 3 +++ unforbid.lua | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index d9d0d44ea0..6415a7ec3c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -29,6 +29,7 @@ Template for new versions: ## New Tools ## New Features +- `unforbid`: added ``-m/--metal-only`` option to only unforbid items made of metal ## Fixes diff --git a/docs/unforbid.rst b/docs/unforbid.rst index 03615492ad..ac68ef97b2 100644 --- a/docs/unforbid.rst +++ b/docs/unforbid.rst @@ -27,3 +27,6 @@ Options ``-X``, ``--include-worn`` Include worn (X) and tattered (XX) items when unforbidding. + +``-m``, ``--metal-only`` + Only unforbid items made of metal. diff --git a/unforbid.lua b/unforbid.lua index 286218a211..0841d72441 100644 --- a/unforbid.lua +++ b/unforbid.lua @@ -2,7 +2,7 @@ local argparse = require('argparse') -local function unforbid_all(include_unreachable, quiet, include_worn) +local function unforbid_all(include_unreachable, quiet, include_worn, metal_only) local p if quiet then p=function(s) return end; else p=function(s) return print(s) end; end p('Unforbidding all items...') @@ -31,6 +31,14 @@ local function unforbid_all(include_unreachable, quiet, include_worn) goto skipitem end + if metal_only then + local matinfo = dfhack.matinfo.decode(item) + if not matinfo or not matinfo.material.flags.IS_METAL then + p((' not metal: %s (skipping)'):format(item)) + goto skipitem + end + end + p((' unforbid: %s'):format(item)) item.flags.forbid = false count = count + 1 @@ -47,7 +55,8 @@ local options, args = { help = false, quiet = false, include_unreachable = false, - include_worn = false + include_worn = false, + metal_only = false }, {...} local positionals = argparse.processArgsGetopt(args, { @@ -55,6 +64,7 @@ local positionals = argparse.processArgsGetopt(args, { { 'q', 'quiet', handler = function() options.quiet = true end }, { 'X', 'include-worn', handler = function() options.include_worn = true end}, { 'u', 'include-unreachable', handler = function() options.include_unreachable = true end }, + { 'm', 'metal-only', handler = function() options.metal_only = true end }, }) if positionals[1] == nil or positionals[1] == 'help' or options.help then @@ -63,5 +73,5 @@ if positionals[1] == nil or positionals[1] == 'help' or options.help then end if positionals[1] == 'all' then - unforbid_all(options.include_unreachable, options.quiet, options.include_worn) + unforbid_all(options.include_unreachable, options.quiet, options.include_worn, options.metal_only) end