예제 #1
0
        /// <summary> Update the graphic if the life stage changed and swap the body graphic if moving </summary>
        public override void Tick()
        {
            base.Tick();

            if (GenTicks.TicksAbs % Frameskip != FrameskipOffset)
            {
                return;                                                               // frameskip
            }
            if (!Spawned)
            {
                return;
            }
            if (Destroyed)
            {
                return;
            }
            if (pather == null)
            {
                return;                             // this can occur if the pawn leaves the map area
            }
            if (Drawer?.renderer == null)
            {
                return;
            }

            // initialize the replacement graphics (once per lifestage)
            if (lifeStageBefore != ageTracker.CurKindLifeStage)
            {
                SetupReplacements();
                lifeStageBefore = ageTracker.CurKindLifeStage;
            }

            // avoid hunting tamed animals, accept non-ideal food instead
            if (Faction != Faction.OfPlayer && jobs?.curJob?.def == JobDefOf.PredatorHunt)
            {
                if ((jobs.curJob.targetA.Thing as Pawn)?.Faction == Faction.OfPlayer)
                {
                    jobs.StopAll();                     // stop predator hunt job

                    if (needs.food.TicksStarving < 30000)
                    {
                        // find food
                        var food = GenClosest.ClosestThingReachable(Position, Map,
                                                                    ThingRequest.ForGroup(ThingRequestGroup.HaulableAlways),
                                                                    AI.PathEndMode.OnCell,
                                                                    TraverseParms.For(this, Danger.Deadly, TraverseMode.ByPawn, false),
                                                                    maxDistance: 100f,
                                                                    validator: (thing) =>
                                                                    thing.def.category == ThingCategory.Item &&
                                                                    thing.def.IsNutritionGivingIngestible
                                                                    /*&& RaceProps.CanEverEat(thing)*/, // omit food preferences
                                                                    customGlobalSearchSet: null,
                                                                    searchRegionsMax: -1,
                                                                    forceAllowGlobalSearch: false);

                        if (food != null)
                        {
                            // try to find other food
                            jobs.StartJob(new AI.Job(JobDefOf.Ingest, food));
                        }
                        else
                        {
                            // wander until food is found or too starving to continue
                            StartJobWander();
                        }
                    }
                    else                     // if desperate
                    {
                        IntVec3 exit_dest;
                        if (RCellFinder.TryFindBestExitSpot(this, out exit_dest, TraverseMode.ByPawn))
                        {
                            // exit map
                            jobs.StartJob(new AI.Job(JobDefOf.Goto, exit_dest)
                            {
                                exitMapOnArrival = true
                            });
                        }
                        else
                        {
                            // fallback to wandering
                            StartJobWander();
                        }
                    }
                }
            }

            // attempt to find a replacement graphic
            foreach (var replacement in replacements)
            {
                if (replacement.TryReplace(Drawer.renderer))
                {
                    break;                     // break on first successful replacement
                }
            }
        }
예제 #2
0
 public List <Thing> ThingsInGroup(ThingRequestGroup group)
 {
     return(this.ThingsMatching(ThingRequest.ForGroup(group)));
 }