You may be past that point, but I'm working on a script to do some management of the fortress' members' food preferences for my own usage. The current state collects the food preferences and prints them in an unordered list. It contains a slight improvement to the "thoughts" script for the printout by getting rid of liver, brain, etc. from animals as well as some seed references.
You can obviously use the logic to store all preferences in the summary by removing the condition that it's a LikeFood preference, but the printing part would then have to be changed to print all versions (or be replaced with the desired processing).
function prefs_of (unit)
local results = {}
for i, preference in ipairs (unit.status.current_soul.preferences) do
if preference.active then
if preference.type == df.unit_preference.T_type.LikeFood then
table.insert (results, preference)
end
end
end
return results
end
--===================================================
function merge (into, from)
for i, from_pref in ipairs (from) do
local found = false
for k, to_pref in ipairs (into) do
if from_pref == to_pref then
found = true
break
end
end
if not found then
table.insert (into, from_pref)
end
end
end
--===================================================
function prefs ()
local civ = df.global.world.world_data.active_site [0].entity_links [0].entity_id
local sum_prefs = {}
for i, unit in ipairs (df.global.world.units.all) do
if unit.civ_id == civ and
not unit.flags1.merchant and
not unit.flags1.diplomat and
not unit.flags1.tame and -- ### Will probably exclude gremlins...
not unit.flags2.killed and
not unit.flags2.visitor then
merge (sum_prefs, prefs_of (unit))
dfhack.println (i, dfhack.TranslateName (unit.name, true))
end
end
dfhack.println ()
for i, preference in ipairs (sum_prefs) do
local material = dfhack.matinfo.decode (preference.mattype, preference.matindex)
if preference.matindex ~= -1 and
(material.mode == "plant" or
material.mode == "creature") then
if preference.item_type == df.item_type.DRINK or
preference.item_type == df.item_type.LIQUID_MISC then -- The state in the preferences seems locked to Solid
dfhack.println (material.material.state_name.Liquid)
else
if material.material.prefix == "" then
dfhack.println (material.material.state_name.Solid)
else
dfhack.println (material.material.prefix)
end
end
else
dfhack.println (df.global.world.raws.creatures.all [preference.mattype].name [0])
end
end
dfhack.println (#sum_prefs)
end
prefs ()
My eventual goal (which I may well give up on) is to assist in the growing of desired plants beyond booze producing ones to keep their produce in stock without flooding the stocks, plus a list of unavailable stuff that would be desirable to buy from caravans.
I've got a mostly untested version of the production management for booze to build on.
Edit: The merge operation doesn't work as intended as it compares two pointers rather than the items. The first 'if' comparison should be:
if from_pref.mattype == to_pref.mattype and
from_pref.matindex == to_pref.matindex then