Fix stockpile inventory not to include inventory items

Inventory items have stale position information. The coordinates can be
very old if item is owned and continuesly carried for long time. The fix
checks if item is carried. To avoid filtering carried items that are
assigned (containers) to the stockpile the assignment needs to be
checked.

Fixes #1288
develop
Pauli 2018-06-19 16:51:36 +03:00
parent 2c106fa7a5
commit bd0d36ec82
1 changed files with 13 additions and 1 deletions

@ -348,10 +348,22 @@ public:
bool inStockpile(df::item *i)
{
df::item *container = Items::getContainer(i);
// Check if the item is assigned to a stockpile
if (i->isAssignedToStockpile())
return i->isAssignedToThisStockpile(sp->id);
// If this is in a container check where the container item is
df::item* container = Items::getContainer(i);
if (container)
return inStockpile(container);
// Inventory items seems to have stale position information. We can
// assume that they are not in the stockpile.
if (i->flags.bits.in_inventory)
return false;
// Only containers are assigned to a stockpile. We need a coordinate
// check for free items.
if (i->pos.z != z) return false;
if (i->pos.x < x1 || i->pos.x >= x2 ||
i->pos.y < y1 || i->pos.y >= y2) return false;