From 465213a03919ddee2e53602523e9d27d8e393269 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 24 Sep 2024 14:49:56 -0700 Subject: [PATCH 1/5] Silence stuck-worship.lua spam --- fix/stuck-worship.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fix/stuck-worship.lua b/fix/stuck-worship.lua index 0781181f5f..1531af139a 100644 --- a/fix/stuck-worship.lua +++ b/fix/stuck-worship.lua @@ -1,3 +1,5 @@ +debug_print = false + local function for_pray_need(needs, fn) for idx, need in ipairs(needs) do if need.id == df.need_type.PrayOrMeditate then @@ -85,7 +87,7 @@ for _,unit in ipairs(dfhack.units.getCitizens(false, true)) do goto next_unit end local needs = unit.status.current_soul.personality.needs - if shuffle_prayer_needs(needs, prayer_targets) then + if shuffle_prayer_needs(needs, prayer_targets) and debug_print then print('rebalanced prayer needs for ' .. dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit)))) end From 50f3f8bc1aab617033ca999f617402131cb4ffe8 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sat, 28 Sep 2024 13:59:34 -0700 Subject: [PATCH 2/5] Add verbose option, update docs * Update stuck-worship.lua * Update dry-buckets.rst * Update stuck-worship.rst * Update changelog.txt --- changelog.txt | 1 + docs/fix/dry-buckets.rst | 7 ++++--- docs/fix/stuck-worship.rst | 7 ++++--- fix/stuck-worship.lua | 24 ++++++++++++++++++++---- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/changelog.txt b/changelog.txt index ff109f1319..647ad7f854 100644 --- a/changelog.txt +++ b/changelog.txt @@ -33,6 +33,7 @@ Template for new versions: ## Fixes ## Misc Improvements +- `fix/stuck-worship`: reduced console output by default. ``--verbose`` option to print all affected units. ## Removed diff --git a/docs/fix/dry-buckets.rst b/docs/fix/dry-buckets.rst index 9d3a7d4e0b..65740e309d 100644 --- a/docs/fix/dry-buckets.rst +++ b/docs/fix/dry-buckets.rst @@ -19,6 +19,7 @@ manually. Usage ----- -:: - - fix/dry-buckets +``fix/dry-buckets`` + Empty water buckets not currently used in jobs. +``fix/dry-buckets -q``, ``fix/dry-buckets --quiet`` + Empty water buckets not currently used in jobs. Don't print to the console. diff --git a/docs/fix/stuck-worship.rst b/docs/fix/stuck-worship.rst index b0dbfe07fe..c4bccc0554 100644 --- a/docs/fix/stuck-worship.rst +++ b/docs/fix/stuck-worship.rst @@ -26,6 +26,7 @@ another task. Usage ----- -:: - - fix/stuck-worship +``fix/stuck-worship`` + Rebalance prayer needs of units in the fort. +``fix/stuck-worship -v``, ``fix/stuck-worship --verbose`` + Rebalance prayer needs of units in the fort. Print names of affected units. diff --git a/fix/stuck-worship.lua b/fix/stuck-worship.lua index 1531af139a..0222dd6fe0 100644 --- a/fix/stuck-worship.lua +++ b/fix/stuck-worship.lua @@ -1,4 +1,9 @@ -debug_print = false +local argparse = require('argparse') + +local verbose = false +argparse.processArgsGetopt({...}, { + {'v', 'verbose', handler=function() verbose = true end}, +}) local function for_pray_need(needs, fn) for idx, need in ipairs(needs) do @@ -81,15 +86,26 @@ local function get_prayer_targets(unit) end end +local function unit_name(unit) + return dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit))) +end + +local count = 0 for _,unit in ipairs(dfhack.units.getCitizens(false, true)) do local prayer_targets = get_prayer_targets(unit) if not unit.status.current_soul or not prayer_targets then goto next_unit end local needs = unit.status.current_soul.personality.needs - if shuffle_prayer_needs(needs, prayer_targets) and debug_print then - print('rebalanced prayer needs for ' .. - dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit)))) + if shuffle_prayer_needs(needs, prayer_targets) then + count = count + 1 + if verbose then + print('Shuffled prayer target for '..unit_name(unit)) + end end ::next_unit:: end + +if verbose or count > 0 then + print(('Rebalanced prayer needs for %d units.'):format(count)) +end From cbffc93a12786768dcf010f873ed391709b415a8 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 29 Sep 2024 21:06:00 -0700 Subject: [PATCH 3/5] Add quiet option * Update stuck-worship.rst * Update stuck-worship.lua * Update registry.lua --- docs/fix/stuck-worship.rst | 25 ++++++++++++++++++++++--- fix/stuck-worship.lua | 5 +++-- internal/control-panel/registry.lua | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/docs/fix/stuck-worship.rst b/docs/fix/stuck-worship.rst index c4bccc0554..2854be122b 100644 --- a/docs/fix/stuck-worship.rst +++ b/docs/fix/stuck-worship.rst @@ -26,7 +26,26 @@ another task. Usage ----- +:: + + fix/stuck-worship [] + +Reshuffle prayer needs of units in the fort. + +Examples +-------- + ``fix/stuck-worship`` - Rebalance prayer needs of units in the fort. -``fix/stuck-worship -v``, ``fix/stuck-worship --verbose`` - Rebalance prayer needs of units in the fort. Print names of affected units. + Rebalance prayer needs and print the total number of affected units. +``fix/stuck-worship -v`` + Same as above, but also print the names of all affected units. + +Options +------- + +``-v``, ``--verbose`` + Print the names of all affected units. +``-q``, ``--quiet`` + Don't print the number of affected units if it's zero. Intended for + automatic use. + diff --git a/fix/stuck-worship.lua b/fix/stuck-worship.lua index 0222dd6fe0..2d48809141 100644 --- a/fix/stuck-worship.lua +++ b/fix/stuck-worship.lua @@ -1,8 +1,9 @@ local argparse = require('argparse') -local verbose = false +local verbose, quiet = false, false argparse.processArgsGetopt({...}, { {'v', 'verbose', handler=function() verbose = true end}, + {'q', 'quiet', handler=function() quiet = true end}, }) local function for_pray_need(needs, fn) @@ -106,6 +107,6 @@ for _,unit in ipairs(dfhack.units.getCitizens(false, true)) do ::next_unit:: end -if verbose or count > 0 then +if not quiet or count > 0 then print(('Rebalanced prayer needs for %d units.'):format(count)) end diff --git a/internal/control-panel/registry.lua b/internal/control-panel/registry.lua index 4e0bdd2e67..7dca4d2b01 100644 --- a/internal/control-panel/registry.lua +++ b/internal/control-panel/registry.lua @@ -90,7 +90,7 @@ COMMANDS_BY_IDX = { desc='Fix activity references on stuck instruments to make them usable again.', params={'--time', '1', '--timeUnits', 'days', '--command', '[', 'fix/stuck-instruments', ']'}}, {command='fix/stuck-worship', group='bugfix', mode='repeat', default=true, - params={'--time', '1', '--timeUnits', 'days', '--command', '[', 'fix/stuck-worship', ']'}}, + params={'--time', '1', '--timeUnits', 'days', '--command', '[', 'fix/stuck-worship', '-q', ']'}}, {command='fix/noexert-exhaustion', group='bugfix', mode='repeat', default=true, params={'--time', '439', '--timeUnits', 'ticks', '--command', '[', 'fix/noexert-exhaustion', ']'}}, {command='flask-contents', help_command='tweak', group='bugfix', mode='tweak', default=true, From 5b43f4a01b53de91cdc0b8b32f7e9de51c667a6c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 04:07:29 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/fix/stuck-worship.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/fix/stuck-worship.rst b/docs/fix/stuck-worship.rst index 2854be122b..04c4129364 100644 --- a/docs/fix/stuck-worship.rst +++ b/docs/fix/stuck-worship.rst @@ -48,4 +48,3 @@ Options ``-q``, ``--quiet`` Don't print the number of affected units if it's zero. Intended for automatic use. - From 8d265ed42cd674d9074c4cb9806a71341399f452 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Mon, 30 Sep 2024 15:16:19 -0700 Subject: [PATCH 5/5] Update changelog.txt --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 0a14d6a6e6..7507a87ba1 100644 --- a/changelog.txt +++ b/changelog.txt @@ -36,7 +36,7 @@ Template for new versions: ## Misc Improvements - `control-panel`: Add realistic-melting tweak to control-panel registry - `idle-crafting`: also support making shell crafts for workshops with linked input stockpiles -- `fix/stuck-worship`: reduced console output by default. ``--verbose`` option to print all affected units. +- `fix/stuck-worship`: reduced console output by default. Added ``--verbose`` and ``--quiet`` options. ## Removed