From 5d01b89c934e443a1d5eba57cc11d13926c47c19 Mon Sep 17 00:00:00 2001 From: lethosor Date: Fri, 15 May 2015 19:25:12 -0400 Subject: [PATCH] Use functions in 'units' module to calculate skill level This is significantly faster than using a lua implementation --- manipulator/utils.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/manipulator/utils.lua b/manipulator/utils.lua index f9bd6a6..813827f 100644 --- a/manipulator/utils.lua +++ b/manipulator/utils.lua @@ -201,14 +201,12 @@ end skill_cache = UnitAttrCache() function skill_cache:lookup(unit, skill) - local ret = {rating = 0, experience = 0} - if unit.status.current_soul then - for _, unit_skill in pairs(unit.status.current_soul.skills) do - if unit_skill.id == skill and (unit_skill.experience > 0 or unit_skill.rating > 0) then - ret.rating = math.min(unit_skill.rating + 1, #SKILL_LEVELS) - ret.experience = unit_skill.experience - end - end + 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