Skip to content

Commit

Permalink
Merge pull request #890 from AndrielChaoti/master
Browse files Browse the repository at this point in the history
unforbid: ignore tattered items by default
  • Loading branch information
myk002 authored Nov 12, 2023
2 parents 87e6f1a + 4b95139 commit 46d4ea8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Template for new versions:
## New Features
- `gui/design`: show selected dimensions next to the mouse cursor when designating with vanilla tools, for example when painting a burrow or designating digging
- `quickfort`: new blueprint mode for designating burrows
- `unforbid`: now ignores worn and tattered items by default (X/XX), use -X to bypass

## Fixes
- `gui/unit-syndromes`: show the syndrome names properly in the UI
Expand Down
3 changes: 3 additions & 0 deletions docs/unforbid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ Options

``-q``, ``--quiet``
Suppress non-error console output.

``-X``, ``--include-worn``
Include worn (X) and tattered (XX) items when unforbidding.
23 changes: 16 additions & 7 deletions unforbid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

local argparse = require('argparse')

local function unforbid_all(include_unreachable, quiet)
if not quiet then print('Unforbidding all items...') end
local function unforbid_all(include_unreachable, quiet, include_worn)
local p
if quiet then p=function(s) return end; else p=function(s) return print(s) end; end
p('Unforbidding all items...')

local citizens = dfhack.units.getCitizens(true)
local count = 0
Expand All @@ -19,32 +21,39 @@ local function unforbid_all(include_unreachable, quiet)
end

if not reachable then
if not quiet then print((' unreachable: %s (skipping)'):format(item)) end
p((' unreachable: %s (skipping)'):format(item))
goto skipitem
end
end

if not quiet then print((' unforbid: %s'):format(item)) end
if ((not include_worn) and item.wear >= 2) then
p((' worn: %s (skipping)'):format(item))
goto skipitem
end

p((' unforbid: %s'):format(item))
item.flags.forbid = false
count = count + 1

::skipitem::
end
end

if not quiet then print(('%d items unforbidden'):format(count)) end
p(('%d items unforbidden'):format(count))
end

-- let the common --help parameter work, even though it's undocumented
local options, args = {
help = false,
quiet = false,
include_unreachable = false,
}, { ... }
include_worn = 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 },
})

Expand All @@ -54,5 +63,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)
unforbid_all(options.include_unreachable, options.quiet, options.include_worn)
end

0 comments on commit 46d4ea8

Please sign in to comment.