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
- `exterminate`: now works in arena mode; all active arena units are valid targets (there is no friendly/dangerous distinction in the arena), corpses are skipped, and the adventure arena player unit is never mass-exterminated

## Misc Improvements
Expand Down
31 changes: 17 additions & 14 deletions internal/caravan/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ 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)
-- 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 = dfhack.items.getContainedItems(item)
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 +615,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
Comment on lines +618 to +620

@SilasD SilasD Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I puzzled over this for a bit before I understood that the old code really was walking a hash table instead of going directly to the element it's trying to check. odd. good catch.

I'm not sure you need the explicit tests for ~= nil; these values should be true or at least truthy, I would think. but ISTR Lua does 'is this nil' in one VM instruction, and 'is this truthy' in one VM instruction, so it's a wash.

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 = dfhack.items.getContainedItems(item)
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