Пример #1
0
        public static bool DetermineNextJob(Pawn_JobTracker __instance, ref ThinkResult __result, out ThinkTreeDef thinkTree)
        {
            ThinkResult constantThinkTreeJob = __instance.DetermineNextConstantThinkTreeJob();

            if (constantThinkTreeJob.Job != null)
            {
                thinkTree = __instance.pawn.thinker.ConstantThinkTree;
                __result  = constantThinkTreeJob;
                return(false);
            }
            ThinkResult thinkResult = ThinkResult.NoJob;

            try
            {
                thinkResult = __instance.pawn.thinker.MainThinkNodeRoot.TryIssueJobPackage(__instance.pawn, new JobIssueParams());
            }
            catch (Exception ex)
            {
                JobUtility.TryStartErrorRecoverJob(__instance.pawn, __instance.pawn.ToStringSafe <Pawn>() + " threw exception while determining job (main)", ex);
                thinkTree = null;
                __result  = ThinkResult.NoJob;
                return(false);
            }
            finally
            {
            }
            thinkTree = __instance?.pawn?.thinker?.MainThinkTree; //changed
            if (thinkTree == null)                                //changed
            {
                thinkResult = ThinkResult.NoJob;                  //changed
            }
            __result = thinkResult;
            return(false);
        }
Пример #2
0
        private static ThinkResult DetermineNextJob2(Pawn_JobTracker __instance, out ThinkTreeDef thinkTree)
        {
            ThinkResult result = __instance.DetermineNextConstantThinkTreeJob();

            if (result.Job != null)
            {
                thinkTree = __instance.pawn.thinker.ConstantThinkTree;
                return(result);
            }

            ThinkResult result2 = ThinkResult.NoJob;

            try
            {
                result2 = __instance.pawn.thinker.MainThinkNodeRoot.TryIssueJobPackage(__instance.pawn, default);
            }
            catch (Exception exception)
            {
                JobUtility.TryStartErrorRecoverJob(__instance.pawn, __instance.pawn.ToStringSafe() + " threw exception while determining job (main)", exception);
                thinkTree = null;
                return(ThinkResult.NoJob);
            }
            finally
            {
            }

            thinkTree = __instance.pawn.thinker.MainThinkTree;
            return(result2);
        }
Пример #3
0
        private static ThinkResult DetermineNextJob2(Pawn_JobTracker __instance, out ThinkTreeDef thinkTree)
        {
            ThinkResult result = funcDetermineNextConstantThinkTreeJob(__instance);

            if (result.Job != null)
            {
                thinkTree = pawnFieldRef(__instance).thinker.ConstantThinkTree;
                return(result);
            }

            ThinkResult result2 = ThinkResult.NoJob;

            try
            {
                result2 = pawnFieldRef(__instance).thinker.MainThinkNodeRoot.TryIssueJobPackage(pawnFieldRef(__instance), default(JobIssueParams));
            }
            catch (Exception exception)
            {
                JobUtility.TryStartErrorRecoverJob(pawnFieldRef(__instance), pawnFieldRef(__instance).ToStringSafe() + " threw exception while determining job (main)", exception);
                thinkTree = null;
                return(ThinkResult.NoJob);
            }

            thinkTree = pawnFieldRef(__instance).thinker.MainThinkTree;
            return(result2);
        }
Пример #4
0
 public override string GetReport()
 {
     if (Takee == null || pawn.HostileTo(Takee))
     {
         return(base.GetReport());
     }
     return(JobUtility.GetResolvedJobReport(JobDefOf.Rescue.reportString, Takee));
 }
 public override string GetReport()
 {
     if (job.GetTarget(TargetIndex.A).Thing is Building_NutrientPasteDispenser && Deliveree != null)
     {
         return(JobUtility.GetResolvedJobReportRaw(job.def.reportString, ThingDefOf.MealNutrientPaste.label, ThingDefOf.MealNutrientPaste, Deliveree.LabelShort, Deliveree, "", ""));
     }
     return(base.GetReport());
 }
 public override string GetReport()
 {
     if (Victim != null)
     {
         return(JobUtility.GetResolvedJobReport(job.def.reportString, Victim));
     }
     return(base.GetReport());
 }
Пример #7
0
        public static bool CheckCurrentToilEndOrFail2(JobDriver __instance)
        {
            try
            {
                Toil curToil = get_CurToil2(__instance);
                List <Func <JobCondition> > listFuncJobConditions = __instance.globalFailConditions;
                if (listFuncJobConditions != null)
                {
                    for (int i = 0; i < listFuncJobConditions.Count; i++)
                    {
                        JobCondition jobCondition = listFuncJobConditions[i]();
                        if (jobCondition != JobCondition.Ongoing)
                        {
                            if (__instance.pawn.jobs.debugLog)
                            {
                                __instance.pawn.jobs.DebugLogEvent(__instance.GetType().Name + " ends current job " + __instance.job.ToStringSafe() + " because of globalFailConditions[" + i + "]");
                            }

                            __instance.EndJobWith(jobCondition);
                            return(true);
                        }
                    }
                }

                if (curToil != null && curToil.endConditions != null)
                {
                    for (int j = 0; j < curToil.endConditions.Count; j++)
                    {
                        JobCondition jobCondition2 = curToil.endConditions[j]();
                        if (jobCondition2 != JobCondition.Ongoing)
                        {
                            if (__instance.pawn.jobs.debugLog)
                            {
                                __instance.pawn.jobs.DebugLogEvent(__instance.GetType().Name + " ends current job " + __instance.job.ToStringSafe() + " because of toils[" + curToilIndex + "].endConditions[" + j + "]");
                            }

                            __instance.EndJobWith(jobCondition2);
                            return(true);
                        }
                    }
                }

                return(false);
            }
            catch (Exception exception)
            {
                JobUtility.TryStartErrorRecoverJob(__instance.pawn, "Exception in CheckCurrentToilEndOrFail for pawn " + __instance.pawn.ToStringSafe(), exception, __instance);
                return(true);
            }
        }
 public static void RunThreadedUpdate()
 {
     Time.Update();
     foreach (var v in ActiveComponents)
     {
         if (v.ShouldThreadedUpdate)
         {
             JobUtility.EnqueueJobOnMostFree(v.ThreadedUpdate());
         }
     }
     while (JobUtility.HasJobs())
     {
         JobUtility.RunJobOnMainThread();
     }
 }
        // Token: 0x0600003D RID: 61 RVA: 0x00003EA0 File Offset: 0x000020A0
        public override string GetReport()
        {
            bool   flag = this.job.GetTarget(TargetIndex.A).Thing is Building_NutrientPasteDispenser && this.Deliveree != null;
            string result;

            if (flag)
            {
                result = JobUtility.GetResolvedJobReportRaw(this.job.def.reportString, ThingDefOf.MealNutrientPaste.label, ThingDefOf.MealNutrientPaste, this.Deliveree.LabelShort, this.Deliveree, "", "");
            }
            else
            {
                result = base.GetReport();
            }
            return(result);
        }
Пример #10
0
        public override string GetReport()
        {
            if (usingNutrientPasteDispenser)
            {
                return(JobUtility.GetResolvedJobReportRaw(job.def.reportString, ThingDefOf.MealNutrientPaste.label, ThingDefOf.MealNutrientPaste, "", "", "", ""));
            }
            Thing thing = job.targetA.Thing;

            if (thing != null && thing.def.ingestible != null)
            {
                if (!thing.def.ingestible.ingestReportStringEat.NullOrEmpty() && (thing.def.ingestible.ingestReportString.NullOrEmpty() || (int)pawn.RaceProps.intelligence < 1))
                {
                    return(thing.def.ingestible.ingestReportStringEat.Formatted(job.targetA.Thing.LabelShort, job.targetA.Thing));
                }
                if (!thing.def.ingestible.ingestReportString.NullOrEmpty())
                {
                    return(thing.def.ingestible.ingestReportString.Formatted(job.targetA.Thing.LabelShort, job.targetA.Thing));
                }
            }
            return(base.GetReport());
        }
Пример #11
0
 public static void SearchForWorkGeneral(List <Pawn> pawns)
 {
     foreach (var pawn in pawns)
     {
         if (pawn.mindState.IsIdle || pawn.mindState.lastJobTag == JobTag.SatisfyingNeeds)
         {
             ThinkResult result = ThinkResult.NoJob;
             try
             {
                 result = pawn.thinker.MainThinkNodeRoot.TryIssueJobPackage(pawn, default(JobIssueParams));
             }
             catch (Exception exception)
             {
                 JobUtility.TryStartErrorRecoverJob(pawn, pawn.ToStringSafe() + " threw exception while determining job (main)", exception);
             }
             if (result.Job != null && result.Job.def != JobDefOf.GotoWander)
             {
                 pawn.jobs.TryTakeOrderedJob(result.Job);
             }
         }
     }
 }
Пример #12
0
 public static void SearchForSocialRelax(List <Pawn> pawns)
 {
     foreach (var pawn in pawns)
     {
         if (!pawn.mindState.IsIdle && pawn.CurJobDef != JobDefOf.SocialRelax)
         {
             Job result = null;
             try
             {
                 var joyGiver = new JoyGiver_SocialRelax();
                 result = joyGiver.TryGiveJob(pawn);
             }
             catch (Exception exception)
             {
                 JobUtility.TryStartErrorRecoverJob(pawn, pawn.ToStringSafe() + " threw exception while determining job (main)", exception);
             }
             if (result != null && result.def != JobDefOf.GotoWander)
             {
                 pawn.jobs.TryTakeOrderedJob(result);
             }
         }
     }
 }
Пример #13
0
 public static void LightsOut(List <Pawn> pawns)
 {
     foreach (var pawn in pawns)
     {
         if (!pawn.mindState.IsIdle && pawn.CurJobDef != JobDefOf.LayDown)
         {
             ThinkResult result = ThinkResult.NoJob;
             try
             {
                 var joyGiver = new JobGiver_GetRest();
                 joyGiver.ResolveReferences();
                 result = joyGiver.TryIssueJobPackage(pawn, default(JobIssueParams));
             }
             catch (Exception exception)
             {
                 JobUtility.TryStartErrorRecoverJob(pawn, pawn.ToStringSafe() + " threw exception while determining job (main)", exception);
             }
             if (result.Job != null && result.Job.def != JobDefOf.GotoWander)
             {
                 pawn.jobs.TryTakeOrderedJob(result.Job);
             }
         }
     }
 }
Пример #14
0
 void OnEnable()
 {
     JobUtility.InitializeWorkers();
 }
Пример #15
0
        public static bool DriverTick(JobDriver __instance)
        {
            try
            {
                __instance.ticksLeftThisToil--;
                __instance.debugTicksSpentThisToil++;
                if (get_CurToil2(__instance) == null)
                {
                    if (!__instance.pawn.stances.FullBodyBusy || get_CanStartNextToilInBusyStance2(__instance))
                    {
                        __instance.ReadyForNextToil();
                    }
                }
                else
                {
                    if (CheckCurrentToilEndOrFail2(__instance))
                    {
                        return(false);
                    }

                    if (curToilCompleteMode(__instance) == ToilCompleteMode.Delay)
                    {
                        if (__instance.ticksLeftThisToil > 0)
                        {
                            goto IL_0099;
                        }

                        __instance.ReadyForNextToil();
                    }
                    else
                    {
                        if (curToilCompleteMode(__instance) != ToilCompleteMode.FinishedBusy || __instance.pawn.stances.FullBodyBusy)
                        {
                            goto IL_0099;
                        }

                        __instance.ReadyForNextToil();
                    }

                    return(false);
                }

                goto end_IL_0000;
IL_01b8:
                if (__instance.job.mote != null)
                {
                    __instance.job.mote.Maintain();
                }

                goto end_IL_0000;
IL_0099:
                if (wantBeginNextToil(__instance))
                {
                    TryActuallyStartNextToil(__instance);
                    return(false);
                }

                if (curToilCompleteMode(__instance) == ToilCompleteMode.Instant && __instance.debugTicksSpentThisToil > 300)
                {
                    Log.Error(string.Concat(__instance.pawn, " had to be broken from frozen state. He was doing job ", __instance.job, ", toilindex=", curToilIndex));
                    __instance.ReadyForNextToil();
                    return(false);
                }

                Job startingJob   = __instance.pawn.CurJob;
                int startingJobId = startingJob.loadID;
                if (get_CurToil2(__instance) != null && get_CurToil2(__instance).preTickActions != null)
                {
                    Toil curToil = get_CurToil2(__instance);
                    for (int i = 0; i < curToil.preTickActions.Count; i++)
                    {
                        curToil.preTickActions[i]();
                        if (JobChanged() || get_CurToil2(__instance) != curToil || wantBeginNextToil(__instance))
                        {
                            return(false);
                        }
                    }
                }
                Toil gct = get_CurToil2(__instance);
                if (gct.tickAction == null)
                {
                    goto IL_01b8;
                }

                gct.tickAction();
                if (!JobChanged())
                {
                    goto IL_01b8;
                }

end_IL_0000:
                bool JobChanged()
                {
                    if (__instance.pawn.CurJob == startingJob)
                    {
                        return(__instance.pawn.CurJob.loadID != startingJobId);
                    }

                    return(true);
                }
            }
            catch (Exception exception)
            {
                JobUtility.TryStartErrorRecoverJob(__instance.pawn, "Exception in JobDriver tick for pawn " + __instance.pawn.ToStringSafe(), exception, __instance);
            }
            return(false);
        }
Пример #16
0
        public static bool TryActuallyStartNextToil(JobDriver __instance)
        {
            if (!__instance.pawn.Spawned || (__instance.pawn.stances.FullBodyBusy && !get_CanStartNextToilInBusyStance2(__instance)) || __instance.job == null || __instance.pawn.CurJob != __instance.job)
            {
                return(false);
            }

            /*
             * if (get_HaveCurToil2(__instance))
             * {
             *  get_CurToil2(__instance).Cleanup(curToilIndex(__instance), __instance);
             * }
             */
            if (curToilIndex(__instance) >= 0 && curToilIndex(__instance) < toils(__instance).Count&& __instance.job != null)
            {
                if (__instance.pawn.CurJob == __instance.job)
                {
                    Toil curToil2 = toils(__instance)[curToilIndex(__instance)];
                    if (curToil2 != null)
                    {
                        curToil2.Cleanup(curToilIndex(__instance), __instance);
                    }
                }
            }

            if (nextToilIndex(__instance) >= 0)
            {
                curToilIndex(__instance)  = nextToilIndex(__instance);
                nextToilIndex(__instance) = -1;
            }
            else
            {
                curToilIndex(__instance)++;
            }

            wantBeginNextToil(__instance) = false;

            if (!get_HaveCurToil2(__instance))
            {
                if (__instance.pawn.stances != null && __instance.pawn.stances.curStance.StanceBusy)
                {
                    Log.ErrorOnce(__instance.pawn.ToStringSafe() + " ended job " + __instance.job.ToStringSafe() + " due to running out of toils during a busy stance.", 6453432);
                }

                __instance.EndJobWith(JobCondition.Succeeded);
                return(false);
            }


            __instance.debugTicksSpentThisToil = 0;
            Toil curToil = get_CurToil2(__instance);

            if (curToil != null)
            {
                __instance.ticksLeftThisToil    = curToil.defaultDuration;
                curToilCompleteMode(__instance) = curToil.defaultCompleteMode;
            }
            if (CheckCurrentToilEndOrFail2(__instance))
            {
                return(false);
            }

            curToil = get_CurToil2(__instance);
            Toil gct = get_CurToil2(__instance);

            if (gct != null && gct.preInitActions != null)
            {
                List <Action> preInitActions = gct.preInitActions;
                for (int i = 0; i < preInitActions.Count; i++)
                {
                    try
                    {
                        gct = get_CurToil2(__instance);
                        if (gct != null)
                        {
                            preInitActions = gct.preInitActions;
                        }
                        else
                        {
                            break;
                        }
                        preInitActions[i]();
                    }
                    catch (Exception exception)
                    {
                        JobUtility.TryStartErrorRecoverJob(__instance.pawn, "JobDriver threw exception in preInitActions[" + i + "] for pawn " + __instance.pawn.ToStringSafe(), exception, __instance);
                        return(false);
                    }

                    if (get_CurToil2(__instance) != curToil)
                    {
                        break;
                    }
                    gct = get_CurToil2(__instance);
                    if (gct != null)
                    {
                        preInitActions = gct.preInitActions;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Toil gct2 = get_CurToil2(__instance);

            if (gct2 == curToil)
            {
                if (gct2 != null)
                {
                    if (gct2.initAction != null)
                    {
                        try
                        {
                            gct2.initAction();
                        }
                        catch (Exception exception2)
                        {
                            JobUtility.TryStartErrorRecoverJob(__instance.pawn, "JobDriver threw exception in initAction for pawn " + __instance.pawn.ToStringSafe(), exception2, __instance);
                            return(false);
                        }
                    }

                    if (!__instance.ended && curToilCompleteMode(__instance) == ToilCompleteMode.Instant && get_CurToil2(__instance) == curToil)
                    {
                        __instance.ReadyForNextToil();
                    }
                }
            }
            return(false);
        }
Пример #17
0
 void OnDisable()
 {
     JobUtility.Shutdown();
 }
Пример #18
0
        public static bool StartJob(Pawn_JobTracker __instance, Job newJob, JobCondition lastJobEndCondition = JobCondition.None, ThinkNode jobGiver = null, bool resumeCurJobAfterwards = false, bool cancelBusyStances = true, ThinkTreeDef thinkTree = null, JobTag?tag = null, bool fromQueue = false, bool canReturnCurJobToPool = false)
        {
            __instance.startingNewJob = true;
            try
            {
                if (!fromQueue && (!Find.TickManager.Paused || lastJobGivenAtFrame == RealTime.frameCount))
                {
                    jobsGivenThisTick++;
                    if (Prefs.DevMode)
                    {
                        jobsGivenThisTickTextual = jobsGivenThisTickTextual + "(" + newJob + ") ";
                    }
                }
                lastJobGivenAtFrame = RealTime.frameCount;
                if (jobsGivenThisTick > 10)
                {
                    string text = jobsGivenThisTickTextual;
                    jobsGivenThisTick         = 0;
                    jobsGivenThisTickTextual  = "";
                    __instance.startingNewJob = false;
                    pawnFieldRef(__instance).ClearReservationsForJob(newJob);
                    JobUtility.TryStartErrorRecoverJob(pawnFieldRef(__instance), string.Concat(new string[]
                    {
                        pawnFieldRef(__instance).ToStringSafe <Pawn>(),
                        " started 10 jobs in one tick. newJob=",
                        newJob.ToStringSafe <Job>(),
                        " jobGiver=",
                        jobGiver.ToStringSafe <ThinkNode>(),
                        " jobList=",
                        text
                    }), null, null);
                }
                else
                {
                    if (__instance.debugLog)
                    {
                        __instance.DebugLogEvent(string.Concat(new object[]
                        {
                            "StartJob [",
                            newJob,
                            "] lastJobEndCondition=",
                            lastJobEndCondition,
                            ", jobGiver=",
                            jobGiver,
                            ", cancelBusyStances=",
                            cancelBusyStances.ToString()
                        }));
                    }
                    if (cancelBusyStances && pawnFieldRef(__instance).stances.FullBodyBusy)
                    {
                        pawnFieldRef(__instance).stances.CancelBusyStanceHard();
                    }
                    if (__instance.curJob != null)
                    {
                        if (lastJobEndCondition == JobCondition.None)
                        {
                            Log.Warning(string.Concat(new object[]
                            {
                                pawnFieldRef(__instance),
                                " starting job ",
                                newJob,
                                " from JobGiver ",
                                newJob.jobGiver,
                                " while already having job ",
                                __instance.curJob,
                                " without a specific job end condition."
                            }), false);
                            lastJobEndCondition = JobCondition.InterruptForced;
                        }
                        if (resumeCurJobAfterwards && __instance.curJob.def.suspendable)
                        {
                            __instance.jobQueue.EnqueueFirst(__instance.curJob, null);
                            if (__instance.debugLog)
                            {
                                __instance.DebugLogEvent("   JobQueue EnqueueFirst curJob: " + __instance.curJob);
                            }
                            CleanupCurrentJob(__instance, lastJobEndCondition, false, cancelBusyStances, false);
                        }
                        else
                        {
                            CleanupCurrentJob(__instance, lastJobEndCondition, true, cancelBusyStances, canReturnCurJobToPool);
                        }
                    }
                    if (newJob == null)
                    {
                        Log.Warning(pawnFieldRef(__instance) + " tried to start doing a null job.", false);
                    }
                    else
                    {
                        newJob.startTick = Find.TickManager.TicksGame;
                        if (pawnFieldRef(__instance).Drafted || newJob.playerForced)
                        {
                            newJob.ignoreForbidden    = true;
                            newJob.ignoreDesignations = true;
                        }
                        __instance.curJob = newJob;
                        __instance.curJob.jobGiverThinkTree = thinkTree;
                        __instance.curJob.jobGiver          = jobGiver;
                        __instance.curDriver = __instance.curJob.MakeDriver(pawnFieldRef(__instance));
                        if (__instance.curDriver.TryMakePreToilReservations(!fromQueue))
                        {
                            Job job = __instance.TryOpportunisticJob(newJob);
                            if (job != null)
                            {
                                __instance.jobQueue.EnqueueFirst(newJob, null);
                                __instance.curJob    = null;
                                __instance.curDriver = null;
                                __instance.StartJob(job, JobCondition.None, null, false, true, null, null, false, false);
                            }
                            else
                            {
                                if (tag != null)
                                {
                                    pawnFieldRef(__instance).mindState.lastJobTag = tag.Value;
                                }
                                __instance.curDriver.SetInitialPosture();
                                __instance.curDriver.Notify_Starting();
                                //JobDriver_Patch.SetupToils(pawnFieldRef(__instance));
                                __instance.curDriver.ReadyForNextToil();
                            }
                        }
                        else if (fromQueue)
                        {
                            __instance.EndCurrentJob(JobCondition.QueuedNoLongerValid, true, true);
                        }
                        else
                        {
                            Log.Warning("TryMakePreToilReservations() returned false for a non-queued job right after StartJob(). This should have been checked before. curJob=" + __instance.curJob.ToStringSafe <Job>(), false);
                            __instance.EndCurrentJob(JobCondition.Errored, true, true);
                        }
                    }
                }
            }
            finally
            {
                __instance.startingNewJob = false;
            }

            return(false);
        }
Пример #19
0
 public static bool StartJob(Pawn_JobTracker __instance,
                             Job newJob,
                             JobCondition lastJobEndCondition = JobCondition.None,
                             ThinkNode jobGiver          = null,
                             bool resumeCurJobAfterwards = false,
                             bool cancelBusyStances      = true,
                             ThinkTreeDef thinkTree      = null,
                             JobTag?tag                 = null,
                             bool fromQueue             = false,
                             bool canReturnCurJobToPool = false)
 {
     __instance.startingNewJob = true;
     try
     {
         if (!fromQueue && (!Find.TickManager.Paused || __instance.lastJobGivenAtFrame == RealTime.frameCount))
         {
             ++__instance.jobsGivenThisTick;
             if (Prefs.DevMode)
             {
                 __instance.jobsGivenThisTickTextual = __instance.jobsGivenThisTickTextual + "(" + newJob.ToString() + ") ";
             }
         }
         __instance.lastJobGivenAtFrame = RealTime.frameCount;
         if (__instance.jobsGivenThisTick > 10)
         {
             string givenThisTickTextual = __instance.jobsGivenThisTickTextual;
             __instance.jobsGivenThisTick        = 0;
             __instance.jobsGivenThisTickTextual = "";
             __instance.startingNewJob           = false;
             __instance.pawn.ClearReservationsForJob(newJob);
             JobUtility.TryStartErrorRecoverJob(__instance.pawn, __instance.pawn.ToStringSafe <Pawn>() + " started 10 jobs in one tick. newJob=" + newJob.ToStringSafe <Job>() + " jobGiver=" + jobGiver.ToStringSafe <ThinkNode>() + " jobList=" + givenThisTickTextual);
         }
         else
         {
             if (__instance.debugLog)
             {
                 __instance.DebugLogEvent("StartJob [" + (object)newJob + "] lastJobEndCondition=" + (object)lastJobEndCondition + ", jobGiver=" + (object)jobGiver + ", cancelBusyStances=" + cancelBusyStances.ToString());
             }
             Pawn_StanceTracker stances = __instance.pawn.stances;             //changed
             if (cancelBusyStances && stances != null && stances.FullBodyBusy) //changed
             {
                 stances.CancelBusyStanceHard();
             }
             if (__instance.curJob != null)
             {
                 if (lastJobEndCondition == JobCondition.None)
                 {
                     Log.Warning(__instance.pawn.ToString() + " starting job " + (object)newJob + " from JobGiver " + (object)newJob.jobGiver + " while already having job " + (object)__instance.curJob + " without a specific job end condition.");
                     lastJobEndCondition = JobCondition.InterruptForced;
                 }
                 if (resumeCurJobAfterwards && __instance.curJob.def.suspendable)
                 {
                     __instance.jobQueue.EnqueueFirst(__instance.curJob);
                     if (__instance.debugLog)
                     {
                         __instance.DebugLogEvent("   JobQueue EnqueueFirst curJob: " + (object)__instance.curJob);
                     }
                     __instance.CleanupCurrentJob(lastJobEndCondition, false, cancelBusyStances);
                 }
                 else
                 {
                     __instance.CleanupCurrentJob(lastJobEndCondition, true, cancelBusyStances, canReturnCurJobToPool);
                 }
             }
             if (newJob == null)
             {
                 Log.Warning(__instance.pawn.ToString() + " tried to start doing a null job.");
             }
             else
             {
                 newJob.startTick = Find.TickManager.TicksGame;
                 if (__instance.pawn.Drafted || newJob.playerForced)
                 {
                     newJob.ignoreForbidden    = true;
                     newJob.ignoreDesignations = true;
                 }
                 __instance.curJob = newJob;
                 __instance.curJob.jobGiverThinkTree = thinkTree;
                 __instance.curJob.jobGiver          = jobGiver;
                 JobDriver cDriver = __instance.curJob.MakeDriver(__instance.pawn); //changed
                 __instance.curDriver = cDriver;                                    //changed
                 bool flag = fromQueue;
                 if (__instance.curDriver.TryMakePreToilReservations(!flag))
                 {
                     Job newJob1 = __instance.TryOpportunisticJob(newJob);
                     if (newJob1 != null)
                     {
                         __instance.jobQueue.EnqueueFirst(newJob);
                         __instance.curJob    = (Job)null;
                         __instance.curDriver = (JobDriver)null;
                         __instance.StartJob(newJob1);
                     }
                     else
                     {
                         if (tag.HasValue)
                         {
                             __instance.pawn.mindState.lastJobTag = tag.Value;
                         }
                         cDriver.SetInitialPosture(); //changed
                         cDriver.Notify_Starting();   //changed
                         cDriver.SetupToils();        //changed
                         cDriver.ReadyForNextToil();  //changed
                     }
                 }
                 else if (flag)
                 {
                     __instance.EndCurrentJob(JobCondition.QueuedNoLongerValid);
                 }
                 else
                 {
                     Log.Warning("TryMakePreToilReservations() returned false for a non-queued job right after StartJob(). This should have been checked before. curJob=" + __instance.curJob.ToStringSafe <Job>());
                     __instance.EndCurrentJob(JobCondition.Errored);
                 }
             }
         }
     }
     finally
     {
         __instance.startingNewJob = false;
     }
     return(false);
 }
 void Start()
 {
     JobUtility.EnqueueJobOnMostFree(ComplicatedJob());
 }