private static void LogCouldNotReserveError(ReservationManager __instance, Pawn claimant, Job job, LocalTargetInfo target, int maxPawns, int stackCount, ReservationLayerDef layer) { Job curJob1 = claimant.CurJob; string str1 = "null"; int num1 = -1; if (curJob1 != null) { str1 = curJob1.ToString(); if (claimant.jobs.curDriver != null) { num1 = claimant.jobs.curDriver.CurToilIndex; } } string str2 = !target.HasThing || target.Thing.def.stackLimit == 1 ? "" : "(current stack count: " + (object)target.Thing.stackCount + ")"; string str3 = "Could not reserve " + target.ToStringSafe <LocalTargetInfo>() + str2 + " (layer: " + layer.ToStringSafe <ReservationLayerDef>() + ") for " + claimant.ToStringSafe <Pawn>() + " for job " + job.ToStringSafe <Job>() + " (now doing job " + str1 + "(curToil=" + (object)num1 + ")) for maxPawns " + (object)maxPawns + " and stackCount " + (object)stackCount + "."; Pawn pawn1 = __instance.FirstRespectedReserver(target, claimant); string text; if (pawn1 != null) { string str4 = "null"; int num2 = -1; Job curJob2 = pawn1.CurJob; if (curJob2 != null) { str4 = curJob2.ToStringSafe <Job>(); if (pawn1.jobs.curDriver != null) { num2 = pawn1.jobs.curDriver.CurToilIndex; } } text = str3 + " Existing reserver: " + pawn1.ToStringSafe <Pawn>() + " doing job " + str4 + " (toilIndex=" + (object)num2 + ")"; } else { text = str3 + " No existing reserver."; } Pawn pawn2 = map(__instance).physicalInteractionReservationManager.FirstReserverOf(target); if (pawn2 != null) { text = text + " Physical interaction reserver: " + pawn2.ToStringSafe <Pawn>(); } Log.Error(text, false); }
public bool Reserve(Pawn claimant, Job job, LocalTargetInfo target, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool errorOnFailed = true) { if (maxPawns > 1 && stackCount == -1) { Log.ErrorOnce("Reserving with maxPawns > 1 and stackCount = All; this will not have a useful effect (suppressing future warnings)", 83269); } if (job == null) { Log.Warning(claimant.ToStringSafe() + " tried to reserve thing " + target.ToStringSafe() + " without a valid job"); return(false); } int num = (!target.HasThing) ? 1 : target.Thing.stackCount; int num2 = (stackCount != -1) ? stackCount : num; for (int i = 0; i < reservations.Count; i++) { Reservation reservation = reservations[i]; if (reservation.Target == target && reservation.Claimant == claimant && reservation.Job == job && reservation.Layer == layer && (reservation.StackCount == -1 || reservation.StackCount >= num2)) { return(true); } } if (!target.IsValid || target.ThingDestroyed) { return(false); } if (!CanReserve(claimant, target, maxPawns, stackCount, layer)) { if (job != null && job.playerForced && CanReserve(claimant, target, maxPawns, stackCount, layer, ignoreOtherReservations: true)) { reservations.Add(new Reservation(claimant, job, maxPawns, stackCount, target, layer)); foreach (Reservation item in reservations.ToList()) { if (item.Target == target && item.Claimant != claimant && item.Layer == layer && RespectsReservationsOf(claimant, item.Claimant)) { item.Claimant.jobs.EndCurrentOrQueuedJob(item.Job, JobCondition.InterruptForced); } } return(true); } if (errorOnFailed) { LogCouldNotReserveError(claimant, job, target, maxPawns, stackCount, layer); } return(false); } reservations.Add(new Reservation(claimant, job, maxPawns, stackCount, target, layer)); return(true); }
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 override string ToString() { return(((claimant == null) ? "null" : claimant.LabelShort) + ":" + job.ToStringSafe() + ", " + target.ToStringSafe() + ", " + layer.ToStringSafe() + ", " + maxPawns + ", " + stackCount); }
public static bool VerifyReservations(Pawn __instance) { if (__instance.jobs == null || __instance.CurJob != null || __instance.jobs.jobQueue.Count > 0 || __instance.jobs.startingNewJob) { return(false); } bool flag = false; List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { LocalTargetInfo obj = maps[i].reservationManager.FirstReservationFor(__instance); if (obj.IsValid) { Log.ErrorOnce($"Reservation manager failed to clean up properly; {__instance.ToStringSafe()} still reserving {obj.ToStringSafe()}", 0x5D3DFA5 ^ __instance.thingIDNumber); flag = true; } LocalTargetInfo obj2 = maps[i].physicalInteractionReservationManager.FirstReservationFor(__instance); if (obj2.IsValid) { Log.ErrorOnce($"Physical interaction reservation manager failed to clean up properly; {__instance.ToStringSafe()} still reserving {obj2.ToStringSafe()}", 0x12ADECD ^ __instance.thingIDNumber); flag = true; } IAttackTarget attackTarget = maps[i].attackTargetReservationManager.FirstReservationFor(__instance); if (attackTarget != null) { Log.ErrorOnce($"Attack target reservation manager failed to clean up properly; {__instance.ToStringSafe()} still reserving {attackTarget.ToStringSafe()}", 0x5FD7206 ^ __instance.thingIDNumber); flag = true; } IntVec3 obj3 = maps[i].pawnDestinationReservationManager.FirstObsoleteReservationFor(__instance); if (obj3.IsValid) { Job job = maps[i].pawnDestinationReservationManager.FirstObsoleteReservationJobFor(__instance); Log.Warning($"Pawn destination reservation manager failed to clean up properly; {__instance.ToStringSafe()}/{job.ToStringSafe()}/{job.def.ToStringSafe()} still reserving {obj3.ToStringSafe()}"); flag = true; } } if (flag) { __instance.ClearAllReservations(); } return(false); }
public static bool Reserve(ReservationManager __instance, ref bool __result, Pawn claimant, Job job, LocalTargetInfo target, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool errorOnFailed = true) { if (maxPawns > 1 && stackCount == -1) { Log.ErrorOnce("Reserving with maxPawns > 1 and stackCount = All; this will not have a useful effect (suppressing future warnings)", 83269, false); } if (job == null) { Log.Warning(claimant.ToStringSafe() + " tried to reserve thing " + target.ToStringSafe() + " without a valid job"); __result = false; return(false); } int num1 = (!target.HasThing) ? 1 : target.Thing.stackCount; int num2 = stackCount == -1 ? num1 : stackCount; lock (reservations(__instance)) { for (int index = 0; index < reservations(__instance).Count; ++index) { Reservation reservation1; try { reservation1 = reservations(__instance)[index]; } catch (ArgumentOutOfRangeException) { break; } if (reservation1 != null && reservation1.Target == target && reservation1.Claimant == claimant && reservation1.Job == job && reservation1.Layer == layer && (reservation1.StackCount == -1 || reservation1.StackCount >= num2)) { __result = true; return(false); } } if (!target.IsValid || target.ThingDestroyed) { __result = false; return(false); } bool canReserveResult = __instance.CanReserve(claimant, target, maxPawns, stackCount, layer); if (!canReserveResult) { //bool canReserveResult2 = __instance.CanReserve(claimant, target, maxPawns, stackCount, layer); if (job != null && job.playerForced && __instance.CanReserve(claimant, target, maxPawns, stackCount, layer)) { reservations(__instance).Add(new Reservation(claimant, job, maxPawns, stackCount, target, layer)); //foreach (ReservationManager.Reservation reservation in reservations(__instance).ToList<ReservationManager.Reservation>()) Reservation reservation2; for (int index = 0; index < reservations(__instance).Count; index++) { try { reservation2 = reservations(__instance)[index]; } catch (ArgumentOutOfRangeException) { break; } if (reservation2.Target == target && reservation2.Claimant != claimant && (reservation2.Layer == layer && RespectsReservationsOf(claimant, reservation2.Claimant))) { reservation2.Claimant.jobs.EndCurrentOrQueuedJob(reservation2.Job, JobCondition.InterruptForced); } } __result = true; return(false); } //HACK - Probably because Reserve is no longer valid after CanReserve time delay with multiple threads. if (errorOnFailed) { //LogCouldNotReserveError(__instance, claimant, job, target, maxPawns, stackCount, layer); Log.Warning("ReservationManager.Reserve cannot reserve. This is likely because reservation is no longer valid after CanReserve was called due to time delay with multiple threads."); } __result = false; return(false); } reservations(__instance).Add(new ReservationManager.Reservation(claimant, job, maxPawns, stackCount, target, layer)); } __result = true; return(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); }
public static bool Reserve(ReservationManager __instance, ref bool __result, Pawn claimant, Job job, LocalTargetInfo target, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool errorOnFailed = true) { lock (__instance) { if (maxPawns > 1 && stackCount == -1) { Log.ErrorOnce("Reserving with maxPawns > 1 and stackCount = All; this will not have a useful effect (suppressing future warnings)", 83269); } if (job == null) { Log.Warning(claimant.ToStringSafe() + " tried to reserve thing " + target.ToStringSafe() + " without a valid job"); __result = false; return(false); } int num1 = (!target.HasThing) ? 1 : target.Thing.stackCount; int num2 = stackCount == -1 ? num1 : stackCount; List <Reservation> reservationTargetList = getReservationTargetList(__instance, target); foreach (Reservation reservation1 in reservationTargetList) { if (reservation1.Claimant == claimant && reservation1.Job == job && reservation1.Layer == layer) { if (reservation1.StackCount == -1 || reservation1.StackCount >= num2) { __result = true; return(false); } Log.Warning("Debug reservation"); } } if (!target.IsValid || target.ThingDestroyed) //TODO reservation should be removed when thing is destroyed { __result = false; return(false); } bool canReserveResult = __instance.CanReserve(claimant, target, maxPawns, stackCount, layer); Reservation reservation; Dictionary <LocalTargetInfo, List <Reservation> > reservationTargetDict; Dictionary <Pawn, List <Reservation> > reservationClaimantDict; Thing haulableThing; if (!canReserveResult) { if (job.playerForced && __instance.CanReserve(claimant, target, maxPawns, stackCount, layer, true)) { reservation = new Reservation(claimant, job, maxPawns, stackCount, target, layer); List <Reservation> claimantReservations; reservationTargetDict = getReservationTargetDict(__instance); //newReservationTargetList = new List<Reservation>(getReservationTargetList(reservationTargetDict, target)) //{ // reservation //}; getReservationTargetList(reservationTargetDict, target).Add(reservation); reservationClaimantDict = getReservationClaimantDict(__instance); //newReservationClaimantList = // new List<Reservation>(getReservationClaimantList(reservationClaimantDict, claimant)) // { // reservation // }; claimantReservations = getReservationClaimantList(reservationClaimantDict, claimant); claimantReservations.Add(reservation); foreach (Reservation reservation2 in claimantReservations) { if (reservation2.Claimant != claimant && (reservation2.Layer == layer && RespectsReservationsOf(claimant, reservation2.Claimant))) { reservation2.Claimant.jobs.EndCurrentOrQueuedJob(reservation2.Job, JobCondition.InterruptForced); } } haulableThing = target.Thing; if (haulableThing != null && haulableThing.def.EverHaulable && haulableThing.Map != null) { //Log.Message("DeregisterHaulableItem " + haulableThing.ToString()); HaulingCache.DeregisterHaulableItem(haulableThing); } __result = true; return(false); } //HACK - Probably because Reserve is no longer valid after CanReserve time delay with multiple threads. if (errorOnFailed) { //LogCouldNotReserveError(__instance, claimant, job, target, maxPawns, stackCount, layer); Log.Warning("ReservationManager.Reserve cannot reserve. This is likely because reservation is no longer valid after CanReserve was called due to time delay with multiple threads."); } __result = false; return(false); } reservation = new Reservation(claimant, job, maxPawns, stackCount, target, layer); reservationTargetDict = getReservationTargetDict(__instance); //newReservationTargetList = new List<Reservation>(getReservationTargetList(reservationTargetDict, target)) // { // reservation // }; getReservationTargetList(reservationTargetDict, target).Add(reservation); reservationClaimantDict = getReservationClaimantDict(__instance); //newReservationClaimantList = new List<Reservation>(getReservationClaimantList(reservationClaimantDict, claimant)) // { // reservation // }; getReservationClaimantList(reservationClaimantDict, claimant).Add(reservation); haulableThing = target.Thing; if (haulableThing != null && haulableThing.def.EverHaulable && haulableThing.Map != null) { //Log.Message("DeregisterHaulableItem " + haulableThing.ToString()); HaulingCache.DeregisterHaulableItem(haulableThing); } } __result = true; return(false); }
public bool Reserve(Pawn claimant, Job job, LocalTargetInfo target, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null) { if (maxPawns > 1 && stackCount == -1) { Log.ErrorOnce("Reserving with maxPawns > 1 and stackCount = All; this will not have a useful effect (suppressing future warnings)", 83269, false); } bool result; if (!target.IsValid) { result = false; } else if (this.ReservedBy(target, claimant, job)) { result = true; } else if (target.ThingDestroyed) { result = false; } else if (job == null) { Log.Warning(claimant.ToStringSafe <Pawn>() + " tried to reserve thing " + target.ToStringSafe <LocalTargetInfo>() + " without a valid job", false); result = false; } else if (!this.CanReserve(claimant, target, maxPawns, stackCount, layer, false)) { if (job != null && job.playerForced && this.CanReserve(claimant, target, maxPawns, stackCount, layer, true)) { this.reservations.Add(new Reservation(claimant, job, maxPawns, stackCount, target, layer)); foreach (Reservation reservation in new List <Reservation>(this.reservations)) { if (reservation.Target == target && reservation.Claimant != claimant && reservation.Layer == layer && ReservationManager.RespectsReservationsOf(claimant, reservation.Claimant)) { reservation.Claimant.jobs.EndJob(reservation.Job, JobCondition.InterruptForced); } } result = true; } else { this.LogCouldNotReserveError(claimant, job, target, maxPawns, stackCount, layer); result = false; } } else { this.reservations.Add(new Reservation(claimant, job, maxPawns, stackCount, target, layer)); result = true; } return(result); }
public static bool Reserve(ReservationManager __instance, ref bool __result, Pawn claimant, Job job, LocalTargetInfo target, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool errorOnFailed = true) { if (maxPawns > 1 && stackCount == -1) { Log.ErrorOnce("Reserving with maxPawns > 1 and stackCount = All; this will not have a useful effect (suppressing future warnings)", 83269, false); } if (job == null) { Log.Warning(claimant.ToStringSafe <Pawn>() + " tried to reserve thing " + target.ToStringSafe <LocalTargetInfo>() + " without a valid job", false); __result = false; return(false); } int num1 = target.HasThing ? target.Thing.stackCount : 1; int num2 = stackCount == -1 ? num1 : stackCount; for (int index = 0; index < reservations(__instance).Count; ++index) { ReservationManager.Reservation reservation = reservations(__instance)[index]; if (reservation.Target == target && reservation.Claimant == claimant && (reservation.Job == job && reservation.Layer == layer) && (reservation.StackCount == -1 || reservation.StackCount >= num2)) { __result = true; return(false); } } if (!target.IsValid || target.ThingDestroyed) { __result = false; return(false); } if (!CanReserve(__instance, claimant, target, maxPawns, stackCount, layer, false)) { if (job != null && job.playerForced && CanReserve(__instance, claimant, target, maxPawns, stackCount, layer, true)) { reservations(__instance).Add(new ReservationManager.Reservation(claimant, job, maxPawns, stackCount, target, layer)); foreach (ReservationManager.Reservation reservation in reservations(__instance).ToList <ReservationManager.Reservation>()) { if (reservation.Target == target && reservation.Claimant != claimant && (reservation.Layer == layer && RespectsReservationsOf(claimant, reservation.Claimant))) { reservation.Claimant.jobs.EndCurrentOrQueuedJob(reservation.Job, JobCondition.InterruptForced, true); } } __result = true; return(false); } if (errorOnFailed) { LogCouldNotReserveError(__instance, claimant, job, target, maxPawns, stackCount, layer); } __result = false; return(false); } reservations(__instance).Add(new ReservationManager.Reservation(claimant, job, maxPawns, stackCount, target, layer)); __result = true; return(false); }