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

Efficiency increase for ban-cooking and change to 'seeds' option #1241

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
65 changes: 37 additions & 28 deletions ban-cooking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,29 @@ funcs.seeds = function()
if p.material_defs.type.seed == -1 or p.material_defs.idx.seed == -1 or p.flags.TREE then goto continue end
ban_cooking(p.name .. ' seeds', p.material_defs.type.seed, p.material_defs.idx.seed, df.item_type.SEEDS, -1)
for _, m in ipairs(p.material) do
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
local has_drink = false
local has_seed = false
for _, s in ipairs(m.reaction_product.id) do
has_seed = has_seed or s.value == "SEED_MAT"
has_drink = has_drink or s.value == "DRINK_MAT"
end
if has_seed and has_drink then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
if m.id == "STRUCTURAL" then
if m.flags.EDIBLE_COOKED then
local has_seed = false
for _, s in ipairs(m.reaction_product.id) do
has_seed = has_seed or s.value == "SEED_MAT"
end
if has_seed then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
end
end
break
myk002 marked this conversation as resolved.
Show resolved Hide resolved
end
end
for k, g in ipairs(p.growths) do
local matinfo = dfhack.matinfo.decode(g)
local m = matinfo.material
if m.flags.EDIBLE_COOKED then
local has_drink = false
local has_seed = false
for _, s in ipairs(m.reaction_product.id) do
has_seed = has_seed or s.value == "SEED_MAT"
has_drink = has_drink or s.value == "DRINK_MAT"
end
if has_seed and has_drink then
if has_seed then
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT_GROWTH, k)
end
end
Expand All @@ -174,14 +173,18 @@ funcs.brew = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
if p.material_defs.type.drink == -1 or p.material_defs.idx.drink == -1 then goto continue end
for _, m in ipairs(p.material) do
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "DRINK_MAT" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
break
if m.id == "STRUCTURAL" then
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "DRINK_MAT" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
break
end
end
end
-- Stop iterating materials since there is only one STRUCTURAL
break
end
end
for k, g in ipairs(p.growths) do
Expand All @@ -205,9 +208,12 @@ funcs.mill = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
if p.material_defs.idx.mill ~= -1 then
for _, m in ipairs(p.material) do
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
if m.id == "STRUCTURAL" then
if m.flags.EDIBLE_COOKED then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
end
break
end
end
end
Expand All @@ -218,14 +224,17 @@ funcs.thread = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
if p.material_defs.idx.thread == -1 then goto continue end
for _, m in ipairs(p.material) do
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "THREAD" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
break
if m.id == "STRUCTURAL" then
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "THREAD" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
break
end
end
end
break
end
end
for k, g in ipairs(p.growths) do
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ Template for new versions:
- `clear-smoke`: properly tag smoke flows for garbage collection to avoid memory leak
- `warn-stranded`: don't warn for babies carried by mothers who happen to be gathering fruit from trees
- `prioritize`: also boost priority of already-claimed jobs when boosting priority of a job type so those jobs are not interrupted
- `ban-cooking`: stop iterating through plant materials when the searched-for material is found
Copy link
Member

Choose a reason for hiding this comment

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

this one is not user-visible and doesn't need a changelog line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I've removed that line from the changelog and updated the documentation file to clarify which items the 'seeds' option affects.

- `ban-cooking`: ban all seed producing items from being cooked when 'seeds' is chosen instead of just brewable seed producing items

## Misc Improvements
- `item`: option for ignoring uncollected spider webs when you search for "silk"
Expand Down