-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-need-wander.lua
More file actions
57 lines (45 loc) · 1.79 KB
/
list-need-wander.lua
File metadata and controls
57 lines (45 loc) · 1.79 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
local utils = require('utils')
local TRIGGER = -5000
local translateName = dfhack.TranslateName or dfhack.translation.translateName
local _, work_detail = utils.linear_index(
df.global.plotinfo.labor_info.work_details, 'Plant gatherers', 'name')
if work_detail == nil then
print("No work detail named 'Plant gatherers'")
return
end
-- work_detail.flags.cannot_be_everybody = true ! I misunderstood this flag.
work_detail.flags.mode = 3 -- 1 == everybody, 2 == nobody, 3 == selected
for k,u in ipairs(df.global.world.units.active) do
if ( dfhack.units.isCitizen(u) )
and (u.status)
and (u.status.current_soul)
and (u.status.current_soul.personality)
and (u.status.current_soul.personality.needs)
then
-- local name = dfhack.df2utf(translateName(dfhack.units.getVisibleName(u))) .. ", " .. dfhack.units.getProfessionName(u, false)
local name = dfhack.units.getReadableName(u) -- returned in in utf.
for _, need in ipairs(u.status.current_soul.personality.needs) do
local enable_herbalism = false
local disable_herbalism = false
--local is_herbalist = false
if need.id == df.need_type.Wander then
if (u.job.current_job) and u.job.current_job.job_type == df.job_type.GatherPlants then
dfhack.println( name .. ": is wandering." )
disable_herbalism = true
elseif need.focus_level < TRIGGER then
dfhack.println(name .. " needs to wander (" .. need.focus_level .. ").")
enable_herbalism = true
else
disable_herbalism = true
end
if disable_herbalism then
u.status.labors[df.unit_labor.HERBALIST] = false
utils.erase_sorted(work_detail.assigned_units, u.id)
elseif enable_herbalism then
u.status.labors[df.unit_labor.HERBALIST] = true
utils.insert_sorted(work_detail.assigned_units, u.id)
end
end
end
end
end