Skip to content

Commit

Permalink
Merge pull request #1309 from Bumber64/worship_spam
Browse files Browse the repository at this point in the history
Silence stuck-worship.lua spam
  • Loading branch information
myk002 authored Oct 2, 2024
2 parents edd662a + 8d265ed commit 0f84c3a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ 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. Added ``--verbose`` and ``--quiet`` options.

## Removed

Expand Down
7 changes: 4 additions & 3 deletions docs/fix/dry-buckets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
21 changes: 20 additions & 1 deletion docs/fix/stuck-worship.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,23 @@ Usage

::

fix/stuck-worship
fix/stuck-worship [<options>]

Reshuffle prayer needs of units in the fort.

Examples
--------

``fix/stuck-worship``
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.
23 changes: 21 additions & 2 deletions fix/stuck-worship.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
local argparse = require('argparse')

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)
for idx, need in ipairs(needs) do
if need.id == df.need_type.PrayOrMeditate then
Expand Down Expand Up @@ -79,15 +87,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) then
print('rebalanced prayer needs for ' ..
dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit))))
count = count + 1
if verbose then
print('Shuffled prayer target for '..unit_name(unit))
end
end
::next_unit::
end

if not quiet or count > 0 then
print(('Rebalanced prayer needs for %d units.'):format(count))
end
2 changes: 1 addition & 1 deletion internal/control-panel/registry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0f84c3a

Please sign in to comment.