Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[immortal-cravings] match active caste flag instead of curse flag #1352

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading