diff --git a/manipulator/gui/manipulator.lua b/manipulator/gui/manipulator.lua index 0955158..591cb86 100644 --- a/manipulator/gui/manipulator.lua +++ b/manipulator/gui/manipulator.lua @@ -32,7 +32,6 @@ function manipulator:init(args) self.grid_idx = 1 self.grid_rows = {} self.diff_enabled = storage.diff_enabled - skill_cache:clear() p_start('init units') for idx, u in pairs(self.units) do self.grid_rows[u] = penarray.new(#SKILL_COLUMNS, 1) @@ -184,12 +183,12 @@ function manipulator:onRenderBody(p) end p:string(unit.status.labors[col.labor] and 'Enabled' or 'Not Enabled', {fg = COLOR_LIGHTBLUE}) else - local skill = skill_cache:get(unit, col.skill) - local lvl = skill.rating + local lvl = skills.rating(unit, col.skill) local prof = df.job_skill.attrs[col.skill].caption_noun p:string((lvl > 0 and SKILL_LEVELS[lvl].name or 'Not') .. ' ' .. prof, {fg = COLOR_LIGHTBLUE}) if lvl < #SKILL_LEVELS then - p:string(' '):string(('(%i/%i)'):format(skill.experience, SKILL_LEVELS[lvl > 0 and lvl or 1].points), {fg = COLOR_LIGHTBLUE}) + p:string(' '):string(('(%i/%i)'):format(skills.experience(unit, col.skill), + SKILL_LEVELS[lvl > 0 and lvl or 1].points), {fg = COLOR_LIGHTBLUE}) end end p:newline() @@ -227,7 +226,7 @@ function manipulator:update_grid_tile(x, y) local skill = SKILL_COLUMNS[x].skill local labor = SKILL_COLUMNS[x].labor if skill ~= df.job_skill.NONE then - local level = skill_cache:get(unit, skill).rating + local level = skills.rating(unit, skill) c = level > 0 and SKILL_LEVELS[level].abbr or '-' end if labor ~= df.unit_labor.NONE then diff --git a/manipulator/utils.lua b/manipulator/utils.lua index 427cc72..02dbae3 100644 --- a/manipulator/utils.lua +++ b/manipulator/utils.lua @@ -79,6 +79,20 @@ if dfhack.units.getKillCount == nil then end end +skills = {} +function skills.experience(unit, skill) + return dfhack.units.getExperience(unit._native, skill) +end + +function skills.rating(unit, skill) + local rating = dfhack.units.getNominalSkill(unit._native, skill) + 1 + local exp = skills.experience(unit, skill) + if exp == 0 and rating == 1 then + return 0 + end + return rating +end + OutputString = dfhack.screen.paintString function OutputKeyString(pen, x, y, key, str) @@ -199,23 +213,11 @@ function UnitAttrCache:clear() self.cache = {} end -skill_cache = UnitAttrCache() -function skill_cache:lookup(unit, skill) - local ret = { - rating = dfhack.units.getNominalSkill(unit._native, skill) + 1, - experience = dfhack.units.getExperience(unit._native, skill) - } - if ret.experience == 0 and ret.rating == 1 then - ret.rating = 0 - end - return ret -end - sort = { skill = function(u1, u2, skill) - local level_diff = skill_cache:get(u2, skill).rating - skill_cache:get(u1, skill).rating + local level_diff = skills.rating(u2, skill) - skills.rating(u1, skill) if level_diff ~= 0 then return level_diff end - return skill_cache:get(u2, skill).experience - skill_cache:get(u1, skill).experience + return skills.experience(u2, skill) - skills.experience(u1, skill) end }