diff options
| author | Alexander Gavrilov | 2012-04-23 21:30:53 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-04-23 21:30:53 +0400 |
| commit | 763a301b4f928bf20c78fb67f864e1623409c710 (patch) | |
| tree | b46ec827b20f49787aa77ba75d293b2951801544 /plugins/lua | |
| parent | 125cd6622a1d2ce7a8dfa7caf40a85049baf4977 (diff) | |
| download | dfhack-763a301b4f928bf20c78fb67f864e1623409c710.tar.gz dfhack-763a301b4f928bf20c78fb67f864e1623409c710.tar.bz2 dfhack-763a301b4f928bf20c78fb67f864e1623409c710.tar.xz | |
Add a few more lua api functions, documentation, and unit sort orders.
Units::getProfessionName appears to work correctly for
everything except nobles.
Diffstat (limited to 'plugins/lua')
| -rw-r--r-- | plugins/lua/sort/units.lua | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/plugins/lua/sort/units.lua b/plugins/lua/sort/units.lua index 84beff8e..7a332d09 100644 --- a/plugins/lua/sort/units.lua +++ b/plugins/lua/sort/units.lua @@ -13,8 +13,9 @@ orders.exists = { orders.name = { key = function(unit) - if unit.name.has_name then - return dfhack.TranslateName(unit.name) + local name = dfhack.units.getVisibleName(unit) + if name and name.has_name then + return dfhack.TranslateName(name) end end, compare = utils.compare_name @@ -29,28 +30,55 @@ orders.age = { -- This assumes that units are added to active in arrival order orders.arrival = { key_table = function(units) - local tmp={} - for i,v in ipairs(units) do - tmp[v.id] = i + local size = units.n or #units + local lookup={} + for i=1,size do + if units[i] then + lookup[units[i].id] = i + end end local idx={} for i,v in ipairs(df.global.world.units.active) do - local ix = tmp[v.id] - if ix ~= nil then - idx[ix] = i + if lookup[v.id] then + idx[lookup[v.id]] = i end end return idx end } +local function findRaceCaste(unit) + local rraw = df.creature_raw.find(unit.race) + return rraw, safe_index(rraw, 'caste', unit.caste) +end + orders.profession = { key = function(unit) - local cp = unit.custom_profession - if cp == '' then - cp = df.profession.attrs[unit.profession].caption + local cp = dfhack.units.getProfessionName(unit) + if cp and cp ~= '' then + return string.lower(cp) + end + end +} + +orders.profession_class = { + key = function(unit) + local pid = unit.profession + local parent = df.profession.attrs[pid].parent + if parent >= 0 then + return parent + else + return pid + end + end +} + +orders.race = { + key = function(unit) + local rraw = findRaceCaste(unit) + if rraw then + return rraw.name[0] end - return cp end } |
