forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allneeds.lua
39 lines (33 loc) · 1.18 KB
/
allneeds.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- Prints the sum of all citizens' needs.
local fort_needs = {}
for _, unit in pairs(df.global.world.units.all) do
if not dfhack.units.isCitizen(unit) or not dfhack.units.isAlive(unit) then
goto skipunit
end
local mind = unit.status.current_soul.personality.needs
-- sum need_level and focus_level for each need
for _,need in pairs(mind) do
local needs = ensure_key(fort_needs, need.id)
needs.cumulative_need = (needs.cumulative_need or 0) + need.need_level
needs.cumulative_focus = (needs.cumulative_focus or 0) + need.focus_level
needs.citizen_count = (needs.citizen_count or 0) + 1
end
:: skipunit ::
end
local sorted_fort_needs = {}
for id, need in pairs(fort_needs) do
table.insert(sorted_fort_needs, {
df.need_type[id],
need.cumulative_need,
need.cumulative_focus,
need.citizen_count
})
end
table.sort(sorted_fort_needs, function(a, b)
return a[2] > b[2]
end)
-- Print sorted output
print(([[%20s %8s %8s %10s]]):format("Need", "Weight", "Focus", "# Dwarves"))
for _, need in pairs(sorted_fort_needs) do
print(([[%20s %8.f %8.f %10d]]):format(need[1], need[2], need[3], need[4]))
end