Skip to content

Commit

Permalink
Merge pull request #1241 from Droseran/ban-cooking-patch
Browse files Browse the repository at this point in the history
Efficiency increase for ban-cooking and change to 'seeds' option
  • Loading branch information
myk002 authored Jul 31, 2024
2 parents 0ac7959 + daf59a3 commit 63801db
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
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
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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ 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`: 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
2 changes: 1 addition & 1 deletion docs/ban-cooking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Valid types are:
- ``milk``
- ``mill`` (millable plants)
- ``oil``
- ``seeds`` (plantable seeds)
- ``seeds`` (plantable seeds and items producing seeds)
- ``tallow``
- ``thread``

Expand Down

0 comments on commit 63801db

Please sign in to comment.