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
|
2012-09-24 07:40:35 -06:00
|
|
|
case curview._rtti_classname
|
|
|
|
when :viewscreen_itemst
|
2012-10-10 10:01:57 -06:00
|
|
|
if ref = curview.entry_ref[curview.cursor_pos]
|
|
|
|
ref.item_tg if ref.kind_of?(GeneralRefItem)
|
|
|
|
else
|
|
|
|
# not a container
|
|
|
|
curview.item
|
|
|
|
end
|
2012-09-24 07:40:35 -06:00
|
|
|
when :viewscreen_storesst # z/stocks
|
|
|
|
if curview.in_group_mode == 0 and curview.in_right_list == 1
|
|
|
|
curview.items[curview.item_cursor]
|
|
|
|
end
|
2012-07-03 11:51:52 -06:00
|
|
|
else
|
|
|
|
case ui.main.mode
|
|
|
|
when :LookAround
|
|
|
|
k = ui_look_list.items[ui_look_cursor]
|
2012-07-04 09:24:46 -06:00
|
|
|
case k.type
|
|
|
|
when :Item
|
|
|
|
k.item
|
|
|
|
when :Building
|
2012-07-04 09:48:44 -06:00
|
|
|
# hilight a constructed bed/coffer
|
|
|
|
mats = k.building.contained_items.find_all { |i| i.use_mode == 2 }
|
|
|
|
mats[0].item if mats.length == 1
|
2012-07-04 09:24:46 -06:00
|
|
|
end
|
2012-07-03 11:51:52 -06:00
|
|
|
when :BuildingItems
|
|
|
|
bld = world.selected_building
|
|
|
|
bld.contained_items[ui_building_item_cursor].item if bld
|
2012-07-03 15:57:15 -06:00
|
|
|
when :ViewUnits
|
|
|
|
u = world.units.active[ui_selected_unit]
|
|
|
|
u.inventory[ui_look_cursor].item if u and u.pos.z == cursor.z and
|
2012-07-04 07:18:36 -06:00
|
|
|
ui_unit_view_mode.value == :Inventory and u.inventory[ui_look_cursor]
|
2012-09-17 13:16:01 -06:00
|
|
|
else
|
|
|
|
ui.follow_item_tg if ui.follow_item != -1
|
2012-07-03 11:51:52 -06:00
|
|
|
end
|
2012-06-24 09:30:26 -06:00
|
|
|
end
|
|
|
|
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
|
|
|
|
def item_isfree(i)
|
|
|
|
!i.flags.trader and
|
|
|
|
!i.flags.in_job and
|
2013-01-02 09:26:30 -07:00
|
|
|
(!i.flags.in_inventory or i.general_refs.grep(GeneralRefContainedInItemst).first) and
|
2012-10-01 03:14:00 -06:00
|
|
|
!i.flags.removed and
|
|
|
|
!i.flags.in_building and
|
|
|
|
!i.flags.owned and
|
|
|
|
!i.flags.forbid
|
|
|
|
end
|
|
|
|
|
2012-06-24 09:30:26 -06:00
|
|
|
end
|
|
|
|
end
|