-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-stress.lua
More file actions
76 lines (59 loc) · 2.1 KB
/
list-stress.lua
File metadata and controls
76 lines (59 loc) · 2.1 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
--[====[
list-stress
===========
If a unit is selected, lists only that unit's longterm stress.
Otherwise lists all citizens with excessive longterm stress.
The change in stress from the last time the script was run is also listed.
]====]
-- TODO print a header line "Long Delta Short Delta Name"
local Level1 = 10000
local Level2 = 20000
local Level3 = 40000
local TicksPerDay = 1200
local TicksPerYear = 403200
local currentTick = dfhack.world.ReadCurrentYear() * TicksPerYear + dfhack.world.ReadCurrentTick()
local deltaTick = 3 * TicksPerDay -- time period to NOT update the old stress record.
oldList = oldList or {} -- global, persistant
oldLong = oldLong or {} -- global, persistant
oldTick = oldTick or 0 -- global, persistant
local unitList
if dfhack.gui.getSelectedUnit(true) then
unitList = { dfhack.gui.getSelectedUnit(true) }
else
unitList = dfhack.units.getCitizens()
end
for k,u in ipairs(unitList) do
local stress = u.status.current_soul.personality.stress
oldList[u.id] = oldList[u.id] or stress
local deltaStress = (stress - oldList[u.id])
local longtermStress = u.status.current_soul.personality.longterm_stress
oldLong[u.id] = oldLong[u.id] or longtermStress
local deltaLong = (longtermStress - oldLong[u.id])
if longtermStress >= Level3 then
dfhack.color(COLOR_LIGHTRED)
elseif longtermStress >= Level2 then
dfhack.color(COLOR_YELLOW)
elseif longtermStress >= Level1 then
dfhack.color(COLOR_WHITE)
elseif #unitList == 1 then
dfhack.color(COLOR_GREY)
else
goto CONTINUE
end
dfhack.println(string.format("%-8d%s%-7s%-8d%s%-7s%s",
longtermStress,
(deltaLong < 0) and '-' or (deltaLong > 0 and '+' or ' '),
(deltaLong == 0) and '' or tostring(math.abs(deltaLong)),
stress,
(deltaStress < 0) and '-' or (deltaStress > 0 and '+' or ' '),
(deltaStress == 0) and '' or tostring(math.abs(deltaStress)),
dfhack.units.getReadableName(u) ))
-- update?
if (oldTick + deltaTick) < currentTick then
oldList[u.id] = stress
oldLong[u.id] = longtermStress
end
::CONTINUE::
dfhack.color(COLOR_RESET)
end
oldTick = currentTick