示例#1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            // Verify processor validity
            this.FailOnDespawnedNullOrForbidden(ProcessorInd);
            this.FailOn(() => !Processor.Finished);

            // Go to the processor
            yield return(Toils_Goto.GotoThing(ProcessorInd, PathEndMode.ClosestTouch));

            // Add delay for collecting items from the processor
            yield return(Toils_General.Wait(Static.GenericWaitDuration)
                         .FailOnDestroyedNullOrForbidden(ProcessorInd)
                         .WithProgressBarToilDelay(ProcessorInd));

            // Collect items
            yield return(new Toil()
            {
                initAction = () =>
                {
                    Thing item = Processor.TakeOutProduct();
                    GenPlace.TryPlaceThing(item, pawn.Position, Map, ThingPlaceMode.Near);
                    StoragePriority storagePriority = StoreUtility.StoragePriorityAtFor(item.Position, item);

                    // Try to find a suitable storage spot for the item
                    if (StoreUtility.TryFindBestBetterStoreCellFor(item, pawn, Map, storagePriority, pawn.Faction, out IntVec3 c))
                    {
                        job.SetTarget(TargetIndex.C, c);
                        job.SetTarget(TargetIndex.B, item);
                        job.count = item.stackCount;
                    }
                    // If there is no spot to store the item, end this job
                    else
                    {
                        EndJobWith(JobCondition.Incompletable);
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(200).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOn(() => !Vat.Fermented).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing thing = Vat.TakeOutThing();
                    GenPlace.TryPlaceThing(thing, pawn.Position, Map, ThingPlaceMode.Near, null);
                    StoragePriority currentPriority = StoreUtility.StoragePriorityAtFor(thing.Position, thing);;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, Map, currentPriority, pawn.Faction, out IntVec3 c, true))
                    {
                        job.SetTarget(TargetIndex.C, c);
                        job.SetTarget(TargetIndex.B, thing);
                        job.count = thing.stackCount;
                    }
示例#3
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;
            }
        }