Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand empty-bin to allow you to empty currently selected stockpile #1173

Merged
merged 12 commits into from
Jun 25, 2024
Merged
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Template for new versions:
- `gui/launcher`: refresh default tag filter when mortal mode is toggled in `gui/control-panel` so changes to which tools autocomplete take effect immediately
- `gui/civ-alert`: you can now register multiple burrows as civilian alert safe spaces
- `exterminate`: add ``all`` target for convenient scorched earth tactics
- `empty-bin`: select a stockpile, tile, or building to empty all containers in the stockpile, tile, or building
- `exterminate`: add ``--limit`` option to limit number of exterminated creatures
- `exterminate`: add ``knockout`` and ``traumatize`` method for a non-lethal incapacitation
- `caravan`: add shortcut to the trade request screen for selecting item types by value (e.g. so you can quickly select expensive gems or cheap leather)
Expand Down
7 changes: 6 additions & 1 deletion docs/empty-bin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ This tool can quickly empty the contents of the selected container (bin,
barrel, pot, wineskin, quiver, etc.) onto the floor, allowing you to access
individual items that might otherwise be hard to get to.

Note that if there are liquides in the container, they will empty onto the floor
Note that if there are liquids in the container, they will empty onto the floor
and become unusable.

If you instead select a stockpile or building, running `empty-bin` will empty
*all* containers in the stockpile or building. Likewise, if you select a tile
that has many items and the UI is showing the list of items, all containers on
the tile will be dumped.

Usage
-----

Expand Down
53 changes: 39 additions & 14 deletions empty-bin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,49 @@
-- https://gist.github.com/stonetoad/11129025
-- http://dwarffortresswiki.org/index.php/DF2014_Talk:Bin

--[====[

empty-bin
=========
local function moveItem(item, to_pos)
print(' ' .. dfhack.items.getReadableDescription(item))
dfhack.items.moveToGround(item, to_pos)
end

Empties the contents of the selected bin onto the floor.
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 bin = dfhack.gui.getSelectedItem(true) or qerror("No item selected")
local items = dfhack.items.getContainedItems(bin)
local viewsheets = df.global.game.main_interface.view_sheets

if #items > 0 then
print('Emptying ' .. dfhack.items.getDescription(bin, 0))
for _, item in pairs(items) do
print(' ' .. dfhack.items.getDescription(item, 0))
dfhack.items.moveToGround(item, xyz2pos(dfhack.items.getPosition(bin)))
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
local containedItems = selectedBuilding.contained_items
for i=#containedItems-1,0,-1 do
contained = containedItems[i]
if contained.use_mode == df.building_item_role_type.TEMP then
emptyContainer(contained.item)
end
end
myk002 marked this conversation as resolved.
Show resolved Hide resolved
elseif viewsheets.open then
for _, item_id in ipairs(viewsheets.viewing_itid) do
local item = df.item.find(item_id)
emptyContainer(item)
end
else
print('No contained items')
qerror("Please select a container, building, stockpile, or tile with a list of items.")
end