Skip to content

Commit 0324a19

Browse files
authored
Merge pull request #1352 from myk002/myk_immortal
[immortal-cravings] match active caste flag instead of curse flag
2 parents 4dd7f61 + 28452f2 commit 0324a19

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Template for new versions:
3434
## Fixes
3535

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

3839
## Removed
3940

docs/immortal-cravings.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ immortal-cravings
77

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

1414
Usage
1515
-----

immortal-cravings.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ local function goDrink(unit)
7979
return
8080
end
8181
dfhack.job.addWorker(job, unit)
82-
local name = dfhack.TranslateName(dfhack.units.getVisibleName(unit))
82+
local name = dfhack.units.getReadableName(unit)
8383
print(dfhack.df2console('immortal-cravings: %s is getting a drink'):format(name))
8484
end
8585

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

@@ -171,20 +171,26 @@ local function unit_loop()
171171
end
172172
end
173173

174+
local function is_active_caste_flag(unit, flag_name)
175+
return not unit.curse.rem_tags1[flag_name] and
176+
(unit.curse.add_tags1[flag_name] or dfhack.units.casteFlagSet(unit.race, unit.caste, df.caste_raw_flags[flag_name]))
177+
end
178+
174179
---main loop: look for citizens with personality needs for food/drink but w/o physiological need
175180
local function main_loop()
176181
-- print('immortal-cravings watching:')
177182
watched = {}
178183
for _, unit in ipairs(dfhack.units.getCitizens()) do
179-
if unit.curse.add_tags1.NO_DRINK or unit.curse.add_tags1.NO_EAT then
180-
for _, need in ipairs(unit.status.current_soul.personality.needs) do
181-
if need.id == DrinkAlcohol and need.focus_level < threshold or
182-
need.id == EatGoodMeal and need.focus_level < threshold
183-
then
184-
table.insert(watched, unit.id)
185-
-- print(' '..dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit))))
186-
goto next_unit
187-
end
184+
if not is_active_caste_flag(unit, 'NO_DRINK') and not is_active_caste_flag(unit, 'NO_EAT') then
185+
goto next_unit
186+
end
187+
for _, need in ipairs(unit.status.current_soul.personality.needs) do
188+
if need.id == DrinkAlcohol and need.focus_level < threshold or
189+
need.id == EatGoodMeal and need.focus_level < threshold
190+
then
191+
table.insert(watched, unit.id)
192+
-- print(' '..dfhack.df2console(dfhack.units.getReadableName(unit)))
193+
goto next_unit
188194
end
189195
end
190196
::next_unit::

0 commit comments

Comments
 (0)