Exemplo n.º 1
0
        private bool TrySetNewPath()
        {
            PawnPath pawnPath = this.GenerateNewPath();

            if (!pawnPath.Found)
            {
                this.PatherFailed();
                return(false);
            }
            if (this.curPath != null)
            {
                this.curPath.ReleaseToPool();
            }
            this.curPath = pawnPath;
            int num = 0;

            while (num < 20 && num < this.curPath.NodesLeftCount)
            {
                IntVec3 c = this.curPath.Peek(num);
                if (PawnUtility.ShouldCollideWithPawns(this.pawn) && PawnUtility.AnyPawnBlockingPathAt(c, this.pawn, false, false, false))
                {
                    this.foundPathWhichCollidesWithPawns = Find.TickManager.TicksGame;
                }
                if (PawnUtility.KnownDangerAt(c, this.pawn.Map, this.pawn))
                {
                    this.foundPathWithDanger = Find.TickManager.TicksGame;
                }
                if (this.foundPathWhichCollidesWithPawns == Find.TickManager.TicksGame && this.foundPathWithDanger == Find.TickManager.TicksGame)
                {
                    break;
                }
                num++;
            }
            return(true);
        }
Exemplo n.º 2
0
        public static bool FindCellForWalking(Pawn pawn, Pawn animal, out IntVec3 walkingCell)
        {
            // extracted from JoyGiver_GoForWalk.TryGiveJob

            var resultCell = new IntVec3();

            bool CellGoodForWalking(IntVec3 cell)
            {
                var map = animal.MapHeld;

                return(
                    !PawnUtility.KnownDangerAt(cell, map, pawn) &&
                    !cell.GetTerrain(map).avoidWander&&
                    cell.Standable(map)
                    );
            }

            bool RegionGoodForWalking(Region region) => (
                !region.IsForbiddenEntirely(animal) &&
                !region.IsForbiddenEntirely(pawn) &&
                region.TryFindRandomCellInRegionUnforbidden(animal, CellGoodForWalking, out resultCell) &&
                !resultCell.IsForbidden(pawn)
                );

            var resultGood = CellFinder.TryFindClosestRegionWith(animal.GetRegion(), TraverseParms.For(animal), RegionGoodForWalking, 100, out _);

            walkingCell = resultCell;
            return(resultGood);
        }
        // Token: 0x06000568 RID: 1384 RVA: 0x00035040 File Offset: 0x00033440
        public override Job TryGiveJob(Pawn pawn)
        {
            float HowMuchSnowIsThere = 0;

            if (pawn.Map.weatherManager.curWeather.snowRate > 0.0f)
            {
                HowMuchSnowIsThere = pawn.Map.weatherManager.curWeather.snowRate;
            }
            if (HowMuchSnowIsThere < 0.1f)
            {
                return(null);
            }
            if (!JoyUtility.EnjoyableOutsideNow(pawn, null))
            {
                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);
            Predicate <Region>  validator     = delegate(Region x)
            {
                IntVec3 intVec;
                return(x.Room.PsychologicallyOutdoors && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec));
            };
            Region reg;

            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;

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

            if (!WalkPathFinder.TryFindWalkPath(pawn, root, out list))
            {
                return(null);
            }
            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;
            return(job);
        }
Exemplo n.º 4
0
        public static bool TrySetNewPath(ref Pawn_PathFollower instance, ref IntVec3 lastPathedTargetPosition, LocalTargetInfo destination, Pawn pawn, Map map, ref PathEndMode peMode)
        {
            PawnPath pawnPath = GenerateNewPath(ref lastPathedTargetPosition, destination, ref pawn, map, peMode);

            if (!pawnPath.Found)
            {
                PatherFailedHelper(ref instance, pawn);
                return(false);
            }
            if (!(instance.curPath is null))
            {
                instance.curPath.ReleaseToPool();
            }
            instance.curPath = pawnPath;
            int num = 0;
            int foundPathWhichCollidesWithPawns = Traverse.Create(instance).Field("foundPathWhichCollidesWithPawns").GetValue <int>();
            int foundPathWithDanger             = Traverse.Create(instance).Field("foundPathWithDanger").GetValue <int>();

            while (num < 20 && num < instance.curPath.NodesLeftCount)
            {
                IntVec3 c = instance.curPath.Peek(num);

                if (pawn.GetComp <CompShips>().beached)
                {
                    break;
                }
                if (PawnUtility.ShouldCollideWithPawns(pawn) && PawnUtility.AnyPawnBlockingPathAt(c, pawn, false, false, false))
                {
                    foundPathWhichCollidesWithPawns = Find.TickManager.TicksGame;
                }
                if (PawnUtility.KnownDangerAt(c, pawn.Map, pawn))
                {
                    foundPathWithDanger = Find.TickManager.TicksGame;
                }
                if (foundPathWhichCollidesWithPawns == Find.TickManager.TicksGame && foundPathWithDanger == Find.TickManager.TicksGame)
                {
                    break;
                }
                num++;
            }
            return(true);
        }
 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);
 }
        public override Job TryGiveJob(Pawn pawn)
        {
            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.SupportsStructureType(pawn.Map, TerrainAffordanceDefOf.Diggable);
            Predicate <Region>  validator     = delegate(Region x)
            {
                IntVec3 intVec;
                return(!x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec));
            };
            Region reg;

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

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

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

            job.targetQueueA = new List <LocalTargetInfo>();
            job.targetQueueA.Add(list[0]);
            job.locomotionUrgency = LocomotionUrgency.Walk;
            return(job);
        }
Exemplo n.º 7
0
        private bool NeedNewPath()
        {
            if (!this.destination.IsValid || this.curPath == null || !this.curPath.Found || this.curPath.NodesLeftCount == 0)
            {
                return(true);
            }
            if (this.destination.HasThing && this.destination.Thing.Map != this.pawn.Map)
            {
                return(true);
            }
            if ((this.pawn.Position.InHorDistOf(this.curPath.LastNode, 15f) || this.pawn.Position.InHorDistOf(this.destination.Cell, 15f)) && !ReachabilityImmediate.CanReachImmediate(this.curPath.LastNode, this.destination, this.pawn.Map, this.peMode, this.pawn))
            {
                return(true);
            }
            if (this.curPath.UsedRegionHeuristics && this.curPath.NodesConsumedCount >= 75)
            {
                return(true);
            }
            if (this.lastPathedTargetPosition != this.destination.Cell)
            {
                float num = (float)(this.pawn.Position - this.destination.Cell).LengthHorizontalSquared;
                float num2;
                if (num > 900f)
                {
                    num2 = 10f;
                }
                else if (num > 289f)
                {
                    num2 = 5f;
                }
                else if (num > 100f)
                {
                    num2 = 3f;
                }
                else if (num > 49f)
                {
                    num2 = 2f;
                }
                else
                {
                    num2 = 0.5f;
                }
                if ((float)(this.lastPathedTargetPosition - this.destination.Cell).LengthHorizontalSquared > num2 * num2)
                {
                    return(true);
                }
            }
            bool    flag  = PawnUtility.ShouldCollideWithPawns(this.pawn);
            bool    flag2 = this.curPath.NodesLeftCount < 30;
            IntVec3 other = IntVec3.Invalid;
            int     num3  = 0;

            while (num3 < 20 && num3 < this.curPath.NodesLeftCount)
            {
                IntVec3 intVec = this.curPath.Peek(num3);
                if (!intVec.Walkable(this.pawn.Map))
                {
                    return(true);
                }
                if (flag && !this.BestPathHadPawnsInTheWayRecently() && (PawnUtility.AnyPawnBlockingPathAt(intVec, this.pawn, false, true, false) || (flag2 && PawnUtility.AnyPawnBlockingPathAt(intVec, this.pawn, false, false, false))))
                {
                    return(true);
                }
                if (!this.BestPathHadDangerRecently() && PawnUtility.KnownDangerAt(intVec, this.pawn.Map, this.pawn))
                {
                    return(true);
                }
                Building_Door building_Door = intVec.GetEdifice(this.pawn.Map) as Building_Door;
                if (building_Door != null)
                {
                    if (!building_Door.CanPhysicallyPass(this.pawn) && !this.pawn.HostileTo(building_Door))
                    {
                        return(true);
                    }
                    if (building_Door.IsForbiddenToPass(this.pawn))
                    {
                        return(true);
                    }
                }
                if (num3 != 0 && intVec.AdjacentToDiagonal(other) && (PathFinder.BlocksDiagonalMovement(intVec.x, other.z, this.pawn.Map) || PathFinder.BlocksDiagonalMovement(other.x, intVec.z, this.pawn.Map)))
                {
                    return(true);
                }
                other = intVec;
                num3++;
            }
            return(false);
        }
Exemplo n.º 8
0
        private static void EvaluateCell(IntVec3 c)
        {
            if (maxRangeFromTargetSquared > 0.01f && maxRangeFromTargetSquared < 250000f && (float)(c - req.target.Position).LengthHorizontalSquared > maxRangeFromTargetSquared)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0f, "range target");
                }
                return;
            }
            if ((double)maxRangeFromLocusSquared > 0.01 && (float)(c - req.locus).LengthHorizontalSquared > maxRangeFromLocusSquared)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.1f, "range home");
                }
                return;
            }
            if (maxRangeFromCasterSquared > 0.01f)
            {
                rangeFromCasterToCellSquared = (c - req.caster.Position).LengthHorizontalSquared;
                if (rangeFromCasterToCellSquared > maxRangeFromCasterSquared)
                {
                    if (DebugViewSettings.drawCastPositionSearch)
                    {
                        req.caster.Map.debugDrawer.FlashCell(c, 0.2f, "range caster");
                    }
                    return;
                }
            }
            if (!c.Walkable(req.caster.Map))
            {
                return;
            }
            if (req.maxRegions > 0 && c.GetRegion(req.caster.Map).mark != inRadiusMark)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.64f, "reg radius");
                }
                return;
            }
            if (!req.caster.Map.reachability.CanReach(req.caster.Position, c, PathEndMode.OnCell, TraverseParms.For(req.caster, Danger.Some)))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.4f, "can't reach");
                }
                return;
            }
            float num = CastPositionPreference(c);

            if (avoidGrid != null)
            {
                byte b = avoidGrid[c];
                num *= Mathf.Max(0.1f, (37.5f - (float)(int)b) / 37.5f);
            }
            if (DebugViewSettings.drawCastPositionSearch)
            {
                req.caster.Map.debugDrawer.FlashCell(c, num / 4f, num.ToString("F3"));
            }
            if (num < bestSpotPref)
            {
                return;
            }
            if (!verb.CanHitTargetFrom(c, req.target))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.6f, "can't hit");
                }
            }
            else if (!req.caster.Map.pawnDestinationReservationManager.CanReserve(c, req.caster))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, num * 0.9f, "resvd");
                }
            }
            else if (PawnUtility.KnownDangerAt(c, req.caster.Map, req.caster))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.9f, "danger");
                }
            }
            else
            {
                bestSpot     = c;
                bestSpotPref = num;
            }
        }
Exemplo n.º 9
0
        private static void EvaluateCell(IntVec3 c)
        {
            if (CastPositionFinder.maxRangeFromTargetSquared > 0.01f && CastPositionFinder.maxRangeFromTargetSquared < 250000f && (float)(c - CastPositionFinder.req.target.Position).LengthHorizontalSquared > CastPositionFinder.maxRangeFromTargetSquared)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, 0f, "range target", 50);
                }
                return;
            }
            if ((double)CastPositionFinder.maxRangeFromLocusSquared > 0.01 && (float)(c - CastPositionFinder.req.locus).LengthHorizontalSquared > CastPositionFinder.maxRangeFromLocusSquared)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, 0.1f, "range home", 50);
                }
                return;
            }
            if (CastPositionFinder.maxRangeFromCasterSquared > 0.01f)
            {
                CastPositionFinder.rangeFromCasterToCellSquared = (float)(c - CastPositionFinder.req.caster.Position).LengthHorizontalSquared;
                if (CastPositionFinder.rangeFromCasterToCellSquared > CastPositionFinder.maxRangeFromCasterSquared)
                {
                    if (DebugViewSettings.drawCastPositionSearch)
                    {
                        CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, 0.2f, "range caster", 50);
                    }
                    return;
                }
            }
            if (!c.Walkable(CastPositionFinder.req.caster.Map))
            {
                return;
            }
            if (CastPositionFinder.req.maxRegionsRadius > 0 && c.GetRegion(CastPositionFinder.req.caster.Map, RegionType.Set_Passable).mark != CastPositionFinder.inRadiusMark)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, 0.64f, "reg radius", 50);
                }
                return;
            }
            if (!CastPositionFinder.req.caster.Map.reachability.CanReach(CastPositionFinder.req.caster.Position, c, PathEndMode.OnCell, TraverseParms.For(CastPositionFinder.req.caster, Danger.Some, TraverseMode.ByPawn, false)))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, 0.4f, "can't reach", 50);
                }
                return;
            }
            float num = CastPositionFinder.CastPositionPreference(c);

            if (CastPositionFinder.avoidGrid != null)
            {
                byte b = CastPositionFinder.avoidGrid[c];
                num *= Mathf.Max(0.1f, (37.5f - (float)b) / 37.5f);
            }
            if (DebugViewSettings.drawCastPositionSearch)
            {
                CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, num / 4f, num.ToString("F3"), 50);
            }
            if (num < CastPositionFinder.bestSpotPref)
            {
                return;
            }
            if (!CastPositionFinder.verb.CanHitTargetFrom(c, CastPositionFinder.req.target))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, 0.6f, "can't hit", 50);
                }
                return;
            }
            if (!CastPositionFinder.req.caster.Map.pawnDestinationReservationManager.CanReserve(c, CastPositionFinder.req.caster))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, num * 0.9f, "resvd", 50);
                }
                return;
            }
            if (PawnUtility.KnownDangerAt(c, CastPositionFinder.req.caster))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    CastPositionFinder.req.caster.Map.debugDrawer.FlashCell(c, 0.9f, "danger", 50);
                }
                return;
            }
            CastPositionFinder.bestSpot     = c;
            CastPositionFinder.bestSpotPref = num;
        }
Exemplo n.º 10
0
        static IntVec3 FindRoofedInHomeArea(Pawn pawn)
        {
            Predicate <IntVec3> cellValidator = (IntVec3 x) => pawn.Map.areaManager.Home[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.OverlapWith(pawn.Map.areaManager.Home) > AreaOverlap.None && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec));
            };
            Region reg;

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

            if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root))
            {
                return(IntVec3.Invalid);
            }

            return(RCellFinder.RandomWanderDestFor(pawn, root, 7, ((Pawn p, IntVec3 v1, IntVec3 v2) => v1.Roofed(p.Map)), PawnUtility.ResolveMaxDanger(pawn, Danger.Deadly)));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Tries to give a job to the given pawn.
        /// </summary>
        /// <param name="pawn">The pawn.</param>
        /// <returns></returns>
        public override Job TryGiveJob(Pawn pawn)
        {
            if (!JoyUtility.EnjoyableOutsideNow(pawn, null))
            {
                return(null);
            }
            if (PawnUtility.WillSoonHaveBasicNeed(pawn))
            {
                return(null);
            }


            if (!def.IsValidFor(pawn))
            {
                return(null);
            }


            var allProductionComps = pawn.health.hediffSet.hediffs.Select(h => h.TryGetComp <Comp_TerrainProduction>()?.Props)
                                     .Where(p => p != null)
                                     .ToList();

            if (allProductionComps.Count == 0)
            {
                return(null);
            }

            bool IsValidCell(IntVec3 cell)
            {
                if (PawnUtility.KnownDangerAt(cell, pawn.Map, pawn))
                {
                    return(false);
                }
                var terrain = cell.GetTerrain(pawn.Map);

                if (terrain == null)
                {
                    return(false);
                }
                if (!allProductionComps.Any(p => p.CanProduceOn(terrain)))
                {
                    return(false);
                }
                return(cell.Standable(pawn.Map));
            }

            bool IsValidRegion(Region region)
            {
                if (region.IsForbiddenEntirely(pawn))
                {
                    return(false);
                }
                return(region.TryFindRandomCellInRegionUnforbidden(pawn, IsValidCell, out IntVec3 _));
            }

            if (!CellFinder.TryFindClosestRegionWith(pawn.GetRegion(RegionType.Set_Passable),
                                                     TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn), IsValidRegion,
                                                     100, out Region reg, RegionType.Set_Passable))
            {
                return(null);
            }

            if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, IsValidCell, out IntVec3 root))
            {
                return(null);
            }

            if (!WalkPathFinder.TryFindWalkPath(pawn, root, out var result))
            {
                return(null);
            }

            Job job = new Job(def.jobDef, result[0])
            {
                targetQueueA = new List <LocalTargetInfo>()
            };

            for (int i = 1; i < result.Count; i++)
            {
                job.targetQueueA.Add(result[i]);
            }

            job.locomotionUrgency = LocomotionUrgency.Walk;
            return(job);
        }
        static bool Prefix(Pawn pawn, ref Job __result, JobGiver_Wander __instance)
        {
            if (pawn.Faction != Faction.OfPlayer ||
                JoyUtility.EnjoyableOutsideNow(pawn.Map) ||
                pawn.Position.Roofed(pawn.Map))
            {
                return(true);
            }


            Predicate <IntVec3> cellValidator = (IntVec3 x) => pawn.Map.areaManager.Home[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.OverlapWith(pawn.Map.areaManager.Home) > AreaOverlap.None && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec));
            };
            Region reg;

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

            if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root))
            {
                return(true);
            }

            root = RCellFinder.RandomWanderDestFor(pawn, root, 7, ((Pawn p, IntVec3 v1, IntVec3 v2) => true), PawnUtility.ResolveMaxDanger(pawn, Danger.Deadly));

            Job job = JobMaker.MakeJob(JobDefOf.GotoWander, root);

            job.locomotionUrgency = LocomotionUrgency.Jog;
            job.expiryInterval    = -1;
            __result = job;

            return(false);
        }
        // Token: 0x06000568 RID: 1384 RVA: 0x00035040 File Offset: 0x00033440
        public override Job TryGiveJob(Pawn pawn)
        {
            string IsCurrentWeatherClear = "Null";

            if (pawn.Map.weatherManager.curWeather != null)
            {
                IsCurrentWeatherClear = pawn.Map.weatherManager.curWeather.ToString();
            }
            if (IsCurrentWeatherClear != "Clear")
            {
                return(null);
            }
            float CurrentCelestialGlow = GenCelestial.CurCelestialSunGlow(pawn.Map);

            if (CurrentCelestialGlow <= 0.4f)
            {
                return(null);
            }

            /*
             * if (GenLocalDate.DayPercent(pawn.Map) < 0.5f)
             * {
             *  return null;
             * }
             */
            if (!JoyUtility.EnjoyableOutsideNow(pawn, null))
            {
                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);
            Predicate <Region>  validator     = delegate(Region x)
            {
                IntVec3 intVec;
                return(x.Room.PsychologicallyOutdoors && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec));
            };
            Region reg;

            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;

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

            if (!WalkPathFinder.TryFindWalkPath(pawn, root, out list))
            {
                return(null);
            }
            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;
            return(job);
        }
        public override Job TryGiveJob(Pawn pawn)
        {
            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.CloseToEdge(pawn.Map, 5);
            Predicate <Region>  validator     = delegate(Region x)
            {
                IntVec3 intVec;
                return(x.Room.PsychologicallyOutdoors && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec));
            };
            Region reg;

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

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

            if (!WalkPathFinder.TryFindWalkPath(pawn, root, out list))
            {
                return(null);
            }
            IntVec3 root2;

            if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root2))
            {
                return(null);
            }
            List <IntVec3> list2;

            if (!WalkPathFinder.TryFindWalkPath(pawn, root2, out list2))
            {
                return(null);
            }
            IntVec3 root4;

            if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root4))
            {
                return(null);
            }
            List <IntVec3> list4;

            if (!WalkPathFinder.TryFindWalkPath(pawn, root4, out list4))
            {
                return(null);
            }
            IntVec3 root5;

            if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root5))
            {
                return(null);
            }
            List <IntVec3> list5;

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

            job.targetQueueA = new List <LocalTargetInfo>();
            //can't figure out how to get hte pawn to wait so this has them sit for an extra tick. sadly not more than that.
            list[1] = list[0];
            list[2] = list2[0];
            list[3] = list2[0];
            list[4] = list4[0];
            list[5] = list4[0];
            list[6] = list5[0];
            list[7] = list5[0];
            job.targetQueueA.Add(list[0]);
            job.targetQueueA.Add(list[1]);
            job.targetQueueA.Add(list[2]);
            job.targetQueueA.Add(list[3]);
            job.targetQueueA.Add(list[4]);
            job.targetQueueA.Add(list[5]);
            job.targetQueueA.Add(list[6]);
            job.targetQueueA.Add(list[7]);

            /* adding this made htem go back to the start again. its intersting. still nots rue how this translates to wandering only in water
             * for (int i = 1; i < list.Count; i++)
             * {
             *  job.targetQueueA.Add(list[i]);
             * }
             */
            job.locomotionUrgency = LocomotionUrgency.Sprint;
            return(job);
        }
Exemplo n.º 15
0
    public static bool TryFindOohWalkPath(Pawn pawn, IntVec3 root, out List <IntVec3> result)
    {
        var list = new List <IntVec3>
        {
            root
        };
        var intVec = root;

        for (var i = 0; i < 8; i++)
        {
            var intVec2 = IntVec3.Invalid;
            var num     = -1f;
            for (var num2 = StartRadialIndex; num2 > EndRadialIndex; num2 -= RadialIndexStride)
            {
                var intVec3 = intVec + GenRadial.RadialPattern[num2];
                if (!intVec3.InBounds(pawn.Map) || !intVec3.Standable(pawn.Map) ||
                    intVec3.GetTerrain(pawn.Map).avoidWander || !GenSight.LineOfSight(intVec, intVec3, pawn.Map) ||
                    intVec3.Roofed(pawn.Map) || PawnUtility.KnownDangerAt(intVec3, pawn.Map, pawn))
                {
                    continue;
                }

                var num3 = 10000f;
                foreach (var vec3 in list)
                {
                    num3 += (vec3 - intVec3).LengthManhattan;
                }

                var num4 = (float)(intVec3 - root).LengthManhattan;
                if (num4 > 40f)
                {
                    num3 *= Mathf.InverseLerp(70f, 40f, num4);
                }

                if (list.Count >= 2)
                {
                    var   angleFlat  = (list[list.Count - 1] - list[list.Count - 2]).AngleFlat;
                    var   angleFlat2 = (intVec3 - intVec).AngleFlat;
                    float num5;
                    if (angleFlat2 > angleFlat)
                    {
                        num5 = angleFlat2 - angleFlat;
                    }
                    else
                    {
                        angleFlat -= 360f;
                        num5       = angleFlat2 - angleFlat;
                    }

                    if (num5 > 110f)
                    {
                        num3 *= 0.01f;
                    }
                }

                if (list.Count >= 4 && (intVec - root).LengthManhattan < (intVec3 - root).LengthManhattan)
                {
                    num3 *= 1E-05f;
                }

                if (!(num3 > num))
                {
                    continue;
                }

                intVec2 = intVec3;
                num     = num3;
            }

            if (num < 0f)
            {
                result = null;
                return(false);
            }

            list.Add(intVec2);
            intVec = intVec2;
        }

        list.Add(root);
        result = list;
        return(true);
    }