|
| 1 | +-- Main module for research-info |
| 2 | +--@ module = true |
| 3 | + |
| 4 | +---@param unit_id df.unit.id |
| 5 | +function getHistoricalFigure(unit_id) |
| 6 | + for _, historical_figure in ipairs(df.global.world.history.figures) do |
| 7 | + if historical_figure.unit_id == unit_id then |
| 8 | + return historical_figure |
| 9 | + end |
| 10 | + end |
| 11 | + print("No historical figure found for unit ID: " .. unit_id) |
| 12 | + return nil |
| 13 | +end |
| 14 | + |
| 15 | +function getKnowledgeGoalCategoryInfo(category_id) |
| 16 | + -- alt: df.scholar_knowledgest |
| 17 | + local topic_categories = { |
| 18 | + [-1] = "None", -- None |
| 19 | + [0] = "Philosophy", -- PHILOSOPHY_FLAG |
| 20 | + [1] = "Philosophy Adv", -- PHILOSOPHY_FLAG2 |
| 21 | + [2] = "Mathematics", -- MATHEMATICS_FLAG |
| 22 | + [3] = "Mathematics Adv", -- MATHEMATICS_FLAG2 |
| 23 | + [4] = "History", -- HISTORY_FLAG |
| 24 | + [5] = "Astronomy", -- ASTRONOMY_FLAG |
| 25 | + [6] = "Naturalist", -- NATURALIST_FLAG |
| 26 | + [7] = "Chemistry", -- CHEMISTRY_FLAG |
| 27 | + [8] = "Geography", -- GEOGRAPHY_FLAG |
| 28 | + [9] = "Medicine 1", -- MEDICINE_FLAG |
| 29 | + [10] = "Medicine 2", -- MEDICINE_FLAG2 |
| 30 | + [11] = "Medicine 3", -- MEDICINE_FLAG3 |
| 31 | + [12] = "Engineering", -- ENGINEERING_FLAG |
| 32 | + [13] = "Engineering Adv" -- ENGINEERING_FLAG2 |
| 33 | + } |
| 34 | + return topic_categories[category_id] or string.format("Unknown Category: %s", category_id) |
| 35 | +end |
| 36 | + |
| 37 | +function getGoalInfo(goal, category) |
| 38 | + local goal_info = '' |
| 39 | + if not goal then |
| 40 | + return goal_info |
| 41 | + end |
| 42 | + |
| 43 | + local goal_info = "" |
| 44 | + for i = 0, 31 do |
| 45 | + if goal[i] then |
| 46 | + local global_flag_index = category * 32 + i -- wizards move |
| 47 | + goal_info = string.format("%s", df.dfhack_knowledge_scholar_flag[global_flag_index]) or string.format("Unknown Flag: %s", i) |
| 48 | + end |
| 49 | + end |
| 50 | + return goal_info |
| 51 | +end |
| 52 | + |
| 53 | +local function getTopicInfo(topic) |
| 54 | + if not topic then |
| 55 | + return "No topic information available." |
| 56 | + end |
| 57 | + |
| 58 | + local topic_info = "" |
| 59 | + |
| 60 | + for key, value in pairs(topic) do |
| 61 | + if type(value) == "boolean" and value then |
| 62 | + -- Если значение булевое и равно true, выводим тему как изученную |
| 63 | + topic_info = topic_info .. string.format("\n\t\t%s", key) |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + if topic_info == "" then |
| 68 | + return "No learned topics." |
| 69 | + end |
| 70 | + |
| 71 | + return topic_info |
| 72 | +end |
| 73 | + |
| 74 | +---@param historical_figure df.historical_figure |
| 75 | +function getHistoricKnowledge(historical_figure) |
| 76 | + if not historical_figure then |
| 77 | + print("Historical figure not found.") |
| 78 | + return nil, "Historical figure not found." |
| 79 | + end |
| 80 | + |
| 81 | + local known_info = historical_figure.info.known_info |
| 82 | + |
| 83 | + if not known_info then |
| 84 | + return nil, "No known_info found." |
| 85 | + end |
| 86 | + |
| 87 | + local knowledge = known_info.knowledge |
| 88 | + |
| 89 | + if not knowledge then |
| 90 | + return nil, "No knowledge found." |
| 91 | + end |
| 92 | + |
| 93 | + return knowledge |
| 94 | +end |
| 95 | + |
| 96 | +---@param unit_id df.unit.id |
| 97 | +function getUnitKnowledge(unit_id) |
| 98 | + return getHistoricKnowledge(getHistoricalFigure(unit_id)) |
| 99 | +end |
| 100 | + |
| 101 | +---@param historical_figure df.historical_figure |
| 102 | +function getResearchData(historical_figure) |
| 103 | + local knowledge = getHistoricKnowledge(historical_figure) |
| 104 | + local data = { |
| 105 | + |
| 106 | + name = dfhack.translation.translateName(historical_figure.name), --dfhack.translation.TranslateName(historical_figure.name), |
| 107 | + knowledge_goal_category = getKnowledgeGoalCategoryInfo(knowledge.knowledge_goal_category), |
| 108 | + --knowledge_goal = getGoalInfo(knowledge.knowledge_goal), |
| 109 | + knowledge_goal = getGoalInfo(knowledge.knowledge_goal, knowledge.knowledge_goal_category), |
| 110 | + research_points = knowledge.research_points, |
| 111 | + research_percentage = string.format("%.2f", (knowledge.research_points / 100000) * 100), |
| 112 | + times_pondered = knowledge.times_pondered, |
| 113 | + research_topics = {} |
| 114 | + } |
| 115 | + |
| 116 | + for i, topic in pairs(knowledge) do |
| 117 | + if type(topic) == "userdata" and i ~= "knowledge_goal" then |
| 118 | + local topic_info = getTopicInfo(topic) |
| 119 | + if topic_info ~= "\tNo topic information available." and topic_info ~= "No learned topics." then |
| 120 | + table.insert(data.research_topics, {name = i, info = topic_info}) |
| 121 | + end |
| 122 | + end |
| 123 | + end |
| 124 | + |
| 125 | + return {data} |
| 126 | +end |
0 commit comments