Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Template for new versions:
## New Tools

## New Features
- `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)

## Fixes
- `bodyswap`: fix "invalid argument count" when the target unit has no nemesis record
Expand Down
201 changes: 5 additions & 196 deletions do-job-now.lua
Original file line number Diff line number Diff line change
@@ -1,202 +1,11 @@
-- makes a job involving current selection high priority

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

local function print_help()
if (...) then
print(dfhack.script_help())
return
end

local function doJobNow(job)
local job_str = dfhack.job.getName(job)
if not job.flags.do_now then
job.flags.do_now = true
print("Made the job " .. job_str .. " top priority")
else
print("The job " .. job_str .. " is already top priority")
end
local building = dfhack.job.getHolder(job)
if building then
print("... at " .. utils.getBuildingName(building))
end
local unit = dfhack.job.getWorker(job)
if unit then
print("... by " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
end
end

local function doItemJobNow(item)
if not item.flags.in_job then
qerror(dfhack.items.getDescription(item, 0) .. " must be in a job! (look for 'TSK')")
end

local sref = dfhack.items.getSpecificRef(item, df.specific_ref_type.JOB)
if sref then
doJobNow(sref.data.job)
return
end
print("Couldn't find any job for " .. dfhack.items.getDescription(item, 0))
end

local function doBuildingJobNow(building)
--print('This will attempt to make a job of a building a top priority')

if #building.jobs > 0
and (
building.jobs[0].job_type == df.job_type.ConstructBuilding
or building.jobs[0].job_type == df.job_type.DestroyBuilding
)
then
doJobNow(building.jobs[0])
return
end
print("Couldn't find either construct or destroy building job for " .. utils.getBuildingName(building))
end

local function doUnitJobNow(unit)
if dfhack.units.isCitizen(unit) then
local t_job = unit.job
if t_job then
local job = t_job.current_job
if job then
doJobNow(job)
return
end
end
print("Couldn't find any job for " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
else
local needle = unit.id
for _link, job in utils.listpairs(df.global.world.jobs.list) do
if #job.general_refs > 0 then
for _, gref in ipairs(job.general_refs) do
--if gref:getType() == df.general_ref_type.UNIT then -- can't do this: there are many different types that can be units
local u = gref:getUnit()
if u and u.id == needle then
doJobNow(job)
return
end
--end
end
end
end

print("Couldn't find any job involving " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
end
end

local function doPlantJobNow(plant)
--print('This will attempt to make a job with a plant a top priority')

for _link, job in utils.listpairs(df.global.world.jobs.list) do
if plant.pos.x == job.pos.x
and plant.pos.y == job.pos.y
and plant.pos.z == job.pos.z
then
doJobNow(job)
return
end
end

print("Couldn't find any job involving this plant.")
end

local function doWorkOrderJobsNow(order)
local needle = order.id
local cnt = 0
for _link, job in utils.listpairs(df.global.world.jobs.list) do
if job.order_id == needle then
doJobNow(job)
cnt = cnt + 1
end
end

if cnt > 0 then
print("Found " .. cnt .. " jobs for this work order.")
else
print("Couldn't find any job for this work order.")
end
end

local function getSelectedWorkOrder()
local scr = dfhack.gui.getCurViewscreen()
local orders
local idx
if df.viewscreen_jobmanagementst:is_instance(scr) then
orders = df.global.world.manager_orders.all
idx = scr.sel_idx
elseif df.viewscreen_workshop_profilest:is_instance(scr)
and scr.tab == df.viewscreen_workshop_profilest.T_tab.Orders
then
orders = scr.orders
idx = scr.order_idx
end
if orders then
if idx < #orders then
return orders[idx]
else
qerror("Invalid work order selected")
end
end

return nil
end

local function doSelectedEntityJobNow()
-- do we have a job selected?
local job = dfhack.gui.getSelectedJob(true)
if job then
doJobNow(job)
return
end

-- do we have an item selected?
local item = dfhack.gui.getSelectedItem(true)
if item then
doItemJobNow(item)
return
end

-- do we have a building selected?
local building = dfhack.gui.getSelectedBuilding(true)
if building then
doBuildingJobNow(building)
return
end

-- do we have a unit selected?
local unit = dfhack.gui.getSelectedUnit(true)
if unit then
doUnitJobNow(unit)
return
end

-- do we have a plant selected?
local plant = dfhack.gui.getSelectedPlant(true)
if plant then
doPlantJobNow(plant)
return
end

-- do we have a work order selected?
local order = getSelectedWorkOrder()
if order then
doWorkOrderJobsNow(order)
return
end

qerror("Select something job-related in game.")
end

local default_action = print_help

local actions = {
-- help
["-?"] = print_help,
["?"] = print_help,
["--help"] = print_help,
["help"] = print_help,
-- action
["default"] = doSelectedEntityJobNow,
}

-- Lua is beautiful.
(actions[ (...) or "default" ] or default_action)(...)
reqscript('prioritize').prioritize_this()
7 changes: 3 additions & 4 deletions docs/do-job-now.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The script will try its best to find a job related to the selected entity (which
can be a job, dwarf, animal, item, building, plant or work order) and then mark
the job as high priority.

This functionality is now part of `prioritize` (see ``prioritize this``), and
``do-job-now`` forwards to it for compatibility with existing keybindings.

Apart from jobs that are queued from buildings, there is normally no visual
indicator that the job is now high priority. If you use ``do-job-now`` from the
keybinding, you have to check the dfhack console for output to see if the
Expand All @@ -17,10 +20,6 @@ command succeeded.
If a work order is selected, every job currently active from this work order is
adjusted, but not the future ones.

Also see the ``do-job-now`` `tweak`, which allows you to adjust job priorities
from the :kbd:`j`obs screen, and `prioritize`, which can automatically adjust
priorities based on the type of job.

Usage
-----

Expand Down
5 changes: 5 additions & 0 deletions docs/prioritize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Usage

enable prioritize
prioritize [<options>] [defaults|<job_type> ...]
prioritize this

Examples
--------
Expand All @@ -44,6 +45,10 @@ Examples
right now.
``prioritize ConstructBuilding DestroyBuilding``
Prioritize all current building construction and destruction jobs.
``prioritize this``
Prioritize the job related to the selected entity (a job, dwarf, animal,
item, building, plant, or work order). This is a good candidate for a
keybinding.
``prioritize -a --haul-labor=Food,Body StoreItemInStockpile``
Prioritize all current and future food and corpse hauling jobs.
``disable prioritize``
Expand Down
Loading