@@ -6,10 +6,6 @@ allneeds
66Show 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-
139local ENUM = {}
1410
1511ENUM [0 ] = " Socialize"
@@ -45,39 +41,39 @@ ENUM[29] = "AdmireArt"
4541
4642
4743local need = {}
48- local focus = {}
4944local n = 0
50- local n_needs = 0
5145for _ , 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
6861end
6962
63+ -- for sorting output
7064function compare (a ,b )
7165 return a [1 ]* a [2 ] > b [1 ]* b [2 ]
7266end
67+
7368sorted = {}
7469i = 1
7570for k ,v in pairs (need ) do
7671 sorted [i ] = {v [1 ], v [2 ], ENUM [k ]}
7772 i = i + 1
7873end
79-
8074table.sort (sorted , compare )
75+
76+ -- Print sorted output
8177print (string.format (" %20s %8s %8s" , " Need" , " Weight" , " Focus" ))
8278for 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