Browse Source

fix an inventory stacking bug

Kolja Strohm 3 years ago
parent
commit
9ed02e7d9e
3 changed files with 6 additions and 5 deletions
  1. 0 1
      FactoryCraft/Area.cpp
  2. 5 3
      FactoryCraft/Inventory.cpp
  3. 1 1
      FactoryCraft/ItemSlot.cpp

+ 0 - 1
FactoryCraft/Area.cpp

@@ -17,7 +17,6 @@ Direction getOppositeDirection( Direction dir )
     case BOTTOM:
         return TOP;
     default:
-        assert( false );
         return NO_DIRECTION;
     }
 }

+ 5 - 3
FactoryCraft/Inventory.cpp

@@ -115,6 +115,7 @@ void InventoryInteraction::transaction( Inventory* zSource, Inventory* zTarget,
                                 if( !sourceSlot->zStack() )
                                     toDelete.add( index, 0 );
                                 targetSlot->addItems( stack, dir );
+                                zSource->updateCache( sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
                                 zSource->afterPullStack( sourceSlot, sourceView, targetSlot->zStack()->zItem(), number );
                                 zTarget->afterPushStack( targetSlot, targetView, targetSlot->zStack()->zItem(), number );
                                 if( stack->getSize() )
@@ -150,7 +151,7 @@ void InventoryInteraction::transaction( Inventory* zSource, Inventory* zTarget,
                         {
                             targetSlot->addItems( stack, dir );
                             zSource->updateCache( sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
-                            zTarget->updateCache( targetSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
+                            zTarget->updateCache( targetSlot, -1 );
                             zSource->afterPullStack( sourceSlot, sourceView, targetSlot->zStack()->zItem(), number );
                             zTarget->afterPushStack( targetSlot, targetView, targetSlot->zStack()->zItem(), number );
                             if( stack->getSize() )
@@ -371,6 +372,7 @@ void Inventory::localTransaction( Array< ItemSlot* >* zSourceSlots, Array< ItemS
                                     if( !sourceSlot->zStack() )
                                         toDelete.add( index, 0 );
                                     targetSlot->addItems( stack, NO_DIRECTION );
+                                    updateCache( sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
                                     if( stack->getSize() )
                                     {
                                         cs.unlock();
@@ -409,7 +411,7 @@ void Inventory::localTransaction( Array< ItemSlot* >* zSourceSlots, Array< ItemS
                         {
                             targetSlot->addItems( stack, NO_DIRECTION );
                             updateCache( sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
-                            updateCache( targetSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
+                            updateCache( targetSlot, -1 );
                             if( stack->getSize() )
                             {
                                 cs.unlock();
@@ -473,7 +475,7 @@ void Inventory::addItems( ItemStack* items, Direction dir )
                         if( stack )
                         {
                             targetSlot->addItems( stack, dir );
-                            updateCache( targetSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
+                            updateCache( targetSlot, -1 );
                             afterPushStack( targetSlot, dir, targetSlot->zStack()->zItem(), number );
                             if( stack->getSize() )
                                 throw stack;

+ 1 - 1
FactoryCraft/ItemSlot.cpp

@@ -91,7 +91,7 @@ int ItemSlot::getPushPriority() const
 
 bool ItemSlot::isFull() const
 {
-    return items ? items->getSize() < items->getMaxSize() : 0;
+    return items ? items->getSize() >= items->getMaxSize() : maxSize > 0;
 }
 
 int ItemSlot::getFreeSpace() const