forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
empty-bin.lua
49 lines (44 loc) · 1.68 KB
/
empty-bin.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- Empty a bin onto the floor
-- Based on "emptybin" by StoneToad
-- https://gist.github.com/stonetoad/11129025
-- http://dwarffortresswiki.org/index.php/DF2014_Talk:Bin
local function moveItem(item, to_pos)
print(' ' .. dfhack.items.getReadableDescription(item))
dfhack.items.moveToGround(item, to_pos)
end
local function emptyContainer(container)
local items = dfhack.items.getContainedItems(container)
if #items > 0 then
print('Emptying ' .. dfhack.items.getReadableDescription(container))
local pos = xyz2pos(dfhack.items.getPosition(container))
for _, item in ipairs(items) do
moveItem(item, pos)
end
end
end
local viewsheets = df.global.game.main_interface.view_sheets
local stockpile = dfhack.gui.getSelectedStockpile(true)
local selectedItem = dfhack.gui.getSelectedItem(true)
local selectedBuilding = dfhack.gui.getSelectedBuilding(true)
if stockpile then
local contents = dfhack.buildings.getStockpileContents(stockpile)
for _, container in ipairs(contents) do
emptyContainer(container)
end
elseif selectedItem then
emptyContainer(selectedItem)
elseif selectedBuilding then
if not df.building_actual:is_instance(selectedBuilding) then return end
for _, contained in ipairs(selectedBuilding.contained_items) do
if contained.use_mode == df.building_item_role_type.TEMP then
emptyContainer(contained.item)
end
end
elseif viewsheets.open then
for _, item_id in ipairs(viewsheets.viewing_itid) do
local item = df.item.find(item_id)
emptyContainer(item)
end
else
qerror("Please select a container, building, stockpile, or tile with a list of items.")
end