|
1 | 1 | -- makes a job involving current selection high priority |
2 | 2 |
|
3 | | -local utils = require('utils') |
| 3 | +-- the implementation moved to `prioritize this`; this script forwards for |
| 4 | +-- compatibility with existing keybindings and aliases |
4 | 5 |
|
5 | | -local function print_help() |
| 6 | +if (...) then |
6 | 7 | print(dfhack.script_help()) |
| 8 | + return |
7 | 9 | end |
8 | 10 |
|
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() |
0 commit comments