public static Toil GotoThing(Pawn pawn, Thing thing, ToilCompleteMode mode = ToilCompleteMode.PatherArrival) { if (pawn == null || thing == null) { Log.Error("Not Going Anywhere...", true); return(null); } Toil toil = new Toil { initAction = delegate() { /* Log.Message("[" + pawn.Name + "] go to [" + thing + "]"); */ pawn?.pather?.StartPath(thing, PathEndMode.OnCell); if (thing is Pawn) { try { (thing as Pawn)?.pather?.StartPath(thing, PathEndMode.OnCell); } catch (Exception e) { ///snarf it. /* Log.Message("Couldn't make the target hold still with pather, nbd." + e.Message, false); */ } } } }; toil.AddFinishAction(delegate { Log.Message("Got to [" + thing + "]."); }); toil.socialMode = RandomSocialMode.Off; toil.defaultCompleteMode = mode; return(toil); }
public static Toil GotoThing(Pawn pawn, Thing thing, ToilCompleteMode mode = ToilCompleteMode.PatherArrival) { if (pawn == null || thing == null) { Log.Error("Not Going Anywhere...", true); return(null); } Toil toil = new Toil { initAction = delegate() { pawn?.pather?.StartPath(thing, PathEndMode.OnCell); if (thing is Pawn) { try { (thing as Pawn)?.pather?.StartPath(thing, PathEndMode.OnCell); } catch (Exception) { } } } }; toil.socialMode = RandomSocialMode.Off; toil.defaultCompleteMode = mode; return(toil); }
private void TryActuallyStartNextToil() { if (this.pawn.Spawned) { if (!this.pawn.stances.FullBodyBusy || this.CanStartNextToilInBusyStance) { if (this.HaveCurToil) { this.CurToil.Cleanup(this.curToilIndex, this); } if (this.nextToilIndex >= 0) { this.curToilIndex = this.nextToilIndex; this.nextToilIndex = -1; } else { this.curToilIndex++; } this.wantBeginNextToil = false; if (!this.HaveCurToil) { if (this.pawn.stances != null && this.pawn.stances.curStance.StanceBusy) { Log.ErrorOnce(this.pawn.ToStringSafe <Pawn>() + " ended job " + this.job.ToStringSafe <Job>() + " due to running out of toils during a busy stance.", 6453432, false); } this.EndJobWith(JobCondition.Succeeded); } else { this.debugTicksSpentThisToil = 0; this.ticksLeftThisToil = this.CurToil.defaultDuration; this.curToilCompleteMode = this.CurToil.defaultCompleteMode; if (!this.CheckCurrentToilEndOrFail()) { Toil curToil = this.CurToil; if (this.CurToil.preInitActions != null) { for (int i = 0; i < this.CurToil.preInitActions.Count; i++) { try { this.CurToil.preInitActions[i](); } catch (Exception exception) { JobUtility.TryStartErrorRecoverJob(this.pawn, string.Concat(new object[] { "JobDriver threw exception in preInitActions[", i, "] for pawn ", this.pawn.ToStringSafe <Pawn>() }), exception, this); return; } if (this.CurToil != curToil) { break; } } } if (this.CurToil == curToil) { if (this.CurToil.initAction != null) { try { this.CurToil.initAction(); } catch (Exception exception2) { JobUtility.TryStartErrorRecoverJob(this.pawn, "JobDriver threw exception in initAction for pawn " + this.pawn.ToStringSafe <Pawn>(), exception2, this); return; } } if (this.CurToil == curToil && !this.ended && this.curToilCompleteMode == ToilCompleteMode.Instant) { this.ReadyForNextToil(); } } } } } } }
private void TryActuallyStartNextToil() { if (this.pawn.Spawned && (!this.pawn.stances.FullBodyBusy || this.CanStartNextToilInBusyStance)) { if (this.HaveCurToil) { this.CurToil.Cleanup(); } if (this.nextToilIndex >= 0) { this.curToilIndex = this.nextToilIndex; this.nextToilIndex = -1; } else { this.curToilIndex++; } this.wantBeginNextToil = false; if (!this.HaveCurToil) { if (this.pawn.stances != null && this.pawn.stances.curStance.StanceBusy) { Log.ErrorOnce(this.pawn + " ended job " + this.job + " due to running out of toils during a busy stance.", 6453432); } this.EndJobWith(JobCondition.Succeeded); } else { this.debugTicksSpentThisToil = 0; this.ticksLeftThisToil = this.CurToil.defaultDuration; this.curToilCompleteMode = this.CurToil.defaultCompleteMode; if (!this.CheckCurrentToilEndOrFail()) { int num = this.CurToilIndex; if (this.CurToil.preInitActions != null) { int num2 = 0; while (num2 < this.CurToil.preInitActions.Count) { this.CurToil.preInitActions[num2](); if (this.CurToilIndex == num) { num2++; continue; } break; } } if (this.CurToilIndex == num) { if (this.CurToil.initAction != null) { try { this.CurToil.initAction(); } catch (Exception ex) { this.pawn.jobs.StartErrorRecoverJob("JobDriver threw exception in initAction. Pawn=" + this.pawn + ", Job=" + this.job + ", Exception: " + ex); return; } } if (this.CurToilIndex == num && !this.ended && this.curToilCompleteMode == ToilCompleteMode.Instant) { this.ReadyForNextToil(); } } } } } }
private void TryActuallyStartNextToil() { if (!this.pawn.Spawned) { return; } if (this.pawn.stances.FullBodyBusy && !this.CanStartNextToilInBusyStance) { return; } if (this.HaveCurToil) { this.CurToil.Cleanup(); } if (this.nextToilIndex >= 0) { this.curToilIndex = this.nextToilIndex; this.nextToilIndex = -1; } else { this.curToilIndex++; } this.wantBeginNextToil = false; if (!this.HaveCurToil) { if (this.pawn.stances != null && this.pawn.stances.curStance.StanceBusy) { Log.ErrorOnce(string.Concat(new object[] { this.pawn, " ended job ", this.job, " due to running out of toils during a busy stance." }), 6453432); } this.EndJobWith(JobCondition.Succeeded); return; } this.debugTicksSpentThisToil = 0; this.ticksLeftThisToil = this.CurToil.defaultDuration; this.curToilCompleteMode = this.CurToil.defaultCompleteMode; if (!this.CheckCurrentToilEndOrFail()) { int num = this.CurToilIndex; if (this.CurToil.preInitActions != null) { for (int i = 0; i < this.CurToil.preInitActions.Count; i++) { this.CurToil.preInitActions[i](); if (this.CurToilIndex != num) { break; } } } if (this.CurToilIndex == num) { if (this.CurToil.initAction != null) { try { this.CurToil.initAction(); } catch (Exception ex) { this.pawn.jobs.StartErrorRecoverJob(string.Concat(new object[] { "JobDriver threw exception in initAction. Pawn=", this.pawn, ", Job=", this.job, ", Exception: ", ex })); return; } } if (this.CurToilIndex == num && !this.ended && this.curToilCompleteMode == ToilCompleteMode.Instant) { this.ReadyForNextToil(); } } } }
private void TryActuallyStartNextToil() { if (!pawn.Spawned || (pawn.stances.FullBodyBusy && !CanStartNextToilInBusyStance) || job == null || pawn.CurJob != job) { return; } if (HaveCurToil) { CurToil.Cleanup(curToilIndex, this); } if (nextToilIndex >= 0) { curToilIndex = nextToilIndex; nextToilIndex = -1; } else { curToilIndex++; } wantBeginNextToil = false; if (!HaveCurToil) { if (pawn.stances != null && pawn.stances.curStance.StanceBusy) { Log.ErrorOnce(pawn.ToStringSafe() + " ended job " + job.ToStringSafe() + " due to running out of toils during a busy stance.", 6453432); } EndJobWith(JobCondition.Succeeded); return; } debugTicksSpentThisToil = 0; ticksLeftThisToil = CurToil.defaultDuration; curToilCompleteMode = CurToil.defaultCompleteMode; if (CheckCurrentToilEndOrFail()) { return; } Toil curToil = CurToil; if (CurToil.preInitActions != null) { for (int i = 0; i < CurToil.preInitActions.Count; i++) { try { CurToil.preInitActions[i](); } catch (Exception exception) { JobUtility.TryStartErrorRecoverJob(pawn, "JobDriver threw exception in preInitActions[" + i + "] for pawn " + pawn.ToStringSafe(), exception, this); return; } if (CurToil != curToil) { break; } } } if (CurToil != curToil) { return; } if (CurToil.initAction != null) { try { CurToil.initAction(); } catch (Exception exception2) { JobUtility.TryStartErrorRecoverJob(pawn, "JobDriver threw exception in initAction for pawn " + pawn.ToStringSafe(), exception2, this); return; } } if (!ended && curToilCompleteMode == ToilCompleteMode.Instant && CurToil == curToil) { ReadyForNextToil(); } }
private void TryActuallyStartNextToil() { if (!this.caravan.Spawned) { return; } if (this.HaveCurToil) { this.CurToil.Cleanup(); } this.curToilIndex++; this.wantBeginNextToil = false; if (!this.HaveCurToil) { this.EndJobWith(JobCondition.Succeeded); return; } this.debugTicksSpentThisToil = 0; this.ticksLeftThisToil = this.CurToil.defaultDuration; this.curToilCompleteMode = this.CurToil.defaultCompleteMode; if (!this.CheckCurrentToilEndOrFail()) { int num = this.CurToilIndex; if (this.CurToil.preInitActions != null) { for (int i = 0; i < this.CurToil.preInitActions.Count; i++) { this.CurToil.preInitActions[i](); if (this.CurToilIndex != num) { break; } } } if (this.CurToilIndex == num) { if (this.CurToil.initAction != null) { try { this.CurToil.initAction(); } catch (Exception ex) { Find.World.GetComponent <CaravanJobGiver>().Tracker(caravan).StartErrorRecoverJob(string.Concat(new object[] { "JobDriver threw exception in initAction. Pawn=", this.caravan, ", Job=", this.CurJob, ", Exception: ", ex })); return; } } if (this.CurToilIndex == num && !this.ended && this.curToilCompleteMode == ToilCompleteMode.Instant) { this.ReadyForNextToil(); } } } }