Beispiel #1
0
        public override Job TryGiveJob(Pawn pawn)
        {
            Job result;

            if (!JoyUtility.EnjoyableOutsideNow(pawn, null))
            {
                result = null;
            }
            else if (PawnUtility.WillSoonHaveBasicNeed(pawn))
            {
                result = null;
            }
            else
            {
                Predicate <IntVec3> cellValidator = (IntVec3 x) => !PawnUtility.KnownDangerAt(x, pawn.Map, pawn) && !x.GetTerrain(pawn.Map).avoidWander&& x.Standable(pawn.Map) && !x.Roofed(pawn.Map);
                Predicate <Region>  validator     = delegate(Region x)
                {
                    IntVec3 intVec;
                    return(x.Room.PsychologicallyOutdoors && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec));
                };
                Region         reg;
                IntVec3        root;
                List <IntVec3> list;
                if (!CellFinder.TryFindClosestRegionWith(pawn.GetRegion(RegionType.Set_Passable), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), validator, 100, out reg, RegionType.Set_Passable))
                {
                    result = null;
                }
                else if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root))
                {
                    result = null;
                }
                else if (!WalkPathFinder.TryFindWalkPath(pawn, root, out list))
                {
                    result = null;
                }
                else
                {
                    Job job = new Job(this.def.jobDef, list[0]);
                    job.targetQueueA = new List <LocalTargetInfo>();
                    for (int i = 1; i < list.Count; i++)
                    {
                        job.targetQueueA.Add(list[i]);
                    }
                    job.locomotionUrgency = LocomotionUrgency.Walk;
                    result = job;
                }
            }
            return(result);
        }
Beispiel #2
0
        public override Job TryGiveJob(Pawn pawn)
        {
            if (!JoyUtility.EnjoyableOutsideNow(pawn, null))
            {
                return(null);
            }
            if (PawnUtility.WillSoonHaveBasicNeed(pawn))
            {
                return(null);
            }
            Predicate <IntVec3> cellValidator = (IntVec3 x) => !PawnUtility.KnownDangerAt(x, pawn);
            IntVec3             intVec        = default(IntVec3);
            Predicate <Region>  validator     = (Region x) => x.Room.PsychologicallyOutdoors && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec);
            Region reg = default(Region);

            if (!CellFinder.TryFindClosestRegionWith(pawn.GetRegion(RegionType.Set_Passable), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), validator, 100, out reg, RegionType.Set_Passable))
            {
                return(null);
            }
            IntVec3 root = default(IntVec3);

            if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root))
            {
                return(null);
            }
            List <IntVec3> list = default(List <IntVec3>);

            if (!WalkPathFinder.TryFindWalkPath(pawn, root, out list))
            {
                return(null);
            }
            Job job = new Job(base.def.jobDef, list[0]);

            job.targetQueueA = new List <LocalTargetInfo>();
            for (int i = 1; i < list.Count; i++)
            {
                job.targetQueueA.Add(list[i]);
            }
            job.locomotionUrgency = LocomotionUrgency.Walk;
            return(job);
        }
Beispiel #3
0
 public static bool TryFindGoodAdjacentSpotToTouch(Pawn toucher, Thing touchee, out IntVec3 result)
 {
     foreach (IntVec3 item in GenAdj.CellsAdjacent8Way(touchee).InRandomOrder())
     {
         if (item.Standable(toucher.Map) && !PawnUtility.KnownDangerAt(item, toucher.Map, toucher))
         {
             result = item;
             return(true);
         }
     }
     foreach (IntVec3 item2 in GenAdj.CellsAdjacent8Way(touchee).InRandomOrder())
     {
         if (item2.Walkable(toucher.Map))
         {
             result = item2;
             return(true);
         }
     }
     result = touchee.Position;
     return(false);
 }
Beispiel #4
0
 public static bool TryFindGoodAdjacentSpotToTouch(Pawn toucher, Thing touchee, out IntVec3 result)
 {
     foreach (IntVec3 current in GenAdj.CellsAdjacent8Way(touchee).InRandomOrder(null))
     {
         if (current.Standable(toucher.Map) && !PawnUtility.KnownDangerAt(current, toucher.Map, toucher))
         {
             result = current;
             bool result2 = true;
             return(result2);
         }
     }
     foreach (IntVec3 current2 in GenAdj.CellsAdjacent8Way(touchee).InRandomOrder(null))
     {
         if (current2.Walkable(toucher.Map))
         {
             result = current2;
             bool result2 = true;
             return(result2);
         }
     }
     result = touchee.Position;
     return(false);
 }
Beispiel #5
0
        public override Job TryGiveJob(Pawn pawn)
        {
            if (!JoyUtility.EnjoyableOutsideNow(pawn))
            {
                return(null);
            }
            if (PawnUtility.WillSoonHaveBasicNeed(pawn))
            {
                return(null);
            }
            Predicate <IntVec3> cellValidator = (IntVec3 x) => !PawnUtility.KnownDangerAt(x, pawn.Map, pawn) && !x.GetTerrain(pawn.Map).avoidWander&& x.Standable(pawn.Map) && !x.Roofed(pawn.Map);
            IntVec3             result4;
            Predicate <Region>  validator = (Region x) => x.Room.PsychologicallyOutdoors && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out result4);

            if (!CellFinder.TryFindClosestRegionWith(pawn.GetRegion(), TraverseParms.For(pawn), validator, 100, out Region result))
            {
                return(null);
            }
            if (!result.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out IntVec3 result2))
            {
                return(null);
            }
            if (!WalkPathFinder.TryFindWalkPath(pawn, result2, out List <IntVec3> result3))
            {
                return(null);
            }
            Job job = JobMaker.MakeJob(def.jobDef, result3[0]);

            job.targetQueueA = new List <LocalTargetInfo>();
            for (int i = 1; i < result3.Count; i++)
            {
                job.targetQueueA.Add(result3[i]);
            }
            job.locomotionUrgency = LocomotionUrgency.Walk;
            return(job);
        }
Beispiel #6
0
        public static bool TryFindWalkPath(Pawn pawn, IntVec3 root, out List <IntVec3> result)
        {
            List <IntVec3> list = new List <IntVec3>();

            list.Add(root);
            IntVec3 intVec = root;

            for (int i = 0; i < 8; i++)
            {
                IntVec3 intVec2 = IntVec3.Invalid;
                float   num     = -1f;
                for (int j = WalkPathFinder.StartRadialIndex; j > WalkPathFinder.EndRadialIndex; j -= WalkPathFinder.RadialIndexStride)
                {
                    IntVec3 intVec3 = intVec + GenRadial.RadialPattern[j];
                    if (intVec3.InBounds(pawn.Map) && intVec3.Standable(pawn.Map) && !intVec3.IsForbidden(pawn) && !intVec3.GetTerrain(pawn.Map).avoidWander&& GenSight.LineOfSight(intVec, intVec3, pawn.Map, false, null, 0, 0) && !intVec3.Roofed(pawn.Map) && !PawnUtility.KnownDangerAt(intVec3, pawn.Map, pawn))
                    {
                        float num2 = 10000f;
                        for (int k = 0; k < list.Count; k++)
                        {
                            num2 += (float)(list[k] - intVec3).LengthManhattan;
                        }
                        float num3 = (float)(intVec3 - root).LengthManhattan;
                        if (num3 > 40f)
                        {
                            num2 *= Mathf.InverseLerp(70f, 40f, num3);
                        }
                        if (list.Count >= 2)
                        {
                            float num4      = (list[list.Count - 1] - list[list.Count - 2]).AngleFlat;
                            float angleFlat = (intVec3 - intVec).AngleFlat;
                            float num5;
                            if (angleFlat > num4)
                            {
                                num5 = angleFlat - num4;
                            }
                            else
                            {
                                num4 -= 360f;
                                num5  = angleFlat - num4;
                            }
                            if (num5 > 110f)
                            {
                                num2 *= 0.01f;
                            }
                        }
                        if (list.Count >= 4 && (intVec - root).LengthManhattan < (intVec3 - root).LengthManhattan)
                        {
                            num2 *= 1E-05f;
                        }
                        if (num2 > num)
                        {
                            intVec2 = intVec3;
                            num     = num2;
                        }
                    }
                }
                if (num < 0f)
                {
                    result = null;
                    return(false);
                }
                list.Add(intVec2);
                intVec = intVec2;
            }
            list.Add(root);
            result = list;
            return(true);
        }
Beispiel #7
0
        private static bool CanWanderToCell(IntVec3 c, Pawn pawn, IntVec3 root, Func <Pawn, IntVec3, IntVec3, bool> validator, int tryIndex, Danger maxDanger)
        {
            bool flag = false;

            if (!c.Walkable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0f, "walk");
                }
                return(false);
            }
            if (c.IsForbidden(pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "forbid");
                }
                return(false);
            }
            if (tryIndex < 10 && !c.Standable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "stand");
                }
                return(false);
            }
            if (!pawn.CanReach(c, PathEndMode.OnCell, maxDanger))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.6f, "reach");
                }
                return(false);
            }
            if (PawnUtility.KnownDangerAt(c, pawn.Map, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.1f, "trap");
                }
                return(false);
            }
            if (tryIndex < 10)
            {
                if (c.GetTerrain(pawn.Map).avoidWander)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.39f, "terr");
                    }
                    return(false);
                }
                if (pawn.Map.pathGrid.PerceivedPathCostAt(c) > 20)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "pcost");
                    }
                    return(false);
                }
                if ((int)c.GetDangerFor(pawn, pawn.Map) > 1)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "danger");
                    }
                    return(false);
                }
            }
            else if (tryIndex < 15 && c.GetDangerFor(pawn, pawn.Map) == Danger.Deadly)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.4f, "deadly");
                }
                return(false);
            }
            if (!pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.75f, "resvd");
                }
                return(false);
            }
            if (validator != null && !validator(pawn, c, root))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.15f, "valid");
                }
                return(false);
            }
            if (c.GetDoor(pawn.Map) != null)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.32f, "door");
                }
                return(false);
            }
            if (c.ContainsStaticFire(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.9f, "fire");
                }
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        public static bool TryFindWalkPath(Pawn pawn, IntVec3 root, out List <IntVec3> result)
        {
            List <IntVec3> list = new List <IntVec3>();

            list.Add(root);
            IntVec3 intVec = root;

            for (int i = 0; i < 8; i++)
            {
                IntVec3 intVec2 = IntVec3.Invalid;
                float   num     = -1f;
                for (int num2 = WalkPathFinder.StartRadialIndex; num2 > WalkPathFinder.EndRadialIndex; num2 -= WalkPathFinder.RadialIndexStride)
                {
                    IntVec3 intVec3 = intVec + GenRadial.RadialPattern[num2];
                    if (intVec3.InBounds(pawn.Map) && intVec3.Standable(pawn.Map) && !intVec3.IsForbidden(pawn) && GenSight.LineOfSight(intVec, intVec3, pawn.Map, false, null, 0, 0) && !intVec3.Roofed(pawn.Map) && !PawnUtility.KnownDangerAt(intVec3, pawn))
                    {
                        float num3 = 10000f;
                        for (int j = 0; j < list.Count; j++)
                        {
                            num3 += (float)(list[j] - intVec3).LengthManhattan;
                        }
                        float num4 = (float)(intVec3 - root).LengthManhattan;
                        if (num4 > 40.0)
                        {
                            num3 *= Mathf.InverseLerp(70f, 40f, num4);
                        }
                        if (list.Count >= 2)
                        {
                            float angleFlat  = (list[list.Count - 1] - list[list.Count - 2]).AngleFlat;
                            float angleFlat2 = (intVec3 - intVec).AngleFlat;
                            float num5;
                            if (angleFlat2 > angleFlat)
                            {
                                num5 = angleFlat2 - angleFlat;
                            }
                            else
                            {
                                angleFlat = (float)(angleFlat - 360.0);
                                num5      = angleFlat2 - angleFlat;
                            }
                            if (num5 > 110.0)
                            {
                                num3 = (float)(num3 * 0.0099999997764825821);
                            }
                        }
                        if (list.Count >= 4 && (intVec - root).LengthManhattan < (intVec3 - root).LengthManhattan)
                        {
                            num3 = (float)(num3 * 9.9999997473787516E-06);
                        }
                        if (num3 > num)
                        {
                            intVec2 = intVec3;
                            num     = num3;
                        }
                    }
                }
                if (num < 0.0)
                {
                    result = null;
                    return(false);
                }
                list.Add(intVec2);
                intVec = intVec2;
            }
            list.Add(root);
            result = list;
            return(true);
        }
Beispiel #9
0
 internal bool <> m__0(IntVec3 x)
 {
     return(!PawnUtility.KnownDangerAt(x, this.pawn.Map, this.pawn) && !x.GetTerrain(this.pawn.Map).avoidWander&& x.Standable(this.pawn.Map) && !x.Roofed(this.pawn.Map));
 }