示例#1
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 = default(IntVec3);

            if (!this.TryFindGoodExitDest(pawn, flag, out c))
            {
                return(null);
            }
            if (flag)
            {
                using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                {
                    IntVec3 cellBeforeBlocker = default(IntVec3);
                    Thing   thing             = path.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                    if (thing != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true, true);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }
            }
            Job job2 = new Job(JobDefOf.Goto, c);

            job2.exitMapOnArrival = true;
            job2.failIfCantJoinOrCreateCaravan = this.failIfCantJoinOrCreateCaravan;
            job2.locomotionUrgency             = PawnUtility.ResolveLocomotion(pawn, this.defaultLocomotion, LocomotionUrgency.Jog);
            job2.expiryInterval = this.jobMaxDuration;
            job2.canBash        = this.canBash;
            return(job2);
        }
示例#2
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
            });
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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
            });
        }