diff options
| author | Alexander Gavrilov | 2012-04-21 16:53:17 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-04-21 16:53:17 +0400 |
| commit | 4af051bab3e455a9115a44e43b8c3da0cd189f43 (patch) | |
| tree | 377a687ab333ed856b739dd993833cbbcd263e56 /plugins/lua | |
| parent | 3282ac3db216ef43cab5744631b57ed05bcf8a12 (diff) | |
| download | dfhack-4af051bab3e455a9115a44e43b8c3da0cd189f43.tar.gz dfhack-4af051bab3e455a9115a44e43b8c3da0cd189f43.tar.bz2 dfhack-4af051bab3e455a9115a44e43b8c3da0cd189f43.tar.xz | |
Add a few more unit orderings, and a way to reverse direction.
Diffstat (limited to 'plugins/lua')
| -rw-r--r-- | plugins/lua/sort.lua | 21 | ||||
| -rw-r--r-- | plugins/lua/sort/units.lua | 50 |
2 files changed, 70 insertions, 1 deletions
diff --git a/plugins/lua/sort.lua b/plugins/lua/sort.lua index 2318d7e0..f042e85c 100644 --- a/plugins/lua/sort.lua +++ b/plugins/lua/sort.lua @@ -15,12 +15,33 @@ function parse_ordering_spec(type,...) local specs = table.pack(...) local rv = { } + for _,spec in ipairs(specs) do + local nil_first = false + if string.sub(spec,1,1) == '<' then + nil_first = true + spec = string.sub(spec,2) + end + + local reverse = false + if string.sub(spec,1,1) == '>' then + reverse = true + spec = string.sub(spec,2) + end + local cm = group[spec] + if cm == nil then dfhack.printerr('Unknown order for '..type..': '..tostring(spec)) return nil end + + if nil_first or reverse then + cm = copyall(cm) + cm.nil_first = nil_first + cm.reverse = reverse + end + rv[#rv+1] = cm end diff --git a/plugins/lua/sort/units.lua b/plugins/lua/sort/units.lua index 872e4942..b92fc6c8 100644 --- a/plugins/lua/sort/units.lua +++ b/plugins/lua/sort/units.lua @@ -6,7 +6,9 @@ orders = orders or {} orders.name = { key = function(unit) - return dfhack.TranslateName(unit.name) + if unit.name.has_name then + return dfhack.TranslateName(unit.name) + end end, compare = utils.compare_name } @@ -17,4 +19,50 @@ orders.age = { end } +-- 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 + 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 + end + end + return idx + end +} + +orders.profession = { + key = function(unit) + local cp = unit.custom_profession + if cp == '' then + cp = df.profession.attrs[unit.profession].caption + end + return cp + end +} + +orders.squad = { + key = function(unit) + local sidx = unit.military.squad_index + if sidx >= 0 then + return sidx + end + end +} + +orders.squad_position = { + key = function(unit) + local sidx = unit.military.squad_index + if sidx >= 0 then + return sidx * 1000 + unit.military.squad_position + end + end +} + return _ENV
\ No newline at end of file |
