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); }
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); }