ruby: add method to check if an item is free for use as construction material

develop
jj 2012-08-11 20:08:33 +02:00
parent 8f4c39d3f5
commit 942b245461
1 changed files with 11 additions and 2 deletions

@ -286,14 +286,23 @@ module DFHack
job
end
# check item flags to see if it is suitable for use as a building material
def building_isitemfree(i)
!i.flags.in_job and
!i.flags.in_inventory and
!i.flags.removed and
!i.flags.in_building and
!i.flags.owned and
!i.flags.forbid
end
# exemple usage
def buildbed(pos=cursor)
raise 'where to ?' if pos.x < 0
item = world.items.all.find { |i|
i.kind_of?(ItemBedst) and
i.itemrefs.empty? and
!i.flags.in_job
building_isitemfree(i)
}
raise 'no free bed, build more !' if not item