Skip to content

Commit

Permalink
Merge pull request #1173 from Crystalwarrior/empty-bin-plus
Browse files Browse the repository at this point in the history
Expand empty-bin to allow you to empty currently selected stockpile
  • Loading branch information
myk002 authored Jun 25, 2024
2 parents dbb57ad + bb8a28e commit ec4a025
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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
51 changes: 37 additions & 14 deletions empty-bin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,47 @@
-- 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
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
print('No contained items')
qerror("Please select a container, building, stockpile, or tile with a list of items.")
end

0 comments on commit ec4a025

Please sign in to comment.