Skip to content

Commit

Permalink
Merge pull request #900 from myk002/myk_containers
Browse files Browse the repository at this point in the history
[caravan] search within containers on trade screen
  • Loading branch information
myk002 authored Nov 21, 2023
2 parents 64db4d9 + 633cd7e commit 02ef6cd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Template for new versions:

## Misc Improvements
- `combine`: prevent stack sizes from growing beyond quantities that you would normally see in vanilla gameplay
- `caravan`: enable searching within containers in trade screen when in "trade bin with contents" mode

## Removed

Expand Down
9 changes: 9 additions & 0 deletions internal/caravan/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ function make_search_key(str)
return table.concat(words, ' ')
end

function make_container_search_key(item, desc)
local words = {}
add_words(words, desc)
for _, contained_item in ipairs(dfhack.items.getContainedItems(item)) do
add_words(words, get_item_description(contained_item))
end
return table.concat(words, ' ')
end

local function get_broker_skill()
local broker = dfhack.units.getUnitByNobleRole('broker')
if not broker then return 0 end
Expand Down
10 changes: 8 additions & 2 deletions internal/caravan/trade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,19 @@ function Trade:cache_choices(list_idx, trade_bins)
parent_data.has_requested = parent_data.has_requested or is_requested
parent_data.ethical = parent_data.ethical and is_ethical
end
local is_container = df.item_binst:is_instance(item)
local search_key
if (trade_bins and is_container) or item:isFoodStorage() then
search_key = common.make_container_search_key(item, desc)
else
search_key = common.make_search_key(desc)
end
local choice = {
search_key=common.make_search_key(desc),
search_key=search_key,
icon=curry(get_entry_icon, data),
data=data,
text=make_choice_text(data.value, desc),
}
local is_container = df.item_binst:is_instance(item)
if not data.update_container_fn then
table.insert(trade_bins_choices, choice)
end
Expand Down

0 comments on commit 02ef6cd

Please sign in to comment.