Example #1
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);
                }
            }
        }
Example #2
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            var mentalState = pawn.MentalState as MentalState_PanicFreezing;

            if (mentalState == null)
            {
                return(null);
            }
            var cells = pawn.ownership.OwnedRoom.Cells;

            if (cells.Count() > 0)
            {
                if (!cells.Contains(pawn.Position))
                {
                    Job job = JobMaker.MakeJob(JobDefOf.Flee, cells.Where(x => x.Walkable(pawn.Map)).RandomElement());
                    job.locomotionUrgency = LocomotionUrgency.Sprint;
                    return(job);
                }
                else
                {
                    Job job = JobMaker.MakeJob(JobDefOf.GotoWander, cells.Where(x => x.Walkable(pawn.Map)).RandomElement());
                    return(job);
                }
            }
            else
            {
                var spot = WanderUtility.BestCloseWanderRoot(pawn.Position, pawn);
                Job job  = JobMaker.MakeJob(JobDefOf.Flee, spot);
                job.locomotionUrgency = LocomotionUrgency.Sprint;
            }
            return(null);
        }
		public static bool IsValidWanderDest(Pawn pawn, IntVec3 loc, IntVec3 root)
		{
			Room room = root.GetRoom(pawn.Map);
			if (room == null || room.RegionType == RegionType.Portal)
			{
				return true;
			}
			return WanderUtility.InSameRoom(root, loc, pawn.Map);
		}
        public static bool IsValidWanderDest(Pawn pawn, IntVec3 loc, IntVec3 root)
        {
            Room room = root.GetRoom(pawn.Map, RegionType.Set_Passable);

            if (room != null && room.RegionType != RegionType.Portal)
            {
                return(WanderUtility.InSameRoom(root, loc, pawn.Map));
            }
            return(true);
        }
Example #5
0
        public static bool GetWanderRoot(JobGiver_WanderNearDutyLocation __instance, ref IntVec3 __result, Pawn pawn)
        {
            __result = IntVec3.Invalid;
            PawnDuty duty = pawn.mindState.duty;

            if (duty != null)
            {
                __result = WanderUtility.BestCloseWanderRoot(duty.focus.Cell, pawn);
            }
            return(false);
        }
Example #6
0
        private void DoGrowSubplant()
        {
            IntVec3 position = parent.Position;

            for (int i = 0; i < 1000; i++)
            {
                IntVec3 intVec = position + GenRadial.RadialPattern[i];
                if (!intVec.InBounds(parent.Map) || !WanderUtility.InSameRoom(position, intVec, parent.Map))
                {
                    continue;
                }
                bool         flag      = false;
                List <Thing> thingList = intVec.GetThingList(parent.Map);
                foreach (Thing item in thingList)
                {
                    if (item.def == Props.subplant)
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag || !Props.subplant.CanEverPlantAt_NewTemp(intVec, parent.Map, canWipePlantsExceptTree: true))
                {
                    continue;
                }
                for (int num = thingList.Count - 1; num >= 0; num--)
                {
                    if (thingList[num].def.category == ThingCategory.Plant)
                    {
                        thingList[num].Destroy();
                    }
                }
                subplants.Add(GenSpawn.Spawn(Props.subplant, intVec, parent.Map));
                if (Props.spawnSound != null)
                {
                    Props.spawnSound.PlayOneShot(new TargetInfo(parent));
                }
                onGrassGrown?.Invoke();
                break;
            }
        }
Example #7
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 IntVec3 GetWanderRoot(Pawn pawn)
 {
     return(WanderUtility.BestCloseWanderRoot(pawn.playerSettings.master.PositionHeld, pawn));
 }
 protected override IntVec3 GetWanderRoot(Pawn pawn)
 {
     return(WanderUtility.GetColonyWanderRoot(pawn));
 }
 protected override IntVec3 GetWanderRoot(Pawn pawn)
 {
     return(WanderUtility.BestCloseWanderRoot(pawn.mindState.duty.focusSecond.Cell, pawn));
 }
Example #11
0
        public static bool CanSpawnAt(IntVec3 c, Map map, int minProximityToArtificialStructures = 40, int minProximityToCenter = 0, int minFertileUnroofedCells = 22, int maxFertileUnroofedCellRadius = 10)
        {
            if (!c.Standable(map) || c.Fogged(map) || !c.GetRoom(map).PsychologicallyOutdoors)
            {
                return(false);
            }
            Plant plant = c.GetPlant(map);

            if (plant != null && plant.def.plant.growDays > 10f)
            {
                return(false);
            }
            List <Thing> thingList = c.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                if (thingList[i].def == ThingDefOf.Plant_TreeAnima)
                {
                    return(false);
                }
            }
            if (minProximityToCenter > 0 && map.Center.InHorDistOf(c, minProximityToCenter))
            {
                return(false);
            }
            if (!map.reachability.CanReachFactionBase(c, map.ParentFaction))
            {
                return(false);
            }
            TerrainDef terrain = c.GetTerrain(map);

            if (terrain.avoidWander || terrain.fertility <= 0f)
            {
                return(false);
            }
            if (c.Roofed(map))
            {
                return(false);
            }
            if (minProximityToArtificialStructures != 0 && GenRadial.RadialDistinctThingsAround(c, map, minProximityToArtificialStructures, useCenter: false).Any(MeditationUtility.CountsAsArtificialBuilding))
            {
                return(false);
            }
            int num  = GenRadial.NumCellsInRadius(maxFertileUnroofedCellRadius);
            int num2 = 0;

            for (int j = 0; j < num; j++)
            {
                IntVec3 intVec = c + GenRadial.RadialPattern[j];
                if (WanderUtility.InSameRoom(intVec, c, map))
                {
                    if (intVec.InBounds(map) && !intVec.Roofed(map) && intVec.GetTerrain(map).fertility > 0f)
                    {
                        num2++;
                    }
                    if (num2 >= minFertileUnroofedCells)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public static IEnumerable <LocalTargetInfo> AllMeditationSpotCandidates(Pawn pawn, bool allowFallbackSpots = true)
        {
            bool flag = false;

            if (pawn.royalty != null && pawn.royalty.AllTitlesInEffectForReading.Count > 0 && !pawn.IsPrisonerOfColony)
            {
                Building_Throne building_Throne = RoyalTitleUtility.FindBestUsableThrone(pawn);
                if (building_Throne != null)
                {
                    yield return(building_Throne);

                    flag = true;
                }
            }
            if (!pawn.IsPrisonerOfColony)
            {
                foreach (Building item in pawn.Map.listerBuildings.AllBuildingsColonistOfDef(ThingDefOf.MeditationSpot).Where(delegate(Building s)
                {
                    if (s.IsForbidden(pawn) || !s.Position.Standable(s.Map))
                    {
                        return(false);
                    }
                    if (s.GetAssignedPawn() != null && s.GetAssignedPawn() != pawn)
                    {
                        return(false);
                    }
                    Room room4 = s.GetRoom();
                    return((room4 == null || CanUseRoomToMeditate(room4, pawn)) && pawn.CanReserveAndReach(s, PathEndMode.OnCell, pawn.NormalMaxDanger()));
                }))
                {
                    yield return(item);

                    flag = true;
                }
            }
            if (flag || !allowFallbackSpots)
            {
                yield break;
            }
            List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.MeditationFocus);

            foreach (Thing item2 in list)
            {
                if (item2.def == ThingDefOf.Wall)
                {
                    continue;
                }
                Room room = item2.GetRoom();
                if ((room == null || CanUseRoomToMeditate(room, pawn)) && item2.GetStatValueForPawn(StatDefOf.MeditationFocusStrength, pawn) > 0f)
                {
                    LocalTargetInfo localTargetInfo = MeditationSpotForFocus(item2, pawn);
                    if (localTargetInfo.IsValid)
                    {
                        yield return(localTargetInfo);
                    }
                }
            }
            Building_Bed bed   = pawn.ownership.OwnedBed;
            Room         room2 = bed?.GetRoom();
            IntVec3      c2;

            if (room2 != null && !room2.PsychologicallyOutdoors && pawn.CanReserveAndReach(bed, PathEndMode.OnCell, pawn.NormalMaxDanger()))
            {
                foreach (LocalTargetInfo item3 in FocusSpotsInTheRoom(pawn, room2))
                {
                    yield return(item3);
                }
                c2 = RCellFinder.RandomWanderDestFor(pawn, bed.Position, WanderRadius, (Pawn p, IntVec3 c, IntVec3 r) => c.Standable(p.Map) && c.GetDoor(p.Map) == null && WanderRoomUtility.IsValidWanderDest(p, c, r), pawn.NormalMaxDanger());
                if (c2.IsValid)
                {
                    yield return(c2);
                }
            }
            if (pawn.IsPrisonerOfColony)
            {
                yield break;
            }
            IntVec3 colonyWanderRoot = WanderUtility.GetColonyWanderRoot(pawn);

            c2 = RCellFinder.RandomWanderDestFor(pawn, colonyWanderRoot, WanderRadius, delegate(Pawn p, IntVec3 c, IntVec3 r)
            {
                if (!c.Standable(p.Map) || c.GetDoor(p.Map) != null || !p.CanReserveAndReach(c, PathEndMode.OnCell, p.NormalMaxDanger()))
                {
                    return(false);
                }
                Room room3 = c.GetRoom(p.Map);
                return((room3 == null || CanUseRoomToMeditate(room3, pawn)) ? true : false);
            }, pawn.NormalMaxDanger());
            if (c2.IsValid)
            {
                yield return(c2);
            }
        }
Example #13
0
 protected override IntVec3 GetWanderRoot(Pawn pawn)
 {
     return((ClosestCharacter(pawn) is Pawn otherPawn) ? WanderUtility.BestCloseWanderRoot(otherPawn.PositionHeld, pawn) : pawn.PositionHeld);
 }
Example #14
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));
        }