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

[caravan] search within containers on trade screen #900

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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