Skip to content

Commit

Permalink
Use functions in 'units' module to calculate skill level
Browse files Browse the repository at this point in the history
This is significantly faster than using a lua implementation
  • Loading branch information
lethosor committed May 15, 2015
1 parent c816862 commit 5d01b89
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions manipulator/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d01b89

Please sign in to comment.