Skip to content

Commit

Permalink
Merge pull request #1352 from myk002/myk_immortal
Browse files Browse the repository at this point in the history
[immortal-cravings] match active caste flag instead of curse flag
  • Loading branch information
myk002 authored Dec 25, 2024
2 parents 4dd7f61 + 28452f2 commit 0324a19
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Template for new versions:
## Fixes

## Misc Improvements
- `immortal-cravings`: goblins and other naturally non-eating/non-drinking races will now also satisfy their needs for eating and drinking

## Removed

Expand Down
6 changes: 3 additions & 3 deletions docs/immortal-cravings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ immortal-cravings

When enabled, this script watches your fort for units that have no physiological
need to eat or drink but still have personality needs that can only be satisfied
by eating or drinking (e.g. necromancers). This enables those units to help
themselves to a drink or a meal when they crave one and are not otherwise
occupied.
by eating or drinking (e.g. necromancers or goblins). This enables those units
to help themselves to a drink or a meal when they crave one and are not
otherwise occupied.

Usage
-----
Expand Down
28 changes: 17 additions & 11 deletions immortal-cravings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ local function goDrink(unit)
return
end
dfhack.job.addWorker(job, unit)
local name = dfhack.TranslateName(dfhack.units.getVisibleName(unit))
local name = dfhack.units.getReadableName(unit)
print(dfhack.df2console('immortal-cravings: %s is getting a drink'):format(name))
end

Expand All @@ -101,7 +101,7 @@ local function goEat(unit)
return
end
dfhack.job.addWorker(job, unit)
local name = dfhack.TranslateName(dfhack.units.getVisibleName(unit))
local name = dfhack.units.getReadableName(unit)
print(dfhack.df2console('immortal-cravings: %s is getting something to eat'):format(name))
end

Expand Down Expand Up @@ -171,20 +171,26 @@ local function unit_loop()
end
end

local function is_active_caste_flag(unit, flag_name)
return not unit.curse.rem_tags1[flag_name] and
(unit.curse.add_tags1[flag_name] or dfhack.units.casteFlagSet(unit.race, unit.caste, df.caste_raw_flags[flag_name]))
end

---main loop: look for citizens with personality needs for food/drink but w/o physiological need
local function main_loop()
-- print('immortal-cravings watching:')
watched = {}
for _, unit in ipairs(dfhack.units.getCitizens()) do
if unit.curse.add_tags1.NO_DRINK or unit.curse.add_tags1.NO_EAT then
for _, need in ipairs(unit.status.current_soul.personality.needs) do
if need.id == DrinkAlcohol and need.focus_level < threshold or
need.id == EatGoodMeal and need.focus_level < threshold
then
table.insert(watched, unit.id)
-- print(' '..dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit))))
goto next_unit
end
if not is_active_caste_flag(unit, 'NO_DRINK') and not is_active_caste_flag(unit, 'NO_EAT') then
goto next_unit
end
for _, need in ipairs(unit.status.current_soul.personality.needs) do
if need.id == DrinkAlcohol and need.focus_level < threshold or
need.id == EatGoodMeal and need.focus_level < threshold
then
table.insert(watched, unit.id)
-- print(' '..dfhack.df2console(dfhack.units.getReadableName(unit)))
goto next_unit
end
end
::next_unit::
Expand Down

0 comments on commit 0324a19

Please sign in to comment.