private void DefragStockpileStacks()
        {
            CompRTQuantumStockpile sourceStockpile = compStockpiles[qsSourceIndex];
            CompRTQuantumStockpile targetStockpile = compStockpiles[qsTargetIndex];

            foreach (IntVec3 targetCell in targetStockpile.parent.OccupiedRect().Cells)
            {
                if (sparklesEnabled)
                {
                    targetCell.ThrowSparkle();
                }
                foreach (IntVec3 sourceCell in sourceStockpile.parent.OccupiedRect().Cells)
                {
                    List <Thing> targetThings = targetCell.GetItemList();
                    for (int i = 0; i < targetThings.Count(); i++)
                    {
                        bool  itemWasMoved = false;
                        Thing targetThing  = targetThings[i];
                        if (targetThing != null && targetCell.AllowedToAccept(targetThing))
                        {
                            List <Thing> sourceThings = sourceCell.GetItemList();
                            for (int j = 0; j < sourceThings.Count(); j++)
                            {
                                Thing sourceThing = sourceThings[j];
                                if (targetThing.CanAbsorb(sourceThing) &&
                                    sourceThing.stackCount < sourceThing.def.stackLimit)
                                {
                                    int targetStackCount = targetThing.stackCount;
                                    if (targetThing.TryAbsorbStack(sourceThing, true))
                                    {
                                        sourceCell.ThrowDustPuff();
                                    }
                                    if (targetStackCount != targetThing.stackCount)
                                    {
                                        ForbidUtility.SetForbidden(targetThing, false, false);
                                        targetCell.DropSound(targetThing.def);
                                    }
                                    itemWasMoved = true;
                                    break;
                                }
                            }
                        }
                        if (itemWasMoved)
                        {
                            break;
                        }
                    }
                }
            }
        }
Example #2
0
 public void DefragStacks()
 {
     foreach (IntVec3 targetCell in GenAdj.CellsOccupiedBy(parent))
     {
         if (sparklesEnabled)
         {
             targetCell.ThrowSparkle(parent.Map);
         }
         foreach (IntVec3 sourceCell in GenAdj.CellsOccupiedBy(parent))
         {
             List <Thing> targetThings = targetCell.GetItemList(parent.Map, true);
             for (int i = 0; i < targetThings.Count(); i++)
             {
                 bool  itemWasMoved = false;
                 Thing targetThing  = targetThings[i];
                 if (targetThing != null)
                 {
                     if (targetThing.IsChunk())
                     {
                         if (compWarehouse != null)
                         {
                             compWarehouse.QueueThing(targetThing);
                         }
                         itemWasMoved = true;
                         break;
                     }
                     else
                     {
                         if (targetCell.AllowedToAccept(parent.Map, targetThing))
                         {
                             List <Thing> sourceThings = sourceCell.GetItemList(parent.Map);
                             for (int j = 0; j < sourceThings.Count(); j++)
                             {
                                 Thing sourceThing = sourceThings[j];
                                 if (targetThing.CanAbsorb(sourceThing) &&
                                     sourceThing.stackCount < sourceThing.def.stackLimit)
                                 {
                                     int targetStackCount = targetThing.stackCount;
                                     if (targetThing.TryAbsorbStack(sourceThing, true))
                                     {
                                         sourceCell.ThrowDustPuff(parent.Map);
                                     }
                                     if (targetStackCount != targetThing.stackCount)
                                     {
                                         ForbidUtility.SetForbidden(targetThing, false, false);
                                         targetCell.DropSound(parent.Map, targetThing.def);
                                     }
                                     itemWasMoved = true;
                                     break;
                                 }
                             }
                         }
                     }
                 }
                 if (itemWasMoved)
                 {
                     break;
                 }
             }
         }
     }
 }