Skip to content

Commit 63801db

Browse files
authored
Merge pull request #1241 from Droseran/ban-cooking-patch
Efficiency increase for ban-cooking and change to 'seeds' option
2 parents 0ac7959 + daf59a3 commit 63801db

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

ban-cooking.lua

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -137,30 +137,29 @@ funcs.seeds = function()
137137
if p.material_defs.type.seed == -1 or p.material_defs.idx.seed == -1 or p.flags.TREE then goto continue end
138138
ban_cooking(p.name .. ' seeds', p.material_defs.type.seed, p.material_defs.idx.seed, df.item_type.SEEDS, -1)
139139
for _, m in ipairs(p.material) do
140-
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
141-
local has_drink = false
142-
local has_seed = false
143-
for _, s in ipairs(m.reaction_product.id) do
144-
has_seed = has_seed or s.value == "SEED_MAT"
145-
has_drink = has_drink or s.value == "DRINK_MAT"
146-
end
147-
if has_seed and has_drink then
148-
local matinfo = dfhack.matinfo.find(p.id, m.id)
149-
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
140+
if m.id == "STRUCTURAL" then
141+
if m.flags.EDIBLE_COOKED then
142+
local has_seed = false
143+
for _, s in ipairs(m.reaction_product.id) do
144+
has_seed = has_seed or s.value == "SEED_MAT"
145+
end
146+
if has_seed then
147+
local matinfo = dfhack.matinfo.find(p.id, m.id)
148+
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
149+
end
150150
end
151+
break
151152
end
152153
end
153154
for k, g in ipairs(p.growths) do
154155
local matinfo = dfhack.matinfo.decode(g)
155156
local m = matinfo.material
156157
if m.flags.EDIBLE_COOKED then
157-
local has_drink = false
158158
local has_seed = false
159159
for _, s in ipairs(m.reaction_product.id) do
160160
has_seed = has_seed or s.value == "SEED_MAT"
161-
has_drink = has_drink or s.value == "DRINK_MAT"
162161
end
163-
if has_seed and has_drink then
162+
if has_seed then
164163
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT_GROWTH, k)
165164
end
166165
end
@@ -174,14 +173,18 @@ funcs.brew = function()
174173
for _, p in ipairs(df.global.world.raws.plants.all) do
175174
if p.material_defs.type.drink == -1 or p.material_defs.idx.drink == -1 then goto continue end
176175
for _, m in ipairs(p.material) do
177-
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
178-
for _, s in ipairs(m.reaction_product.id) do
179-
if s.value == "DRINK_MAT" then
180-
local matinfo = dfhack.matinfo.find(p.id, m.id)
181-
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
182-
break
176+
if m.id == "STRUCTURAL" then
177+
if m.flags.EDIBLE_COOKED then
178+
for _, s in ipairs(m.reaction_product.id) do
179+
if s.value == "DRINK_MAT" then
180+
local matinfo = dfhack.matinfo.find(p.id, m.id)
181+
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
182+
break
183+
end
183184
end
184185
end
186+
-- Stop iterating materials since there is only one STRUCTURAL
187+
break
185188
end
186189
end
187190
for k, g in ipairs(p.growths) do
@@ -205,9 +208,12 @@ funcs.mill = function()
205208
for _, p in ipairs(df.global.world.raws.plants.all) do
206209
if p.material_defs.idx.mill ~= -1 then
207210
for _, m in ipairs(p.material) do
208-
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
209-
local matinfo = dfhack.matinfo.find(p.id, m.id)
210-
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
211+
if m.id == "STRUCTURAL" then
212+
if m.flags.EDIBLE_COOKED then
213+
local matinfo = dfhack.matinfo.find(p.id, m.id)
214+
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
215+
end
216+
break
211217
end
212218
end
213219
end
@@ -218,14 +224,17 @@ funcs.thread = function()
218224
for _, p in ipairs(df.global.world.raws.plants.all) do
219225
if p.material_defs.idx.thread == -1 then goto continue end
220226
for _, m in ipairs(p.material) do
221-
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
222-
for _, s in ipairs(m.reaction_product.id) do
223-
if s.value == "THREAD" then
224-
local matinfo = dfhack.matinfo.find(p.id, m.id)
225-
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
226-
break
227+
if m.id == "STRUCTURAL" then
228+
if m.flags.EDIBLE_COOKED then
229+
for _, s in ipairs(m.reaction_product.id) do
230+
if s.value == "THREAD" then
231+
local matinfo = dfhack.matinfo.find(p.id, m.id)
232+
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
233+
break
234+
end
227235
end
228236
end
237+
break
229238
end
230239
end
231240
for k, g in ipairs(p.growths) do

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Template for new versions:
9494
- `clear-smoke`: properly tag smoke flows for garbage collection to avoid memory leak
9595
- `warn-stranded`: don't warn for babies carried by mothers who happen to be gathering fruit from trees
9696
- `prioritize`: also boost priority of already-claimed jobs when boosting priority of a job type so those jobs are not interrupted
97+
- `ban-cooking`: ban all seed producing items from being cooked when 'seeds' is chosen instead of just brewable seed producing items
9798

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

docs/ban-cooking.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Valid types are:
4545
- ``milk``
4646
- ``mill`` (millable plants)
4747
- ``oil``
48-
- ``seeds`` (plantable seeds)
48+
- ``seeds`` (plantable seeds and items producing seeds)
4949
- ``tallow``
5050
- ``thread``
5151

0 commit comments

Comments
 (0)