Repository navigation
Movegoods fix #1655
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
base: master
Are you sure you want to change the base?
Movegoods fix #1655
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it turns out that getContainedItems does the right thing if the item being probed isn't a container; it returns an empty list instead of throwing or otherwise misfunctioning. I think it's just as fast to call it as to test a flag bit and choose between two options.
Suggested change
|
||||||
| 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) | ||||||
|
|
@@ -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 | ||||||
|
Comment on lines
+620
to
+622
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
| 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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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 | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like having this constant. it made me wonder, is something being maintained in this between yields? is this something that needs to be cleared out when the calling script exits?
I think you should zap it and just use a
{}empty-table constructor in the two places it's used.Edit: wait, hold the phone, it's completely unneccesary. discussion below. zap it.