Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docs/unforbid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 13 additions & 3 deletions unforbid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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...')
Expand Down Expand Up @@ -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
Expand All @@ -47,14 +55,16 @@ local options, args = {
help = false,
quiet = false,
include_unreachable = false,
include_worn = false
include_worn = false,
metal_only = false
}, {...}

local positionals = argparse.processArgsGetopt(args, {
{ 'h', 'help', handler = function() options.help = true end },
{ '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
Expand All @@ -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