예제 #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);
        }
예제 #2
0
        public static void DebugFlashWalkPath(IntVec3 root, int numEntries = 8)
        {
            Map            currentMap = Find.CurrentMap;
            List <IntVec3> list;

            if (!WalkPathFinder.TryFindWalkPath(currentMap.mapPawns.FreeColonistsSpawned.First <Pawn>(), root, out list))
            {
                currentMap.debugDrawer.FlashCell(root, 0.2f, "NOPATH", 50);
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                currentMap.debugDrawer.FlashCell(list[i], (float)i / (float)numEntries, i.ToString(), 50);
                if (i > 0)
                {
                    currentMap.debugDrawer.FlashLine(list[i], list[i - 1], 50, SimpleColor.White);
                }
            }
        }
예제 #3
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);
        }
예제 #4
0
        public static void DebugFlashWalkPath(IntVec3 root, int numEntries = 8)
        {
            Map            visibleMap = Find.VisibleMap;
            List <IntVec3> list       = default(List <IntVec3>);

            if (!WalkPathFinder.TryFindWalkPath(visibleMap.mapPawns.FreeColonistsSpawned.First(), root, out list))
            {
                visibleMap.debugDrawer.FlashCell(root, 0.2f, "NOPATH", 50);
            }
            else
            {
                for (int i = 0; i < list.Count; i++)
                {
                    visibleMap.debugDrawer.FlashCell(list[i], (float)i / (float)numEntries, i.ToString(), 50);
                    if (i > 0)
                    {
                        visibleMap.debugDrawer.FlashLine(list[i], list[i - 1], 50);
                    }
                }
            }
        }
예제 #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);
        }