public static bool ReservationIsItemCompatible(this CompDecorate comp)
        {
            if (!comp.IsReserved)
            {
                return(false);
            }

            if (comp.FirstReservation == null)
            {
                return(false);
            }

            ReservationManager.Reservation resItem = comp.FirstReservation;

            bool compatible = true;

            if (comp.CurItem.condition.HasIncludedJob)
            {
                if (!(compatible &= comp.CurItem.condition.includeJob.Contains(resItem.Job.def)))
                {
                    return(false);
                }
            }

            if (comp.CurItem.condition.HasExcludedJob)
            {
                if (!(compatible &= !comp.CurItem.condition.excludeJob.Contains(resItem.Job.def)))
                {
                    return(false);
                }
            }

            if (comp.CurItem.condition.HasIncludedRecipe && resItem.Job.RecipeDef != null)
            {
                if (!(compatible &= comp.CurItem.condition.includeRecipe.Contains(resItem.Job.RecipeDef)))
                {
                    return(false);
                }
            }

            if (comp.CurItem.condition.HasExcludedRecipe && resItem.Job.RecipeDef != null)
            {
                if (!(compatible &= !comp.CurItem.condition.excludeRecipe.Contains(resItem.Job.RecipeDef)))
                {
                    return(false);
                }
            }

            return(compatible);
        }
        public static bool ReservationIsItemCompatible(this CompConditionalPostDraw comp)
        {
            if (!comp.CurCondition.HasWorkCondition || !comp.IsReserved || comp.FirstReservation == null)
            {
                return(false);
            }

            ReservationManager.Reservation resItem = comp.FirstReservation;

            if (comp.CurCondition.ifWork.HasIncludedJob)
            {
                if (!comp.CurCondition.ifWork.includeJob.Contains(resItem.Job.def))
                {
                    return(false);
                }
            }

            if (comp.CurCondition.ifWork.HasExcludedJob)
            {
                if (!comp.CurCondition.ifWork.excludeJob.Contains(resItem.Job.def))
                {
                    return(false);
                }
            }

            if (comp.CurCondition.ifWork.HasIncludedRecipe && resItem.Job.RecipeDef != null)
            {
                if (comp.CurCondition.ifWork.includeRecipe.Contains(resItem.Job.RecipeDef))
                {
                    return(false);
                }
            }

            if (comp.CurCondition.ifWork.HasExcludedRecipe && resItem.Job.RecipeDef != null)
            {
                if (!comp.CurCondition.ifWork.excludeRecipe.Contains(resItem.Job.RecipeDef))
                {
                    return(false);
                }
            }

            return(true);
        }
 public static bool ReleaseClaimedBy(ReservationManager __instance, Pawn claimant, Job job)
 {
     lock (reservations(__instance))
     {
         ReservationManager.Reservation[] reservations2 = reservations(__instance).ToArray();
         for (int i = reservations2.Length - 1; i >= 0; i--)
         {
             ReservationManager.Reservation r = reservations2[i];
             if (null != r)
             {
                 if (r.Claimant == claimant && r.Job == job)
                 {
                     reservations(__instance).RemoveAt(i);
                 }
             }
         }
     }
     return(false);
 }
 public static bool FirstReservationFor(ReservationManager __instance, ref LocalTargetInfo __result, Pawn claimant)
 {
     if (claimant == null)
     {
         __result = LocalTargetInfo.Invalid;
         return(false);
     }
     ReservationManager.Reservation[] reservations2 = reservations(__instance).ToArray();
     for (int i = 0; i < reservations2.Length; i++)
     {
         ReservationManager.Reservation r = reservations2[i];
         if (null != r)
         {
             if (r.Claimant == claimant)
             {
                 __result = r.Target;
                 return(false);
             }
         }
     }
     __result = LocalTargetInfo.Invalid;
     return(false);
 }
        private void generalReserve()
        {
            if (PRFGameComponent.PRF_StaticPawn == null)
            {
                PRFGameComponent.GenStaticPawn();
            }
            if (PRFGameComponent.PRF_StaticJob == null)
            {
                PRFGameComponent.PRF_StaticJob = new Job(PRFDefOf.PRFStaticJob);
            }

            Building tb = researchBench ?? drilltypeBuilding;

            List <ReservationManager.Reservation> reservations;

            reservations = (List <ReservationManager.Reservation>)ReflectionUtility.sal_reservations.GetValue(Map.reservationManager);
            var res = new ReservationManager.Reservation(PRFGameComponent.PRF_StaticPawn, PRFGameComponent.PRF_StaticJob, 1, -1, tb /*(Position + Rotation.FacingCell)*/, null);

            if (!reservations.Where(r => r.Claimant == PRFGameComponent.PRF_StaticPawn && r.Job == PRFGameComponent.PRF_StaticJob && r.Target == tb).Any())
            {
                reservations.Add(res);
            }
            ReflectionUtility.sal_reservations.SetValue(Map.reservationManager, reservations);

            //Spammy Debug

            /*
             * reservations = (List<ReservationManager.Reservation>)ReflectionUtility.sal_reservations.GetValue(Map.reservationManager);
             * reservations = reservations.Where(r => r.Faction != null && r.Faction.IsPlayer).ToList();
             * foreach (ReservationManager.Reservation res in reservations)
             * {
             *  Log.Message("Reservation for " + res.Claimant + " at " + res.Target);
             *
             * }
             */
        }
        public static bool CanReserve(ReservationManager __instance,
                                      Pawn claimant,
                                      LocalTargetInfo target,
                                      int maxPawns                 = 1,
                                      int stackCount               = -1,
                                      ReservationLayerDef layer    = null,
                                      bool ignoreOtherReservations = false)
        {
            if (claimant == null)
            {
                Log.Error("CanReserve with null claimant", false);
                return(false);
            }
            if (!claimant.Spawned || claimant.Map != map(__instance) || (!target.IsValid || target.ThingDestroyed) || target.HasThing && target.Thing.SpawnedOrAnyParentSpawned && target.Thing.MapHeld != map(__instance))
            {
                return(false);
            }
            int num1 = target.HasThing ? target.Thing.stackCount : 1;
            int num2 = stackCount == -1 ? num1 : stackCount;

            if (num2 > num1)
            {
                return(false);
            }
            if (!ignoreOtherReservations)
            {
                if (map(__instance).physicalInteractionReservationManager.IsReserved(target) && !map(__instance).physicalInteractionReservationManager.IsReservedBy(claimant, target))
                {
                    return(false);
                }
                for (int index = 0; index < reservations(__instance).Count; ++index)
                {
                    ReservationManager.Reservation reservation = reservations(__instance)[index];
                    if (null != reservation)
                    {
                        if (reservation.Target == target && reservation.Layer == layer && reservation.Claimant == claimant && (reservation.StackCount == -1 || reservation.StackCount >= num2))
                        {
                            return(true);
                        }
                    }
                }
                int num3 = 0;
                int num4 = 0;
                for (int index = 0; index < reservations(__instance).Count; ++index)
                {
                    ReservationManager.Reservation reservation = reservations(__instance)[index];
                    if (null != reservation)
                    {
                        if (!(reservation.Target != target) && reservation.Layer == layer && (reservation.Claimant != claimant && RespectsReservationsOf(claimant, reservation.Claimant)))
                        {
                            if (reservation.MaxPawns != maxPawns)
                            {
                                return(false);
                            }
                            ++num3;
                            if (reservation.StackCount == -1)
                            {
                                num4 += num1;
                            }
                            else
                            {
                                num4 += reservation.StackCount;
                            }
                            if (num3 >= maxPawns || num2 + num4 > num1)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
        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);
        }