Skip to content

Commit f0dbb1c

Browse files
previsualconsentvallode
authored andcommitted
cleanup and comments
1 parent ffa964e commit f0dbb1c

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

allneeds.lua

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ allneeds
66
Show which neesd are high for all dwarfs
77
88
]====]
9-
local utils = require('utils')
10-
local validArgs = utils.invert({})
11-
local args = utils.processArgs({...}, validArgs)
12-
139
local ENUM = {}
1410

1511
ENUM[0] = "Socialize"
@@ -45,39 +41,39 @@ ENUM[29] = "AdmireArt"
4541

4642

4743
local need = {}
48-
local focus = {}
4944
local n = 0
50-
local n_needs = 0
5145
for _, unit in ipairs(df.global.world.units.all) do
52-
-- local unit = dfhack.gui.getSelectedUnit(true)
5346
if not unit then
54-
qerror('A unit must be specified or selected.')
47+
qerror('Unit not real.')
5548
end
49+
-- Select valid dwarf
5650
if unit.status.current_soul and unit.race == 572 then
5751
n = n+1
58-
local mind = unit.status.current_soul.personality.needs
59-
for k,v in pairs(mind) do
60-
n_needs = n_needs +1
61-
if need[v.id] == nil then
62-
need[v.id] = {0, 0}
63-
end
64-
need[v.id] = {need[v.id][1] + v.need_level, need[v.id][2] + v.focus_level}
65-
end
52+
local mind = unit.status.current_soul.personality.needs
53+
-- sum need_level and focus_level for each need
54+
for k,v in pairs(mind) do
55+
if need[v.id] == nil then
56+
need[v.id] = {0, 0}
57+
end
58+
need[v.id] = {need[v.id][1] + v.need_level, need[v.id][2] + v.focus_level}
59+
end
6660
end
67-
-- break
6861
end
6962

63+
-- for sorting output
7064
function compare(a,b)
7165
return a[1]*a[2] > b[1]*b[2]
7266
end
67+
7368
sorted = {}
7469
i = 1
7570
for k,v in pairs(need) do
7671
sorted[i] = {v[1], v[2], ENUM[k]}
7772
i = i + 1
7873
end
79-
8074
table.sort(sorted, compare)
75+
76+
-- Print sorted output
8177
print(string.format("%20s %8s %8s", "Need", "Weight", "Focus"))
8278
for k,v in ipairs(sorted) do
8379
print(string.format("%20s %8.1f %8.1f", v[3], v[1]/n, v[2]/n))

0 commit comments

Comments
 (0)