Merge pull request #2670 from eamondo2/automelt

Initial automelt implementation
develop
Myk 2023-01-23 13:48:53 -08:00 committed by GitHub
commit 1b02e66284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 850 additions and 197 deletions

@ -84,6 +84,9 @@ enable overlay
# Allow buildings to be placed now and built later when materials are available # Allow buildings to be placed now and built later when materials are available
enable buildingplan enable buildingplan
#Allow designated stockpiles to automatically mark items for melting
enable automelt
# Dwarf Manipulator (simple in-game Dwarf Therapist replacement) # Dwarf Manipulator (simple in-game Dwarf Therapist replacement)
#enable manipulator #enable manipulator

@ -6,9 +6,9 @@ automelt
:tags: untested fort productivity items stockpiles :tags: untested fort productivity items stockpiles
:no-command: :no-command:
When `enabled <enable>`, this plugin adds an option to the :kbd:`q` menu for Automelt checks monitor-enabled stockpiles once every in-game day, and will mark valid items for melting.
stockpiles. When the ``automelt`` option is selected for the stockpile, any
items placed in the stockpile will automatically be designated to be melted. Please see `gui/automelt` for the interactive configuration dialog.
Usage Usage
----- -----
@ -16,3 +16,40 @@ Usage
:: ::
enable automelt enable automelt
automelt [status]
automelt designate
automelt (monitor|nomonitor) <stockpile>[,<stockpile>...]
Examples
--------
Automatically monitor stockpile ("melt"), marking new valid items for melting. This also immediately marks all present items for melting::
enable automelt
automelt monitor melt
Enable monitoring for ("Stockpile #52"), which has not been given a custom name::
automelt monitor "Stockpile #52"
Enable monitoring for ("Stockpile #52"), which has not been given a custom name::
automelt monitor 52
Enable monitoring for multiple stockpiles ("Stockpile #52", "Stockpile #35", and "melt")::
automelt monitor 52,"Stockpile #35",melt
Commands
--------
``status``
Shows current configuration and relevant statistics
``designate``
Designates items in monitored stockpiles for melting right now. This works even if ``automelt`` is not currently enabled.
``(no)monitor <stockpile>``
Enable/disable monitoring of a given stockpile. Works with either the stockpile's name (if set) or ID.
If the stockpile has no custom name set, you may designate it by either the full name as reported by
the status command, or by just the number.

@ -83,7 +83,7 @@ dfhack_plugin(autofarm autofarm.cpp)
#dfhack_plugin(autogems autogems.cpp LINK_LIBRARIES jsoncpp_static) #dfhack_plugin(autogems autogems.cpp LINK_LIBRARIES jsoncpp_static)
#add_subdirectory(autolabor) #add_subdirectory(autolabor)
#dfhack_plugin(automaterial automaterial.cpp LINK_LIBRARIES lua) #dfhack_plugin(automaterial automaterial.cpp LINK_LIBRARIES lua)
#dfhack_plugin(automelt automelt.cpp) dfhack_plugin(automelt automelt.cpp LINK_LIBRARIES lua)
#dfhack_plugin(autonestbox autonestbox.cpp LINK_LIBRARIES lua) #dfhack_plugin(autonestbox autonestbox.cpp LINK_LIBRARIES lua)
#dfhack_plugin(autotrade autotrade.cpp) #dfhack_plugin(autotrade autotrade.cpp)
dfhack_plugin(blueprint blueprint.cpp LINK_LIBRARIES lua) dfhack_plugin(blueprint blueprint.cpp LINK_LIBRARIES lua)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,80 @@
local _ENV = mkmodule('plugins.automelt')
local argparse = require('argparse')
local function process_args(opts, args)
if args[1] == 'help' then
opts.help = true
return
end
return argparse.processArgsGetopt(args, {
{'h', 'help', handler=function() opts.help = true end},
})
end
local function do_set_stockpile_config(var_name, val, stockpiles)
for _,bspec in ipairs(argparse.stringList(stockpiles)) do
local config = automelt_getStockpileConfig(bspec)
config[var_name] = val
automelt_setStockpileConfig(config.id, config.monitor, config.melt)
end
end
function parse_commandline(...)
local args, opts = {...}, {}
local positionals = process_args(opts, args)
if opts.help then
return false
end
local command = positionals[1]
if not command or command == 'status' then
automelt_printStatus()
elseif command == 'designate' then
automelt_designate()
elseif command == 'monitor' then
do_set_stockpile_config('monitor', true, args[2])
elseif command == 'nomonitor' or command == 'unmonitor' then
do_set_stockpile_config('monitor', false, args[2])
else
return false
end
return true
end
-- used by gui/automelt
function setStockpileConfig(config)
automelt_setStockpileConfig(config.id, config.monitored)
end
function getItemCountsAndStockpileConfigs()
local fmt = 'Stockpile #%-5s'
local data = {automelt_getItemCountsAndStockpileConfigs()}
local ret = {}
ret.summary = table.remove(data, 1)
ret.item_counts = table.remove(data, 1)
ret.marked_item_counts = table.remove(data, 1)
ret.premarked_item_counts = table.remove(data, 1)
ret.stockpile_configs = data
for _,c in ipairs(ret.stockpile_configs) do
if not c.id or c.id == -1 then
c.name = "ERROR"
c.monitored = false
else
c.name = df.building.find(c.id).name
if not c.name or c.name == '' then
c.name = (fmt):format(tostring(df.building.find(c.id).stockpile_number))
end
c.monitored = c.monitored ~= 0
end
end
return ret
end
return _ENV