Skip to content

Commit

Permalink
Merge pull request DFHack#1053 from terribleperson/master
Browse files Browse the repository at this point in the history
zero-noexert-exhaustion bugfix script, doc, and control-panel registry entry
  • Loading branch information
myk002 authored Mar 21, 2024
2 parents f3caae6 + 1d3db85 commit 3413b06
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/fix/noexert-exhaustion.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
fix/noexert-exhaustion
======================

.. dfhack-tool::
:summary: Prevents NOEXERT units from getting tired when training.
:tags: fort bugfix units

This tool zeroes the "exhaustion" counter of all NOEXERT units (e.g. Vampires, Necromancers, and Intelligent Undead),
fixing any that are stuck 'Tired' from an activity that doesn't respect NOEXERT. This is not a permanent fix -
the issue will reoccur next time they partake in an activity that does not respect the NOEXERT tag.

Running this regularly works around :bug:`8389`, which permanently debuffs NOEXERT units and prevents them from
properly partaking in military training. It should be run if you notice Vampires, Necromancers, or Intelligent
Undead becoming 'Tired'. Enabling this script via `control-panel` or `gui/control-panel` will run it often enough to
prevent NOEXERT units from becoming 'Tired'.

Usage
-----
::

fix/noexert-exhaustion

Technical details
-----------------

Units with the NOEXERT tag ignore most sources of physical exertion, and have no means to recover from it.
Individual Combat Drill seems to add approximately 50 'Exhaustion' every 9 ticks, ignoring NOEXERT.
Units become Tired at 2000 Exhaustion, and switch from Individual Combat Drill to Individual Combat Drill/Resting at 3000.
Setting the Exhaustion counter of every NOEXERT-tagged unit to 0 every 350 ticks should prevent them from becoming Tired from Individual Combat Drill.
27 changes: 27 additions & 0 deletions fix/noexert-exhaustion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--checks all units for the NOEXERT tag, and sets their Exhaustion counter to zero
--NOEXERT units (including Vampires, Necromancers, and Intelligent Undead) are unable to lower their Exhaustion, and are not supposed to gain Exhaustion.
--at least one activity (Individual Combat Drill) doesn't respect NOEXERT, and will leave NOEXERT units permanently Tired. This script will fix 'Tired' NOEXERT units.
--Individual Combat Drill seems to add 50 Exhaustion approximately every 9 ticks. 'Tired' appears at 2000 Exhaustion, and dwarves switch to Individual Combat Drill/Resting at 3000 Exhaustion.
--Running this script on repeat approximately at least every 350 ticks should prevent NOEXERT units from becoming Tired as a result of Individual Combat Drill.

function isNoExert(u)
if(u.curse.rem_tags1.NOEXERT) then --tag removal overrides tag addition, so if the NOEXERT tag is removed the unit cannot be NOEXERT.
return false
end
if(u.curse.add_tags1.NOEXERT) then--if the tag hasn't been removed, and the unit has a curse that adds it, they must be NOEXERT.
return true
end
if(dfhack.units.casteFlagSet(u.race,u.caste, df.caste_raw_flags.NOEXERT)) then --if the tag hasn't been added or removed, but their race and caste has the tag, they're NOEXERT.
return true
end
end

function fixNoExertExhaustion()
for _, unit in ipairs(dfhack.units.getCitizens()) do
if(isNoExert(unit)) then
unit.counters2.exhaustion = 0 -- 0 represents no Exhaustion. NOEXERT units should never have Exhaustion above 0.
end
end
end

fixNoExertExhaustion()
2 changes: 2 additions & 0 deletions internal/control-panel/registry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ COMMANDS_BY_IDX = {
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', ']'}},
{command='fix/noexert-exhaustion', group='bugfix', mode='repeat', default=true,
params={'--time', '439', '--timeUnits', 'ticks', '--command', '[', 'fix/zero-noexert-exhaustion', ']'}},
{command='flask-contents', help_command='tweak', group='bugfix', mode='tweak', default=true,
desc='Displays flask contents in the item name, similar to barrels and bins.'},
{command='preserve-tombs', group='bugfix', mode='enable', default=true},
Expand Down

0 comments on commit 3413b06

Please sign in to comment.