Skip to content

Instantly share code, notes, and snippets.

@angavrilov
Created May 7, 2012 17:01
Show Gist options
  • Save angavrilov/2628981 to your computer and use it in GitHub Desktop.
Save angavrilov/2628981 to your computer and use it in GitHub Desktop.
A script to verify integrity of block item lists and occupancy.
-- This scripts verifies that:
--
-- 1) Item has flags.on_ground <=> it is in the correct block item list
-- 2) A tile has items in block item list <=> it has occupancy.item
function check_block_items()
local cnt = 0
local icnt = 0
local found = {}
for _,block in ipairs(df.global.world.map.map_blocks) do
local itable = {}
local bx,by,bz = pos2xyz(block.map_pos)
for _,id in ipairs(block.items) do
local item = df.item.find(id)
local ix,iy,iz = pos2xyz(item.pos)
local dx,dy,dz = ix-bx,iy-by,iz-bz
found[id] = true
if dx < 0 or dx >= 16 or dy < 0 or dy >= 16 or dz ~= 0 then
print(bx,by,bz,id,dx,dy,dz,'invalid pos')
elseif not item.flags.on_ground then
print(bx,by,bz,id,dx,dy,'in block & not on ground')
else
itable[dx + dy*16] = true;
if not block.occupancy[dx][dy].item then
print(bx,by,bz,dx,dy,'item & not occupied')
end
end
end
icnt = icnt + #block.items
for x=0,15 do
local ocx = block.occupancy[x]
for y=0,15 do
if ocx[y].item and not itable[x + y*16] then
print(bx,by,bz,x,y,'occupied & no item')
end
end
end
cnt = cnt + 256
end
for _,item in ipairs(df.global.world.items.all) do
if item.flags.on_ground and not found[item.id] then
print(id,item.pos.x,item.pos.y,item.pos.z,'on ground & not in block')
end
end
print(cnt.." tiles and "..icnt.." items checked")
end
dfhack.with_suspend(check_block_items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment