protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(() => !base.Map.lordManager.lords.Contains(this.job.lord));
            Toil reserve = Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null).FailOnDespawnedOrNull(TargetIndex.A);

            yield return(reserve);

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

            yield return(this.DetermineNumToHaul());

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A, false, true, false));

            yield return(this.AddCarriedThingToTransferables());

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserve, TargetIndex.A, TargetIndex.None, true, (Thing x) => this.Transferable.things.Contains(x)));

            Toil findCarrier = this.FindCarrier();

            yield return(findCarrier);

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch).JumpIf(() => !JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(this.Carrier, this.pawn, true), findCarrier));

            yield return(Toils_General.Wait(25, TargetIndex.None).JumpIf(() => !JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(this.Carrier, this.pawn, true), findCarrier).WithProgressBarToilDelay(TargetIndex.B, false, -0.5f));

            yield return(this.PlaceTargetInCarrierInventory());

            yield break;
        }
        private Pawn FindBestCarrier(bool onlyAnimals)
        {
            Lord  lord = this.job.lord;
            Pawn  pawn = null;
            float num  = 0f;

            if (lord != null)
            {
                for (int i = 0; i < lord.ownedPawns.Count; i++)
                {
                    Pawn pawn2 = lord.ownedPawns[i];
                    if (pawn2 != this.pawn)
                    {
                        if (!onlyAnimals || pawn2.RaceProps.Animal)
                        {
                            if (JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(pawn2, this.pawn, false))
                            {
                                float carrierScore = this.GetCarrierScore(pawn2);
                                if (pawn == null || carrierScore > num)
                                {
                                    pawn = pawn2;
                                    num  = carrierScore;
                                }
                            }
                        }
                    }
                }
            }
            return(pawn);
        }
 private bool AnyReachableCarrierOrColonist(Pawn forPawn, Lord lord)
 {
     for (int i = 0; i < lord.ownedPawns.Count; i++)
     {
         if (JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(lord.ownedPawns[i], forPawn, false) && !lord.ownedPawns[i].IsForbidden(forPawn) && forPawn.CanReach(lord.ownedPawns[i], PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #4
0
        public static Pawn GetPawnToFollow(Pawn forPawn)
        {
            Pawn result;

            if (!forPawn.RaceProps.packAnimal || forPawn.inventory.UnloadEverything || MassUtility.IsOverEncumbered(forPawn))
            {
                result = null;
            }
            else
            {
                Lord lord = forPawn.GetLord();
                if (lord == null)
                {
                    result = null;
                }
                else
                {
                    List <Pawn> ownedPawns = lord.ownedPawns;
                    for (int i = 0; i < ownedPawns.Count; i++)
                    {
                        Pawn pawn = ownedPawns[i];
                        if (pawn != forPawn && CaravanUtility.IsOwner(pawn, forPawn.Faction) && pawn.CurJob != null && pawn.CurJob.def == JobDefOf.PrepareCaravan_GatherItems && forPawn.CanReach(pawn, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn))
                        {
                            JobDriver_PrepareCaravan_GatherItems jobDriver_PrepareCaravan_GatherItems = (JobDriver_PrepareCaravan_GatherItems)pawn.jobs.curDriver;
                            if (jobDriver_PrepareCaravan_GatherItems.Carrier == forPawn)
                            {
                                return(pawn);
                            }
                        }
                    }
                    Pawn pawn2 = null;
                    for (int j = 0; j < ownedPawns.Count; j++)
                    {
                        Pawn pawn3 = ownedPawns[j];
                        if (pawn3 != forPawn && CaravanUtility.IsOwner(pawn3, forPawn.Faction) && pawn3.CurJob != null && pawn3.CurJob.def == JobDefOf.PrepareCaravan_GatherItems && forPawn.CanReach(pawn3, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn) && (pawn2 == null || forPawn.Position.DistanceToSquared(pawn3.Position) < forPawn.Position.DistanceToSquared(pawn2.Position)))
                        {
                            pawn2 = pawn3;
                        }
                    }
                    result = pawn2;
                }
            }
            return(result);
        }
 private Toil FindCarrier()
 {
     return(new Toil
     {
         initAction = delegate()
         {
             Pawn pawn = this.FindBestCarrier(true);
             if (pawn == null)
             {
                 bool flag = this.pawn.GetLord() == this.job.lord;
                 if (flag && !MassUtility.IsOverEncumbered(this.pawn))
                 {
                     pawn = this.pawn;
                 }
                 else
                 {
                     pawn = this.FindBestCarrier(false);
                     if (pawn == null)
                     {
                         if (flag)
                         {
                             pawn = this.pawn;
                         }
                         else
                         {
                             IEnumerable <Pawn> source = from x in this.job.lord.ownedPawns
                                                         where JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(x, this.pawn, true)
                                                         select x;
                             if (!source.Any <Pawn>())
                             {
                                 base.EndJobWith(JobCondition.Incompletable);
                                 return;
                             }
                             pawn = source.RandomElement <Pawn>();
                         }
                     }
                 }
             }
             this.job.SetTarget(TargetIndex.B, pawn);
         }
     });
 }
Beispiel #6
0
        private Toil FindCarrier()
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn pawn = this.FindBestCarrier(true);
                if (pawn == null)
                {
                    bool flag = base.pawn.GetLord() == base.job.lord;
                    if (flag && !MassUtility.IsOverEncumbered(base.pawn))
                    {
                        pawn = base.pawn;
                    }
                    else
                    {
                        pawn = this.FindBestCarrier(false);
                        if (pawn == null)
                        {
                            if (!flag)
                            {
                                IEnumerable <Pawn> source = from x in base.job.lord.ownedPawns
                                                            where JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(x, base.pawn, true)
                                                            select x;
                                if (source.Any())
                                {
                                    pawn = source.RandomElement();
                                    goto IL_00aa;
                                }
                                base.EndJobWith(JobCondition.Incompletable);
                                return;
                            }
                            pawn = base.pawn;
                        }
                    }
                }
                goto IL_00aa;
IL_00aa:
                base.job.SetTarget(TargetIndex.B, pawn);
            };
            return(toil);
        }
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.FailOn(() => !base.Map.lordManager.lords.Contains(this.job.lord));
                    reserve       = Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null).FailOnDespawnedOrNull(TargetIndex.A);
                    this.$current = reserve;
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                    this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);

                case 2u:
                    this.$current = base.DetermineNumToHaul();
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);

                case 3u:
                    this.$current = Toils_Haul.StartCarryThing(TargetIndex.A, false, true, false);
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 4u:
                    this.$current = base.AddCarriedThingToTransferables();
                    if (!this.$disposing)
                    {
                        this.$PC = 5;
                    }
                    return(true);

                case 5u:
                    this.$current = Toils_Haul.CheckForGetOpportunityDuplicate(reserve, TargetIndex.A, TargetIndex.None, true, (Thing x) => base.Transferable.things.Contains(x));
                    if (!this.$disposing)
                    {
                        this.$PC = 6;
                    }
                    return(true);

                case 6u:
                    findCarrier   = base.FindCarrier();
                    this.$current = findCarrier;
                    if (!this.$disposing)
                    {
                        this.$PC = 7;
                    }
                    return(true);

                case 7u:
                    this.$current = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch).JumpIf(() => !JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(base.Carrier, this.pawn, true), findCarrier);
                    if (!this.$disposing)
                    {
                        this.$PC = 8;
                    }
                    return(true);

                case 8u:
                    this.$current = Toils_General.Wait(25, TargetIndex.None).JumpIf(() => !JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(base.Carrier, this.pawn, true), findCarrier).WithProgressBarToilDelay(TargetIndex.B, false, -0.5f);
                    if (!this.$disposing)
                    {
                        this.$PC = 9;
                    }
                    return(true);

                case 9u:
                    this.$current = base.PlaceTargetInCarrierInventory();
                    if (!this.$disposing)
                    {
                        this.$PC = 10;
                    }
                    return(true);

                case 10u:
                    this.$PC = -1;
                    break;
                }
                return(false);
            }
 private bool <FindCarrier> m__4(Pawn x)
 {
     return(JobDriver_PrepareCaravan_GatherItems.IsUsableCarrier(x, this.pawn, true));
 }