private void LogCouldNotReserveError(Pawn claimant, Job job, LocalTargetInfo target, int maxPawns, int stackCount, ReservationLayerDef layer) { Job curJob = claimant.CurJob; string text = "null"; int num = -1; if (curJob != null) { text = curJob.ToString(); if (claimant.jobs.curDriver != null) { num = claimant.jobs.curDriver.CurToilIndex; } } Pawn pawn = this.FirstRespectedReserver(target, claimant); string text2 = "null"; int num2 = -1; if (pawn != null) { Job curJob2 = pawn.CurJob; if (curJob2 != null) { text2 = curJob2.ToString(); if (pawn.jobs.curDriver != null) { num2 = pawn.jobs.curDriver.CurToilIndex; } } } Log.Error(string.Concat(new object[] { "Could not reserve ", target, "/", layer, " for ", claimant, " for job ", job.ToStringSafe <Job>(), " (now doing job ", text, "(curToil=", num, ")) for maxPawns ", maxPawns, " and stackCount ", stackCount, ". Existing reserver: ", pawn, " doing job ", text2, "(curToil=", num2, ")" })); }
private void LogCouldNotReserveError(Pawn claimant, Job job, LocalTargetInfo target, int maxPawns, int stackCount, ReservationLayerDef layer) { Job curJob = claimant.CurJob; string text = "null"; int num = -1; if (curJob != null) { text = curJob.ToString(); if (claimant.jobs.curDriver != null) { num = claimant.jobs.curDriver.CurToilIndex; } } string text2 = (!target.HasThing || target.Thing.def.stackLimit == 1) ? string.Empty : ("(current stack count: " + target.Thing.stackCount + ")"); string text3 = "Could not reserve " + target.ToStringSafe() + text2 + " (layer: " + layer.ToStringSafe() + ") for " + claimant.ToStringSafe() + " for job " + job.ToStringSafe() + " (now doing job " + text + "(curToil=" + num + ")) for maxPawns " + maxPawns + " and stackCount " + stackCount + "."; Pawn pawn = FirstRespectedReserver(target, claimant); if (pawn != null) { string text4 = "null"; int num2 = -1; Job curJob2 = pawn.CurJob; if (curJob2 != null) { text4 = curJob2.ToStringSafe(); if (pawn.jobs.curDriver != null) { num2 = pawn.jobs.curDriver.CurToilIndex; } } string text5 = text3; text3 = text5 + " Existing reserver: " + pawn.ToStringSafe() + " doing job " + text4 + " (toilIndex=" + num2 + ")"; } else { text3 += " No existing reserver."; } Pawn pawn2 = map.physicalInteractionReservationManager.FirstReserverOf(target); if (pawn2 != null) { text3 = text3 + " Physical interaction reserver: " + pawn2.ToStringSafe(); } Log.Error(text3); }
public void Cleanup(JobCondition condition) { for (int i = 0; i < globalFinishActions.Count; i++) { try { globalFinishActions[i](); } catch (Exception ex) { Log.Error("Pawn " + pawn.ToStringSafe() + " threw exception while executing a global finish action (" + i + "), jobDriver=" + this.ToStringSafe() + ", job=" + job.ToStringSafe() + ": " + ex); } } if (curToilIndex >= 0 && curToilIndex < toils.Count) { toils[curToilIndex].Cleanup(curToilIndex, this); } }
public bool TryTakeOrderedJob(Job job, JobTag tag = JobTag.Misc) { if (this.debugLog) { this.DebugLogEvent("TryTakeOrderedJob " + job); } job.playerForced = true; bool result; if (this.curJob != null && this.curJob.JobIsSameAs(job)) { result = true; } else { bool flag = this.pawn.jobs.IsCurrentJobPlayerInterruptible(); bool flag2 = this.pawn.mindState.IsIdle || this.pawn.CurJob == null || this.pawn.CurJob.def.isIdle; bool isDownEvent = KeyBindingDefOf.QueueOrder.IsDownEvent; if (isDownEvent) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.QueueOrders, KnowledgeAmount.NoteTaught); } if (flag && (!isDownEvent || flag2)) { this.pawn.stances.CancelBusyStanceSoft(); if (this.debugLog) { this.DebugLogEvent(" Queueing job"); } this.ClearQueuedJobs(); if (job.TryMakePreToilReservations(this.pawn)) { this.jobQueue.EnqueueFirst(job, new JobTag?(tag)); if (this.curJob != null) { this.curDriver.EndJobWith(JobCondition.InterruptForced); } else { this.CheckForJobOverride(); } result = true; } else { Log.Warning("TryMakePreToilReservations() returned false right after TryTakeOrderedJob(). This should have been checked before. job=" + job.ToStringSafe <Job>(), false); this.pawn.ClearReservationsForJob(job); result = false; } } else if (isDownEvent) { if (job.TryMakePreToilReservations(this.pawn)) { this.jobQueue.EnqueueLast(job, new JobTag?(tag)); result = true; } else { Log.Warning("TryMakePreToilReservations() returned false right after TryTakeOrderedJob(). This should have been checked before. job=" + job.ToStringSafe <Job>(), false); this.pawn.ClearReservationsForJob(job); result = false; } } else { this.ClearQueuedJobs(); if (job.TryMakePreToilReservations(this.pawn)) { this.jobQueue.EnqueueLast(job, new JobTag?(tag)); result = true; } else { Log.Warning("TryMakePreToilReservations() returned false right after TryTakeOrderedJob(). This should have been checked before. job=" + job.ToStringSafe <Job>(), false); this.pawn.ClearReservationsForJob(job); result = false; } } } return(result); }
public void StartJob(Job newJob, JobCondition lastJobEndCondition = JobCondition.None, ThinkNode jobGiver = null, bool resumeCurJobAfterwards = false, bool cancelBusyStances = true, ThinkTreeDef thinkTree = null, JobTag?tag = null, bool fromQueue = false) { this.startingNewJob = true; try { if (!fromQueue && (!Find.TickManager.Paused || this.lastJobGivenAtFrame == RealTime.frameCount)) { this.jobsGivenThisTick++; this.jobsGivenThisTickTextual = this.jobsGivenThisTickTextual + "(" + newJob.ToString() + ") "; } this.lastJobGivenAtFrame = RealTime.frameCount; if (this.jobsGivenThisTick > 10) { string text = this.jobsGivenThisTickTextual; this.jobsGivenThisTick = 0; this.jobsGivenThisTickTextual = ""; this.startingNewJob = false; this.pawn.ClearReservationsForJob(newJob); JobUtility.TryStartErrorRecoverJob(this.pawn, string.Concat(new string[] { this.pawn.ToStringSafe <Pawn>(), " started 10 jobs in one tick. newJob=", newJob.ToStringSafe <Job>(), " jobGiver=", jobGiver.ToStringSafe <ThinkNode>(), " jobList=", text }), null, null); } else { if (this.debugLog) { this.DebugLogEvent(string.Concat(new object[] { "StartJob [", newJob, "] lastJobEndCondition=", lastJobEndCondition, ", jobGiver=", jobGiver, ", cancelBusyStances=", cancelBusyStances })); } if (cancelBusyStances && this.pawn.stances.FullBodyBusy) { this.pawn.stances.CancelBusyStanceHard(); } if (this.curJob != null) { if (lastJobEndCondition == JobCondition.None) { Log.Warning(string.Concat(new object[] { this.pawn, " starting job ", newJob, " from JobGiver ", this.pawn.mindState.lastJobGiver, " while already having job ", this.curJob, " without a specific job end condition." }), false); lastJobEndCondition = JobCondition.InterruptForced; } if (resumeCurJobAfterwards && this.curJob.def.suspendable) { this.jobQueue.EnqueueFirst(this.curJob, null); if (this.debugLog) { this.DebugLogEvent(" JobQueue EnqueueFirst curJob: " + this.curJob); } this.CleanupCurrentJob(lastJobEndCondition, false, cancelBusyStances); } else { this.CleanupCurrentJob(lastJobEndCondition, true, cancelBusyStances); } } if (newJob == null) { Log.Warning(this.pawn + " tried to start doing a null job.", false); } else { newJob.startTick = Find.TickManager.TicksGame; if (this.pawn.Drafted || newJob.playerForced) { newJob.ignoreForbidden = true; newJob.ignoreDesignations = true; } this.curJob = newJob; this.pawn.mindState.lastJobGiver = jobGiver; this.pawn.mindState.lastJobGiverThinkTree = thinkTree; this.curDriver = this.curJob.MakeDriver(this.pawn); if (this.curDriver.TryMakePreToilReservations()) { Job job = this.TryOpportunisticJob(newJob); if (job != null) { this.jobQueue.EnqueueFirst(newJob, null); this.curJob = null; this.curDriver = null; this.StartJob(job, JobCondition.None, null, false, true, null, null, false); } else { if (tag != null) { this.pawn.mindState.lastJobTag = tag.Value; } this.curDriver.SetInitialPosture(); this.curDriver.Notify_Starting(); this.curDriver.SetupToils(); this.curDriver.ReadyForNextToil(); } } else if (fromQueue) { this.EndCurrentJob(JobCondition.QueuedNoLongerValid, true); } else { Log.Warning("TryMakePreToilReservations() returned false for a non-queued job right after StartJob(). This should have been checked before. curJob=" + this.curJob.ToStringSafe <Job>(), false); this.EndCurrentJob(JobCondition.Errored, true); } } } } finally { this.startingNewJob = false; } }
public override string ToString() { return(((claimant == null) ? "null" : claimant.LabelShort) + ":" + job.ToStringSafe() + ", " + target.ToStringSafe() + ", " + layer.ToStringSafe() + ", " + maxPawns + ", " + stackCount); }
public bool TryTakeOrderedJob_NewTemp(Job job, JobTag?tag = JobTag.Misc, bool requestQueueing = false) { if (debugLog) { DebugLogEvent("TryTakeOrderedJob " + job); } job.playerForced = true; if (curJob != null && curJob.JobIsSameAs(job)) { return(true); } bool num = pawn.jobs.IsCurrentJobPlayerInterruptible(); bool flag = pawn.mindState.IsIdle || pawn.CurJob == null || pawn.CurJob.def.isIdle; bool isDownEvent = KeyBindingDefOf.QueueOrder.IsDownEvent; if (isDownEvent) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.QueueOrders, KnowledgeAmount.NoteTaught); } isDownEvent = isDownEvent || requestQueueing; if (num && (!isDownEvent || flag)) { pawn.stances.CancelBusyStanceSoft(); if (debugLog) { DebugLogEvent(" Queueing job"); } ClearQueuedJobs(); if (job.TryMakePreToilReservations(pawn, errorOnFailed: true)) { jobQueue.EnqueueFirst(job, tag); if (curJob != null) { curDriver.EndJobWith(JobCondition.InterruptForced); } else { CheckForJobOverride(); } return(true); } Log.Warning("TryMakePreToilReservations() returned false right after TryTakeOrderedJob(). This should have been checked before. job=" + job.ToStringSafe()); pawn.ClearReservationsForJob(job); return(false); } if (isDownEvent) { if (job.TryMakePreToilReservations(pawn, errorOnFailed: true)) { jobQueue.EnqueueLast(job, tag); return(true); } Log.Warning("TryMakePreToilReservations() returned false right after TryTakeOrderedJob(). This should have been checked before. job=" + job.ToStringSafe()); pawn.ClearReservationsForJob(job); return(false); } ClearQueuedJobs(); if (job.TryMakePreToilReservations(pawn, errorOnFailed: true)) { jobQueue.EnqueueLast(job, tag); return(true); } Log.Warning("TryMakePreToilReservations() returned false right after TryTakeOrderedJob(). This should have been checked before. job=" + job.ToStringSafe()); pawn.ClearReservationsForJob(job); return(false); }
public void StartJob(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) { startingNewJob = true; try { if (!fromQueue && (!Find.TickManager.Paused || lastJobGivenAtFrame == RealTime.frameCount)) { jobsGivenThisTick++; if (Prefs.DevMode) { jobsGivenThisTickTextual = jobsGivenThisTickTextual + "(" + newJob.ToString() + ") "; } } lastJobGivenAtFrame = RealTime.frameCount; if (jobsGivenThisTick > 10) { string text = jobsGivenThisTickTextual; jobsGivenThisTick = 0; jobsGivenThisTickTextual = ""; startingNewJob = false; pawn.ClearReservationsForJob(newJob); JobUtility.TryStartErrorRecoverJob(pawn, pawn.ToStringSafe() + " started 10 jobs in one tick. newJob=" + newJob.ToStringSafe() + " jobGiver=" + jobGiver.ToStringSafe() + " jobList=" + text); return; } if (debugLog) { DebugLogEvent(string.Concat("StartJob [", newJob, "] lastJobEndCondition=", lastJobEndCondition, ", jobGiver=", jobGiver, ", cancelBusyStances=", cancelBusyStances.ToString())); } if (cancelBusyStances && pawn.stances.FullBodyBusy) { pawn.stances.CancelBusyStanceHard(); } if (curJob != null) { if (lastJobEndCondition == JobCondition.None) { Log.Warning(string.Concat(pawn, " starting job ", newJob, " from JobGiver ", newJob.jobGiver, " while already having job ", curJob, " without a specific job end condition.")); lastJobEndCondition = JobCondition.InterruptForced; } if (resumeCurJobAfterwards && curJob.def.suspendable) { jobQueue.EnqueueFirst(curJob); if (debugLog) { DebugLogEvent(" JobQueue EnqueueFirst curJob: " + curJob); } CleanupCurrentJob(lastJobEndCondition, releaseReservations: false, cancelBusyStances); } else { CleanupCurrentJob(lastJobEndCondition, releaseReservations: true, cancelBusyStances, canReturnCurJobToPool); } } if (newJob == null) { Log.Warning(string.Concat(pawn, " tried to start doing a null job.")); return; } newJob.startTick = Find.TickManager.TicksGame; if (pawn.Drafted || newJob.playerForced) { newJob.ignoreForbidden = true; newJob.ignoreDesignations = true; } curJob = newJob; curJob.jobGiverThinkTree = thinkTree; curJob.jobGiver = jobGiver; curDriver = curJob.MakeDriver(pawn); bool flag = fromQueue; if (curDriver.TryMakePreToilReservations(!flag)) { Job job = TryOpportunisticJob(newJob); if (job != null) { jobQueue.EnqueueFirst(newJob); curJob = null; curDriver = null; StartJob(job); return; } if (tag.HasValue) { pawn.mindState.lastJobTag = tag.Value; } curDriver.SetInitialPosture(); curDriver.Notify_Starting(); curDriver.SetupToils(); curDriver.ReadyForNextToil(); } else if (flag) { EndCurrentJob(JobCondition.QueuedNoLongerValid); } else { Log.Warning("TryMakePreToilReservations() returned false for a non-queued job right after StartJob(). This should have been checked before. curJob=" + curJob.ToStringSafe()); EndCurrentJob(JobCondition.Errored); } } finally { startingNewJob = false; } }
private void LogCouldNotReserveError(Pawn claimant, Job job, LocalTargetInfo target, int maxPawns, int stackCount, ReservationLayerDef layer) { Job curJob = claimant.CurJob; string text = "null"; int num = -1; if (curJob != null) { text = curJob.ToString(); if (claimant.jobs.curDriver != null) { num = claimant.jobs.curDriver.CurToilIndex; } } Pawn pawn = this.FirstRespectedReserver(target, claimant); string text2 = "null"; int num2 = -1; if (pawn != null) { Job curJob2 = pawn.CurJob; if (curJob2 != null) { text2 = curJob2.ToString(); if (pawn.jobs.curDriver != null) { num2 = pawn.jobs.curDriver.CurToilIndex; } } } Log.Error("Could not reserve " + target + "/" + layer + " for " + claimant + " for job " + job.ToStringSafe() + " (now doing job " + text + "(curToil=" + num + ")) for maxPawns " + maxPawns + " and stackCount " + stackCount + ". Existing reserver: " + pawn + " doing job " + text2 + "(curToil=" + num2 + ")"); }
private void LogCouldNotReserveError(Pawn claimant, Job job, LocalTargetInfo target, int maxPawns, int stackCount, ReservationLayerDef layer) { Job curJob = claimant.CurJob; string text = "null"; int num = -1; if (curJob != null) { text = curJob.ToString(); if (claimant.jobs.curDriver != null) { num = claimant.jobs.curDriver.CurToilIndex; } } string text2; if (target.HasThing && target.Thing.def.stackLimit != 1) { text2 = "(current stack count: " + target.Thing.stackCount + ")"; } else { text2 = string.Empty; } string text3 = string.Concat(new object[] { "Could not reserve ", target.ToStringSafe <LocalTargetInfo>(), text2, " (layer: ", layer.ToStringSafe <ReservationLayerDef>(), ") for ", claimant.ToStringSafe <Pawn>(), " for job ", job.ToStringSafe <Job>(), " (now doing job ", text, "(curToil=", num, ")) for maxPawns ", maxPawns, " and stackCount ", stackCount, "." }); Pawn pawn = this.FirstRespectedReserver(target, claimant); if (pawn != null) { string text4 = "null"; int num2 = -1; Job curJob2 = pawn.CurJob; if (curJob2 != null) { text4 = curJob2.ToStringSafe <Job>(); if (pawn.jobs.curDriver != null) { num2 = pawn.jobs.curDriver.CurToilIndex; } } string text5 = text3; text3 = string.Concat(new object[] { text5, " Existing reserver: ", pawn.ToStringSafe <Pawn>(), " doing job ", text4, " (toilIndex=", num2, ")" }); } else { text3 += " No existing reserver."; } Pawn pawn2 = this.map.physicalInteractionReservationManager.FirstReserverOf(target); if (pawn2 != null) { text3 = text3 + " Physical interaction reserver: " + pawn2.ToStringSafe <Pawn>(); } Log.Error(text3, false); }