public static TransferableOneWay TransferableMatchingDesperate(Thing thing, List <TransferableOneWay> transferables)
 {
     if (thing != null && transferables != null)
     {
         for (int i = 0; i < transferables.Count; i++)
         {
             TransferableOneWay transferableOneWay = transferables[i];
             if (transferableOneWay.HasAnyThing && transferableOneWay.things.Contains(thing))
             {
                 return(transferableOneWay);
             }
         }
         for (int j = 0; j < transferables.Count; j++)
         {
             TransferableOneWay transferableOneWay2 = transferables[j];
             if (transferableOneWay2.HasAnyThing && TransferableUtility.TransferAsOne(thing, transferableOneWay2.AnyThing))
             {
                 return(transferableOneWay2);
             }
         }
         for (int k = 0; k < transferables.Count; k++)
         {
             TransferableOneWay transferableOneWay3 = transferables[k];
             if (transferableOneWay3.HasAnyThing && transferableOneWay3.ThingDef == thing.def)
             {
                 return(transferableOneWay3);
             }
         }
         return(null);
     }
     return(null);
 }
예제 #2
0
        private static int TransferableCountHauledByOthers(Pawn pawn, TransferableOneWay transferable, Lord lord)
        {
            if (!transferable.HasAnyThing)
            {
                Log.Warning("Can't determine transferable count hauled by others because transferable has 0 things.", false);
                return(0);
            }
            List <Pawn> allPawnsSpawned = lord.Map.mapPawns.AllPawnsSpawned;
            int         num             = 0;

            for (int i = 0; i < allPawnsSpawned.Count; i++)
            {
                Pawn pawn2 = allPawnsSpawned[i];
                if (pawn2 != pawn)
                {
                    if (pawn2.CurJob != null && pawn2.CurJob.def == JobDefOf.PrepareCaravan_GatherItems && pawn2.CurJob.lord == lord)
                    {
                        Thing toHaul = ((JobDriver_PrepareCaravan_GatherItems)pawn2.jobs.curDriver).ToHaul;
                        if (transferable.things.Contains(toHaul) || TransferableUtility.TransferAsOne(transferable.AnyThing, toHaul, TransferAsOneMode.PodsOrCaravanPacking))
                        {
                            num += toHaul.stackCount;
                        }
                    }
                }
            }
            return(num);
        }
        public static Tradeable TradeableMatching(Thing thing, List <Tradeable> tradeables)
        {
            Tradeable result;

            if (thing == null || tradeables == null)
            {
                result = null;
            }
            else
            {
                for (int i = 0; i < tradeables.Count; i++)
                {
                    Tradeable tradeable = tradeables[i];
                    if (tradeable.HasAnyThing)
                    {
                        TransferAsOneMode mode = (!tradeable.TraderWillTrade) ? TransferAsOneMode.InactiveTradeable : TransferAsOneMode.Normal;
                        if (TransferableUtility.TransferAsOne(thing, tradeable.AnyThing, mode))
                        {
                            return(tradeable);
                        }
                    }
                }
                result = null;
            }
            return(result);
        }
        public static T TransferableMatching <T>(Thing thing, List <T> transferables, TransferAsOneMode mode) where T : Transferable
        {
            T result;

            if (thing == null || transferables == null)
            {
                result = (T)((object)null);
            }
            else
            {
                for (int i = 0; i < transferables.Count; i++)
                {
                    T result2 = transferables[i];
                    if (result2.HasAnyThing)
                    {
                        if (TransferableUtility.TransferAsOne(thing, result2.AnyThing, mode))
                        {
                            return(result2);
                        }
                    }
                }
                result = (T)((object)null);
            }
            return(result);
        }
예제 #5
0
 public static Thing ThingFromStockToMergeWith(ITrader trader, Thing thing)
 {
     if (thing is Pawn)
     {
         return(null);
     }
     foreach (Thing good in trader.Goods)
     {
         if (TransferableUtility.TransferAsOne(good, thing, TransferAsOneMode.Normal) && good.CanStackWith(thing) && good.def.stackLimit != 1)
         {
             return(good);
         }
     }
     return(null);
 }
예제 #6
0
 public static Thing ThingFromStockToMergeWith(ITrader trader, Thing thing)
 {
     if (thing is Pawn)
     {
         return(null);
     }
     foreach (Thing current in trader.Goods)
     {
         if (TransferableUtility.TransferAsOne(current, thing))
         {
             return(current);
         }
     }
     return(null);
 }
 public static T TransferableMatching <T>(Thing thing, List <T> transferables) where T : Transferable
 {
     if (thing != null && transferables != null)
     {
         for (int i = 0; i < transferables.Count; i++)
         {
             T result = transferables[i];
             if (result.HasAnyThing && TransferableUtility.TransferAsOne(thing, result.AnyThing))
             {
                 return(result);
             }
         }
         return((T)null);
     }
     return((T)null);
 }
        public static TransferableOneWay TransferableMatchingDesperate(Thing thing, List <TransferableOneWay> transferables, TransferAsOneMode mode)
        {
            TransferableOneWay result;

            if (thing == null || transferables == null)
            {
                result = null;
            }
            else
            {
                for (int i = 0; i < transferables.Count; i++)
                {
                    TransferableOneWay transferableOneWay = transferables[i];
                    if (transferableOneWay.HasAnyThing)
                    {
                        if (transferableOneWay.things.Contains(thing))
                        {
                            return(transferableOneWay);
                        }
                    }
                }
                for (int j = 0; j < transferables.Count; j++)
                {
                    TransferableOneWay transferableOneWay2 = transferables[j];
                    if (transferableOneWay2.HasAnyThing)
                    {
                        if (TransferableUtility.TransferAsOne(thing, transferableOneWay2.AnyThing, mode))
                        {
                            return(transferableOneWay2);
                        }
                    }
                }
                for (int k = 0; k < transferables.Count; k++)
                {
                    TransferableOneWay transferableOneWay3 = transferables[k];
                    if (transferableOneWay3.HasAnyThing)
                    {
                        if (transferableOneWay3.ThingDef == thing.def)
                        {
                            return(transferableOneWay3);
                        }
                    }
                }
                result = null;
            }
            return(result);
        }
예제 #9
0
 public static T TransferableMatching <T>(Thing thing, List <T> transferables) where T : Transferable
 {
     if (thing == null || transferables == null)
     {
         return((T)((object)null));
     }
     for (int i = 0; i < transferables.Count; i++)
     {
         T result = transferables[i];
         if (result.HasAnyThing)
         {
             if (TransferableUtility.TransferAsOne(thing, result.AnyThing))
             {
                 return(result);
             }
         }
     }
     return((T)((object)null));
 }
예제 #10
0
        public static Thing ThingFromStockToMergeWith(ITrader trader, Thing thing)
        {
            Thing result;

            if (thing is Pawn)
            {
                result = null;
            }
            else
            {
                foreach (Thing thing2 in trader.Goods)
                {
                    if (TransferableUtility.TransferAsOne(thing2, thing, TransferAsOneMode.Normal) && thing2.CanStackWith(thing) && thing2.def.stackLimit != 1)
                    {
                        return(thing2);
                    }
                }
                result = null;
            }
            return(result);
        }
예제 #11
0
 private void AssignTransferablesToRandomTransporters()
 {
     tmpLeftToLoadCopy.Clear();
     for (int j = 0; j < transporters.Count; j++)
     {
         tmpLeftToLoadCopy.Add((transporters[j].leftToLoad != null) ? transporters[j].leftToLoad.ToList() : new List <TransferableOneWay>());
         if (transporters[j].leftToLoad != null)
         {
             transporters[j].leftToLoad.Clear();
         }
     }
     tmpLeftCountToTransfer.Clear();
     for (int k = 0; k < transferables.Count; k++)
     {
         tmpLeftCountToTransfer.Add(transferables[k], transferables[k].CountToTransfer);
     }
     if (LoadingInProgressOrReadyToLaunch)
     {
         int i;
         for (i = 0; i < transferables.Count; i++)
         {
             if (!transferables[i].HasAnyThing || tmpLeftCountToTransfer[transferables[i]] <= 0)
             {
                 continue;
             }
             for (int l = 0; l < tmpLeftToLoadCopy.Count; l++)
             {
                 TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatching(transferables[i].AnyThing, tmpLeftToLoadCopy[l], TransferAsOneMode.PodsOrCaravanPacking);
                 if (transferableOneWay != null)
                 {
                     int num = Mathf.Min(tmpLeftCountToTransfer[transferables[i]], transferableOneWay.CountToTransfer);
                     if (num > 0)
                     {
                         transporters[l].AddToTheToLoadList(transferables[i], num);
                         tmpLeftCountToTransfer[transferables[i]] -= num;
                     }
                 }
                 Thing thing = transporters[l].innerContainer.FirstOrDefault((Thing x) => TransferableUtility.TransferAsOne(transferables[i].AnyThing, x, TransferAsOneMode.PodsOrCaravanPacking));
                 if (thing != null)
                 {
                     int num2 = Mathf.Min(tmpLeftCountToTransfer[transferables[i]], thing.stackCount);
                     if (num2 > 0)
                     {
                         transporters[l].AddToTheToLoadList(transferables[i], num2);
                         tmpLeftCountToTransfer[transferables[i]] -= num2;
                     }
                 }
             }
         }
     }
     tmpLeftToLoadCopy.Clear();
     if (transferables.Any())
     {
         TransferableOneWay transferableOneWay2 = transferables.MaxBy((TransferableOneWay x) => tmpLeftCountToTransfer[x]);
         int num3 = 0;
         for (int m = 0; m < transferables.Count; m++)
         {
             if (transferables[m] != transferableOneWay2 && tmpLeftCountToTransfer[transferables[m]] > 0)
             {
                 transporters[num3 % transporters.Count].AddToTheToLoadList(transferables[m], tmpLeftCountToTransfer[transferables[m]]);
                 num3++;
             }
         }
         if (num3 < transporters.Count)
         {
             int num4 = tmpLeftCountToTransfer[transferableOneWay2];
             int num5 = num4 / (transporters.Count - num3);
             for (int n = num3; n < transporters.Count; n++)
             {
                 int num6 = (n == transporters.Count - 1) ? num4 : num5;
                 if (num6 > 0)
                 {
                     transporters[n].AddToTheToLoadList(transferableOneWay2, num6);
                 }
                 num4 -= num6;
             }
         }
         else
         {
             transporters[num3 % transporters.Count].AddToTheToLoadList(transferableOneWay2, tmpLeftCountToTransfer[transferableOneWay2]);
         }
     }
     tmpLeftCountToTransfer.Clear();
     for (int num7 = 0; num7 < transporters.Count; num7++)
     {
         for (int num8 = 0; num8 < transporters[num7].innerContainer.Count; num8++)
         {
             Thing thing2 = transporters[num7].innerContainer[num8];
             int   num9   = transporters[num7].SubtractFromToLoadList(thing2, thing2.stackCount, sendMessageOnFinished: false);
             if (num9 < thing2.stackCount)
             {
                 transporters[num7].innerContainer.TryDrop(thing2, ThingPlaceMode.Near, thing2.stackCount - num9, out Thing _);
             }
         }
     }
 }