示例#1
0
        private Toil Manage(TargetIndex targetIndex)
        {
            var station = CurJob.GetTarget(targetIndex).Thing as Building_ManagerStation;

            if (station == null)
            {
                Log.Error("Target of manager job was not a manager station. This should never happen.");
                return(null);
            }

            var comp = station.GetComp <Comp_ManagerStation>();

            if (comp == null)
            {
                Log.Error("Target of manager job does not have manager station comp. This should never happen.");
                return(null);
            }

            var toil = new Toil();

            toil.defaultDuration =
                (int)(comp.Props.Speed * (1 - pawn.GetStatValue(StatDef.Named("ManagingSpeed")) + .5));
#if DEBUG_WORKGIVER
            Log.Message("Pawn stat: " + pawn.GetStatValue(StatDef.Named("ManagingSpeed")) + " (+0.5) Station speed: " + comp.Props.Speed + "Total time: " + toil.defaultDuration);
#endif
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.tickAction          =
                delegate
            { toil.actor.skills.GetSkill(DefDatabase <SkillDef> .GetNamed("Managing")).Learn(0.11f); };
            var finishers = new List <Action>();
            finishers.Add(delegate
                          { Manager.For(pawn.Map).TryDoWork(); });
            toil.finishActions = finishers;
            return(toil);
        }
示例#2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Apparel_Backpack backpack = CurJob.GetTarget(BackpackInd).Thing as Apparel_Backpack;

            // no free slots
            this.FailOn(() => backpack.slotsComp.slots.Count >= backpack.MaxItem);

            // reserve resources
            yield return(Toils_Reserve.ReserveQueue(HaulableInd));

            // extract next target thing from targetQueue
            Toil toilExtractNextTarget = Toils_JobTransforms.ExtractNextTargetFromQueue(HaulableInd);

            yield return(toilExtractNextTarget);

            Toil toilGoToThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch)
                                 .FailOnDespawnedOrNull(HaulableInd);

            yield return(toilGoToThing);

            Toil pickUpThingIntoSlot = new Toil
            {
                initAction = () =>
                {
                    if (!backpack.slotsComp.slots.TryAdd(CurJob.targetA.Thing))
                    {
                        EndJobWith(JobCondition.Incompletable);
                    }
                }
            };

            yield return(pickUpThingIntoSlot);

            yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, toilExtractNextTarget));
        }
示例#3
0
        private Toil FindNextWanderSpot(int waitTicks)
        {
            return(new Toil
            {
                initAction = delegate
                {
                    pawn.pather.StopDead();

                    var rect = CellRect.CenteredOn(pawn.Position, 4);
                    var dest = rect.Cells
                               .Where(c => c != pawn.Position && pawn.CanReach(c, PathEndMode.OnCell, Danger.None))
                               .RandomElement();
                    if (dest.IsValid)
                    {
                        CurJob.SetTarget(TargetIndex.A, dest);
                    }
                    else
                    {
                        EndJobWith(JobCondition.Succeeded);
                    }
                },
                socialMode = RandomSocialMode.SuperActive,
                defaultCompleteMode = ToilCompleteMode.Delay,
                defaultDuration = waitTicks
            });
        }
示例#4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(MountableInd);
            if (TargetThingB.IsForbidden(pawn.Faction))
            {
                this.FailOnForbidden(MountableInd);
            }

            yield return(Toils_Reserve.Reserve(MountableInd, CurJob.def.joyMaxParticipants));

            Toil toil = Toils_Goto.GotoCell(DrivePathInd, PathEndMode.OnCell);

            toil.tickAction = delegate
            {
                if (Find.TickManager.TicksGame > startTick + CurJob.def.joyDuration)
                {
                    EndJobWith(JobCondition.Succeeded);
                    return;
                }
                JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, 1f);
            };
            ThingWithComps cart = CurJob.GetTarget(MountableInd).Thing as ThingWithComps;

            //JumpIf already mounted
            yield return(Toils_Jump.JumpIf(toil, () =>
            {
                if (cart.TryGetComp <CompMountable>().Driver == pawn)
                {
                    return true;
                }
                return false;
            }));

            //Mount on Target
            yield return(Toils_Goto.GotoThing(MountableInd, PathEndMode.ClosestTouch)
                         .FailOnDestroyedOrNull(MountableInd));

            yield return(Toils_Cart.MountOn(MountableInd));



            yield return(toil);

            yield return(new Toil
            {
                initAction = delegate
                {
                    if (CurJob.targetQueueA.Count > 0)
                    {
                        TargetInfo targetA = CurJob.targetQueueA[0];
                        CurJob.targetQueueA.RemoveAt(0);
                        CurJob.targetA = targetA;
                        JumpToToil(toil);
                        return;
                    }
                }
            });

            yield break;
        }
        internal List <JAMS.CurJob> GetMonitorData()
        {
            List <JAMS.CurJob> curJobList = new List <JAMS.CurJob>();


            var newList = CurJob.Find(m_Owner.JobName, m_Owner.StateType, m_Owner.Server);

            foreach (JAMS.CurJob h in newList)
            {
                curJobList.Add(h);
            }

            return(curJobList);
        }
示例#6
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            ///
            //Set fail conditions
            ///

            this.FailOnDestroyed(HaulableInd);
            this.FailOnDestroyed(CarrierInd);
            //Note we only fail on forbidden if the target doesn't start that way
            //This helps haul-aside jobs on forbidden items
            if (!TargetThingA.IsForbidden(pawn.Faction))
            {
                this.FailOnForbidden(HaulableInd);
            }



            ///
            //Define Toil
            ///
            Toil toilGoto = null;

            toilGoto = Toils_Goto.GotoThing(HaulableInd, PathMode.ClosestTouch)
                       .FailOn(() =>
            {
                Vehicle_Cargo vc = CurJob.GetTarget(CarrierInd).Thing as Vehicle_Cargo;

                if (!vc.storage.CanAcceptAnyOf(CurJob.GetTarget(HaulableInd).Thing))
                {
                    return(true);
                }
                return(false);
            });



            ///
            //Toils Start
            ///

            //Reserve thing to be stored and storage cell
            yield return(Toils_Reserve.Reserve(HaulableInd));

            //Collect Target
            yield return(toilGoto);

            yield return(ToolsForHaul.Toils_Collect.CollectThing(HaulableInd, CarrierInd));
        }
 private Toil FindTrashSpot()
 {
     // Doubting that this needs to be done this way.
     // Only use case is if this step needs to ever be jumped back to.
     return(new Toil
     {
         initAction = delegate
         {
             var target = Info.GetNextTrashCellFor(this.ThingToHaul, this.pawn);
             if (!target.IsValid)
             {
                 base.EndJobWith(JobCondition.Errored);
             }
             CurJob.SetTarget(TargetIndex.B, target);
         }
     });
 }
        public override string GetReport()
        {
            Thing hauledThing = TargetThingB;

            string repString;

            if (hauledThing != null)
            {
                repString = "ReportPutInInventory".Translate(hauledThing.LabelCap, CurJob.GetTarget(BackpackInd).Thing.LabelCap);
            }
            else
            {
                repString = "ReportPutSomethingInInventory".Translate(CurJob.GetTarget(BackpackInd).Thing.LabelCap);
            }

            return(repString);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //yield return Toils_Reserve.Reserve(TargetIndex.A);
            yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.Touch));

            yield return(new Toil {
                tickAction = delegate {
                    pawn.Drawer.rotator.FaceCell(CurJob.GetTarget(TargetIndex.B).Cell);
                    pawn.GainComfortFromCellIfPossible();
                    if (pawn.IsHashIntervalTick(100))
                    {
                        pawn.jobs.CheckForJobOverride();
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Never
            });
        }
示例#10
0
        private Toil FindTicketTaker()
        {
            return(new Toil
            {
                initAction = delegate
                {
                    var ticketTaker = Info.GetBestEntertainer(false);

                    if (ticketTaker == null)
                    {
                        Log.Error("[Carnivale] Found no ticket taker to give silver to.");
                        base.EndJobWith(JobCondition.Errored);
                    }

                    DutyUtility.HitchToSpot(ticketTaker, ticketTaker.Position);

                    CurJob.SetTarget(TargetIndex.B, ticketTaker);
                }
            });
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Apparel_Backpack backpack = CurJob.GetTarget(BackpackInd).Thing as Apparel_Backpack;
            Thing            lastItem = ToolsForHaulUtility.TryGetBackpackLastItem(pawn);

            ///
            //Set fail conditions
            ///

            ///
            //Define Toil
            ///

            Toil endOfJob = new Toil();

            endOfJob.initAction = () => { EndJobWith(JobCondition.Succeeded); };
            Toil checkStoreCellEmpty = Toils_Jump.JumpIf(endOfJob, () => CurJob.GetTargetQueue(StoreCellInd).NullOrEmpty());
            Toil checkHaulableEmpty  = Toils_Jump.JumpIf(checkStoreCellEmpty, () => CurJob.GetTargetQueue(HaulableInd).NullOrEmpty());

            ///
            //Toils Start
            ///

            //Reserve thing to be stored and storage cell
            yield return(Toils_Reserve.ReserveQueue(HaulableInd));

            yield return(Toils_Reserve.ReserveQueue(StoreCellInd));

            //JumpIf checkStoreCellEmpty
            yield return(checkHaulableEmpty);

            //Collect TargetQueue
            {
                Toil extractA = Toils_Collect.Extract(HaulableInd);
                yield return(extractA);

                Toil gotoThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch)
                                 .FailOnDestroyed(HaulableInd);
                yield return(gotoThing);

                yield return(ToolsForHaul.Toils_Collect.CollectInInventory(HaulableInd));

                yield return(Toils_Collect.CheckDuplicates(gotoThing, BackpackInd, HaulableInd));

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractA));
            }

            //JumpIf toilEnd
            yield return(checkStoreCellEmpty);

            //Drop TargetQueue
            {
                Toil extractB = Toils_Collect.Extract(StoreCellInd);
                yield return(extractB);

                yield return(Toils_Goto.GotoCell(StoreCellInd, PathEndMode.ClosestTouch)
                             .FailOnBurningImmobile(StoreCellInd));

                yield return(ToolsForHaul.Toils_Collect.DropTheCarriedInCell(StoreCellInd, ThingPlaceMode.Direct, lastItem));

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(StoreCellInd, extractB));
            }

            yield return(endOfJob);
        }
示例#12
0
        internal List <JAMS.CurJob> GetMonitorData()
        {
            ICollection <int>  folderDescendantIDList = null;
            CurJob             masterEntry;
            List <JAMS.CurJob> curJobList = new List <JAMS.CurJob>();

            //
            // If a Folder was specified get its descendant IDs
            //
            if (!String.IsNullOrWhiteSpace(m_Owner.SystemName) && m_Owner.SystemName != @"\" && m_Owner.SystemName != "*")
            {
                Folder queryFolder;

                //
                // Get descendant FolderId's
                //
                JAMS.Folder.Load(out queryFolder, m_Owner.SystemName, m_Owner.Server);
                folderDescendantIDList = queryFolder.GetFolderDescendants();
            }

            //
            // Get the collection of CurJobs matching Name and State
            //
            var newList = CurJob.Find(m_Owner.JobName, m_Owner.StateType, m_Owner.Server);

            //
            // Add matching CurJobs to the result list
            //
            bool matches;
            int  checkFolderID = 0;

            foreach (JAMS.CurJob h in newList)
            {
                matches = true;

                //
                // If a folder was specified check if this CurJob should be included
                //
                if (folderDescendantIDList != null)
                {
                    // By default we check the CurJob's parent Folder
                    checkFolderID = h.ParentFolderID;

                    //
                    // If this is a subjob we need to check the master entry's Folder instead
                    //
                    if (h.MasterRON != 0 && h.MasterRON != h.RON)
                    {
                        // Try to get the master entry
                        masterEntry = newList.FirstOrDefault(c => c.RON == h.MasterRON);

                        if (masterEntry != null)
                        {
                            checkFolderID = masterEntry.ParentFolderID;
                        }
                    }

                    //
                    // The parent FolderID must be a descendant to match
                    //
                    if (!folderDescendantIDList.Contains(checkFolderID))
                    {
                        matches = false;
                    }
                }

                //
                // Add the entry if it's a match
                //
                if (matches)
                {
                    curJobList.Add(h);
                }
            }

            return(curJobList);
        }
示例#13
0
        private Toil Collect()
        {
            Toil toil = new Toil();

            toil.initAction = delegate {
                // Increment the record for how many cells this pawn has mined since this counts as mining
                pawn.records.Increment(RecordDefOf.CellsMined);

                // Start with None to act as a fallback. Rubble will be returned with this parameter
                ResourceRequest req = ResourceRequest.None;

                // Use the mineModeToggle to determine the request
                req = (Quarry.mineModeToggle ? ResourceRequest.Resources : ResourceRequest.Blocks);

                MoteType mote = MoteType.None;

                // Get the resource from the quarry
                Thing haulableResult = Quarry.GiveResources(req, out mote);
                // Place the resource near the pawn
                GenPlace.TryPlaceThing(haulableResult, pawn.Position, Map, ThingPlaceMode.Near);

                // If the resource had a mote, throw it
                if (mote == MoteType.LargeVein)
                {
                    MoteMaker.ThrowText(haulableResult.DrawPos, Map, Static.TextMote_LargeVein, Color.green, 3f);
                }
                else if (mote == MoteType.Failure)
                {
                    MoteMaker.ThrowText(haulableResult.DrawPos, Map, Static.TextMote_MiningFailed, Color.red, 3f);
                }

                // Prevent the colonists from trying to haul rubble, which just makes them visit the platform
                if (haulableResult.def == ThingDefOf.RockRubble)
                {
                    EndJobWith(JobCondition.Succeeded);
                }

                // If this is a chunk or slag, mark it as haulable if allowed to
                if (haulableResult.def.designateHaulable && Quarry.autoHaul)
                {
                    Map.designationManager.AddDesignation(new Designation(haulableResult, DesignationDefOf.Haul));
                }

                // Setup IntVec for assigning
                IntVec3 c;

                // Try to find a suitable storage spot for the resource, removing it from the quarry
                // If there are no platforms, hauling will be done by haulers
                if (Quarry.autoHaul && Quarry.TryFindBestStoreCellFor(haulableResult, pawn, Map, pawn.Faction, out c))
                {
                    CurJob.SetTarget(TargetIndex.B, haulableResult);
                    CurJob.count = haulableResult.stackCount;
                    CurJob.SetTarget(TargetIndex.C, c);
                }
                // If there is no spot to store the resource, end this job
                else
                {
                    EndJobWith(JobCondition.Succeeded);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;

            return(toil);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            ///
            //Set fail conditions
            ///

            this.FailOnDestroyedOrNull(MountableInd);
            this.FailOnDowned(DriverInd);
            //Note we only fail on forbidden if the target doesn't start that way
            //This helps haul-aside jobs on forbidden items
            if (!TargetThingA.IsForbidden(pawn.Faction))
            {
                this.FailOnForbidden(MountableInd);
            }



            ///
            //Define Toil
            ///

            Toil toilMakeStandby = new Toil();

            toilMakeStandby.initAction = () =>
            {
                Pawn driver = CurJob.GetTarget(DriverInd).Thing as Pawn;
                driver.jobs.StartJob(new Job(HaulJobDefOf.StandBy, driver.Position, 2400 + (int)((pawn.Position - driver.Position).LengthHorizontal * 120)), JobCondition.InterruptForced);
            };

            Toil toilGoto = null;

            toilGoto = Toils_Goto.GotoThing(MountableInd, PathEndMode.ClosestTouch)
                       .FailOn(() =>
            {
                //Note we don't fail on losing hauling designation
                //Because that's a special case anyway

                //While hauling to cell storage, ensure storage dest is still valid
                Pawn actor = toilGoto.actor;
                Job curJob = actor.jobs.curJob;
                if (curJob.haulMode == HaulMode.ToCellStorage)
                {
                    Thing haulThing = curJob.GetTarget(MountableInd).Thing;

                    IntVec3 destLoc = actor.jobs.curJob.GetTarget(TargetIndex.B).Cell;
                    if (!destLoc.IsValidStorageFor(haulThing))
                    {
                        return(true);
                    }
                }

                return(false);
            });

            Toil toilMountOn = new Toil();

            toilMountOn.initAction = () =>
            {
                Pawn driver = TargetB.Thing as Pawn;
                if (driver != null && TargetThingA.TryGetComp <CompMountable>() != null)
                {
                    TargetThingA.TryGetComp <CompMountable>().MountOn(driver);
                }
                else
                {
                    Log.Error(GetActor().LabelCap + ": Try make mount without target B Driver");
                    EndJobWith(JobCondition.Errored);
                }
            };

            Toil toilEnd = new Toil();

            toilEnd.initAction = () =>
            {
                Vehicle_Cart cart = CurJob.GetTarget(MountableInd).Thing as Vehicle_Cart;

                //Vehicle_Saddle saddle = CurJob.GetTarget(MountableInd).Thing as Vehicle_Saddle;
                if (cart == null)// && saddle == null)
                {
                    Log.Error(GetActor().LabelCap + ": MakeMount get TargetA not cart or saddle.");
                    EndJobWith(JobCondition.Errored);
                    return;
                }
                if (cart != null && cart.mountableComp.IsMounted && cart.mountableComp.Driver.CurJob.def == HaulJobDefOf.StandBy)
                {
                    cart.mountableComp.Driver.jobs.curDriver.EndJobWith(JobCondition.Succeeded);
                }
                EndJobWith(JobCondition.Succeeded);
            };

            ///
            //Toils Start
            ///

            //Reserve thing to be stored and storage cell
            yield return(Toils_Reserve.Reserve(MountableInd));

            yield return(Toils_Reserve.Reserve(DriverInd));

            yield return(toilMakeStandby);

            yield return(toilGoto);

            yield return(Toils_Haul.StartCarryThing(MountableInd));

            yield return(Toils_Haul.CarryHauledThingToCell(DriverInd));

            yield return(toilMountOn);

            yield return(toilEnd);
        }
示例#15
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Vehicle_Cart cart   = CurJob.GetTarget(CartInd).Thing as Vehicle_Cart;
            Job          jobNew = new Job();

            ///
            //Set fail conditions
            ///

            this.FailOnDestroyed(CartInd);
            this.FailOn(() => !cart.mountableComp.IsMounted);
            //Note we only fail on forbidden if the target doesn't start that way
            //This helps haul-aside jobs on forbidden items
            if (!TargetThingA.IsForbidden(pawn.Faction))
            {
                this.FailOnForbidden(CartInd);
            }

            ///
            //Define Toil
            ///

            Toil releaseAnimalCart   = Toils_Cart.ReleaseAnimalCart(CartInd);
            Toil checkCartEmpty      = Toils_Jump.JumpIf(releaseAnimalCart, () => cart.storage.Count <= 0);
            Toil checkStoreCellEmpty = Toils_Jump.JumpIf(releaseAnimalCart, () => CurJob.GetTargetQueue(StoreCellInd).NullOrEmpty());
            Toil checkHaulableEmpty  = Toils_Jump.JumpIf(checkStoreCellEmpty, () => CurJob.GetTargetQueue(HaulableInd).NullOrEmpty());

            ///
            //Toils Start
            ///

            //Reserve thing to be stored and storage cell
            yield return(Toils_Reserve.Reserve(CartInd));

            yield return(Toils_Reserve.ReserveQueue(HaulableInd));

            yield return(Toils_Reserve.ReserveQueue(StoreCellInd));

            yield return(Toils_Goto.GotoThing(CartInd, PathEndMode.Touch)
                         .FailOn(() => cart.Destroyed || !cart.TryGetComp <CompMountable>().IsMounted));

            //JumpIf toilCheckStoreCellEmpty
            yield return(checkHaulableEmpty);

            //Collect TargetQueue
            {
                Toil extractA = Toils_Collect.Extract(HaulableInd);
                yield return(extractA);

                Toil callAnimalCartForCollect = Toils_Cart.CallAnimalCart(CartInd, HaulableInd)
                                                .FailOnDestroyed(HaulableInd);
                yield return(callAnimalCartForCollect);

                yield return(Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch)
                             .FailOnDestroyed(HaulableInd));

                yield return(Toils_Cart.WaitAnimalCart(CartInd, HaulableInd));

                yield return(Toils_Collect.CollectInCarrier(CartInd, HaulableInd));

                yield return(Toils_Collect.CheckDuplicates(callAnimalCartForCollect, CartInd, HaulableInd));

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractA));
            }

            //JumpIf releaseAnimalCart
            yield return(checkStoreCellEmpty);

            //Drop TargetQueue
            {
                yield return(checkCartEmpty);

                Toil extractB = Toils_Collect.Extract(StoreCellInd);
                yield return(extractB);

                Toil callAnimalCartForDrop = Toils_Cart.CallAnimalCart(CartInd, StoreCellInd);
                yield return(callAnimalCartForDrop);

                yield return(Toils_Goto.GotoCell(StoreCellInd, PathEndMode.ClosestTouch)
                             .FailOnBurningImmobile(StoreCellInd));

                yield return(Toils_Cart.WaitAnimalCart(CartInd, HaulableInd));

                yield return(Toils_Collect.DropTheCarriedInCell(StoreCellInd, ThingPlaceMode.Direct, CartInd));

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(StoreCellInd, checkCartEmpty));

                yield return(Toils_Collect.CheckNeedStorageCell(callAnimalCartForDrop, CartInd, StoreCellInd));
            }

            yield return(releaseAnimalCart);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Apparel_Backpack backpack = CurJob.GetTarget(BackpackInd).Thing as Apparel_Backpack;

            ///
            //Set fail conditions
            ///
            // no free slots
            this.FailOn(() => backpack.slotsComp.slots.Count >= backpack.MaxItem);

            //// hauling stuff not allowed
            //foreach (ThingCategoryDef category in CurJob.targetA.Thing.def.thingCategories)
            //{
            //    this.FailOn(() => !backpack.slotsComp.Properties.allowedThingCategoryDefs.Contains(category));
            //    this.FailOn(() => backpack.slotsComp.Properties.forbiddenSubThingCategoryDefs.Contains(category));
            //}


            ///
            //Define Toil
            ///

            Toil endOfJob = new Toil();

            endOfJob.initAction = () => { EndJobWith(JobCondition.Succeeded); };
            Toil checkStoreCellEmpty = Toils_Jump.JumpIf(endOfJob, () => CurJob.GetTargetQueue(StoreCellInd).NullOrEmpty());
            Toil checkHaulableEmpty  = Toils_Jump.JumpIf(checkStoreCellEmpty, () => CurJob.GetTargetQueue(HaulableInd).NullOrEmpty());

            Toil checkBackpackEmpty = Toils_Jump.JumpIf(endOfJob, () => backpack.slotsComp.slots.Count <= 0);

            ///
            //Toils Start
            ///

            //Reserve thing to be stored and storage cell
            yield return(Toils_Reserve.ReserveQueue(HaulableInd));

            yield return(Toils_Reserve.ReserveQueue(StoreCellInd));

            //JumpIf checkStoreCellEmpty
            yield return(checkHaulableEmpty);

            //Collect TargetQueue
            {
                Toil extractA = Toils_Collect.Extract(HaulableInd);
                yield return(extractA);

                Toil gotoThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch)
                                 .FailOnDestroyedOrNull(HaulableInd);
                yield return(gotoThing);

                //   yield return Toils_Collect.CollectInBackpack(HaulableInd, backpack);

                Toil pickUpThingIntoSlot = new Toil
                {
                    initAction = () =>
                    {
                        if (!backpack.slotsComp.slots.TryAdd(CurJob.targetA.Thing))
                        {
                            EndJobWith(JobCondition.Incompletable);
                        }
                    }
                };
                yield return(pickUpThingIntoSlot);

                yield return(Toils_Collect.CheckDuplicates(gotoThing, BackpackInd, HaulableInd));

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractA));
            }

            //JumpIf toilEnd
            yield return(checkStoreCellEmpty);

            //Drop TargetQueue
            {
                yield return(checkBackpackEmpty);

                Toil extractB = Toils_Collect.Extract(StoreCellInd);
                yield return(extractB);

                Toil gotoCell = Toils_Goto.GotoCell(StoreCellInd, PathEndMode.ClosestTouch);
                yield return(gotoCell);

                yield return(Toils_Collect.DropTheCarriedFromBackpackInCell(StoreCellInd, ThingPlaceMode.Direct, backpack));

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(StoreCellInd, checkBackpackEmpty));

                yield return(Toils_Collect.CheckNeedStorageCell(gotoCell, BackpackInd, StoreCellInd));
            }

            yield return(endOfJob);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Apparel_Backpack backpack = CurJob.GetTarget(BackpackInd).Thing as Apparel_Backpack;

            ///
            //Set fail conditions
            ///


            //Backpack is full.
            this.FailOn(() => { return((pawn.inventory.container.Count < backpack.MaxItem) ? false : true); });

            ///
            //Define Toil
            ///

            Toil extractB = new Toil();

            extractB.initAction = () =>
            {
                if (!CurJob.targetQueueB.NullOrEmpty())
                {
                    CurJob.targetB = CurJob.targetQueueB.First();
                    CurJob.targetQueueB.RemoveAt(0);
                    this.FailOnDestroyedOrNull(HaulableInd);
                }
                else
                {
                    this.EndJobWith(JobCondition.Succeeded);
                }
            };

            Toil toilGoToThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch)
                                 .FailOnDestroyedOrNull(HaulableInd);

            ///
            //Toils Start
            ///

            //Reserve thing to be stored and storage cell
            yield return(Toils_Reserve.Reserve(BackpackInd));

            yield return(Toils_Reserve.Reserve(HaulableInd));

            yield return(Toils_Reserve.ReserveQueue(HaulableInd));


            yield return(Toils_Jump.JumpIf(toilGoToThing, () => { return (CurJob.targetB.HasThing) ? true : false; }));

            //Collect TargetQueue
            {
                //Extract an haulable into TargetA
                yield return(extractB);

                yield return(toilGoToThing);

                //CollectIntoCarrier
                Toil toilPutInInventory = new Toil();
                toilPutInInventory.initAction = () =>
                {
                    if (pawn.inventory.container.Count < backpack.MaxItem &&
                        backpack.wearer.inventory.container.TotalStackCount < backpack.MaxStack)
                    {
                        if (CurJob.targetB.Thing.TryGetComp <CompForbiddable>() != null && CurJob.targetB.Thing.TryGetComp <CompForbiddable>().Forbidden == true)
                        {
                            CurJob.targetB.Thing.TryGetComp <CompForbiddable>().Forbidden = false;
                        }
                        if (pawn.inventory.container.TryAdd(CurJob.targetB.Thing, CurJob.maxNumToCarry))
                        {
                            CurJob.targetB.Thing.holder       = pawn.inventory.GetContainer();
                            CurJob.targetB.Thing.holder.owner = pawn.inventory;
                            backpack.numOfSavedItems++;
                        }
                    }
                    else
                    {
                        this.EndJobWith(JobCondition.Incompletable);
                    }
                };
                yield return(toilPutInInventory);

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractB));
            }
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Vehicle_Cart cart = CurJob.GetTarget(CartInd).Thing as Vehicle_Cart;

            ///
            //Set fail conditions
            ///

            this.FailOnDestroyedOrNull(CartInd);
            //Note we only fail on forbidden if the target doesn't start that way
            //This helps haul-aside jobs on forbidden items
            if (!TargetThingA.IsForbidden(pawn.Faction))
            {
                this.FailOnForbidden(CartInd);
            }


            ///
            //Define Toil
            ///

            Toil findStoreCellForCart = Toils_Cart.FindStoreCellForCart(CartInd);
            Toil checkCartEmpty       = Toils_Jump.JumpIf(findStoreCellForCart, () => cart.storage.Count <= 0);
            Toil checkStoreCellEmpty  = Toils_Jump.JumpIf(findStoreCellForCart, () => CurJob.GetTargetQueue(StoreCellInd).NullOrEmpty());
            Toil checkHaulableEmpty   = Toils_Jump.JumpIf(checkStoreCellEmpty, () => CurJob.GetTargetQueue(HaulableInd).NullOrEmpty());

            ///
            //Toils Start
            ///

            //Reserve thing to be stored and storage cell
            yield return(Toils_Reserve.Reserve(CartInd));

            yield return(Toils_Reserve.ReserveQueue(HaulableInd));

            yield return(Toils_Reserve.ReserveQueue(StoreCellInd));

            //JumpIf already mounted
            yield return(Toils_Jump.JumpIf(checkHaulableEmpty, () => { return (cart.GetComp <CompMountable>().Driver == pawn) ? true : false; }));

            //Mount on Target
            yield return(Toils_Goto.GotoThing(CartInd, PathEndMode.ClosestTouch)
                         .FailOnDestroyedOrNull(CartInd));

            yield return(Toils_Cart.MountOn(CartInd));

            //JumpIf checkStoreCellEmpty
            yield return(checkHaulableEmpty);

            //Collect TargetQueue
            {
                Toil extractA = Toils_Collect.Extract(HaulableInd);
                yield return(extractA);

                Toil gotoThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch)
                                 .FailOnDestroyedOrNull(HaulableInd);
                yield return(gotoThing);

                yield return(Toils_Collect.CollectInCarrier(CartInd, HaulableInd));

                yield return(Toils_Collect.CheckDuplicates(gotoThing, CartInd, HaulableInd));

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractA));
            }

            //JumpIf findStoreCellForCart
            yield return(checkStoreCellEmpty);

            //Drop TargetQueue
            {
                yield return(checkCartEmpty);

                Toil extractB = Toils_Collect.Extract(StoreCellInd);
                yield return(extractB);

                Toil gotoCell = Toils_Goto.GotoCell(StoreCellInd, PathEndMode.ClosestTouch);
                yield return(gotoCell);

                yield return(Toils_Collect.DropTheCarriedInCell(StoreCellInd, ThingPlaceMode.Direct, CartInd));

                yield return(Toils_Jump.JumpIfHaveTargetInQueue(StoreCellInd, checkCartEmpty));

                yield return(Toils_Collect.CheckNeedStorageCell(gotoCell, CartInd, StoreCellInd));
            }

            yield return(findStoreCellForCart);

            yield return(Toils_Goto.GotoCell(StoreCellInd, PathEndMode.OnCell));

            yield return(Toils_Cart.DismountAt(CartInd, StoreCellInd));
        }