Skip to content

Commit

Permalink
fix bugs / handle enable and disable / improved status information
Browse files Browse the repository at this point in the history
  • Loading branch information
chdoc committed Aug 7, 2024
1 parent dad2cdf commit 510c0eb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
25 changes: 23 additions & 2 deletions docs/idle-crafting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ Usage
::

idle-crafting status
idle-crafting disable
disable idle-crafting

The ``status`` command prints statistics about the status of the tool and the
satisfaction of "craft item" needs in your fort. Both variants of the
``disable`` command disallow idle crafting at all workshops and disable the
tool.

Examples
--------

``idle-crafting -t 10000,1000,500 status``
Reset all thresholds to defaults and print status information.

Options
-------

``-t <number list>``, ``--thresholds <number list>``
Sets the threshold(s) for the "craft item" need (i.e. the negated
``focus_level``) at which the tool starts to generate crafting jobs for a
given unit. Units meeting earlier (higher) thresholds will be
prioritized. Defaults to ``10000,1000,500``.


Overlay
-------
Expand All @@ -31,5 +54,3 @@ carving being the preferred option. This script respects linked stockpiles and
the setting for permitted general work orders from the "Workers" tab. Thus, to
designate a workshop for stone crafting only, simply disable the bone carving
labor on that tab.


47 changes: 44 additions & 3 deletions idle-crafting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ local function makeBoneCraft(unit, workshop)
return false
end
workshop.jobs:insert("#", job)
job.flags.fetching = true
job.items[0].flags.is_fetching = true
return dfhack.job.addWorker(job, unit)
end

Expand Down Expand Up @@ -160,6 +162,8 @@ local function makeRockCraft(unit, workshop)
return false
end
workshop.jobs:insert("#", job)
job.flags.fetching = true
job.items[0].flags.is_fetching = true
return dfhack.job.addWorker(job, unit)
end

Expand Down Expand Up @@ -417,6 +421,9 @@ IdleCraftingOverlay.ATTRS {
'dwarfmode/ViewSheets/BUILDING/Workshop/Craftsdwarfs/Tasks',
},
frame = { w = 55, h = 1 },
visible = function ()
return #df.global.game.main_interface.building.button == 0
end
}

function IdleCraftingOverlay:init()
Expand Down Expand Up @@ -453,7 +460,6 @@ function IdleCraftingOverlay:onRenderBody(painter)
if not workshop then
return
end
persist_state()
self.subviews.leisure_toggle:setOption(allowed[workshop.id] or false)
end

Expand All @@ -467,15 +473,38 @@ if dfhack_flags.module then
return
end

if dfhack_flags.enable then
if dfhack_flags.enable_state then
print('This tool is enabled by permitting idle crafting at a Craftsdarf\'s workshop')
return
else
allowed = {}
stop()
persist_state()
return
end
end

if df.global.gamemode ~= df.game_mode.DWARF then
print('this tool requires a loaded fort')
return
end

local fulfillment_level =
{ 'unfettered', 'level-headed', 'untroubled', 'not distracted', 'unfocused', 'distracted', 'badly distracted' }
local fulfillment_threshold =
{ 300, 200, 100, -999, -9999, -99999, -500000 }

local argparse = require('argparse')

local positionals = require('argparse').processArgsGetopt({ ... }, {})
load_state()
local positionals = argparse.processArgsGetopt({ ... }, {
{ 't', 'thresholds', hasArg = true, handler = function (optarg)
thresholds = argparse.numberList(optarg, 'thresholds')
end}
})

if not positionals or positionals[1] == 'status' then
if positionals[1] == 'status' then
---@type integer[]
stats = {}
for _, unit in ipairs(dfhack.units.getCitizens(true, false)) do
Expand All @@ -492,4 +521,16 @@ if not positionals or positionals[1] == 'status' then
for k, v in pairs(stats) do
print(('%4d %s'):format(v, fulfillment_level[k]))
end
local num_workshops = 0
for _, _ in pairs(allowed) do
num_workshops = num_workshops + 1
end
print(('Script is %s with %d workshops configured for idle crafting'):
format(enabled and 'enabled' or 'disabled', num_workshops))
print(('The thresholds for "craft item" needs are %s'):
format(table.concat(thresholds, '/')))
elseif positionals[1] == 'disable' then
allowed = {}
stop()
end
persist_state()

0 comments on commit 510c0eb

Please sign in to comment.