public static bool FarEnoughAndPossibleToStartJob(Pawn follower, Pawn followee, float radius)
        {
            bool result;

            if (radius <= 0f)
            {
                string text = "Checking follow job with radius <= 0. pawn=" + follower.ToStringSafe <Pawn>();
                if (follower.mindState != null && follower.mindState.duty != null)
                {
                    text = text + " duty=" + follower.mindState.duty.def;
                }
                Log.ErrorOnce(text, follower.thingIDNumber ^ 843254009, false);
                result = false;
            }
            else if (!follower.CanReach(followee, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn))
            {
                result = false;
            }
            else
            {
                float radius2 = radius * 1.2f;
                result = (!JobDriver_FollowClose.NearFollowee(follower, followee, radius2) || (!JobDriver_FollowClose.NearDestinationOrNotMoving(follower, followee, radius2) && follower.CanReach(followee.pather.LastPassableCellInPath, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)));
            }
            return(result);
        }
Exemple #2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(TargetIndex.A);
            yield return(new Toil
            {
                tickAction = delegate()
                {
                    Pawn followee = this.Followee;
                    float followRadius = this.job.followRadius;
                    if (!this.pawn.pather.Moving || this.pawn.IsHashIntervalTick(30))
                    {
                        bool flag = false;
                        if (this.CurrentlyWalkingToFollowee)
                        {
                            if (JobDriver_FollowClose.NearFollowee(this.pawn, followee, followRadius))
                            {
                                flag = true;
                            }
                        }
                        else
                        {
                            float radius = followRadius * 1.2f;
                            if (JobDriver_FollowClose.NearFollowee(this.pawn, followee, radius))
                            {
                                flag = true;
                            }
                            else
                            {
                                if (!this.pawn.CanReach(followee, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn))
                                {
                                    base.EndJobWith(JobCondition.Incompletable);
                                    return;
                                }
                                this.pawn.pather.StartPath(followee, PathEndMode.Touch);
                                this.locomotionUrgencySameAs = null;
                            }
                        }
                        if (flag)
                        {
                            if (JobDriver_FollowClose.NearDestinationOrNotMoving(this.pawn, followee, followRadius))
                            {
                                base.EndJobWith(JobCondition.Succeeded);
                                return;
                            }
                            IntVec3 lastPassableCellInPath = followee.pather.LastPassableCellInPath;
                            if (!this.pawn.pather.Moving || this.pawn.pather.Destination.HasThing || !this.pawn.pather.Destination.Cell.InHorDistOf(lastPassableCellInPath, followRadius))
                            {
                                IntVec3 intVec = CellFinder.RandomClosewalkCellNear(lastPassableCellInPath, base.Map, Mathf.FloorToInt(followRadius), null);
                                if (intVec == this.pawn.Position)
                                {
                                    base.EndJobWith(JobCondition.Succeeded);
                                    return;
                                }
                                if (!intVec.IsValid || !this.pawn.CanReach(intVec, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn))
                                {
                                    base.EndJobWith(JobCondition.Incompletable);
                                    return;
                                }
                                this.pawn.pather.StartPath(intVec, PathEndMode.OnCell);
                                this.locomotionUrgencySameAs = followee;
                            }
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Never
            });

            yield break;
        }
Exemple #3
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                {
                    this.FailOnDespawnedOrNull(TargetIndex.A);
                    Toil follow = new Toil();
                    follow.tickAction = delegate()
                    {
                        Pawn  followee     = base.Followee;
                        float followRadius = this.job.followRadius;
                        if (!this.pawn.pather.Moving || this.pawn.IsHashIntervalTick(30))
                        {
                            bool flag = false;
                            if (base.CurrentlyWalkingToFollowee)
                            {
                                if (JobDriver_FollowClose.NearFollowee(this.pawn, followee, followRadius))
                                {
                                    flag = true;
                                }
                            }
                            else
                            {
                                float radius = followRadius * 1.2f;
                                if (JobDriver_FollowClose.NearFollowee(this.pawn, followee, radius))
                                {
                                    flag = true;
                                }
                                else
                                {
                                    if (!this.pawn.CanReach(followee, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn))
                                    {
                                        base.EndJobWith(JobCondition.Incompletable);
                                        return;
                                    }
                                    this.pawn.pather.StartPath(followee, PathEndMode.Touch);
                                    this.locomotionUrgencySameAs = null;
                                }
                            }
                            if (flag)
                            {
                                if (JobDriver_FollowClose.NearDestinationOrNotMoving(this.pawn, followee, followRadius))
                                {
                                    base.EndJobWith(JobCondition.Succeeded);
                                    return;
                                }
                                IntVec3 lastPassableCellInPath = followee.pather.LastPassableCellInPath;
                                if (!this.pawn.pather.Moving || this.pawn.pather.Destination.HasThing || !this.pawn.pather.Destination.Cell.InHorDistOf(lastPassableCellInPath, followRadius))
                                {
                                    IntVec3 intVec = CellFinder.RandomClosewalkCellNear(lastPassableCellInPath, base.Map, Mathf.FloorToInt(followRadius), null);
                                    if (intVec == this.pawn.Position)
                                    {
                                        base.EndJobWith(JobCondition.Succeeded);
                                        return;
                                    }
                                    if (!intVec.IsValid || !this.pawn.CanReach(intVec, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn))
                                    {
                                        base.EndJobWith(JobCondition.Incompletable);
                                        return;
                                    }
                                    this.pawn.pather.StartPath(intVec, PathEndMode.OnCell);
                                    this.locomotionUrgencySameAs = followee;
                                }
                            }
                        }
                    };
                    follow.defaultCompleteMode = ToilCompleteMode.Never;
                    this.$current = follow;
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);
                }

                case 1u:
                    this.$PC = -1;
                    break;
                }
                return(false);
            }