Skip to content

Commit db60966

Browse files
authored
Merge pull request #1522 from SilasD/combine
combine.lua when 'here' is specified, try harder to determine the target stockpile.
2 parents 0b54694 + d4712b8 commit db60966

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Template for new versions:
3535
- `empty-bin`: renamed ``--liquids`` parameter to ``--force`` and made emptying of containers (bags) with powders contingent on that parameter. Previously powders would just always get disposed.
3636

3737
## Misc Improvements
38+
- `combine`: try harder to find the currently-selected stockpile
3839

3940
## Removed
4041

combine.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,26 @@ local function get_stockpile_here()
736736
-- return the stockpile as a table
737737
local stockpiles = {}
738738
local building = dfhack.gui.getSelectedStockpile(true)
739+
740+
-- try finding the stockpile by viewed item or first item in itemlist viewsheet.
741+
if building == nil then
742+
local item = nil
743+
if dfhack.gui.getSelectedItem(true) ~= nil then
744+
item = dfhack.gui.getSelectedItem(true)
745+
elseif tonumber(dfhack.DF_VERSION:match("^0*%.*(%d+%.%d+)")) >= 50.07 -- matchFocusString() in Commit a770a4c
746+
and dfhack.gui.matchFocusString("dwarfmode/ViewSheets/ITEM_LIST", dfhack.gui.getDFViewscreen())
747+
and df.global.game.main_interface.view_sheets.open == true
748+
and df.global.game.main_interface.view_sheets.active_sheet == df.view_sheet_type.ITEM_LIST
749+
and #df.global.game.main_interface.view_sheets.viewing_itid > 0
750+
then
751+
local itemid = df.global.game.main_interface.view_sheets.viewing_itid[0]
752+
item = df.item.find(itemid)
753+
end
754+
local pos = (item) and xyz2pos(dfhack.items.getPosition(item)) or nil
755+
building = (pos) and dfhack.buildings.findAtTile(pos) or nil
756+
building = (df.building_stockpilest:is_instance(building)) and building or nil
757+
end
758+
739759
if not building then qerror('Please select a stockpile.') end
740760
table.insert(stockpiles, building)
741761
if opts.verbose > 0 then

docs/combine.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ Commands
3838
``all``
3939
Search all stockpiles.
4040
``here``
41-
Search the currently selected stockpile.
41+
Search the currently selected stockpile, or the stockpile that the
42+
currently-seelected item is in, or the stockpile that the currently-
43+
displayed item-list is in.
4244

4345
Options
4446
-------

0 commit comments

Comments
 (0)