2012-06-24 09:30:26 -06:00
|
|
|
module DFHack
|
|
|
|
class << self
|
|
|
|
# return an Item
|
|
|
|
# arg similar to unit.rb/unit_find; no arg = 'k' menu
|
2012-07-04 10:34:41 -06:00
|
|
|
def item_find(what=:selected, y=nil, z=nil)
|
2012-06-24 09:30:26 -06:00
|
|
|
if what == :selected
|
2020-05-01 20:50:02 -06:00
|
|
|
return world.items.all.binsearch(df.get_selected_item_id)
|
2012-06-24 09:30:26 -06:00
|
|
|
elsif what.kind_of?(Integer)
|
2012-07-04 10:34:41 -06:00
|
|
|
# search by id
|
|
|
|
return world.items.all.binsearch(what) if not z
|
|
|
|
# search by position
|
|
|
|
x = what
|
2012-07-05 06:15:34 -06:00
|
|
|
world.items.all.find { |i| i.pos.x == x and i.pos.y == y and i.pos.z == z }
|
2012-06-24 09:30:26 -06:00
|
|
|
elsif what.respond_to?(:x) or what.respond_to?(:pos)
|
|
|
|
world.items.all.find { |i| same_pos?(what, i) }
|
|
|
|
else
|
|
|
|
raise "what what?"
|
|
|
|
end
|
|
|
|
end
|
2012-10-01 03:14:00 -06:00
|
|
|
|
|
|
|
# check item flags to see if it is suitable for use as a job input material
|
2013-04-30 10:31:52 -06:00
|
|
|
def item_isfree(i, check_empty=true)
|
2012-10-01 03:14:00 -06:00
|
|
|
!i.flags.trader and
|
|
|
|
!i.flags.in_job and
|
2013-04-30 10:31:52 -06:00
|
|
|
!i.flags.construction and
|
2012-10-01 03:14:00 -06:00
|
|
|
!i.flags.removed and
|
2013-04-30 10:31:52 -06:00
|
|
|
!i.flags.forbid and
|
|
|
|
!i.flags.dump and
|
2012-10-01 03:14:00 -06:00
|
|
|
!i.flags.owned and
|
2013-04-30 10:31:52 -06:00
|
|
|
!i.flags.in_chest and # used as hospital supply ?
|
|
|
|
(!i.flags.container or not check_empty or
|
|
|
|
!i.general_refs.find { |ir| ir.kind_of?(DFHack::GeneralRefContainsItemst) }) and
|
|
|
|
(!i.flags.in_inventory or
|
|
|
|
(!i.general_refs.find { |ir| ir.kind_of?(DFHack::GeneralRefUnitHolderst) and # allow hauled items TODO check if holder is a thief
|
|
|
|
ir.unit_tg.inventory.find { |ii| ii.item == i and ii.mode != :Hauled } } and
|
|
|
|
!i.general_refs.find { |ir| ir.kind_of?(DFHack::GeneralRefContainedInItemst) and
|
|
|
|
!item_isfree(ir.item_tg, false) })) and
|
|
|
|
(!i.flags.in_building or
|
|
|
|
!i.general_refs.find { |ir| ir.kind_of?(DFHack::GeneralRefBuildingHolderst) and
|
|
|
|
ir.building_tg.contained_items.find { |bi| bi.use_mode == 2 and bi.item == i } }) and
|
|
|
|
(!i.flags.on_ground or !df.map_tile_at(i).designation.hidden) # i.flags.unk11?
|
2012-10-01 03:14:00 -06:00
|
|
|
end
|
2012-06-24 09:30:26 -06:00
|
|
|
end
|
|
|
|
end
|