コード例 #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 SetCountLimit(Pawn p, Thing t, ref Job __result, IntVec3 storeCell)
        {
            SlotGroup toSlotGroup = p.Map.haulDestinationManager.SlotGroupAt(storeCell);            // ?? __result.targetB.Thing?.GetSlotGroup();

            if (toSlotGroup == null)
            {
                //It is a haul destination without a SlotGroup, e.g. a grave
                return;
            }

            int toLimit = Limits.GetLimit(toSlotGroup.Settings);

            //int currentStack = __result.count < 0 ? t.stackCount : __result.count;
            int stackCount = __result.targetA.Thing.stackCount;

            if (stackCount < 1)
            {
                stackCount = int.MaxValue;
            }
            int currentStack = Math.Min(__result.count, stackCount);

            currentStack = Math.Min(currentStack, p.carryTracker.AvailableStackSpace(__result.targetA.Thing.def));


            bool hasSetFirstLimit = false;

            SlotGroup fromSlotGroup = StoreUtility.GetSlotGroup(t.Position, t.Map);

            if (fromSlotGroup != null)
            {
                int fromLimit = Limits.GetLimit(fromSlotGroup.Settings);

                if (fromLimit > 0 && StoreUtility.CurrentStoragePriorityOf(t) > StoreUtility.StoragePriorityAtFor(storeCell, t))
                {
                    //Hauling from limited high priority to low priority. Only haul the minimum necessary to go to exact limit.
                    int stockpileStack1 = fromSlotGroup.TotalPrecalculatedItemsStack();
                    __result.count   = stockpileStack1 - fromLimit;
                    hasSetFirstLimit = true;
                }
            }

            if (toLimit < 0)
            {
                return;
            }

            int stockpileStack = toSlotGroup.TotalPrecalculatedItemsStack();

            if (stockpileStack >= toLimit)
            {
                //Say no spot availible
                JobFailReason.Is(GetNoEmptyPlaceLowerTransString(), null);
                __result = null;
            }
            else if (stockpileStack + currentStack > toLimit)            //It will go over the limit
            {
                int newLimit = toLimit - stockpileStack;

                __result.count = hasSetFirstLimit ? Math.Min(newLimit, __result.count < 0 ? int.MaxValue : __result.count) : newLimit;
            }

            if (__result != null && __result.count <= 0)
            {
                JobFailReason.Is(GetNoEmptyPlaceLowerTransString(), null);
                __result = null;
            }
        }