コード例 #1
0
        public static GraveDig_JobParameters RetrieveGDJP(this Pawn p, GraveDiggerDef GDD, bool MyDebug = false)
        {
            string myDebugStr = MyDebug ? p.LabelShort + " RetrieveGraveDiggerDef RetrieveGDJP " : "";

            GraveDig_JobParameters GDJP = p.WorkerFulfillsRequirements(GDD);

            if (GDJP == null)
            {
                if (MyDebug)
                {
                    Log.Warning(myDebugStr + "pawns does not fulfil requirements; exit");
                }
                return(null);
            }

            if (!GDJP.target.HasEligibleGraves)
            {
                if (MyDebug)
                {
                    Log.Warning(myDebugStr + "CRS has no eligible category def; exit");
                }
                return(null);
            }

            return(GDJP);
        }
コード例 #2
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            string myDebugStr = PreRetrieveDebug ? pawn.LabelShort + " Ai_GraveDigger_JobGiver TryGiveJob " : "";

            if (pawn.NegligiblePawn())
            {
                if (PreRetrieveDebug)
                {
                    Log.Warning(myDebugStr + "negligible; exit");
                }
                return(null);
            }

            GraveDiggerDef         DefToUse = pawn.RetrieveGDD(out MyDebug, PreRetrieveDebug);
            GraveDig_JobParameters GDJP     = pawn.RetrieveGDJP(DefToUse, MyDebug);

            if (!pawn.GetClosestCompatibleGrave(GDJP.target, out Thing FoundGrave, out Thing FoundCorpse, MyDebug))
            {
                if (MyDebug)
                {
                    Log.Warning(myDebugStr + "grave or corpse " + FoundGrave?.Label + " " + FoundGrave?.Position + " is not ok; exit");
                }
                return(null);
            }

            if (MyDebug)
            {
                Log.Warning(myDebugStr + " accepting " + DefToUse.jobDef.defName + " for grave " + FoundGrave?.Label + " " + FoundGrave?.Position + " => go go");
            }
            Job job = JobMaker.MakeJob(DefToUse.jobDef, FoundGrave, FoundCorpse);

            return(job);
        }
コード例 #3
0
        public static GraveDiggerDef RetrieveGDD(this Pawn p, out bool outDebug, bool MyDebug = false)
        {
            string         myDebugStr = MyDebug ? p.LabelShort + " RetrieveGraveDiggerDef RetrieveGDD " : "";
            GraveDiggerDef DefToUse   = DefDatabase <GraveDiggerDef> .AllDefs.Where(gdd => gdd.workerPawnKind.Contains(p.kindDef)).FirstOrFallback(null);

            outDebug = false;
            if (DefToUse == null || DefToUse.IsEmpty)
            {
                if (MyDebug)
                {
                    Log.Warning(myDebugStr + "found no GraveDiggerDef for " + p.kindDef + "; exit");
                }
                return(null);
            }
            outDebug = DefToUse.debug;
            return(DefToUse);
        }
コード例 #4
0
        public static GraveDig_JobParameters WorkerFulfillsRequirements(this Pawn p, GraveDiggerDef GDD)
        {
            //if (p.NegligiblePawn() || GDD.IsEmpty)
            if (GDD.IsEmpty)
            {
                return(null);
            }

            if (!GDD.jobParameters.Any(jp => jp.HasWorkerRequirement))
            {
                return(GDD.jobParameters.FirstOrFallback(null));
            }

            foreach (GraveDig_JobParameters GDJP in GDD.jobParameters)
            {
                if (GDJP.HasWorkerRequirement)
                {
                    WorkerRequirement WR = GDJP.workerRequirement;

                    if (WR.HasRelevantMinHp && !p.FulfilsHPRrequirement(WR))
                    {
                        continue;
                    }

                    if (WR.HasHediffRequirement && !p.FulfilsHediffRequirement(WR))
                    {
                        continue;
                    }

                    if (WR.HasFactionRequirement && !p.FulfilsFactionRequirement(WR))
                    {
                        continue;
                    }

                    if (WR.HasLifeStageRequirement && !p.FulfilsLifeStageRequirement(WR))
                    {
                        continue;
                    }

                    return(GDJP);
                }
            }

            return(null);
        }