protected override Job TryGiveJob(Pawn pawn)
        {
            string myDebugStr = PreRetrieveDebug ? pawn.LabelShort + " AiCorpse_JobGiver TryGiveJob " : "";

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

            CorpseJobDef DefToUse = pawn.RetrieveCorpseJobDef(out MyDebug, PreRetrieveDebug);

            if (DefToUse == null)
            {
                if (PreRetrieveDebug)
                {
                    Log.Warning(myDebugStr + " found no CorpseJobDef; exit");
                }
                return(null);
            }

            IEnumerable <CorpseRecipeSettings> CRSList = pawn.RetrieveCorpseRecipeSettings(DefToUse, MyDebug);

            if (CRSList.EnumerableNullOrEmpty())
            {
                if (MyDebug)
                {
                    Log.Warning(myDebugStr + " found no CorpseRecipeSettings; exit");
                }
                return(null);
            }


            foreach (CorpseRecipeSettings CRS in CRSList)
            {
                Corpse FoundCorpse = pawn.GetClosestCompatibleCorpse(CRS.target, MyDebug);

                if (FoundCorpse.NegligibleThing())
                {
                    if (MyDebug)
                    {
                        Log.Warning(myDebugStr + "corpse " + FoundCorpse?.Label + " " + FoundCorpse?.Position + " is negligible; exit");
                    }
                    continue;
                }

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

                return(job);
            }
            return(null);
        }
        public static CorpseJobDef RetrieveCorpseJobDef(this Pawn p, out bool outDebug, bool MyDebug = false)
        {
            string       myDebugStr = MyDebug ? p.ThingID + " MoharAiJob.RetrieveDefs.RetrieveCorpseJobDef - " : string.Empty;
            CorpseJobDef DefToUse   = DefDatabase <CorpseJobDef> .AllDefs.Where(cjd => cjd.workerPawnKind.Contains(p.kindDef)).FirstOrFallback(null);

            outDebug = false;
            if (DefToUse == null || DefToUse.IsEmpty)
            {
                if (MyDebug)
                {
                    Log.Warning(myDebugStr + "found no CorpseJobDef for " + p.kindDef + "; exit");
                }
                return(null);
            }
            outDebug = DefToUse.debug;

            //if (MyDebug) Log.Warning(myDebugStr + "found CJD for " + p.kindDef + ", debug is now:" + outDebug + "; OK");

            return(DefToUse);
        }
        public static IEnumerable <CorpseRecipeSettings> RetrieveCorpseRecipeSettings(this Pawn p, CorpseJobDef CJD, bool MyDebug = false)
        {
            string myDebugStr = MyDebug ? p.ThingID + " MoharAiJob.RetrieveDefs.RetrieveCorpseRecipeSettings " : string.Empty;

            IEnumerable <CorpseRecipeSettings> CRSList = p.WorkerFulfillsRequirements(CJD, MyDebug);

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

            if (!CRSList.Any(c => c.HasTargetSpec))
            {
                if (MyDebug)
                {
                    Log.Warning(myDebugStr + "CRS has no Corpse category def; exit");
                }
                return(null);
            }

            //if (MyDebug) Log.Warning(myDebugStr + "found CRS ("+CRSList.Count()+") OK");

            return(CRSList);
        }
Example #4
0
        // By default return null
        // Browses all corpse recipes until find an ok one
        public static IEnumerable <CorpseRecipeSettings> WorkerFulfillsRequirements(this Pawn p, CorpseJobDef CJD, bool debug = false)
        {
            string DebugStr = debug ? "WorkerFulfillsRequirements - " : string.Empty;

            //if (p.NegligiblePawn() || CJD.IsEmpty)
            //if (p.NegligiblePawnDebug(debug) || CJD.IsEmpty)
            if (CJD.IsEmpty)
            {
                //if (debug) Log.Warning("negligible pawn or empy CJD");
                if (debug)
                {
                    Log.Warning("empy CJD");
                }
                yield break;
            }
            if (debug)
            {
                DebugStr = p.ThingID + DebugStr;
            }

            foreach (CorpseRecipeSettings CRS in CJD.corpseRecipeList)
            {
                if (!CRS.HasWorkerSpec)
                {
                    if (debug)
                    {
                        Log.Warning(DebugStr + " no workrequirement, yield");
                    }
                    yield return(CRS);
                }
                else
                {
                    WorkerRequirement WR = CRS.worker;

                    if (WR.HasRelevantMinHp && !p.FulfilsHPRrequirement(WR))
                    {
                        if (debug)
                        {
                            Log.Warning(DebugStr + " HP requirement ko, continue");
                        }
                        continue;
                    }

                    if (WR.HasHediffRequirement && !p.FulfilsHediffRequirement(WR))
                    {
                        if (debug)
                        {
                            Log.Warning(DebugStr + " Hediff requirement ko, continue");
                        }
                        continue;
                    }

                    if (WR.HasFactionRequirement && !p.FulfilsFactionRequirement(WR))
                    {
                        if (debug)
                        {
                            Log.Warning(DebugStr + " Faction requirement ko, continue");
                        }
                        continue;
                    }

                    if (WR.HasLifeStageRequirement && !p.FulfilsLifeStageRequirement(WR))
                    {
                        if (debug)
                        {
                            Log.Warning(DebugStr + " lifestage requirement ko, continue");
                        }
                        continue;
                    }

                    if (WR.HasRelevantChancesToWorkDivider && !p.FulfilsChancesToWorkDivider(WR))
                    {
                        if (debug)
                        {
                            Log.Warning(DebugStr + " had not luck, continue");
                        }
                        continue;
                    }
                    yield return(CRS);
                }
            }

            yield break;
        }