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 EndCurrentJob(JobCondition condition, bool startNewJob = true, bool canReturnToPool = true) { if (debugLog) { DebugLogEvent(string.Concat("EndCurrentJob ", (curJob != null) ? curJob.ToString() : "null", " condition=", condition, " curToil=", (curDriver != null) ? curDriver.CurToilIndex.ToString() : "null_driver")); } if (condition == JobCondition.Ongoing) { Log.Warning("Ending a job with Ongoing as the condition. This makes no sense."); } if (condition == JobCondition.Succeeded && curJob != null && curJob.def.taleOnCompletion != null) { TaleRecorder.RecordTale(curJob.def.taleOnCompletion, curDriver.TaleParameters()); } JobDef jobDef = ((curJob != null) ? curJob.def : null); CleanupCurrentJob(condition, releaseReservations: true, cancelBusyStancesSoft: true, canReturnToPool); if (!startNewJob) { return; } switch (condition) { case JobCondition.Errored: case JobCondition.ErroredPather: StartJob(JobMaker.MakeJob(JobDefOf.Wait, 250)); return; case JobCondition.Succeeded: if (jobDef != null && jobDef != JobDefOf.Wait_MaintainPosture && !pawn.pather.Moving) { StartJob(JobMaker.MakeJob(JobDefOf.Wait_MaintainPosture, 1), JobCondition.None, null, resumeCurJobAfterwards: false, cancelBusyStances: false); return; } break; } TryFindAndStartJob(); }
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 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; } } 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); }
// Token: 0x0600002F RID: 47 RVA: 0x00003958 File Offset: 0x00001B58 public static Toil FinishRecipeAndStartStoringProduct() { Log.Message("start finish recipe, store product.", false); Toil toil = new Toil(); toil.initAction = delegate() { Log.Message("in finishing", false); Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; string str = "curJob"; Job job = curJob; string str2 = (job != null) ? job.ToString() : null; string str3 = " actor "; Pawn pawn = actor; Log.Message(str + str2 + str3 + ((pawn != null) ? pawn.ToString() : null), false); JobDriver_WPDoBill jobDriver_WPDoBill = (JobDriver_WPDoBill)actor.jobs.curDriver; List <Thing> list = Toils_WPRecipe.CalculateIngredients(curJob, actor); for (int i = 0; i < list.Count; i++) { string str4 = "toils_wprecipe: ingredient[i] "; Thing thing = list[i]; Log.Message(str4 + ((thing != null) ? thing.ToString() : null), false); } Thing thing2 = Toils_WPRecipe.CalculateDominantIngredient(curJob, list); string[] array = new string[8]; array[0] = "finishing: curJob.RecipeDef "; int num = 1; RecipeDef recipeDef = curJob.RecipeDef; array[num] = ((recipeDef != null) ? recipeDef.ToString() : null); array[2] = " actor "; int num2 = 3; Pawn pawn2 = actor; array[num2] = ((pawn2 != null) ? pawn2.ToString() : null); array[4] = " ingredients "; int num3 = 5; List <Thing> list2 = list; array[num3] = ((list2 != null) ? list2.ToString() : null); array[6] = " dominantIngredient "; int num4 = 7; Thing thing3 = thing2; array[num4] = ((thing3 != null) ? thing3.ToString() : null); Log.Message(string.Concat(array), false); List <Thing> list3 = WPGenRecipe.MakeRecipeProducts(curJob.RecipeDef, actor, list, thing2).ToList <Thing>(); Toils_WPRecipe.ConsumeIngredients(list, curJob.RecipeDef, actor.Map); curJob.bill.Notify_IterationCompleted(actor, list); RecordsUtility.Notify_BillDone(actor, list3); UnfinishedThing unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing; bool flag = list3.Count == 0; if (flag) { actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true); } else { bool flag2 = curJob.bill.GetStoreMode() == BillStoreModeDefOf.DropOnFloor; if (flag2) { for (int j = 0; j < list3.Count; j++) { bool flag3 = !GenPlace.TryPlaceThing(list3[j], actor.Position, actor.Map, ThingPlaceMode.Near, null, null, default(Rot4)); if (flag3) { Log.Error(string.Concat(new object[] { actor, " could not drop recipe product ", list3[j], " near ", actor.Position }), false); } } actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true); } else { bool flag4 = list3.Count > 1; if (flag4) { for (int k = 1; k < list3.Count; k++) { bool flag5 = !GenPlace.TryPlaceThing(list3[k], actor.Position, actor.Map, ThingPlaceMode.Near, null, null, default(Rot4)); if (flag5) { Log.Error(string.Concat(new object[] { actor, " could not drop recipe product ", list3[k], " near ", actor.Position }), false); } } } list3[0].SetPositionDirect(actor.Position); IntVec3 c; bool flag6 = StoreUtility.TryFindBestBetterStoreCellFor(list3[0], actor, actor.Map, StoragePriority.Unstored, actor.Faction, out c, true); if (flag6) { actor.carryTracker.TryStartCarry(list3[0]); curJob.targetB = c; curJob.targetA = list3[0]; curJob.count = 99999; } else { bool flag7 = !GenPlace.TryPlaceThing(list3[0], actor.Position, actor.Map, ThingPlaceMode.Near, null, null, default(Rot4)); if (flag7) { Log.Error(string.Concat(new object[] { "Bill doer could not drop product ", list3[0], " near ", actor.Position }), false); } actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true); } } } }; return(toil); }
public void StartJob(Job newJob, JobCondition lastJobEndCondition = JobCondition.None, ThinkNode jobGiver = null, bool resumeCurJobAfterwards = false, bool cancelBusyStances = true, ThinkTreeDef thinkTree = null, JobTag?tag = default(JobTag?), 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 = string.Empty; this.startingNewJob = false; this.pawn.ClearReservationsForJob(newJob); this.StartErrorRecoverJob(this.pawn + " started 10 jobs in one tick. newJob=" + newJob + " jobGiver=" + jobGiver + " jobList=" + text); } else { PawnPosture posture = this.pawn.GetPosture(); LayingDownState layingDown = (this.pawn.jobs != null && this.pawn.jobs.curDriver != null) ? this.pawn.jobs.curDriver.layingDown : LayingDownState.NotLaying; if (this.debugLog) { this.DebugLogEvent("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(this.pawn + " starting job " + newJob + " from JobGiver " + this.pawn.mindState.lastJobGiver + " while already having job " + this.curJob + " without a specific job end condition."); 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."); } 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()) { if (tag.HasValue) { this.pawn.mindState.lastJobTag = tag.Value; } this.curDriver.Notify_Starting(); this.curDriver.Notify_LastPosture(posture, layingDown); 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()); this.EndCurrentJob(JobCondition.Errored, true); } } } } finally { this.startingNewJob = false; } }