-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathresearch-info.lua
More file actions
69 lines (57 loc) · 2.13 KB
/
Copy pathresearch-info.lua
File metadata and controls
69 lines (57 loc) · 2.13 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
local researchInfo = reqscript("internal/research-info/info")
local function sortResearchDataByPercAndPondered(data_list)
table.sort(data_list, function(a, b)
if tonumber(a.research_percentage) == tonumber(b.research_percentage) then
return a.times_pondered > b.times_pondered
end
return tonumber(a.research_percentage) > tonumber(b.research_percentage)
end)
return data_list
end
local function printResearchData(data)
if not data then
print("No data to display.")
return
end
if data.research_points == 0 and data.knowledge_goal == "" and data.times_pondered == 0 then
return
end
print("==================")
print("Dwarf: " .. data.name)
print("\tKnowledge Goal Category: " .. data.knowledge_goal_category)
print("\tKnowledge Goal: " .. data.knowledge_goal)
print("\tResearch Points: " .. data.research_points .. "/100000")
print("\tResearch Percentage: " .. data.research_percentage .. "%")
print("\tTimes Pondered: " .. data.times_pondered)
if #data.research_topics > 0 then
print("Knowledge:")
for _, topic in ipairs(data.research_topics) do
print("\t" .. topic.name .. ": " .. topic.info)
end
end
end
--
local unit = dfhack.units.getCitizens()
local selected_unit = dfhack.gui.getSelectedUnit()
if unit then
local research_data_list = {}
for i, unit in pairs(dfhack.units.getCitizens()) do
if selected_unit and selected_unit.id ~= unit.id then
goto continue
end
local historical_figure = df.historical_figure.find(unit.hist_figure_id)
if historical_figure then
local research_data, error_msg = researchInfo.getResearchData(historical_figure)
if research_data then
for _, data in ipairs(research_data) do
table.insert(research_data_list, data)
end
end
end
::continue::
end
research_data_list = sortResearchDataByPercAndPondered(research_data_list)
for _, data in ipairs(research_data_list) do
printResearchData(data)
end
end