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);
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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));
        }