From f3684fa4cb0813a332035925b6ee276c8f022dbc Mon Sep 17 00:00:00 2001 From: git--amade Date: Mon, 27 Oct 2025 07:50:04 +0800 Subject: [PATCH 1/6] change item.lua to use getOverallQuality --- item.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/item.lua b/item.lua index 7b91bdbf8a..5787eb7369 100644 --- a/item.lua +++ b/item.lua @@ -141,7 +141,7 @@ end --- @param upper number # range: 0 (standard) to 5 (masterwork) --- @param negate { negate : boolean }|nil function condition_quality(tab, lower, upper, negate) - local pred = function(item) return lower <= item:getQuality() and item:getQuality() <= upper end + local pred = function(item) return lower <= item:getOverallQuality() and item:getOverallQuality() <= upper end addPositiveOrNegative(tab, pred, negate) end From 3cb5ff0fd6e739d0b4d3811e644f75b3ce05c4e4 Mon Sep 17 00:00:00 2001 From: git--amade Date: Mon, 27 Oct 2025 07:56:00 +0800 Subject: [PATCH 2/6] Update changelog.txt --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 9393bba89f..30304c124a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -33,6 +33,7 @@ Template for new versions: ## New Features ## Fixes +- `item`: the ``--min-quality`` and ``--max-quality`` options now evaluate overall item quality ## Misc Improvements From aa5b63aa818a8e190141c9f6f25a395dd1f4741b Mon Sep 17 00:00:00 2001 From: git--amade Date: Tue, 28 Oct 2025 10:43:52 +0800 Subject: [PATCH 3/6] Put getOverallQuality method in its own function with option to call it --- changelog.txt | 2 +- docs/item.rst | 16 +++++++++++++--- item.lua | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/changelog.txt b/changelog.txt index 30304c124a..2a3388fad6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -33,9 +33,9 @@ Template for new versions: ## New Features ## Fixes -- `item`: the ``--min-quality`` and ``--max-quality`` options now evaluate overall item quality ## Misc Improvements +- `item`: new ``--total-quality`` option for use in conjunction with ``--min-quality`` or ``--max-quality`` to filter items according to their total quality ## Removed diff --git a/docs/item.rst b/docs/item.rst index 465382eebe..403dadcafe 100644 --- a/docs/item.rst +++ b/docs/item.rst @@ -49,7 +49,8 @@ Examples flood-fill to create a burrow covering an entire cavern layer). ``item melt -t weapon -m steel --max-quality 3`` - Designate all steel weapons whose quality is at most superior for melting. + Designate all steel weapons whose core quality is at most superior for + melting. ``item hide -t boulder --scattered`` Hide all scattered boulders, i.e. those that are not in stockpiles. @@ -121,6 +122,11 @@ Options Only include items whose quality level is at most ``integer``. Useful values are 0 (ordinary) to 5 (masterwork). +``--total-quality`` + Only applies to ``--min-quality`` and ``--max-quality`` options. Filter items + according to their total quality (to include improvements) of instead of + their core quality. + ``--stockpiled`` Only include items that are in stockpiles. Does not include empty bins, barrels, and wheelbarrows assigned as storage and transport for stockpiles. @@ -201,8 +207,12 @@ the filter is described. see above). * ``condition_quality(tab, lower, upper, negate)`` - Selects items with quality between ``lower`` and ``upper`` (Range 0-5, see - above). + Selects items with core quality between ``lower`` and ``upper`` (Range 0-5, + see above). + +* ``condition_overall_quality(tab, lower, upper, negate)`` + Selects items with total quality between ``lower`` and ``upper`` (Range 0-5, + see above). * ``condition_stockpiled(tab, negate)`` Corresponds to ``--stockpiled``. diff --git a/item.lua b/item.lua index 5787eb7369..c59c61d5b0 100644 --- a/item.lua +++ b/item.lua @@ -141,6 +141,15 @@ end --- @param upper number # range: 0 (standard) to 5 (masterwork) --- @param negate { negate : boolean }|nil function condition_quality(tab, lower, upper, negate) + local pred = function(item) return lower <= item:getQuality() and item:getQuality() <= upper end + addPositiveOrNegative(tab, pred, negate) +end + +--- @param tab conditions +--- @param lower number # range: 0 (standard) to 5 (masterwork) +--- @param upper number # range: 0 (standard) to 5 (masterwork) +--- @param negate { negate : boolean }|nil +function condition_overall_quality(tab, lower, upper, negate) local pred = function(item) return lower <= item:getOverallQuality() and item:getOverallQuality() <= upper end addPositiveOrNegative(tab, pred, negate) end @@ -346,11 +355,14 @@ local options = { owned = false, nowebs = false, verbose = false, + totalquality = false, } --- @type (fun(item:item):boolean)[] local conditions = {} +local minQuality, maxQuality + local function flagsFilter(args, negate) local flags = argparse.stringList(args, "flag list") for _,flag in ipairs(flags) do @@ -375,6 +387,7 @@ local positionals = argparse.processArgsGetopt({ ... }, { { nil, 'ignore-webs', handler = function() options.nowebs = true end }, { 'n', 'dry-run', handler = function() options.dryrun = true end }, { nil, 'by-type', handler = function() options.bytype = true end }, + { nil, 'total-quality', handler = function() options.totalquality = true end }, { 'i', 'inside', hasArg = true, handler = function (name) local burrow = dfhack.burrows.findByName(name,true) @@ -407,14 +420,18 @@ local positionals = argparse.processArgsGetopt({ ... }, { handler = function(levelst) local level = argparse.nonnegativeInt(levelst, 'max-wear') condition_wear(conditions, 0, level) end }, + -- Need to process total-quality argument before processing min/max-quality arguments, + -- since there's no guarantee the user will call total-quality first in the command line. { 'q', 'min-quality', hasArg = true, handler = function(levelst) local level = argparse.nonnegativeInt(levelst, 'min-quality') - condition_quality(conditions, level, 5) end }, + minQuality = level end }, + -- condition_quality(conditions, level, 5) end }, { 'Q', 'max-quality', hasArg = true, handler = function(levelst) local level = argparse.nonnegativeInt(levelst, 'max-quality') - condition_quality(conditions, 0, level) end }, + maxQuality = level end }, + -- condition_quality(conditions, 0, level) end }, { nil, 'stockpiled', handler = function () condition_stockpiled(conditions) end }, { nil, 'scattered', @@ -432,6 +449,22 @@ if options.help or positionals[1] == 'help' then return end +if minQuality then + if options.totalquality then + condition_overall_quality(conditions, minQuality, 5) + else + condition_quality(conditions, minQuality, 5) + end +end + +if maxQuality then + if options.totalquality then + condition_overall_quality(conditions, 0, maxQuality) + else + condition_quality(conditions, 0, maxQuality) + end +end + for i=2,#positionals do condition_description(conditions, positionals[i]) end From 003ae7dbdcaa61907b5ddc93b9c3ea97b940a9bc Mon Sep 17 00:00:00 2001 From: git--amade Date: Tue, 28 Oct 2025 10:48:02 +0800 Subject: [PATCH 4/6] Fix incorrect change category in changelog.txt --- changelog.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index 2a3388fad6..b532294de8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -31,11 +31,11 @@ Template for new versions: - `resize-armor`: resize armor or clothing item to any creature size. ## New Features +- `item`: new ``--total-quality`` option for use in conjunction with ``--min-quality`` or ``--max-quality`` to filter items according to their total quality ## Fixes -## Misc Improvements -- `item`: new ``--total-quality`` option for use in conjunction with ``--min-quality`` or ``--max-quality`` to filter items according to their total quality +## Misc Improvement ## Removed From be052f8ff605ef19331a3bad45b85537050dbe76 Mon Sep 17 00:00:00 2001 From: git--amade Date: Tue, 28 Oct 2025 11:12:54 +0800 Subject: [PATCH 5/6] Remove code duplication --- item.lua | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/item.lua b/item.lua index c59c61d5b0..7077984410 100644 --- a/item.lua +++ b/item.lua @@ -355,13 +355,14 @@ local options = { owned = false, nowebs = false, verbose = false, + filterquality = false, totalquality = false, } --- @type (fun(item:item):boolean)[] local conditions = {} -local minQuality, maxQuality +local minQuality, maxQuality = 0, 5 local function flagsFilter(args, negate) local flags = argparse.stringList(args, "flag list") @@ -425,12 +426,12 @@ local positionals = argparse.processArgsGetopt({ ... }, { { 'q', 'min-quality', hasArg = true, handler = function(levelst) local level = argparse.nonnegativeInt(levelst, 'min-quality') - minQuality = level end }, + minQuality = level options.filterquality = true end }, -- condition_quality(conditions, level, 5) end }, { 'Q', 'max-quality', hasArg = true, handler = function(levelst) local level = argparse.nonnegativeInt(levelst, 'max-quality') - maxQuality = level end }, + maxQuality = level options.filterquality = true end }, -- condition_quality(conditions, 0, level) end }, { nil, 'stockpiled', handler = function () condition_stockpiled(conditions) end }, @@ -449,19 +450,11 @@ if options.help or positionals[1] == 'help' then return end -if minQuality then +if options.filterquality then if options.totalquality then - condition_overall_quality(conditions, minQuality, 5) + condition_overall_quality(conditions, minQuality, maxQuality) else - condition_quality(conditions, minQuality, 5) - end -end - -if maxQuality then - if options.totalquality then - condition_overall_quality(conditions, 0, maxQuality) - else - condition_quality(conditions, 0, maxQuality) + condition_quality(conditions, minQuality, maxQuality) end end From 478e606245b82dc1a06206295d805d2d3ac522ef Mon Sep 17 00:00:00 2001 From: git--amade Date: Tue, 28 Oct 2025 11:16:37 +0800 Subject: [PATCH 6/6] Fix incorrect changelog.txt again --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index b532294de8..5415716601 100644 --- a/changelog.txt +++ b/changelog.txt @@ -35,7 +35,7 @@ Template for new versions: ## Fixes -## Misc Improvement +## Misc Improvements ## Removed