Skip to content

Instantly share code, notes, and snippets.

@eswald
Forked from warmist/thoughts.lua
Last active December 17, 2015 04:58
Show Gist options
  • Save eswald/5553920 to your computer and use it in GitHub Desktop.
Save eswald/5553920 to your computer and use it in GitHub Desktop.
local events_by_type={}
local event_types={}
for k,v in pairs(df.global.world.units.active) do
if dfhack.units.isCitizen(v) then
local mytypes={}
for idx,event in pairs(v.status.recent_events) do
local t=event.type
if mytypes[t]==nil then
if events_by_type[t] then
events_by_type[t]=events_by_type[t]+1
else
events_by_type[t]=1
table.insert(event_types,t)
end
mytypes[t]=true
end
end
end
end
local function thought_cmp(a, b)
return events_by_type[a] < events_by_type[b]
end
table.sort(event_types,thought_cmp)
for k,v in ipairs(event_types) do
print(events_by_type[v],df.unit_thought_type.attrs[v].caption)
end
@eswald
Copy link
Author

eswald commented May 10, 2013

Prints good and bad thoughts experienced by your dwarves, in ascending order by number of occurrences.

(Perhaps age and severity should be taken into account, but that's trickier.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment