-
Notifications
You must be signed in to change notification settings - Fork 196
/
ban-cooking.lua
299 lines (273 loc) · 10.7 KB
/
ban-cooking.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
-- convenient way to ban cooking categories of food
-- based on ban-cooking.rb by Putnam: https://github.com/DFHack/scripts/pull/427/files
-- Putnams work completed by TBSTeun
local argparse = require('argparse')
local kitchen = df.global.plotinfo.kitchen
local options = {}
local banned = {}
local count = 0
local function make_key(mat_type, mat_index, type, subtype)
return ('%s:%s:%s:%s'):format(mat_type, mat_index, type, subtype)
end
local function ban_cooking(print_name, mat_type, mat_index, type, subtype)
local key = make_key(mat_type, mat_index, type, subtype)
-- Skip adding a new entry further below if there's nothing to do
if (banned[key] and not options.unban) or (not banned[key] and options.unban) then
return
end
-- The item hasn't already been (un)banned, so we do that here by appending/removing
-- its values to/from the various arrays
count = count + 1
if options.verbose then
print(print_name .. ' has been ' .. (options.unban and 'un' or '') .. 'banned!')
end
if options.unban then
dfhack.kitchen.removeExclusion({Cook=true}, type, subtype, mat_type, mat_index)
banned[key] = nil
else
dfhack.kitchen.addExclusion({Cook=true}, type, subtype, mat_type, mat_index)
banned[key] = {
mat_type=mat_type,
mat_index=mat_index,
type=type,
subtype=subtype,
}
end
end
local function init_banned()
-- Iterate over the elements of the kitchen.item_types list
for i in ipairs(kitchen.item_types) do
if kitchen.exc_types[i].Cook then
local key = make_key(kitchen.mat_types[i], kitchen.mat_indices[i], kitchen.item_types[i], kitchen.item_subtypes[i])
if not banned[key] then
banned[key] = {
mat_type=kitchen.mat_types[i],
mat_index=kitchen.mat_indices[i],
type=kitchen.item_types[i],
subtype=kitchen.item_subtypes[i],
}
end
end
end
end
local funcs = {}
funcs.booze = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
for _, m in ipairs(p.material) do
if m.flags.ALCOHOL 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.DRINK, -1)
end
end
end
for _, c in ipairs(df.global.world.raws.creatures.all) do
for _, m in ipairs(c.material) do
if m.flags.ALCOHOL and m.flags.EDIBLE_COOKED then
local matinfo = dfhack.matinfo.find(c.creature_id, m.id)
ban_cooking(c.name[2] .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.DRINK, -1)
end
end
end
end
funcs.honey = function()
local mat = dfhack.matinfo.find("CREATURE:HONEY_BEE:HONEY")
ban_cooking('honey bee honey', mat.type, mat.index, df.item_type.LIQUID_MISC, -1)
end
funcs.tallow = function()
for _, c in ipairs(df.global.world.raws.creatures.all) do
for _, m in ipairs(c.material) do
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "SOAP_MAT" then
local matinfo = dfhack.matinfo.find(c.creature_id, m.id)
ban_cooking(c.name[2] .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.GLOB, -1)
break
end
end
end
end
end
end
funcs.milk = function()
for _, c in ipairs(df.global.world.raws.creatures.all) do
for _, m in ipairs(c.material) do
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "CHEESE_MAT" then
local matinfo = dfhack.matinfo.find(c.creature_id, m.id)
ban_cooking(c.name[2] .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.LIQUID_MISC, -1)
break
end
end
end
end
end
end
funcs.oil = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
for _, m in ipairs(p.material) do
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "SOAP_MAT" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.LIQUID_MISC, -1)
break
end
end
end
end
end
end
funcs.seeds = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
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" 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_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
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT_GROWTH, k)
end
end
end
::continue::
end
end
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" 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
local matinfo = dfhack.matinfo.decode(g)
local m = matinfo.material
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "DRINK_MAT" then
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT_GROWTH, k)
break
end
end
end
end
::continue::
end
end
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" 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
end
end
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" 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
local matinfo = dfhack.matinfo.decode(g)
local m = matinfo.material
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "THREAD" then
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT_GROWTH, k)
break
end
end
end
end
::continue::
end
end
funcs.fruit = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
for k, g in ipairs(p.growths) do
local matinfo = dfhack.matinfo.decode(g)
local m = matinfo.material
if m.id == "FRUIT" and m.flags.EDIBLE_COOKED and m.flags.STOCKPILE_PLANT_GROWTH then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "DRINK_MAT" then
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT_GROWTH, k)
break
end
end
end
end
end
end
local classes = argparse.processArgsGetopt({...}, {
{'h', 'help', handler=function() options.help = true end},
{'u', 'unban', handler=function() options.unban = true end},
{'v', 'verbose', handler=function() options.verbose = true end},
})
if options.help == true then
print(dfhack.script_help())
return
end
init_banned()
if classes[1] == 'all' then
for _, func in pairs(funcs) do
func()
end
else
for _, v in ipairs(classes) do
if funcs[v] then
funcs[v]()
end
end
end
print((options.unban and 'un' or '') .. 'banned ' .. count .. ' types.')