Skip to content

Commit e50bc81

Browse files
committed
Refactor: Strip out redundant logic and reaction conditionals
1 parent aa6eeb9 commit e50bc81

1 file changed

Lines changed: 7 additions & 47 deletions

File tree

item-uses.lua

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ end
150150
if has_flag('WOOD') and is_raw then
151151
add_use("Carpenter's workshop", 'Make wooden items/furniture')
152152
add_use('Wood furnace', 'Make charcoal/ash')
153+
add_use("Bowyer's workshop", 'Make crossbow')
153154
end
154155
if has_flag('IS_METAL') then
155156
if is_raw then add_use("Metalsmith's forge", 'Forge metal items') end
@@ -225,47 +226,24 @@ end
225226
---------------------------------------------------------------------------
226227
-- 3. ITEM TYPE USES
227228
---------------------------------------------------------------------------
228-
if item_type == df.item_type.PLANT then
229-
add_use("Farmer's workshop", 'Process plant')
230-
elseif item_type == df.item_type.SEEDS then
229+
if item_type == df.item_type.SEEDS then
231230
add_use('Farm plot', 'Plant seeds')
232-
elseif item_type == df.item_type.BOULDER then
233-
add_use("Mason's workshop", 'Construct furniture')
234-
add_use("Craftsdwarf's workshop", 'Make crafts')
235231
elseif item_type == df.item_type.ROUGH then
236232
add_use("Jeweler's workshop", 'Cut rough gem')
237233
elseif item_type == df.item_type.SMALLGEM then
238234
add_use("Jeweler's workshop", 'Encrust with gem')
239-
elseif item_type == df.item_type.WOOD then
240-
add_use("Carpenter's workshop", 'Make wooden furniture/items')
241-
add_use('Wood furnace', 'Make charcoal/ash')
242-
add_use("Bowyer's workshop", 'Make crossbow')
243235
elseif item_type == df.item_type.CLOTH then
244236
add_use("Clothier's shop", 'Make clothing')
245237
add_use("Dyer's shop", 'Dye cloth')
246238
elseif item_type == df.item_type.THREAD then
247239
add_use('Loom', 'Weave into cloth')
248240
add_use("Dyer's shop", 'Dye thread')
249-
elseif item_type == df.item_type.SKIN_TANNED then
250-
add_use('Leatherworks', 'Make leather items')
251-
elseif item_type == df.item_type.MEAT then
252-
add_use('Kitchen', 'Cook in meal')
253241
elseif item_type == df.item_type.FISH_RAW then
254242
add_use('Fishery', 'Prepare raw fish')
255243
elseif item_type == df.item_type.EGG then
256-
add_use('Kitchen', 'Cook in meal')
257244
add_use('Nest box', 'Hatch (if fertile)')
258-
elseif item_type == df.item_type.GLOB then
259-
add_use('Kitchen', 'Render fat / Cook tallow')
260-
elseif item_type == df.item_type.CHEESE then
261-
add_use('Kitchen', 'Cook in meal')
262245
elseif item_type == df.item_type.DRINK then
263246
add_use('Tavern', 'Drink')
264-
elseif item_type == df.item_type.BAR then
265-
if has_flag('IS_METAL') then
266-
add_use("Metalsmith's forge", 'Forge weapons/armor/items')
267-
end
268-
if has_flag('SOAP') then add_use('Hospital', 'Cleaning') end
269247
elseif item_type == df.item_type.BLOCKS then
270248
add_use('Construction', 'Build walls/floors/stairs')
271249
end
@@ -306,34 +284,16 @@ for _, r in ipairs(df.global.world.raws.reactions.reactions) do
306284

307285
-- If BOTH item_type and mat_type are -1 (accepts anything),
308286
-- require at least has_material_reaction_product or reaction_class
309-
local has_hmrp = false
310-
local hmrp_val = nil
311-
if ir.has_material_reaction_product and #ir.has_material_reaction_product > 0 then
312-
has_hmrp = true
313-
hmrp_val = ir.has_material_reaction_product
314-
end
315-
316-
local has_rc = false
317-
local rc_val = nil
318-
if ir.reaction_class and #ir.reaction_class > 0 then
319-
has_rc = true
320-
rc_val = ir.reaction_class
321-
end
287+
local hmrp = ir.has_material_reaction_product ~= "" and ir.has_material_reaction_product or nil
288+
local rc = ir.reaction_class ~= "" and ir.reaction_class or nil
322289

323290
-- Skip overly generic reagents (both type and mat are wildcard, no extra filters)
324-
if ir.item_type == -1 and ir.mat_type == -1 and not has_hmrp and not has_rc then
291+
if ir.item_type == -1 and ir.mat_type == -1 and not hmrp and not rc then
325292
goto next_reaction
326293
end
327294

328-
-- Verify has_material_reaction_product
329-
if has_hmrp then
330-
if not mat_has_product(material, hmrp_val) then goto next_reaction end
331-
end
332-
333-
-- Verify reaction_class
334-
if has_rc then
335-
if not mat_has_class(material, rc_val) then goto next_reaction end
336-
end
295+
if hmrp and not mat_has_product(material, hmrp) then goto next_reaction end
296+
if rc and not mat_has_class(material, rc) then goto next_reaction end
337297

338298
-- Match!
339299
add_use(get_workshop_name(r), r.name)

0 commit comments

Comments
 (0)