コード例 #1
0
        public static bool Prefix(Pawn pawn, Thing thing, WorkGiver_HaulToInventory __instance, bool forced, ref bool __result)
        {
            #region PickUpAndHaul code
            //bulky gear (power armor + minigun) so don't bother.
            if (MassUtility.GearMass(pawn) / MassUtility.Capacity(pawn) >= 0.8f)
            {
                return(false);
            }

            if (!WorkGiver_HaulToInventory.GoodThingToHaul(thing, pawn) || !HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, thing, forced))
            {
                return(false);
            }

            StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);
            bool            foundCell       = StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true);
            #endregion

            if (!foundCell)
            {
                __result = false;
            }
            else
            {
                SlotGroup slotGroup = pawn.Map.haulDestinationManager.SlotGroupAt(storeCell);
                __result = !(slotGroup != null && Limits.HasLimit(slotGroup.Settings) && Limits.GetLimit(slotGroup.Settings) >= slotGroup.TotalPrecalculatedItemsStack());
            }

            return(false);
        }
コード例 #2
0
 public static void RemoveUnusedSlotGroups(Map map, List <SlotGroup> activeSlotGroups)
 {
     if (heldItems.ContainsKey(map))
     {
         var dk = heldItems[map];
         dk.RemoveAll(x => !activeSlotGroups.Contains(x.Key) || !Limits.HasLimit(x.Key.Settings));
     }
 }
コード例 #3
0
        public static void Prefix(Thing t, Pawn carrier, Map map, ref StoragePriority currentPriority, Faction faction)
        {
            var slotGroup0 = t.GetSlotGroup();

            if (slotGroup0 != null && Limits.HasLimit(slotGroup0.Settings))
            {
                int stockpileMax = Limits.GetLimit(slotGroup0.Settings);

                if (slotGroup0.TotalPrecalculatedItemsStack(false) > stockpileMax)
                {
                    currentPriority = StoragePriority.Unstored;
                }
            }
        }
コード例 #4
0
        public static void Postfix(ref List <IHaulDestination> __result)
        {
            int HeldItems(IHaulDestination x) => StoreUtility.GetSlotGroup(x.Position, x.Map).TotalPrecalculatedItemsStack();

            __result = __result.Where(x =>
            {
                if (!Limits.HasLimit(x.GetStoreSettings()))
                {
                    return(true);
                }

                int limit = Limits.GetLimit(x.GetStoreSettings());
                if (limit < 0)
                {
                    limit = int.MaxValue;
                }

                return(HeldItems(x) < limit);
            })
                       .OrderByDescending(x => x.GetStoreSettings().Priority)
                       .ThenByDescending(x =>
            {
                if (!Limits.HasLimit(x.GetStoreSettings()))
                {
                    return(0);
                }

                int limit = Limits.GetLimit(x.GetStoreSettings());
                if (limit < 0)
                {
                    limit = int.MaxValue;
                }

                return(limit - HeldItems(x));
            })

                       /*.ThenByDescending(x =>
                        * {
                        *      int limit = Limits.GetLimit(x.GetStoreSettings());
                        *      if (limit < 0)
                        *              return int.MaxValue;
                        *      else
                        *      {
                        *              int heldItems = HeldItems(x);
                        *              int spaceLeft = limit - heldItems;
                        *              return spaceLeft;
                        *      }
                        * })*/
                       .ToList();
        }
コード例 #5
0
        public static void Postfix(ref List <SlotGroup> __result)
        {
            __result = __result.Where(x =>
            {
                if (!Limits.HasLimit(x.Settings))
                {
                    return(true);
                }

                int limit = Limits.GetLimit(x.Settings);
                if (limit < 0)
                {
                    limit = int.MaxValue;
                }

                return(x.TotalPrecalculatedItemsStack() < limit);
            })
                       .OrderByDescending(x => x.Settings.Priority)
                       .ThenByDescending(x =>
            {
                if (!Limits.HasLimit(x.Settings))
                {
                    return(0);
                }

                int limit = Limits.GetLimit(x.Settings);
                if (limit < 0)
                {
                    limit = int.MaxValue;
                }

                return(limit - x.TotalPrecalculatedItemsStack());
            })

                       /*.ThenByDescending(x =>
                        * {
                        *      int limit = Limits.GetLimit(x.Settings);
                        *      if (limit < 0)
                        *              return int.MaxValue;
                        *      else
                        *      {
                        *              int heldItems = x.TotalItemsStack();
                        *              int spaceLeft = limit - heldItems;
                        *              return spaceLeft;
                        *      }
                        * })*/
                       .ToList();
        }
コード例 #6
0
        public static bool Prefix(Pawn pawn, Thing thing, ref Job __result)
        {
            StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);

            if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
            {
                SlotGroup slotGroup = StoreUtility.GetSlotGroup(storeCell, thing.Map);
                if (Limits.HasLimit(slotGroup.Settings))
                {
                    __result = HaulAIUtility.HaulToStorageJob(pawn, thing);
                    return(false);
                }
            }

            return(true);
        }
コード例 #7
0
        public static void Postfix(Map __instance)
        {
            var hdm = __instance.haulDestinationManager;

            if (hdm != null)
            {
                var slotGroups = (List <SlotGroup>) typeof(HaulDestinationManager).GetField("allGroupsInOrder", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(hdm);

                if (slotGroups != null)
                {
                    foreach (SlotGroup slotGroup in slotGroups.Where(x => x != null && Limits.HasLimit(x.Settings)))
                    {
                        HeldItemsCounter.UpdateSlotGroup(__instance, slotGroup);
                    }

                    HeldItemsCounter.RemoveUnusedSlotGroups(__instance, slotGroups);
                }
            }

            //HeldItemsCounter.TestOutput();
        }