Skip to content
Open
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 @@ -31,6 +31,7 @@ Template for new versions:
## New Features

## Fixes
- `caravan`: fix UI freeze in the ``Move goods to/from depot`` dialog when marking or unmarking large item groups; item lists are now built incrementally so the UI stays responsive, and the item scan itself is faster

## Misc Improvements

Expand Down
33 changes: 19 additions & 14 deletions internal/caravan/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ function obfuscate_value(value, threshold)
return ('%s?'):format(estimate(threshold*30, 999, 1000))
end

-- takes into account trade agreements
function get_perceived_value(item, caravan_state)
local EMPTY_CONTAINED = {}

-- takes into account trade agreements. contained is an optional precomputed
-- contents list so callers that scan many items can look it up once per item.
function get_perceived_value(item, caravan_state, contained)
local value = dfhack.items.getValue(item, caravan_state)
for _,contained_item in ipairs(dfhack.items.getContainedItems(item)) do
if not contained then
contained = item.flags.container and dfhack.items.getContainedItems(item) or EMPTY_CONTAINED
end
for _,contained_item in ipairs(contained) do
value = value + dfhack.items.getValue(contained_item, caravan_state)
for _,contained_contained_item in ipairs(dfhack.items.getContainedItems(contained_item)) do
value = value + dfhack.items.getValue(contained_contained_item, caravan_state)
Expand Down Expand Up @@ -611,21 +617,20 @@ function get_info_widgets(self, export_agreements, strict_ethical_bins_default,
end

local function match_risky(item, risky_items)
for item_type, subtypes in pairs(risky_items) do
for subtype in pairs(subtypes) do
if item_type == item:getType() and (subtype == -1 or subtype == item:getSubtype()) then
return true
end
end
end
return false
local subtypes = risky_items[item:getType()]
if not subtypes then return false end
return subtypes[-1] ~= nil or subtypes[item:getSubtype()] ~= nil
end

-- returns is_banned, is_risky
function scan_banned(item, risky_items)
-- returns is_banned, is_risky. contained is an optional precomputed contents
-- list so callers that scan many items can look it up once per item.
function scan_banned(item, risky_items, contained)
if not dfhack.items.checkMandates(item) then return true, true end
if match_risky(item, risky_items) then return false, true end
for _,contained_item in ipairs(dfhack.items.getContainedItems(item)) do
if not contained then
contained = item.flags.container and dfhack.items.getContainedItems(item) or EMPTY_CONTAINED
end
for _,contained_item in ipairs(contained) do
if not dfhack.items.checkMandates(contained_item) then return true, true end
if match_risky(contained_item, risky_items) then return false, true end
end
Expand Down
Loading
Loading