public static bool ReleaseAllClaimedBy(PhysicalInteractionReservationManager __instance, Pawn claimant)
 {
     if (instancePawnToTargetToJob.TryGetValue(__instance, out Dictionary <Pawn, Dictionary <LocalTargetInfo, Job> > pawnToTargetToJob))
     {
         if (pawnToTargetToJob.TryGetValue(claimant, out Dictionary <LocalTargetInfo, Job> targetToJob) && targetToJob.Count > 0)
         {
             lock (__instance)
             {
                 foreach (KeyValuePair <LocalTargetInfo, Job> kvp in targetToJob)
                 {
                     LocalTargetInfo localTargetInfo = kvp.Key;
                     if (instanceTargetToPawnToJob.TryGetValue(__instance, out Dictionary <LocalTargetInfo, Dictionary <Pawn, Job> > targetToPawnToJob))
                     {
                         if (targetToPawnToJob.TryGetValue(localTargetInfo, out Dictionary <Pawn, Job> pawnToJob))
                         {
                             if (pawnToJob.TryGetValue(claimant, out _))
                             {
                                 pawnToJob.Remove(claimant);
                                 PlantHarvest_Cache.ReregisterObject(claimant.Map, localTargetInfo.Cell, PlantHarvest_Cache.awaitingHarvestCellsMapDict);
                             }
                         }
                     }
                 }
                 pawnToTargetToJob.Remove(claimant);
             }
         }
     }
     return(false);
 }
 public static bool ReleaseAllForTarget(PhysicalInteractionReservationManager __instance, LocalTargetInfo target)
 {
     if (instanceTargetToPawnToJob.TryGetValue(__instance, out Dictionary <LocalTargetInfo, Dictionary <Pawn, Job> > targetToPawnToJob))
     {
         if (targetToPawnToJob.TryGetValue(target, out _))
         {
             lock (__instance)
             {
                 if (targetToPawnToJob.TryGetValue(target, out Dictionary <Pawn, Job> pawnToJob))
                 {
                     foreach (KeyValuePair <Pawn, Job> kvp in pawnToJob)
                     {
                         if (instancePawnToTargetToJob.TryGetValue(__instance, out Dictionary <Pawn, Dictionary <LocalTargetInfo, Job> > pawnToTargetToJob))
                         {
                             Pawn pawn = kvp.Key;
                             if (pawnToTargetToJob.TryGetValue(pawn, out Dictionary <LocalTargetInfo, Job> targetToJob))
                             {
                                 if (targetToJob.TryGetValue(target, out _))
                                 {
                                     targetToJob.Remove(target);
                                 }
                             }
                         }
                     }
                     targetToPawnToJob.Remove(target);
                     if (target != null && target.Thing != null && target.Thing.Map != null)
                     {
                         PlantHarvest_Cache.ReregisterObject(target.Thing.Map, target.Cell, PlantHarvest_Cache.awaitingHarvestCellsMapDict);
                     }
                 }
             }
         }
     }
     return(false);
 }
コード例 #3
0
 public static void set_Growth(Plant __instance, float value)
 {
     if (__instance.Map != null && __instance.LifeStage == PlantLifeStage.Mature)
     {
         PlantHarvest_Cache.ReregisterObject(__instance.Map, __instance.Position, PlantHarvest_Cache.awaitingHarvestCellsMapDict);
     }
 }
コード例 #4
0
        internal static IntVec3 ClosestLocationReachable(WorkGiver_GrowerHarvest workGiver_GrowerHarvest, Pawn pawn)
        {
            Danger maxDanger = pawn.NormalMaxDanger();
            //bool forced = false;
            Map         map         = pawn.Map;
            ZoneManager zoneManager = pawn.Map.zoneManager;

            foreach (IntVec3 actionableLocation in PlantHarvest_Cache.GetClosestActionableLocations(pawn, map, PlantHarvest_Cache.awaitingHarvestCellsMapDict))
            {
                List <Thing> thingsAtLocation = GridsUtility.GetThingList(actionableLocation, map);
                foreach (Thing thingAtLocation in thingsAtLocation)
                {
                    if (thingAtLocation is Building_PlantGrower building_PlantGrower)
                    {
                        if (building_PlantGrower == null || !workGiver_GrowerHarvest.ExtraRequirements(building_PlantGrower, pawn) ||
                            building_PlantGrower.IsForbidden(pawn) ||
                            !pawn.CanReach(building_PlantGrower, PathEndMode.OnCell, maxDanger)
                            )
                        {
                            continue;
                        }
                        return(actionableLocation);
                    }
                }
                if (!(zoneManager.ZoneAt(actionableLocation) is Zone_Growing growZone))
                {
                    continue;
                }
                if (!workGiver_GrowerHarvest.ExtraRequirements(growZone, pawn))
                {
                    continue;
                }
                //if (!JobOnCellTest(workGiver_GrowerHarvest, pawn, actionableLocation, forced))
                //{
                //	continue;
                //}
                if (!workGiver_GrowerHarvest.HasJobOnCell(pawn, actionableLocation))
                {
                    PlantHarvest_Cache.ReregisterObject(pawn.Map, actionableLocation, PlantHarvest_Cache.awaitingHarvestCellsMapDict);
                    continue;
                }
                if (!pawn.CanReach(actionableLocation, PathEndMode.OnCell, maxDanger))
                {
                    continue;
                }
                return(actionableLocation);
            }
            return(IntVec3.Invalid);
        }
        public static bool Release(PhysicalInteractionReservationManager __instance, Pawn claimant, Job job, LocalTargetInfo target)
        {
            bool plantReregistered = false;

            lock (__instance)
            {
                if (instanceTargetToPawnToJob.TryGetValue(__instance, out Dictionary <LocalTargetInfo, Dictionary <Pawn, Job> > targetToPawnToJob))
                {
                    if (targetToPawnToJob.TryGetValue(target, out Dictionary <Pawn, Job> pawnToJob))
                    {
                        if (pawnToJob.TryGetValue(claimant, out Job outJob))
                        {
                            if (outJob == job)
                            {
                                pawnToJob.Remove(claimant);
                                plantReregistered = true;
                                PlantHarvest_Cache.ReregisterObject(claimant.Map, target.Cell, PlantHarvest_Cache.awaitingHarvestCellsMapDict);
                            }
                            else
                            {
                                Log.Warning(claimant.ToString() + " tried to release reservation on target " + target + ", but job was different.");
                            }
                        }
                        else
                        {
                            Log.Warning(claimant.ToString() + " tried to release reservation on target " + target + ", but job was different.");
                        }
                    }
                    else
                    {
                        Log.Warning(claimant.ToString() + " tried to release reservation on target " + target + ", but claimant was not found.");
                    }
                }
                else
                {
                    Log.Warning(claimant.ToString() + " tried to release reservation on target " + target + ", but target had no physical reservations.");
                }
                if (instancePawnToTargetToJob.TryGetValue(__instance, out Dictionary <Pawn, Dictionary <LocalTargetInfo, Job> > pawnToTargetToJob))
                {
                    if (pawnToTargetToJob.TryGetValue(claimant, out Dictionary <LocalTargetInfo, Job> targetToJob))
                    {
                        if (targetToJob.TryGetValue(target, out Job outJob2))
                        {
                            if (outJob2 == job)
                            {
                                bool targetToJobResult = targetToJob.Remove(target);
                                if (!plantReregistered)
                                {
                                    PlantHarvest_Cache.ReregisterObject(claimant.Map, target.Cell, PlantHarvest_Cache.awaitingHarvestCellsMapDict);
                                }
                            }
                            else
                            {
                                Log.Warning(claimant.ToString() + " tried to release reservation on target " + target + ", but job was different.");
                            }
                        }
                        else
                        {
                            Log.Warning(claimant.ToString() + " tried to release reservation on target " + target + ", but job was different.");
                        }
                    }
                    else
                    {
                        Log.Warning(claimant.ToString() + " tried to release reservation on target " + target + ", but claimant was not found.");
                    }
                }
                else
                {
                    Log.Warning(claimant.ToString() + " tried to release reservation on target " + target + ", but target had no physical reservations.");
                }
            }
            return(false);
        }