Skip to content

Instantly share code, notes, and snippets.

@shaver
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaver/69356ef7d8bfac4452bf to your computer and use it in GitHub Desktop.
Save shaver/69356ef7d8bfac4452bf to your computer and use it in GitHub Desktop.
load stockpile settings saved with save-stockpile
-- load stockpile settings saved with save-stockpile
-- usage: load-stockpile <id/name> file
-- load-stockpile file # uses currently-selected stockpile
local args = {...}
local pile = nil
local filename, file
if #args > 1 then
id = tostring(args[1])
for k, v in pairs(df.global.world.buildings.all) do
if v:getType() == df.building_type.Stockpile then
if v.name == id or tostring(v.stockpile_number) == id then
pile = v
break
end
end
end
if pile == nil then
qerror("no stockpile found named or having number '" .. id .. "'")
return
end
filename = args[2]
else
pile = dfhack.gui.getSelectedBuilding()
if pile == nil then
return
end
filename = args[1]
end
local settings = pile.settings;
function resetVector(vec, len)
vec:resize(0)
vec:resize(len)
end
function setVector(vec, first, last)
for i = first, last do
vec[i] = 1
end
end
local env = {["rV"] = resetVector,
["sV"] = setVector,
["S"] = settings }
local f,err = loadfile(filename, 't', env)
if f == nil then
qerror(err)
return
end
f()
print("Loaded stockpile settings from "..filename.." to stockpile " .. pile.name ..
" #" .. pile.stockpile_number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment