@@ -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 ))
8484end
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 ))
106106end
107107
@@ -171,20 +171,26 @@ local function unit_loop()
171171 end
172172end
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
175180local 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