|
21 | 21 | --- @return boolean |
22 | 22 | function fastReachable(item,wgroups) |
23 | 23 | local x, y, z = dfhack.items.getPosition(item) |
24 | | - if x then -- item has a valid position |
25 | | - local igroup = dfhack.maps.getWalkableGroup(xyz2pos(x, y, z)) |
26 | | - return not not wgroups[igroup] |
27 | | - else |
| 24 | + if not x then |
| 25 | + return false -- item has no valid position (e.g., inside inventories) |
| 26 | + end |
| 27 | + local igroup = dfhack.maps.getWalkableGroup(xyz2pos(x, y, z)) |
| 28 | + if wgroups[igroup] then |
| 29 | + return true |
| 30 | + end |
| 31 | + -- items on unwalkable building tiles can still be retrieved by standing |
| 32 | + -- next to the building, unless they are installed parts (use_mode PERM) |
| 33 | + local bld = dfhack.items.getHolderBuilding(item) or |
| 34 | + dfhack.buildings.findAtTile(xyz2pos(x, y, z)) |
| 35 | + if not bld or bld:getType() == df.building_type.Construction then |
28 | 36 | return false |
29 | 37 | end |
| 38 | + if df.building_actual:is_instance(bld) then |
| 39 | + for _, ci in ipairs(bld.contained_items) do |
| 40 | + if ci.item == item then |
| 41 | + if ci.use_mode == df.building_item_role_type.PERM then |
| 42 | + return false |
| 43 | + end |
| 44 | + break |
| 45 | + end |
| 46 | + end |
| 47 | + end |
| 48 | + for bx = bld.x1 - 1, bld.x2 + 1 do |
| 49 | + for by = bld.y1 - 1, bld.y2 + 1 do |
| 50 | + if wgroups[dfhack.maps.getWalkableGroup(xyz2pos(bx, by, bld.z))] then |
| 51 | + return true |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + return false |
30 | 56 | end |
31 | 57 |
|
32 | 58 | --- @return table<integer,boolean> |
|
0 commit comments