示例#1
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            bool flag = forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig && !pawn.CanReachMapEdge()) || (forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge()) || (forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction, countDormantPawnsAsHostile: true));

            if (!TryFindGoodExitDest(pawn, flag, out IntVec3 dest))
            {
                return(null);
            }
            if (flag)
            {
                using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, dest, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings)))
                {
                    IntVec3 cellBefore;
                    Thing   thing = path.FirstBlockingBuilding(out cellBefore, pawn);
                    if (thing != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, thing, cellBefore, canMineMineables: true, canMineNonMineables: true);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }
            }
            Job job2 = JobMaker.MakeJob(JobDefOf.Goto, dest);

            job2.exitMapOnArrival = true;
            job2.failIfCantJoinOrCreateCaravan = failIfCantJoinOrCreateCaravan;
            job2.locomotionUrgency             = PawnUtility.ResolveLocomotion(pawn, defaultLocomotion, LocomotionUrgency.Jog);
            job2.expiryInterval = jobMaxDuration;
            job2.canBash        = canBash;
            return(job2);
        }
        public static void MakeExit(Pawn pawn)
        {
            bool flag = (pawn.mindState.duty != null && pawn.mindState.duty.canDig && !pawn.CanReachMapEdge()) || (!pawn.CanReachMapEdge()) ||
                        (pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction, countDormantPawnsAsHostile: true));

            if (!TryFindGoodExitDest(pawn, flag, out IntVec3 dest))
            {
                return;
            }
            if (flag)
            {
                using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, dest, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings)))
                {
                    IntVec3 cellBefore;
                    Thing   thing = path.FirstBlockingBuilding(out cellBefore, pawn);
                    if (thing != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, thing, cellBefore, canMineMineables: true, canMineNonMineables: true);
                        if (job != null)
                        {
                            pawn.jobs.TryTakeOrderedJob(job);
                            return;
                        }
                    }
                }
            }

            Job job2 = JobMaker.MakeJob(JobDefOf.Goto, dest);

            job2.exitMapOnArrival  = true;
            job2.locomotionUrgency = LocomotionUrgency.Jog;
            job2.expiryInterval    = 1000;
            job2.canBashDoors      = true;
            pawn.jobs.TryTakeOrderedJob(job2);
        }
示例#3
0
 private static Job GotoForce(Pawn pawn, LocalTargetInfo target, PathEndMode pathEndMode)
 {
     using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, target, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAnything, false), pathEndMode))
     {
         IntVec3 cellBeforeBlocker;
         Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
         if (thing != null)
         {
             Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true);
             if (job != null)
             {
                 return(job);
             }
         }
         if (thing == null)
         {
             return(new Job(JobDefOf.Goto, target, 100, true));
         }
         if (pawn.equipment.Primary != null)
         {
             Verb primaryVerb = pawn.equipment.PrimaryEq.PrimaryVerb;
             if (primaryVerb.verbProps.ai_IsBuildingDestroyer && (!primaryVerb.verbProps.ai_IsIncendiary || thing.FlammableNow))
             {
                 return(new Job(JobDefOf.UseVerbOnThing)
                 {
                     targetA = thing,
                     verbToUse = primaryVerb,
                     expiryInterval = 100
                 });
             }
         }
         return(MeleeOrWaitJob(pawn, thing, cellBeforeBlocker));
     }
 }
示例#4
0
        private Job ExitMap(Pawn pawn)
        {
            bool canDig = !pawn.CanReachMapEdge();

            if (!TryFindGoodExitDest(pawn, canDig, out var dest))
            {
                return(null);
            }
            if (canDig)
            {
                using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, dest, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings)))
                {
                    IntVec3 cellBefore;
                    Thing   thing = path.FirstBlockingBuilding(out cellBefore, pawn);
                    if (thing != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, thing, cellBefore, canMineMineables: true, canMineNonMineables: true);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }
            }
            Job job2 = JobMaker.MakeJob(JobDefOf.Goto, dest);

            job2.exitMapOnArrival = true;
            job2.failIfCantJoinOrCreateCaravan = false;
            job2.expiryInterval = recheckInterval;
            job2.canBash        = true;
            return(job2);
        }
        // Token: 0x06003DA3 RID: 15779 RVA: 0x0016D63C File Offset: 0x0016B83C
        protected override Job TryGiveJob(Pawn pawn)
        {
            Room room = pawn.GetRoom(RegionType.Set_Passable);

            if (room.PsychologicallyOutdoors && room.TouchesMapEdge)
            {
                return(null);
            }
            if (!pawn.CanReachMapEdge())
            {
                return(null);
            }
            bool    flag = this.forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig && !pawn.CanReachMapEdge()) || (this.forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge()) || (this.forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction, true));
            IntVec3 c;

            if (!this.TryFindGoodExitDest(pawn, flag, out c))
            {
                return(null);
            }
            if (flag)
            {
                using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                {
                    IntVec3 cellBeforeBlocker;
                    Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                    if (thing.def == XenomorphDefOf.RRY_Xenomorph_Hive_Wall)
                    {
                        CellRect rect = new CellRect(thing.Position.x - 1, thing.Position.y - 1, 3, 3);
                        foreach (IntVec3 cell in rect)
                        {
                            if (cell.InBounds(thing.Map))
                            {
                                if (cell.GetThingList(thing.Map).All(x => x.def != XenomorphDefOf.RRY_Xenomorph_Hive_Wall))
                                {
                                    thing = cell.GetFirstMineable(thing.Map);
                                    break;
                                }
                            }
                        }
                    }
                    if (thing != null && thing.def != XenomorphDefOf.RRY_Xenomorph_Hive_Wall)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true, true);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }
            }
            return(null);
        }
示例#6
0
        public static bool TryGiveJob(JobGiver_ExitMap __instance, ref Job __result, Pawn pawn)
        {
            Pawn_MindState mindState = pawn.mindState;
            bool           canDig    = __instance.forceCanDig ||
                                       (mindState != null && mindState.duty != null) &&
                                       mindState.duty.canDig &&
                                       !pawn.CanReachMapEdge() ||
                                       __instance.forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge() ||
                                       __instance.forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null &&
                                       GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction, true);
            IntVec3 dest;

            if (!__instance.TryFindGoodExitDest(pawn, canDig, out dest))
            {
                __result = null;
                return(false);
            }
            if (canDig)
            {
                using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, (LocalTargetInfo)dest, TraverseParms.For(pawn, mode: TraverseMode.PassAllDestroyableThings)))
                {
                    IntVec3 cellBefore;
                    Thing   blocker = path.FirstBlockingBuilding(out cellBefore, pawn);
                    if (blocker != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, blocker, cellBefore, true, true);
                        if (job != null)
                        {
                            __result = job;
                            return(false);
                        }
                    }
                }
            }
            Job job1 = JobMaker.MakeJob(JobDefOf.Goto, (LocalTargetInfo)dest);

            job1.exitMapOnArrival = true;
            job1.failIfCantJoinOrCreateCaravan = __instance.failIfCantJoinOrCreateCaravan;
            job1.locomotionUrgency             = PawnUtility.ResolveLocomotion(pawn, __instance.defaultLocomotion, LocomotionUrgency.Jog);
            job1.expiryInterval = __instance.jobMaxDuration;
            job1.canBashDoors   = __instance.canBash;
            __result            = job1;
            return(false);
        }
示例#7
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            bool flag = false;

            if (this.forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig) || (this.forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge()) || (this.forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction)))
            {
                flag = true;
            }
            IntVec3 c;
            Job     result;

            if (!this.TryFindGoodExitDest(pawn, flag, out c))
            {
                result = null;
            }
            else
            {
                if (flag)
                {
                    using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                    {
                        IntVec3 cellBeforeBlocker;
                        Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                        if (thing != null)
                        {
                            Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true, true);
                            if (job != null)
                            {
                                return(job);
                            }
                        }
                    }
                }
                result = new Job(JobDefOf.Goto, c)
                {
                    exitMapOnArrival = true,
                    failIfCantJoinOrCreateCaravan = this.failIfCantJoinOrCreateCaravan,
                    locomotionUrgency             = PawnUtility.ResolveLocomotion(pawn, this.defaultLocomotion, LocomotionUrgency.Jog),
                    expiryInterval = this.jobMaxDuration,
                    canBash        = this.canBash
                };
            }
            return(result);
        }
示例#8
0
        // Token: 0x06003EB7 RID: 16055 RVA: 0x001D76A8 File Offset: 0x001D5AA8
        protected override Job TryGiveJob(Pawn pawn)
        {
            bool flag = false;

            if (this.forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig) || (this.forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge()) || (this.forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction)))
            {
                flag = true;
            }
            IntVec3 c;

            if (pawn.xenomorph().HiveLoc == null)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} no hiveloc", pawn));
                }
                return(null);
            }
            if (!pawn.xenomorph().HiveLoc.IsValid)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} no hiveloc", pawn));
                }
                return(null);
            }
            if (pawn.xenomorph().HiveLoc == IntVec3.Zero)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} hiveloc zero", pawn));
                }
                return(null);
            }
            c = pawn.xenomorph().HiveLoc;

            if (!c.IsValid)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} no c", pawn));
                }
                return(null);
            }
            if (c == IntVec3.Zero)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} c zero", pawn));
                }
                return(null);
            }

            if (flag)
            {
                using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                {
                    IntVec3 cellBeforeBlocker;
                    Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                    if (thing != null)
                    {
                        if (!thing.def.defName.Contains("Xenomorph_Hive"))
                        {
                            Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true, true);
                            if (job != null)
                            {
                                return(job);
                            }
                        }
                    }
                }
            }

            /*
             * //    Log.Message("TryGiveJob 6");
             * //    Log.Message(string.Format("TryGiveJob 6 {0}, {1}", pawn.Map, c));
             * if (c.GetFirstBuilding(pawn.Map)!=null)
             * {
             * //    Log.Message(string.Format("TryGiveJob 6 {0}, {1} Building == {2}", pawn.Map, c, c.GetFirstBuilding(pawn.Map)));
             *  if (c.GetFirstBuilding(pawn.Map).def == XenomorphDefOf.RRY_Xenomorph_Hive)
             *  {
             *  //    Log.Message("TryGiveJob 6 1");
             *      return null;
             *  }
             * }
             * else
             * {
             * //    Log.Message(string.Format("TryGiveJob 6 {0}, {1} Building == Null", pawn.Map, c));
             *  if (c.GetFirstThing(pawn.Map, XenomorphDefOf.RRY_Xenomorph_Hive) != null)
             *  {
             *  //    Log.Message(string.Format("TryGiveJob 6 {0}, {1} Building == {2}", pawn.Map, c, c.GetFirstThing(pawn.Map, XenomorphDefOf.RRY_Xenomorph_Hive)));
             *      if (c.GetFirstBuilding(pawn.Map).def == )
             *      {
             *      //    Log.Message("TryGiveJob 6 1");
             *          return null;
             *      }
             *  }
             *  else
             *  {
             *  //    Log.Message(string.Format("TryGiveJob 6 {0}, {1} Building == Null", pawn.Map, c));
             *  }
             * }
             * //    Log.Message("TryGiveJob 7");
             */
            return(new Job(JobDefOf.Goto, c)
            {
                exitMapOnArrival = false,
                failIfCantJoinOrCreateCaravan = this.failIfCantJoinOrCreateCaravan,
                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, this.defaultLocomotion, LocomotionUrgency.Jog),
                expiryInterval = this.jobMaxDuration,
                canBash = this.canBash
            });
        }
示例#9
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Room room = pawn.GetRoom(RegionType.Set_Passable);

            if (room != null)
            {
                if (room.PsychologicallyOutdoors)
                {
                    Area area = pawn.MapHeld.areaManager.Home;
                    if (area != null)
                    {
                        if (area.ActiveCells.FirstOrDefault(x => x.Roofed(pawn.Map) && x.Walkable(pawn.Map)) is IntVec3 safePlace && !IsZero(safePlace) && safePlace.IsValid)
                        {
                            //Log.Message("Safe Place");
                            return(new Job(JobDefOf.Goto, safePlace)
                            {
                                locomotionUrgency = LocomotionUrgency.Sprint
                            });
                        }
                    }


                    Thing thing = GenClosest.ClosestThingReachable(pawn.PositionHeld, pawn.Map, ThingRequest.ForDef(ThingDefOf.Fire), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 23, null, null, 0, -1, false, RegionType.Set_Passable, false);
                    if (thing != null)
                    {
                        //Log.Message("Flee Place");

                        IntVec3 fleeLoc = CellFinderLoose.GetFleeDest(pawn, new List <Thing>()
                        {
                            thing
                        }, 23);
                        return(new Job(JobDefOf.FleeAndCower, thing));
                    }

                    Region region;
                    CellFinder.TryFindClosestRegionWith(pawn.GetRegion(RegionType.Set_Passable), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn), (x => !x.Room.PsychologicallyOutdoors), 9999, out region, RegionType.Set_All);   //.ClosestRegionIndoors(pawn.Position, pawn.Map, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), RegionType.Set_Passable);
                    if (region != null)
                    {
                        IntVec3 result;
                        if (region.TryFindRandomCellInRegion(x => !IsZero(x) && x.IsValid && x.InBounds(pawn.MapHeld) && x.GetDoor(pawn.MapHeld) == null, out result))
                        {
                            //Log.Message("Region Place");

                            return(new Job(JobDefOf.Goto, result)
                            {
                                locomotionUrgency = LocomotionUrgency.Sprint
                            });
                        }
                    }
                    IntVec3?cellResult = null;
                    cellResult = CellFinderLoose.RandomCellWith(x => !IsZero(x) && x.IsValid && x.InBounds(pawn.MapHeld) && x.Roofed(pawn.MapHeld) && x.Walkable(pawn.MapHeld) &&
                                                                pawn.Map.reachability.CanReach(pawn.PositionHeld, x, PathEndMode.OnCell, TraverseMode.ByPawn, Danger.Deadly), pawn.MapHeld, 1000);
                    if (cellResult != null && cellResult.Value.IsValid && !IsZero(cellResult.Value))
                    {
                        //Log.Message("Random Place");

                        return(new Job(JobDefOf.Goto, cellResult.Value)
                        {
                            locomotionUrgency = LocomotionUrgency.Sprint
                        });
                    }

                    if (pawn.Faction != pawn.Map.ParentFaction)
                    {
                        bool flag = false;
                        if (pawn.mindState.duty != null && pawn.mindState.duty.canDig)
                        {
                            flag = true;
                        }
                        IntVec3 c;
                        if (RCellFinder.TryFindBestExitSpot(pawn, out c, (!flag) ? TraverseMode.ByPawn : TraverseMode.PassAllDestroyableThings))
                        {
                            if (flag)
                            {
                                using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                                {
                                    IntVec3 cellBeforeBlocker;
                                    Thing   thingY = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                                    if (thingY != null)
                                    {
                                        Job job = DigUtility.PassBlockerJob(pawn, thingY, cellBeforeBlocker, true);
                                        if (job != null)
                                        {
                                            return(job);
                                        }
                                    }
                                }
                            }
                            return(new Job(JobDefOf.Goto, c)
                            {
                                exitMapOnArrival = true,
                                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, LocomotionUrgency.Sprint, LocomotionUrgency.Jog),
                                expiryInterval = 400,
                                canBash = true
                            });
                        }
                    }

                    IntVec3?hideyHoleResult = null;
                    hideyHoleResult = VampireUtility.FindHideyHoleSpot(VampDefOf.ROMV_HideyHole, Rot4.Random, pawn.PositionHeld, pawn.MapHeld);
                    if (hideyHoleResult != null && hideyHoleResult.Value.IsValid)
                    {
                        //Log.Message("Hidey Place");

                        return(new Job(VampDefOf.ROMV_DigAndHide, hideyHoleResult.Value)
                        {
                            locomotionUrgency = LocomotionUrgency.Sprint
                        });
                    }
                }
                //bool nextMoveOrderIsWait = pawn.mindState.nextMoveOrderIsWait;
                //pawn.mindState.nextMoveOrderIsWait = !pawn.mindState.nextMoveOrderIsWait;
                //if (nextMoveOrderIsWait)
                //{
                //    return new Job(JobDefOf.WaitWander)
                //    {
                //        expiryInterval = this.ticksBetweenWandersRange.RandomInRange
                //    };
                //}
                //IntVec3 exactWanderDest = this.GetExactWanderDest(pawn);
                //if (!exactWanderDest.IsValid)
                //{
                //    pawn.mindState.nextMoveOrderIsWait = false;
                //    return null;
                //}
                //pawn.Map.pawnDestinationManager.ReserveDestinationFor(pawn, exactWanderDest);
                //return new Job(JobDefOf.GotoWander, exactWanderDest)
                //{
                //    locomotionUrgency = this.locomotionUrgency
                //};
            }
            return(null);
        }
示例#10
0
        protected override Job TryGiveJob(
            Pawn pawn)
        {
            var intVec = (IntVec3)pawn.mindState.duty.focus;

            if (intVec.IsValid)
            {
                if (intVec.DistanceToSquared(pawn.Position) < 100f &&
                    intVec.GetRoom(pawn.Map, RegionType.Set_Passable)
                    == pawn.GetRoom(RegionType.Set_Passable) && intVec.WithinRegions(pawn.Position,
                                                                                     pawn.Map,
                                                                                     9,
                                                                                     TraverseMode.NoPassClosedDoors,
                                                                                     RegionType.Set_Passable))
                {
                    pawn.GetLord().Notify_ReachedDutyLocation(pawn);
                    return(null);
                }
            }

            if (!intVec.IsValid)
            {
                if (!(from x in pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn)
                      where !x.ThreatDisabled(pawn) && x.Thing.Faction == Faction.OfPlayer &&
                      pawn.CanReach(x.Thing,
                                    PathEndMode.OnCell,
                                    Danger.Deadly,
                                    false,
                                    TraverseMode.PassAllDestroyableThings)
                      select x)
                    .TryRandomElement(out IAttackTarget attackTarget))
                {
                    return(null);
                }

                intVec = attackTarget.Thing.Position;
            }

            Job result;

            if (!pawn.CanReach(intVec,
                               PathEndMode.OnCell,
                               Danger.Deadly,
                               false,
                               TraverseMode.PassAllDestroyableThings))
            {
                result = null;
            }
            else
            {
                using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position,
                                                                        intVec,
                                                                        TraverseParms.For(pawn,
                                                                                          Danger.Deadly,
                                                                                          TraverseMode.PassAllDestroyableThings,
                                                                                          false),
                                                                        PathEndMode.OnCell))
                {
                    Thing thing =
                        pawnPath.FirstBlockingBuilding(out IntVec3 cellBeforeBlocker, pawn);
                    if (thing != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn,
                                                            thing,
                                                            cellBeforeBlocker,
                                                            true,
                                                            false);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }

                result = new Job(JobDefOf.Goto, intVec, 500, true);
            }

            return(result);
        }
示例#11
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            List <Thing> steelVehicle = new List <Thing>();

            foreach (Vehicle_Cart vehicle_Cart in ToolsForHaulUtility.Cart)
            {
                if (ToolsForHaulUtility.IsDriver(pawn))
                {
                    break;
                }
                if (pawn.RaceProps.Animal || !pawn.RaceProps.Humanlike || !pawn.RaceProps.hasGenders)
                {
                    break;
                }
                if (!vehicle_Cart.IsBurning() && vehicle_Cart.Position.InHorDistOf(pawn.Position, 20f) && !vehicle_Cart.mountableComp.IsMounted && (float)vehicle_Cart.HitPoints / vehicle_Cart.MaxHitPoints > 0.2f && vehicle_Cart.VehicleSpeed >= pawn.GetStatValue(StatDefOf.MoveSpeed) && pawn.CanReserveAndReach(vehicle_Cart, PathEndMode.InteractionCell, Danger.Deadly))
                {
                    steelVehicle.Add(vehicle_Cart);
                }
            }

            foreach (Vehicle_Turret vehicle_Cart in ToolsForHaulUtility.CartTurret)
            {
                if (ToolsForHaulUtility.IsDriver(pawn))
                {
                    break;
                }
                if (pawn.RaceProps.Animal || !pawn.RaceProps.Humanlike || !pawn.RaceProps.hasGenders)
                {
                    break;
                }
                if (!vehicle_Cart.IsBurning() && vehicle_Cart.Position.InHorDistOf(pawn.Position, 20f) && !vehicle_Cart.mountableComp.IsMounted && (float)vehicle_Cart.HitPoints / vehicle_Cart.MaxHitPoints > 0.2f && vehicle_Cart.VehicleSpeed >= pawn.GetStatValue(StatDefOf.MoveSpeed) && pawn.CanReserveAndReach(vehicle_Cart, PathEndMode.InteractionCell, Danger.Deadly))
                {
                    steelVehicle.Add(vehicle_Cart);
                }
            }

            if (steelVehicle.Any())
            {
                IOrderedEnumerable <Thing> orderedEnumerable = steelVehicle.OrderBy(x => x.Position.DistanceToSquared(pawn.Position));
                Job job = new Job(HaulJobDefOf.Mount);
                orderedEnumerable.First().SetFaction(null);
                job.targetA = orderedEnumerable.First();

                return(job);
            }

            bool flag = false;

            if (this.forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig))
            {
                flag = true;
            }
            IntVec3 vec;

            if (!this.TryFindGoodExitDest(pawn, flag, out vec))
            {
                return(null);
            }
            if (flag)
            {
                using (PawnPath pawnPath = PathFinder.FindPath(pawn.Position, vec, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAnything)))
                {
                    IntVec3 cellBeforeBlocker;
                    Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                    if (thing != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }
            }
            return(new Job(JobDefOf.Goto, vec)
            {
                exitMapOnArrival = true,
                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, this.defaultLocomotion, LocomotionUrgency.Jog),
                expiryInterval = this.jobMaxDuration,
                canBash = this.canBash
            });
        }