Skip to content

Commit 7f18d2c

Browse files
committed
[ban-cooking] Update for DFHack/df-structures@238b305.
Remove undocumented debugging commands. Fixes DFHack/dfhack#1293.
1 parent 5bd8f0d commit 7f18d2c

File tree

1 file changed

+6
-63
lines changed

1 file changed

+6
-63
lines changed

ban-cooking.rb

+6-63
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
# Just create a shorthand reference to the kitchen object
1717
kitchen = df.ui.kitchen
1818

19-
# Store our list of banned items in the dictionary/hash table, along with their index number
20-
# -- index number storage was added from the original script so as to assist in addressing
21-
# the specific kitchen array entry directly later in the script, rather than search through it again.
19+
# Store our list of banned items in the dictionary/hash table
2220
kitchen.item_types.length.times { |i|
23-
already_banned[[kitchen.mat_types[i], kitchen.mat_indices[i], kitchen.item_types[i], kitchen.item_subtypes[i]]] = [ kitchen.exc_types[i] & 1, i ]
21+
if kitchen.exc_types[i] == :Cook
22+
already_banned[[kitchen.mat_types[i], kitchen.mat_indices[i], kitchen.item_types[i], kitchen.item_subtypes[i]]] = true
23+
end
2424
}
2525

2626
# The function for actually banning cooking of an item.
@@ -35,20 +35,6 @@
3535
key = [mat_type, mat_index, type, subtype]
3636
# Skip adding a new entry further below, if the item is already banned.
3737
if already_banned[key]
38-
# Get our stored index kitchen arrays' index value
39-
index = already_banned[key][1]
40-
# Check that the banned flag is set.
41-
return if already_banned[key][0] == 1
42-
# Added a check here to ensure that the exc_types array entry had something at the index entry
43-
# as the original script didn't check for :EDIBLE_COOKED before banning certain plants, so that
44-
# lead to mismatched array lengths, and a crash possibly due to memory corruption.
45-
if kitchen.exc_types[index]
46-
# Or's the value of the exc_type to turn the first bit of the byte on.
47-
puts(print_name + ' has been banned!')
48-
kitchen.exc_types[index] |= 1
49-
end
50-
# Record in the dictionary/hash table that the item is now cooking banned.
51-
already_banned[key][0] = 1
5238
return
5339
end
5440
# The item hasn't already been banned, so we do that here by appending its values to the various arrays
@@ -59,8 +45,8 @@
5945
df.ui.kitchen.mat_indices << mat_index
6046
df.ui.kitchen.item_types << type
6147
df.ui.kitchen.item_subtypes << subtype
62-
df.ui.kitchen.exc_types << 1
63-
already_banned[key] = [ 1, length ]
48+
df.ui.kitchen.exc_types << :Cook
49+
already_banned[key] = true
6450
}
6551

6652
$script_args.each do |arg|
@@ -354,51 +340,8 @@
354340
# There's no entry for this item in our calculated list of cookable items. So, it's not a plant, alcohol, tallow, or milk. It's likely that it's a meat that has been banned.
355341
output += '|"' + key.inspect + ' unknown banned material type (meat?) " ' + '|item type: "' + b[0][2].inspect + '"|item subtype: "' + b[0][3].inspect
356342
end
357-
output += '|exc type: "' + kitchen.exc_types[b[1][1]].inspect + '"'
358343
puts output
359344
end
360-
361-
# prints out the data structures for several different plants and one animal so that their data structure can be examined/understood
362-
when 'potato'
363-
df.world.raws.plants.all.each_with_index do |p, i|
364-
if p.name.include?('potato')
365-
puts(p.inspect)
366-
end
367-
end
368-
369-
when 'pig'
370-
df.world.raws.plants.all.each_with_index do |p, i|
371-
if p.name.include?('pig tail')
372-
puts(p.inspect)
373-
end
374-
end
375-
376-
when 'cherry'
377-
df.world.raws.plants.all.each_with_index do |p, i|
378-
if p.name.include?('cherry')
379-
puts(p.inspect)
380-
end
381-
end
382-
383-
# an example of both milling and thread in one plant
384-
when 'hemp'
385-
df.world.raws.plants.all.each_with_index do |p, i|
386-
if p.name.include?('hemp')
387-
puts(p.inspect)
388-
end
389-
end
390-
391-
when 'cow'
392-
df.world.raws.creatures.all.each_with_index do |c, i|
393-
# can't just do "cow", as that would print reindeer cow, yak cow, and cow
394-
if c.name.include?('yak')
395-
# c.inspect truncates output too early to get to the materials we want to view
396-
c.material.each_with_index do |m, j|
397-
puts(m.inspect)
398-
end
399-
end
400-
end
401-
402345
else
403346
puts "ban-cooking booze - bans cooking of drinks"
404347
puts "ban-cooking honey - bans cooking of honey bee honey"

0 commit comments

Comments
 (0)