Пример #1
0
        public static int TotalPrecalculatedItemsStack(this SlotGroup slotGroup, bool usePending = true)
        {
            if (slotGroup == null)
            {
                return(0);
            }

            int pending     = usePending ? PendingHaulJobsTracker.GetPendingStack(slotGroup) : 0;
            int inSlotGroup = HeldItemsCounter.GetTotalItemsStack(slotGroup);

            return(pending + inSlotGroup);
        }
Пример #2
0
        public static void AddNewJob(Pawn pawn, int stackSize, SlotGroup slotGroup, bool clearPreviousJob = true)
        {
            if (clearPreviousJob)
            {
                ClearJobForPawn(pawn);
            }

            if (slotGroup == null)
            {
                return;
            }

            //pendingHaulJobs.Remove(slotGroup);
            ListTuple list;

            if (pendingHaulJobs.ContainsKey(slotGroup))
            {
                list = pendingHaulJobs[slotGroup];
            }
            else
            {
                list = new ListTuple();
                pendingHaulJobs[slotGroup] = list;
            }

            list.Add(Tuple.Create(stackSize, pawn));

            if (precalculatedSlotGroupTotalPendingStack.ContainsKey(slotGroup))
            {
                precalculatedSlotGroupTotalPendingStack[slotGroup] += stackSize;
            }
            else
            {
                precalculatedSlotGroupTotalPendingStack[slotGroup] = stackSize;
            }

            if (!pawnsWithHaulingJobs.Contains(pawn))
            {
                pawnsWithHaulingJobs.Add(pawn);
            }
            else
            {
                Log.Warning($"Already found job for {pawn}, adding new one anyway.");
            }

            HeldItemsCounter.UpdateSlotGroup(slotGroup.parent.Map, slotGroup);
        }
        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();
        }