-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathunits.lua
More file actions
118 lines (103 loc) · 2.44 KB
/
units.lua
File metadata and controls
118 lines (103 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
local _ENV = mkmodule('plugins.sort.units')
local utils = require('utils')
orders = orders or {}
-- Relies on NULL being auto-translated to NULL, and then sorted
orders.exists = {
key = function(unit)
return 1
end
}
orders.name = {
key = function(unit)
local name = dfhack.units.getVisibleName(unit)
if name and name.has_name then
return dfhack.translation.translateName(name)
end
end,
compare = utils.compare_name
}
orders.age = {
key = function(unit)
return dfhack.units.getAge(unit)
end
}
-- This assumes that units are added to active in arrival order
orders.arrival = {
key_table = function(units)
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
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.noble = {
key = function(unit)
local info = dfhack.units.getNoblePositions(unit)
if info then
return info[1].position.precedence
end
end
}
orders.profession = {
key = function(unit)
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
end
}
orders.squad = {
key = function(unit)
local sidx = unit.military.squad_id
if sidx >= 0 then
return sidx
end
end
}
orders.squad_position = {
key = function(unit)
local sidx = unit.military.squad_id
if sidx >= 0 then
return sidx * 1000 + unit.military.squad_position
end
end
}
orders.happiness = {
key = function(unit)
return unit.status.happiness
end
}
return _ENV