Bit of a speed challenge (bit over a hour with this post, could have gone faster >_>), decided to implement old idea: Have minecarts automatically add settings of any stockpiles you set them to take from.
local helptext = [===[
minecart-copystockpilelinks
===========================
v 1.0
Takes currently viewed hauling route stop
and copies the settings of all stockpiles
it is linked to take from to.
In case of multiple stockpile, enables all.
Intended to be used with keybinding
keybinding add S@dwarfmode/Hauling/DefineStop minecart-copystockpilelinks
]===]
function getStockpileSettings(building_id)
local rvalue = df.building.find(building_id)
return rvalue and rvalue.settings or false
end
function getTakePilesOfStop(stop)
local returnpileids = {}
for i, v in pairs(stop.stockpiles) do
if v.mode.take then
table.insert(returnpileids, v.building_id)
end
end
return returnpileids
end
function addToStockpileSettings(combinedpile, addedpile)
if addedpile then
--if accidentially pressing s on plain floor there's boolean instead
for i,v in pairs(addedpile) do
if v then
if i == "allow_organic" or i == "allow_inorganic" or i == "unk1" then
--some options are not complex structures.
combinedpile[i] = addedpile[i]
else
for j, w in pairs(v) do
if w then
if w == true then
combinedpile[i][j] = true
else
if #w > 0 and #w == #(combinedpile[i][j])then
for k, t in pairs(w) do
combinedpile[i][j][k] = t
end
elseif #w> 0 and 0 == #(combinedpile[i][j]) then
combinedpile[i][j]:assign(w)
end
end
end
end
end
end
end
end
end
function setCurStop()
if df.global.ui.hauling.in_stop then
--In stop
local cur_stop = df.global.ui.hauling.view_stops[df.global.ui.hauling.cursor_top]
if cur_stop then
local takepiles = getTakePilesOfStop(cur_stop)
--Got stockpiles
if takepiles and #takepiles > 0 then
for index = 1, #takepiles do
addToStockpileSettings(cur_stop.settings, getStockpileSettings(takepiles[index]))
end
end
end
end
end
local args = {...}
if #args > 0 then print(helptext) else setCurStop() end
What it does: If you're currently viewing a stop, sets it to take all things enabled in all the piles it is linked to take from to.
Why? To simplify placing minecart qsps with multiple or custom stockpile settings.
Convenient usage: Place
keybinding add S@dwarfmode/Hauling/DefineStop minecart-copystockpilelinks
in dfhack.init
and save the code into /hacks/scripts as text file ending in .lua.
Tested in DFHack 43.05-r2, 43.03-r1, 42.06-r1.
E: Forgot that I removed case for ==1 links which caused script to not work on single link due not matching case of >1 links.