protected override Job TryGiveJob(Pawn pawn)
        {
            pawn.mindState.nextMoveOrderIsWait = !pawn.mindState.nextMoveOrderIsWait;

            if (!pawn.mindState.duty.focus.HasThing)
            {
                return(null);
            }

            Thing thing = pawn.mindState.duty.focus.Thing;

            IntVec3 cell = thing.InteractionCell;

            if (!pawn.CanReach(cell, PathEndMode.OnCell, PawnUtility.ResolveMaxDanger(pawn, maxDanger)))
            {
                return(null);
            }
            if (pawn.Position == cell)
            {
                return(null);
            }

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

            job2.locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, locomotionUrgency);
            job2.expiryInterval    = jobMaxDuration;
            return(job2);
        }
Ejemplo n.º 2
0
        public override Job TryGiveJob(Pawn pawn)
        {
            LocalTargetInfo targetInfo = pawn.mindState.duty.focus;

            if (!pawn.CanReach(targetInfo, PathEndMode.OnCell, PawnUtility.ResolveMaxDanger(pawn, maxDanger), false, false, TraverseMode.ByPawn))
            {
                return(null);
            }

            if (pawn.carryTracker.CarriedThing == null)
            {
                pawn.GetLord().Notify_ReachedDutyLocation(pawn);
                return(null);
            }

            if (targetInfo.Pawn is Pawn target && target.carryTracker.CarriedThing != null)
            {
                return(new Job(DefDatabase <JobDef> .GetNamed("FCFollowCloseAndCarry"), targetInfo)
                {
                    followRadius = 4,
                });
            }

            return(new Job(DefDatabase <JobDef> .GetNamed("FCGotoAndDrop"), targetInfo));
        }
Ejemplo n.º 3
0
        protected virtual IntVec3 GetExactWanderDest(Pawn pawn)
        {
            IntVec3 wanderRoot = this.GetWanderRoot(pawn);

            return(RCellFinder.RandomWanderDestFor(pawn, wanderRoot, this.wanderRadius, this.wanderDestValidator, PawnUtility.ResolveMaxDanger(pawn, this.maxDanger)));
        }
Ejemplo n.º 4
0
        protected virtual IntVec3 GetExactWanderDest(Pawn pawn)
        {
            IntVec3 wanderRoot = pawn.PositionHeld;

            return(RCellFinder.RandomWanderDestFor(pawn, wanderRoot, wanderRadius, delegate(Pawn p, IntVec3 v) { if (v.Roofed(p.MapHeld))
                                                                                                                 {
                                                                                                                     return true;
                                                                                                                 }
                                                                                                                 return false; }, PawnUtility.ResolveMaxDanger(pawn, maxDanger)));
        }
Ejemplo n.º 5
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            pawn.drafter.Drafted = true;

            IntVec3 cell = pawn.mindState.duty.focus.Cell;

            if (pawn.IsBoat() && !ShipReachabilityUtility.CanReachShip(pawn, cell, PathEndMode.OnCell, PawnUtility.ResolveMaxDanger(pawn, maxDanger), false, TraverseMode.ByPawn))
            {
                return(null);
            }
            else if (!pawn.IsBoat() && pawn is VehiclePawn vehicle && !ReachabilityUtility.CanReach(vehicle, cell, PathEndMode.OnCell, PawnUtility.ResolveMaxDanger(vehicle, maxDanger), false))
            {
                return(null);
            }
            if (exactCell && pawn.Position == cell)
            {
                return(null);
            }

            return(new Job(JobDefOf.Goto, cell)
            {
                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, locomotionUrgency),
                expiryInterval = jobMaxDuration
            });
        }
Ejemplo n.º 6
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.interactions.InteractedTooRecentlyToInteract() || lastRomanceTick > Find.TickManager.TicksGame - 1000)
            {
                return(null);
            }
            Predicate <Thing> validator = delegate(Thing t)
            {
                Pawn pawn3 = (Pawn)t;
                return(pawn3 != pawn && pawn3.Spawned && !pawn3.Dead && !pawn3.Downed && pawn3.Awake() && pawn3.IsColonist);
            };
            Pawn pawn2 = (Pawn)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator);

            if (pawn2 == null)
            {
                return(null);
            }
            if (Rand.Chance(0.005f) && new InteractionWorker_RomanceAttempt().SuccessChance(pawn2, pawn) > 0f)
            {
                return(new Job(JobDefOfPsychology.MakeAdvance, pawn2));
            }
            else if (Rand.Value < 0.5f)
            {
                IntVec3 root = WanderUtility.BestCloseWanderRoot(pawn2.PositionHeld, pawn);
                Func <Pawn, IntVec3, IntVec3, bool> wanderDestValidator = delegate(Pawn p, IntVec3 c, IntVec3 wRoot)
                {
                    Room room = root.GetRoom(p.Map, RegionType.Set_Passable);
                    if (room != null && !WanderRoomUtility.IsValidWanderDest(p, c, root))
                    {
                        return(false);
                    }
                    return(true);
                };
                return(new Job(JobDefOf.Goto, RCellFinder.RandomWanderDestFor(pawn, root, 3f, wanderDestValidator, PawnUtility.ResolveMaxDanger(pawn, Danger.Deadly))));
            }
            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            pawn.mindState.nextMoveOrderIsWait = !pawn.mindState.nextMoveOrderIsWait;
            if (pawn.mindState.nextMoveOrderIsWait && !this.exactCell)
            {
                return(new Job(JobDefOf_Ships.IdleShip)
                {
                    expiryInterval = this.WaitTicks.RandomInRange
                });
            }
            IntVec3 cell = pawn.mindState.duty.focus.Cell;

            if (!ShipReachabilityUtility.CanReachShip(pawn, cell, PathEndMode.OnCell, PawnUtility.ResolveMaxDanger(pawn, this.maxDanger), false, TraverseMode.ByPawn))
            {
                return(null);
            }
            if (this.exactCell && pawn.Position == cell)
            {
                return(null);
            }
            IntVec3 c = cell;

            return(new Job(JobDefOf.Goto, c)
            {
                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, this.locomotionUrgency),
                expiryInterval = this.jobMaxDuration
            });
        }
Ejemplo n.º 8
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)));
        }
        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);
        }
        private IntVec3 getSwimmingCell(Pawn pawn)
        {
            IntVec3 wanderRoot = this.GetWanderRoot(pawn);
            IntVec3 c          = RCellFinder.RandomWanderDestFor(pawn, wanderRoot, this.wanderRadius, this.wanderDestValidator, PawnUtility.ResolveMaxDanger(pawn, this.maxDanger));

            for (int i = 0; i < 20; i++)
            {
                IntVec3 c2 = c + GenAdj.AdjacentCellsAndInside[i];
                if (!c2.InBounds(pawn.Map))
                {
                    return(IntVec3.Invalid);
                }
                if (!c2.Standable(pawn.Map))
                {
                    return(IntVec3.Invalid);
                }

                if (c2 is IntVec3 && c2.IsValid)
                {
                    TerrainDef terrain = c2.GetTerrain(pawn.Map);
                    if (terrain.HasTag("TKKN_Swim"))
                    {
                        return(c2);
                    }
                }
            }
            return(IntVec3.Invalid);
        }
Ejemplo n.º 11
0
        protected virtual IntVec3 GetExactWanderDest(Pawn pawn)
        {
            IntVec3  wanderRoot = GetWanderRoot(pawn);
            PawnDuty duty       = pawn.mindState.duty;

            if (duty != null && duty.wanderRadius.HasValue)
            {
                wanderRadius = duty.wanderRadius.Value;
            }
            return(RCellFinder.RandomWanderDestFor(pawn, wanderRoot, wanderRadius, wanderDestValidator, PawnUtility.ResolveMaxDanger(pawn, maxDanger)));
        }
Ejemplo n.º 12
0
        protected override IntVec3 GetExactWanderDest(Pawn pawn)
        {
            Area outpostArea = OG_Util.FindOutpostArea();

            if ((outpostArea != null) &&
                outpostArea.ActiveCells.Contains(pawn.Position))
            {
                return(RCellFinder.RandomWanderDestFor(pawn, pawn.Position, this.wanderRadius, this.wanderDestValidator, PawnUtility.ResolveMaxDanger(pawn, this.maxDanger)));
            }
            else
            {
                Building_OutpostCommandConsole console = OG_Util.FindOutpostCommandConsole(OG_Util.FactionOfMiningCo);
                if (console != null)
                {
                    IntVec3 cell1 = WanderUtility.BestCloseWanderRoot(console.Position, pawn);
                    return(cell1);
                }
                else
                {
                    for (int cellIndex = 0; cellIndex < 50; cellIndex++)
                    {
                        IntVec3 cell2 = outpostArea.ActiveCells.RandomElement();
                        if (pawn.CanReserveAndReach(cell2, PathEndMode.Touch, Danger.Some))
                        {
                            return(cell2);
                        }
                    }
                    IntVec3 cell3 = WanderUtility.BestCloseWanderRoot(pawn.Position, pawn);
                    return(cell3);
                }
            }
        }
Ejemplo n.º 13
0
        protected virtual IntVec3 GetExactWanderDest(Pawn pawn)
        {
            IntVec3 wanderRoot = pawn.PositionHeld;

            return(RCellFinder.RandomWanderDestFor(pawn, wanderRoot, wanderRadius,
                                                   (p, loc, root) => loc.Roofed(p.MapHeld), PawnUtility.ResolveMaxDanger(pawn, maxDanger)));
        }
Ejemplo n.º 14
0
        protected virtual IntVec3 GetExactWanderDest(Pawn pawn)
        {
            IntVec3 wanderRoot = this.GetWanderRoot(pawn);

            if (!wanderRoot.GetTerrain(pawn.Map).defName.Contains("Water"))
            {
                IntVec3 position;
                float   radius = 12;
                if (TryFindRandomCellNear(wanderRoot, pawn.Map, Mathf.FloorToInt(radius), (IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn) && !c.IsForbidden(pawn), out position))
                {
                    if (position != wanderRoot)
                    {
                        return(position);
                    }
                }
            }
            return(RCellFinder.RandomWanderDestFor(pawn, wanderRoot, this.wanderRadius, this.wanderDestValidator, PawnUtility.ResolveMaxDanger(pawn, this.maxDanger)));
        }
Ejemplo n.º 15
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            LordToil_HangOut toil   = pawn.GetLord().CurLordToil as LordToil_HangOut;
            Pawn             friend = (pawn == toil.friends[0] ? toil.friends[1] : toil.friends[0]);

            if (pawn.needs.food.CurLevel < 0.33f)
            {
                return(null);
            }
            if (friend.needs.food.CurLevel < 0.33f)
            {
                return(null);
            }
            if (LovePartnerRelationUtility.LovePartnerRelationExists(pawn, friend) && pawn.jobs.curDriver != null && pawn.jobs.curDriver.layingDown == LayingDownState.NotLaying && (pawn.IsHashIntervalTick(GenDate.TicksPerHour) || friend.IsHashIntervalTick(GenDate.TicksPerHour)))
            {
                return(new Job(JobDefOf.LayDown, pawn.ownership.OwnedBed));
            }
            if (toil.hangOut != null && toil.hangOut.GetTarget(TargetIndex.A) != null && !pawn.CanReserve(toil.hangOut.GetTarget(TargetIndex.A), toil.hangOut.def.joyMaxParticipants, 0, null))
            {
                Log.Message("can't reserve the target of the hangout");
                /* Try our best to figure out which JoyGiver was used for the unreservable job. */
                int prefix = "JoyGiver".Count();
                var def    = (
                    from j in DefDatabase <JoyGiverDef> .AllDefs
                    where j.jobDef == toil.hangOut.def ||
                    (j.jobDef == null && DefDatabase <JobDef> .GetNamedSilentFail(nameof(j.giverClass).Substring(prefix)) == toil.hangOut.def)
                    select j
                    ).FirstOrDefault();
                if (def != null)
                {
                    Log.Message("giving job of def " + def.defName);
                    do
                    {
                        toil.hangOut = base.TryGiveJobFromJoyGiverDefDirect(def, pawn);
                    } while (toil.hangOut.GetTarget(TargetIndex.A).Thing.GetRoom() != friend.GetRoom());
                }
                else
                {
                    toil.hangOut = null;
                }
            }
            if (toil.hangOut == null || toil.ticksToNextJoy < Find.TickManager.TicksGame)
            {
                toil.hangOut        = base.TryGiveJob(pawn);
                toil.ticksToNextJoy = Find.TickManager.TicksGame + Rand.RangeInclusive(GenDate.TicksPerHour, GenDate.TicksPerHour * 3);
            }
            if (pawn.needs.joy.CurLevel < 0.8f)
            {
                return(toil.hangOut);
            }
            Log.Message("no joy hangout available");
            IntVec3 root = WanderUtility.BestCloseWanderRoot(toil.hangOut.targetA.Cell, pawn);
            Func <Pawn, IntVec3, bool> validator = delegate(Pawn wanderer, IntVec3 loc)
            {
                IntVec3 wanderRoot = root;
                Room    room       = wanderRoot.GetRoom(pawn.Map);
                return(room == null || WanderUtility.InSameRoom(wanderRoot, loc, pawn.Map));
            };

            pawn.mindState.nextMoveOrderIsWait = !pawn.mindState.nextMoveOrderIsWait;
            IntVec3 wanderDest = RCellFinder.RandomWanderDestFor(pawn, root, 5f, validator, PawnUtility.ResolveMaxDanger(pawn, Danger.Some));

            if (!wanderDest.IsValid || pawn.mindState.nextMoveOrderIsWait)
            {
                if ((pawn.Position - friend.Position).LengthHorizontalSquared >= 42f && friend.jobs.curJob.def != JobDefOf.Goto)
                {
                    Log.Message("friend not nearby, going to friend");
                    IntVec3 friendDest = RCellFinder.RandomWanderDestFor(pawn, friend.Position, 5f, validator, PawnUtility.ResolveMaxDanger(pawn, Danger.Some));
                    pawn.Map.pawnDestinationManager.ReserveDestinationFor(pawn, friendDest);
                    return(new Job(JobDefOf.Goto, friendDest));
                }
                Log.Message("waiting");
                return(null);
            }
            Log.Message("wandering");
            pawn.Map.pawnDestinationManager.ReserveDestinationFor(pawn, wanderDest);
            return(new Job(JobDefOf.GotoWander, wanderDest));
        }