Script to detect equipment corruption, attempting to fix equipment that's not assigned.
function fix_corruption ()
for i, item in ipairs (df.global.ui.equipment.items_unassigned.FLASK) do
if item._type ~= df.item_flaskst then
dfhack.printerr ("Corrupted unassigned flask, removing", i)
df.global.ui.equipment.items_unassigned.FLASK:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.WEAPON) do
if item._type ~= df.item_weaponst then
dfhack.printerr ("Corrupted unassigned weapon, removing", i)
df.global.ui.equipment.items_unassigned.WEAPON:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.ARMOR) do
if item._type ~= df.item_armorst then
dfhack.printerr ("Corrupted unassigned armor, removing", i)
df.global.ui.equipment.items_unassigned.ARMOR:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.SHOES) do
if item._type ~= df.item_shoesst then
dfhack.printerr ("Corrupted unassigned shoes, removing", i)
df.global.ui.equipment.items_unassigned.SHOES:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.SHIELD) do
if item._type ~= df.item_shieldst then
dfhack.printerr ("Corrupted unassigned shield, removing", i)
df.global.ui.equipment.items_unassigned.SHIELD:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.HELM) do
if item._type ~= df.item_helmst then
dfhack.printerr ("Corrupted unassigned helm, removing", i)
df.global.ui.equipment.items_unassigned.HELM:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.GLOVES) do
if item._type ~= df.item_glovesst then
dfhack.printerr ("Corrupted unassigned gloves, removing", i)
df.global.ui.equipment.items_unassigned.GLOVES:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.AMMO) do
if item._type ~= df.item_ammost then
dfhack.printerr ("Corrupted unassigned ammo, removing", i)
df.global.ui.equipment.items_unassigned.AMMO:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.PANTS) do
if item._type ~= df.item_pantsst then
dfhack.printerr ("Corrupted unassigned pants, removing", i)
df.global.ui.equipment.items_unassigned.PANTS:erase (i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.BACKPACK) do
if item._type ~= df.item_backpackst then
df.global.ui.equipment.items_unassigned.BACKPACK:erase (i)
dfhack.printerr ("Corrupted unassigned backpack, removing", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_unassigned.QUIVER) do
if item._type ~= df.item_quiverst then
df.global.ui.equipment.items_unassigned.QUIVER:erase (i)
dfhack.printerr ("Corrupted unassigned quiver, removing", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.FLASK) do
if item._type ~= df.item_flaskst then
dfhack.printerr ("Corrupted assigned flask. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.WEAPON) do
if item._type ~= df.item_weaponst then
dfhack.printerr ("Corrupted assigned weapon. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.ARMOR) do
if item._type ~= df.item_armorst then
dfhack.printerr ("Corrupted assigned armor. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.SHOES) do
if item._type ~= df.item_shoesst then
dfhack.printerr ("Corrupted assigned shoes. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.SHIELD) do
if item._type ~= df.item_shieldst then
dfhack.printerr ("Corrupted assigned shield. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.HELM) do
if item._type ~= df.item_helmst then
dfhack.printerr ("Corrupted assigned helm. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.GLOVES) do
if item._type ~= df.item_glovesst then
dfhack.printerr ("Corrupted assigned gloves. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.AMMO) do
if item._type ~= df.item_ammost then
dfhack.printerr ("Corrupted assigned ammo. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.PANTS) do
if item._type ~= df.item_pantsst then
dfhack.printerr ("Corrupted assigned pant. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.BACKPACK) do
if item._type ~= df.item_backpackst then
dfhack.printerr ("Corrupted assigned backpack. DETECTION ONLY", i)
end
end
for i, item in ipairs (df.global.ui.equipment.items_assigned.QUIVER) do
if item._type ~= df.item_quiverst then
dfhack.printerr ("Corrupted assigned quiver. DETECTION ONLY", i)
end
end
end
fix_corruption ()
Based on Toady's answer in FotF, but the script's testing has been limited to verifying that a corrupt entry doesn't reappear.
Note that the script doesn't try to fix corrupt assigned equipment I've seen that in a save), as that likely requires additional handling to deal with the unit to which the equipment has been assigned.