Skip to content

Commit fb6812a

Browse files
authored
Merge pull request #1615 from Alistair-Afton/prioritize-this
prioritize: add 'this' action to absorb do-job-now
2 parents 706e914 + 1100d61 commit fb6812a

6 files changed

Lines changed: 450 additions & 372 deletions

File tree

‎changelog.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Template for new versions:
3838
- `gui/mod-manager`: warn when loading a preset that doesn't include vanilla mods that were added to the game after the preset was saved
3939
- `gui/unit-info-viewer`: the unit character sheet now shows the viewed unit's current and long-term mood, color-coded by stress level
4040
- `idle-crafting`: support cloth, silk, and yarn crafts
41+
- `prioritize`: ``prioritize this`` boosts the job related to the currently selected entity, absorbing the functionality of `do-job-now` (which still works and forwards to the new command)
4142

4243
## Fixes
4344
- `bodyswap`: fix "invalid argument count" when the target unit has no nemesis record

‎do-job-now.lua‎

Lines changed: 5 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -1,202 +1,11 @@
11
-- makes a job involving current selection high priority
22

3-
local utils = require('utils')
3+
-- the implementation moved to `prioritize this`; this script forwards for
4+
-- compatibility with existing keybindings and aliases
45

5-
local function print_help()
6+
if (...) then
67
print(dfhack.script_help())
8+
return
79
end
810

9-
local function doJobNow(job)
10-
local job_str = dfhack.job.getName(job)
11-
if not job.flags.do_now then
12-
job.flags.do_now = true
13-
print("Made the job " .. job_str .. " top priority")
14-
else
15-
print("The job " .. job_str .. " is already top priority")
16-
end
17-
local building = dfhack.job.getHolder(job)
18-
if building then
19-
print("... at " .. utils.getBuildingName(building))
20-
end
21-
local unit = dfhack.job.getWorker(job)
22-
if unit then
23-
print("... by " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
24-
end
25-
end
26-
27-
local function doItemJobNow(item)
28-
if not item.flags.in_job then
29-
qerror(dfhack.items.getDescription(item, 0) .. " must be in a job! (look for 'TSK')")
30-
end
31-
32-
local sref = dfhack.items.getSpecificRef(item, df.specific_ref_type.JOB)
33-
if sref then
34-
doJobNow(sref.data.job)
35-
return
36-
end
37-
print("Couldn't find any job for " .. dfhack.items.getDescription(item, 0))
38-
end
39-
40-
local function doBuildingJobNow(building)
41-
--print('This will attempt to make a job of a building a top priority')
42-
43-
if #building.jobs > 0
44-
and (
45-
building.jobs[0].job_type == df.job_type.ConstructBuilding
46-
or building.jobs[0].job_type == df.job_type.DestroyBuilding
47-
)
48-
then
49-
doJobNow(building.jobs[0])
50-
return
51-
end
52-
print("Couldn't find either construct or destroy building job for " .. utils.getBuildingName(building))
53-
end
54-
55-
local function doUnitJobNow(unit)
56-
if dfhack.units.isCitizen(unit) then
57-
local t_job = unit.job
58-
if t_job then
59-
local job = t_job.current_job
60-
if job then
61-
doJobNow(job)
62-
return
63-
end
64-
end
65-
print("Couldn't find any job for " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
66-
else
67-
local needle = unit.id
68-
for _link, job in utils.listpairs(df.global.world.jobs.list) do
69-
if #job.general_refs > 0 then
70-
for _, gref in ipairs(job.general_refs) do
71-
--if gref:getType() == df.general_ref_type.UNIT then -- can't do this: there are many different types that can be units
72-
local u = gref:getUnit()
73-
if u and u.id == needle then
74-
doJobNow(job)
75-
return
76-
end
77-
--end
78-
end
79-
end
80-
end
81-
82-
print("Couldn't find any job involving " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
83-
end
84-
end
85-
86-
local function doPlantJobNow(plant)
87-
--print('This will attempt to make a job with a plant a top priority')
88-
89-
for _link, job in utils.listpairs(df.global.world.jobs.list) do
90-
if plant.pos.x == job.pos.x
91-
and plant.pos.y == job.pos.y
92-
and plant.pos.z == job.pos.z
93-
then
94-
doJobNow(job)
95-
return
96-
end
97-
end
98-
99-
print("Couldn't find any job involving this plant.")
100-
end
101-
102-
local function doWorkOrderJobsNow(order)
103-
local needle = order.id
104-
local cnt = 0
105-
for _link, job in utils.listpairs(df.global.world.jobs.list) do
106-
if job.order_id == needle then
107-
doJobNow(job)
108-
cnt = cnt + 1
109-
end
110-
end
111-
112-
if cnt > 0 then
113-
print("Found " .. cnt .. " jobs for this work order.")
114-
else
115-
print("Couldn't find any job for this work order.")
116-
end
117-
end
118-
119-
local function getSelectedWorkOrder()
120-
local scr = dfhack.gui.getCurViewscreen()
121-
local orders
122-
local idx
123-
if df.viewscreen_jobmanagementst:is_instance(scr) then
124-
orders = df.global.world.manager_orders.all
125-
idx = scr.sel_idx
126-
elseif df.viewscreen_workshop_profilest:is_instance(scr)
127-
and scr.tab == df.viewscreen_workshop_profilest.T_tab.Orders
128-
then
129-
orders = scr.orders
130-
idx = scr.order_idx
131-
end
132-
if orders then
133-
if idx < #orders then
134-
return orders[idx]
135-
else
136-
qerror("Invalid work order selected")
137-
end
138-
end
139-
140-
return nil
141-
end
142-
143-
local function doSelectedEntityJobNow()
144-
-- do we have a job selected?
145-
local job = dfhack.gui.getSelectedJob(true)
146-
if job then
147-
doJobNow(job)
148-
return
149-
end
150-
151-
-- do we have an item selected?
152-
local item = dfhack.gui.getSelectedItem(true)
153-
if item then
154-
doItemJobNow(item)
155-
return
156-
end
157-
158-
-- do we have a building selected?
159-
local building = dfhack.gui.getSelectedBuilding(true)
160-
if building then
161-
doBuildingJobNow(building)
162-
return
163-
end
164-
165-
-- do we have a unit selected?
166-
local unit = dfhack.gui.getSelectedUnit(true)
167-
if unit then
168-
doUnitJobNow(unit)
169-
return
170-
end
171-
172-
-- do we have a plant selected?
173-
local plant = dfhack.gui.getSelectedPlant(true)
174-
if plant then
175-
doPlantJobNow(plant)
176-
return
177-
end
178-
179-
-- do we have a work order selected?
180-
local order = getSelectedWorkOrder()
181-
if order then
182-
doWorkOrderJobsNow(order)
183-
return
184-
end
185-
186-
qerror("Select something job-related in game.")
187-
end
188-
189-
local default_action = print_help
190-
191-
local actions = {
192-
-- help
193-
["-?"] = print_help,
194-
["?"] = print_help,
195-
["--help"] = print_help,
196-
["help"] = print_help,
197-
-- action
198-
["default"] = doSelectedEntityJobNow,
199-
}
200-
201-
-- Lua is beautiful.
202-
(actions[ (...) or "default" ] or default_action)(...)
11+
reqscript('prioritize').prioritize_this()

‎docs/do-job-now.rst‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ The script will try its best to find a job related to the selected entity (which
99
can be a job, dwarf, animal, item, building, plant or work order) and then mark
1010
the job as high priority.
1111

12+
This functionality is now part of `prioritize` (see ``prioritize this``), and
13+
``do-job-now`` forwards to it for compatibility with existing keybindings.
14+
1215
Apart from jobs that are queued from buildings, there is normally no visual
1316
indicator that the job is now high priority. If you use ``do-job-now`` from the
1417
keybinding, you have to check the dfhack console for output to see if the
@@ -17,10 +20,6 @@ command succeeded.
1720
If a work order is selected, every job currently active from this work order is
1821
adjusted, but not the future ones.
1922

20-
Also see the ``do-job-now`` `tweak`, which allows you to adjust job priorities
21-
from the :kbd:`j`obs screen, and `prioritize`, which can automatically adjust
22-
priorities based on the type of job.
23-
2423
Usage
2524
-----
2625

‎docs/prioritize.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Usage
3030

3131
enable prioritize
3232
prioritize [<options>] [defaults|<job_type> ...]
33+
prioritize this
3334

3435
Examples
3536
--------
@@ -44,6 +45,10 @@ Examples
4445
right now.
4546
``prioritize ConstructBuilding DestroyBuilding``
4647
Prioritize all current building construction and destruction jobs.
48+
``prioritize this``
49+
Prioritize the job related to the selected entity (a job, dwarf, animal,
50+
item, building, plant, or work order). This is a good candidate for a
51+
keybinding.
4752
``prioritize -a --haul-labor=Food,Body StoreItemInStockpile``
4853
Prioritize all current and future food and corpse hauling jobs.
4954
``disable prioritize``

0 commit comments

Comments
 (0)