Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unforbid: ignore tattered items by default #890

Merged
merged 10 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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 @@ -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
myk002 marked this conversation as resolved.
Show resolved Hide resolved

## 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``
AndrielChaoti marked this conversation as resolved.
Show resolved Hide resolved
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