예제 #1
0
        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            ISlotGroupParent slotGroupParent = thing as ISlotGroupParent;

            if (slotGroupParent == null)
            {
                return(null);
            }
            if (!pawn.CanReserve(thing.Position))
            {
                return(null);
            }
            int          num  = 0;
            List <Thing> list = pawn.Map.thingGrid.ThingsListAt(thing.Position);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing2 = list[i];
                if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thing2.def))
                {
                    num += thing2.stackCount;
                }
            }
            if (num > 25)
            {
                JobFailReason.Is("AlreadyFilledLower".Translate());
                return(null);
            }
            return(HopperFillFoodJob(pawn, slotGroupParent));
        }
 public static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp)
 {
     Building building = hopperSgp as Building;
     if (!pawn.CanReserveAndReach(building.Position, PathEndMode.Touch, pawn.NormalMaxDanger(), 1))
     {
         return null;
     }
     ThingDef thingDef = null;
     Thing firstItem = building.Position.GetFirstItem();
     if (firstItem != null)
     {
         if (Building_AquacultureBasin.IsAcceptableFeedstock(firstItem.def))
         {
             thingDef = firstItem.def;
         }
         else
         {
             if (firstItem.IsForbidden(pawn))
             {
                 return null;
             }
             return HaulAIUtility.HaulAsideJobFor(pawn, firstItem);
         }
     }
     List<Thing> list;
     if (thingDef == null)
     {
         list = Find.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree);
     }
     else
     {
         list = Find.Map.listerThings.ThingsOfDef(thingDef);
     }
     for (int i = 0; i < list.Count; i++)
     {
         Thing thing = list[i];
         if (thing.def.IsNutritionGivingIngestible)
         {
             if (thing.def.ingestible.preferability == FoodPreferability.RawBad || thing.def.ingestible.preferability == FoodPreferability.RawTasty)
             {
                 if (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, thing))
                 {
                     if (Find.SlotGroupManager.SlotGroupAt(building.Position).Settings.AllowedToAccept(thing))
                     {
                         StoragePriority storagePriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing);
                         if (storagePriority < hopperSgp.GetSlotGroup().Settings.Priority)
                         {
                             Job job = HaulAIUtility.HaulMaxNumToCellJob(pawn, thing, building.Position, true);
                             if (job != null)
                             {
                                 return job;
                             }
                         }
                     }
                 }
             }
         }
     }
     return null;
 }
        public void AddHaulDestination(IHaulDestination haulDestination)
        {
            if (this.allHaulDestinationsInOrder.Contains(haulDestination))
            {
                Log.Error("Double-added haul destination " + haulDestination.ToStringSafe <IHaulDestination>(), false);
                return;
            }
            this.allHaulDestinationsInOrder.Add(haulDestination);
            this.allHaulDestinationsInOrder.InsertionSort(new Comparison <IHaulDestination>(HaulDestinationManager.CompareHaulDestinationPrioritiesDescending));
            ISlotGroupParent slotGroupParent = haulDestination as ISlotGroupParent;

            if (slotGroupParent != null)
            {
                SlotGroup slotGroup = slotGroupParent.GetSlotGroup();
                if (slotGroup == null)
                {
                    Log.Error("ISlotGroupParent gave null slot group: " + slotGroupParent.ToStringSafe <ISlotGroupParent>(), false);
                }
                else
                {
                    this.allGroupsInOrder.Add(slotGroup);
                    this.allGroupsInOrder.InsertionSort(new Comparison <SlotGroup>(HaulDestinationManager.CompareSlotGroupPrioritiesDescending));
                    List <IntVec3> cellsList = slotGroup.CellsList;
                    for (int i = 0; i < cellsList.Count; i++)
                    {
                        this.SetCellFor(cellsList[i], slotGroup);
                    }
                    this.map.listerHaulables.Notify_SlotGroupChanged(slotGroup);
                    this.map.listerMergeables.Notify_SlotGroupChanged(slotGroup);
                }
            }
        }
        public void AddHaulDestination(IHaulDestination haulDestination)
        {
            if (allHaulDestinationsInOrder.Contains(haulDestination))
            {
                Log.Error("Double-added haul destination " + haulDestination.ToStringSafe());
                return;
            }
            allHaulDestinationsInOrder.Add(haulDestination);
            allHaulDestinationsInOrder.InsertionSort(CompareHaulDestinationPrioritiesDescending);
            ISlotGroupParent slotGroupParent = haulDestination as ISlotGroupParent;

            if (slotGroupParent == null)
            {
                return;
            }
            SlotGroup slotGroup = slotGroupParent.GetSlotGroup();

            if (slotGroup == null)
            {
                Log.Error("ISlotGroupParent gave null slot group: " + slotGroupParent.ToStringSafe());
                return;
            }
            allGroupsInOrder.Add(slotGroup);
            allGroupsInOrder.InsertionSort(CompareSlotGroupPrioritiesDescending);
            List <IntVec3> cellsList = slotGroup.CellsList;

            for (int i = 0; i < cellsList.Count; i++)
            {
                SetCellFor(cellsList[i], slotGroup);
            }
            map.listerHaulables.Notify_SlotGroupChanged(slotGroup);
            map.listerMergeables.Notify_SlotGroupChanged(slotGroup);
        }
        public void RemoveHaulDestination(IHaulDestination haulDestination)
        {
            if (!allHaulDestinationsInOrder.Contains(haulDestination))
            {
                Log.Error("Removing haul destination that isn't registered " + haulDestination.ToStringSafe());
                return;
            }
            allHaulDestinationsInOrder.Remove(haulDestination);
            ISlotGroupParent slotGroupParent = haulDestination as ISlotGroupParent;

            if (slotGroupParent == null)
            {
                return;
            }
            SlotGroup slotGroup = slotGroupParent.GetSlotGroup();

            if (slotGroup == null)
            {
                Log.Error("ISlotGroupParent gave null slot group: " + slotGroupParent.ToStringSafe());
                return;
            }
            allGroupsInOrder.Remove(slotGroup);
            List <IntVec3> cellsList = slotGroup.CellsList;

            for (int i = 0; i < cellsList.Count; i++)
            {
                IntVec3 intVec = cellsList[i];
                groupGrid[intVec.x, intVec.y, intVec.z] = null;
            }
            map.listerHaulables.Notify_SlotGroupChanged(slotGroup);
            map.listerMergeables.Notify_SlotGroupChanged(slotGroup);
        }
예제 #6
0
        public override Job JobOnThing(Pawn pawn, Thing thing)
        {
            ISlotGroupParent slotGroupParent = thing as ISlotGroupParent;

            if (slotGroupParent == null)
            {
                return(null);
            }
            if (!pawn.CanReserve(thing.Position, 1))
            {
                return(null);
            }
            int          num  = 0;
            List <Thing> list = pawn.MapHeld.thingGrid.ThingsListAt(thing.Position);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing2 = list[i];
                if (Building_AquacultureBasin.IsAcceptableFeedstock(thing2.def))
                {
                    num += thing2.stackCount;
                }
            }
            if (num > 25)
            {
                JobFailReason.Is("AlreadyFilledLower".Translate());
                return(null);
            }
            return(WorkGiver_FillAquacultureHopper.HopperFillFoodJob(pawn, slotGroupParent));
        }
예제 #7
0
        public static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp)
        {
            Building building = hopperSgp as Building;

            if (!pawn.CanReserveAndReach(building.Position, PathEndMode.Touch, pawn.NormalMaxDanger(), 1))
            {
                return(null);
            }
            ThingDef thingDef  = null;
            Thing    firstItem = building.Position.GetFirstItem();

            if (firstItem != null)
            {
                if (firstItem.def.IsNutritionSource)
                {
                    thingDef = firstItem.def;
                }
                else
                {
                    if (firstItem.IsForbidden(pawn.Faction))
                    {
                        return(null);
                    }
                    return(HaulAIUtility.HaulAsideJobFor(pawn, firstItem));
                }
            }
            List <Thing> list;

            if (thingDef == null)
            {
                list = Find.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodNotPlantOrTree);
            }
            else
            {
                list = Find.Map.listerThings.ThingsOfDef(thingDef);
            }
            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.ingestible.preferability == FoodPreferability.Raw)
                {
                    if (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, thing))
                    {
                        if (Find.SlotGroupManager.SlotGroupAt(building.Position).Settings.AllowedToAccept(thing))
                        {
                            StoragePriority storagePriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing);
                            if (storagePriority < hopperSgp.GetSlotGroup().Settings.Priority)
                            {
                                Job job = HaulAIUtility.HaulMaxNumToCellJob(pawn, thing, building.Position, true);
                                if (job != null)
                                {
                                    return(job);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
예제 #8
0
 public static void Prefix(ref Rect rect)
 {
     selected = Find.Selector.SingleSelectedObject as ISlotGroupParent;
     if (selected != null)
     {
         rect.yMin += 90f;
     }
 }
        //[DetourMethod(typeof(RimWorld.JobGiver_GetFood),"TryGiveJob")]
        // RimWorld.JobGiver_GetFood
        protected override Job TryGiveJob(Pawn pawn)
        {
            bool flag;

            if (pawn.RaceProps.Animal)
            {
                flag = true;
            }
            else
            {
                Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition);
                flag = (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f);
            }
            bool     desperate   = pawn.needs.food.CurCategory == HungerCategory.Starving;
            bool     allowCorpse = flag;
            Thing    thing;
            ThingDef def;

            if (!RimWorld.FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out thing, out def, true, true, false, allowCorpse))
            {
                return(null);
            }
            Pawn pawn2 = thing as Pawn;

            if (pawn2 != null)
            {
                return(new Job(JobDefOf.PredatorHunt, pawn2)
                {
                    killIncappedTarget = true
                });
            }
            var building_NutrientPasteDispenser = thing as Building_NutrientPasteDispenser;

            if (building_NutrientPasteDispenser != null && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers())
            {
                Building building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn);
                if (building != null)
                {
                    ISlotGroupParent hopperSgp = building as ISlotGroupParent;
                    //TODO utiliser original?
                    Job job = RimWorld.WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp);
                    if (job != null)
                    {
                        return(job);
                    }
                }
                thing = RimWorld.FoodUtility.BestFoodSourceOnMap(pawn, pawn, desperate, FoodPreferability.MealLavish, false, false, false, false, false, false);
                if (thing == null)
                {
                    return(null);
                }
                def = thing.def;
            }
            return(new Job(JobDefOf.Ingest, thing)
            {
                count = RimWorld.FoodUtility.WillIngestStackCountOf(pawn, def)
            });
        }
예제 #10
0
        [HarmonyPriority(Priority.First)] // MUST execute, cannot be postfix,
                                          // as some elements already null (e.g., map)
        public static void Prefix(Building __instance)
        {
            CompDeepStorage cds;

            if ((cds = __instance.GetComp <CompDeepStorage>()) == null)
            {
                return;
            }
            Map map = __instance.Map;

            if (map == null)
            {
                Log.Error("DeepStorage despawning: Map is null; some assets may not display properly: "
                          + __instance.ToString()); return;
            }
            ISlotGroupParent DSU = __instance as Building_Storage;

            foreach (IntVec3 cell in DSU.AllSlotCells())
            {
                List <Thing> list = map.thingGrid.ThingsListAt(cell);
                Thing        t;
                for (int i = 0; i < list.Count; i++)
                {
                    t = list[i];
                    Utils.TopThingInDeepStorage.Remove(t); // just take them all, to be safe
                    if (t == null)
                    {
                        Log.Warning("DeepStorage despawning: tried to clean up null object"); continue;
                    }
                    if (!t.Spawned || !t.def.EverStorable(false))
                    {
                        continue;
                    }
                    if (t.def.drawerType != DrawerType.MapMeshOnly)
                    {   // should be safe to register even if already registered
                        map.dynamicDrawManager.RegisterDrawable(t);
                    }
                    // from the ListerThings code:
                    if (ThingRequestGroup.HasGUIOverlay.Includes(t.def))
                    {
                        if (!map.listerThings.ThingsInGroup(ThingRequestGroup.HasGUIOverlay).Contains(t))
                        {
                            map.listerThings.ThingsInGroup(ThingRequestGroup.HasGUIOverlay).Add(t);
                        }
                    }
                    // Just to make sure it's not in the tooltip list twice:
                    //    Is this ineffecient?  Yes.
                    //    It also means that if anything changes whether cds.showContents, nothing breaks
                    //    Also, this only happens rarely, so ineffecient is okay.
                    map.tooltipGiverList.Notify_ThingDespawned(t);
                    map.tooltipGiverList.Notify_ThingSpawned(t);
                } // end list of things at
            }     // end foreach cell of despawning DSU
        }         //end postfix
예제 #11
0
        public static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp)
        {
            Building building = (Building)hopperSgp;

            if (!pawn.CanReserveAndReach(building.Position, PathEndMode.Touch, pawn.NormalMaxDanger()))
            {
                return(null);
            }
            ThingDef thingDef  = null;
            Thing    firstItem = building.Position.GetFirstItem(building.Map);

            if (firstItem != null)
            {
                if (!Building_NutrientPasteDispenser.IsAcceptableFeedstock(firstItem.def))
                {
                    if (firstItem.IsForbidden(pawn))
                    {
                        return(null);
                    }
                    return(HaulAIUtility.HaulAsideJobFor(pawn, firstItem));
                }
                thingDef = firstItem.def;
            }
            List <Thing> list = (thingDef != null) ? pawn.Map.listerThings.ThingsOfDef(thingDef) : pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree);
            bool         flag = false;

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.IsNutritionGivingIngestible && (thing.def.ingestible.preferability == FoodPreferability.RawBad || thing.def.ingestible.preferability == FoodPreferability.RawTasty) && HaulAIUtility.PawnCanAutomaticallyHaul(pawn, thing, forced: false) && pawn.Map.haulDestinationManager.SlotGroupAt(building.Position).Settings.AllowedToAccept(thing))
                {
                    StoragePriority storagePriority = StoreUtility.CurrentStoragePriorityOf(thing);
                    if ((int)storagePriority >= (int)hopperSgp.GetSlotGroup().Settings.Priority)
                    {
                        flag = true;
                        JobFailReason.Is(TheOnlyAvailableFoodIsInStorageOfHigherPriorityTrans);
                    }
                    else
                    {
                        Job job = HaulAIUtility.HaulToCellStorageJob(pawn, thing, building.Position, fitInStoreCell: true);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }
            }
            if (!flag)
            {
                JobFailReason.Is(NoFoodToFillHopperTrans);
            }
            return(null);
        }
예제 #12
0
        private List <Thing> SetStoredItems(ISlotGroupParent buildingStorage)
        {
            var slotCells = buildingStorage?.AllSlotCells().ToList();
            var thingGrid = Find.CurrentMap.thingGrid;

            if (slotCells == null || thingGrid == null || slotCells.OptimizedNullOrEmpty())
            {
                return(null);
            }

            slotCount = slotCells.Count;
            return(slotCells.SelectMany(slotCell => thingGrid.ThingsListAt(slotCell).Where(thing => thing.Spawned && thing.def.EverStorable(false))).ToList());
        }
예제 #13
0
        private static Job                  HopperFillJob(Pawn pawn, ISlotGroupParent hopperSgp, Thing resource)
        {
            Building building = hopperSgp as Building;

            // Get a sorted list (by distance) of matching resources
            List <Thing> resources = null;

            if (resource != null)
            {
                resources = Find.Map.listerThings.ThingsOfDef(resource.def)
                            .Where(t => (
                                       (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t)) &&
                                       (hopperSgp.GetStoreSettings().AllowedToAccept(t)) &&
                                       (HaulAIUtility.StoragePriorityAtFor(t.Position, t) < hopperSgp.GetSlotGroup().Settings.Priority)
                                       )).ToList();
            }
            else
            {
                resources = Find.Map.listerThings.AllThings
                            .Where(t => (
                                       (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t)) &&
                                       (hopperSgp.GetStoreSettings().AllowedToAccept(t)) &&
                                       (HaulAIUtility.StoragePriorityAtFor(t.Position, t) < hopperSgp.GetSlotGroup().Settings.Priority)
                                       )).ToList();
            }

            if (resources.NullOrEmpty())
            {
                return((Job)null);
            }

            // Sort by distance (closest first)
            resources.Sort((Thing x, Thing y) => (Gen.ManhattanDistanceFlat(x.Position, building.Position) < Gen.ManhattanDistanceFlat(y.Position, building.Position)) ? -1 : 1);

            var grabResource = resources.First();

            if (grabResource != null)
            {
                // Try to haul the first (closest) resource found
                var job = HaulAIUtility.HaulMaxNumToCellJob(pawn, grabResource, building.Position, true);
                if (job != null)
                {
                    return(job);
                }
            }
            return((Job)null);
        }
예제 #14
0
        private static Job HopperFillJob( Pawn pawn, ISlotGroupParent hopperSgp, Thing resource )
        {
            Building building = hopperSgp as Building;

            // Get a sorted list (by distance) of matching resources
            List< Thing > resources = null;

            if( resource != null )
            {
                resources = Find.Map.listerThings.ThingsOfDef( resource.def )
                    .Where( t => (
                        ( HaulAIUtility.PawnCanAutomaticallyHaul( pawn, t ) )&&
                        ( hopperSgp.GetStoreSettings().AllowedToAccept( t ) )&&
                        ( HaulAIUtility.StoragePriorityAtFor( t.Position, t ) < hopperSgp.GetSlotGroup().Settings.Priority )
                    ) ).ToList();
            }
            else
            {
                resources = Find.Map.listerThings.AllThings
                    .Where( t => (
                        ( HaulAIUtility.PawnCanAutomaticallyHaul( pawn, t ) )&&
                        ( hopperSgp.GetStoreSettings().AllowedToAccept( t ) )&&
                        ( HaulAIUtility.StoragePriorityAtFor( t.Position, t ) < hopperSgp.GetSlotGroup().Settings.Priority )
                    ) ).ToList();
            }

            if( resources.NullOrEmpty() )
            {
                return (Job) null;
            }

            // Sort by distance (closest first)
            resources.Sort( ( Thing x, Thing y ) => ( Gen.ManhattanDistanceFlat( x.Position, building.Position ) < Gen.ManhattanDistanceFlat( y.Position, building.Position ) ) ? -1 : 1 );

            var grabResource = resources.First();
            if( grabResource != null )
            {
                // Try to haul the first (closest) resource found
                var job = HaulAIUtility.HaulMaxNumToCellJob( pawn, grabResource, building.Position, true );
                if( job != null )
                {
                    return job;
                }
            }
            return (Job) null;
        }
        private static Thing HopperGetCurrentResource( IntVec3 position, ISlotGroupParent hopperSgp )
        {
            var list = Find.ThingGrid.ThingsListAt( position ).Where( t => (
                ( !HopperDefs.Contains( t.def ) )&&
                ( hopperSgp.GetStoreSettings().AllowedToAccept( t ) )
            ) ).ToList();
            if( list.NullOrEmpty() )
            {
                return (Thing) null;
            }

            return list.First();
        }
        public static IEnumerable <Gizmo> InsertUrgentRefillGizmos(IEnumerable <Gizmo> __result, Map map, ISlotGroupParent parent)
        {
            foreach (var r in __result)
            {
                yield return(r);
            }
            if (!UrgentRefill.active)
            {
                yield break;
            }
            SlotGroup group = parent.GetSlotGroup();

            yield return(new Command_Toggle()
            {
                defaultLabel = "TD.GizmoUrgentRefill".Translate(),
                defaultDesc = "TD.GizmoUrgentRefillDesc".Translate(),
                icon = haulUrgentlyIcon,
                isActive = () => group.IsMarkedForRefill(map),
                toggleAction = delegate
                {
                    group.MarkForRefill(map, !group.IsMarkedForRefill(map));
                }
            });
        }
        public static void InsertUrgentRefillGizmos(ref IEnumerable <Gizmo> __result, Map map, ISlotGroupParent parent)
        {
            SlotGroup group = parent.GetSlotGroup();

            __result = __result.Add(new Command_Toggle()
            {
                defaultLabel = "Urgent Refill",
                defaultDesc  = "If any cell is unoccupied, it will be urgently refilled",
                icon         = haulUrgentlyIcon,
                isActive     = () => AllowToolController.Instance.WorldSettings.IsMarkedForRefill(map, group),
                toggleAction = delegate
                {
                    AllowToolController.Instance.WorldSettings.MarkForRefill(map, group,
                                                                             !AllowToolController.Instance.WorldSettings.IsMarkedForRefill(map, group));
                }
            });
        }
        internal static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp, Thing parent)
        {
            var building = hopperSgp as Building;

            if (
                (!pawn.CanReserveAndReach(
                     ( TargetInfo )building.Position,
                     PathEndMode.Touch,
                     pawn.NormalMaxDanger(),
                     1)
                )
                )
            {
                return((Job)null);
            }
            ThingDef resourceDef = null;
            var      firstItem   = building.Position.GetFirstItem();

            if (firstItem != null)
            {
                if (
                    (
                        (parent is Building_NutrientPasteDispenser) &&
                        (Building_NutrientPasteDispenser.IsAcceptableFeedstock(firstItem.def))
                    ) ||
                    (
                        (parent is Building_AutomatedFactory) &&
                        (((Building_AutomatedFactory)parent).CompHopperUser.ResourceSettings.AllowedToAccept(firstItem))
                    )
                    )
                {
                    resourceDef = firstItem.def;
                }
                else
                {
                    if (firstItem.IsForbidden(pawn))
                    {
                        return(( Job )null);
                    }
                    return(HaulAIUtility.HaulAsideJobFor(pawn, firstItem));
                }
            }
            List <Thing> list =
                resourceDef != null
                ? Find.Map.listerThings.ThingsOfDef(resourceDef)
                : Find.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodNotPlantOrTree);

            for (int index = 0; index < list.Count; ++index)
            {
                Thing t = list[index];
                if (
                    (t.def.ingestible.preferability == FoodPreferability.Raw) &&
                    (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t)) &&
                    (
                        (Find.SlotGroupManager.SlotGroupAt(building.Position).Settings.AllowedToAccept(t)) &&
                        (HaulAIUtility.StoragePriorityAtFor(t.Position, t) < hopperSgp.GetSlotGroup().Settings.Priority)
                    )
                    )
                {
                    Job job = HaulAIUtility.HaulMaxNumToCellJob(pawn, t, building.Position, true);
                    if (job != null)
                    {
                        return(job);
                    }
                }
            }
            return((Job)null);
        }
예제 #19
0
 public SlotGroup(ISlotGroupParent parent)
 {
     this.parent = parent;
 }
예제 #20
0
 // RimWorld.WorkGiver_CookFillHopper
 public static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp)
 {
     return((Job)Type.GetType("RimWorld.WorkGiver_CookFillHopper").GetMethod("HopperFillFoodJob", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { pawn, hopperSgp }));
 }
예제 #21
0
        private static Thing                HopperGetCurrentResource(IntVec3 position, ISlotGroupParent hopperSgp)
        {
            var list = Find.ThingGrid.ThingsListAt(position).Where(t => (
                                                                       (!HopperDefs.Contains(t.def)) &&
                                                                       (hopperSgp.GetStoreSettings().AllowedToAccept(t))
                                                                       )).ToList();

            if (list.NullOrEmpty())
            {
                return((Thing)null);
            }

            return(list.First());
        }
예제 #22
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Need_Food food = pawn.needs.food;

            if (food == null || food.CurCategory < this.minCategory)
            {
                return(null);
            }
            bool flag;

            if (pawn.AnimalOrWildMan())
            {
                flag = true;
            }
            else
            {
                Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition, false);
                flag = (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f);
            }
            bool     flag2              = pawn.needs.food.CurCategory == HungerCategory.Starving;
            bool     desperate          = flag2;
            bool     canRefillDispenser = true;
            bool     canUseInventory    = true;
            bool     allowCorpse        = flag;
            bool     flag3              = this.forceScanWholeMap;
            Thing    thing;
            ThingDef thingDef;

            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out thing, out thingDef, canRefillDispenser, canUseInventory, false, allowCorpse, false, pawn.IsWildMan(), flag3))
            {
                return(null);
            }
            Pawn pawn2 = thing as Pawn;

            if (pawn2 != null)
            {
                return(new Job(JobDefOf.PredatorHunt, pawn2)
                {
                    killIncappedTarget = true
                });
            }
            if (thing is Plant && thing.def.plant.harvestedThingDef == thingDef)
            {
                return(new Job(JobDefOf.Harvest, thing));
            }
            Building_NutrientPasteDispenser building_NutrientPasteDispenser = thing as Building_NutrientPasteDispenser;

            if (building_NutrientPasteDispenser != null && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers())
            {
                Building building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn);
                if (building != null)
                {
                    ISlotGroupParent hopperSgp = building as ISlotGroupParent;
                    Job job = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp);
                    if (job != null)
                    {
                        return(job);
                    }
                }
                thing = FoodUtility.BestFoodSourceOnMap(pawn, pawn, flag2, out thingDef, FoodPreferability.MealLavish, false, !pawn.IsTeetotaler(), false, false, false, false, false, false, this.forceScanWholeMap);
                if (thing == null)
                {
                    return(null);
                }
            }
            float nutrition = FoodUtility.GetNutrition(thing, thingDef);

            return(new Job(JobDefOf.Ingest, thing)
            {
                count = FoodUtility.WillIngestStackCountOf(pawn, thingDef, nutrition)
            });
        }
예제 #23
0
 public SlotGroup(ISlotGroupParent parent)
 {
     this.parent = parent;
     this.Map.slotGroupManager.AddGroup(this);
 }
예제 #24
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Need_Food food = pawn.needs.food;

            if (food == null || (int)food.CurCategory < (int)minCategory)
            {
                return(null);
            }
            bool flag;

            if (pawn.AnimalOrWildMan())
            {
                flag = true;
            }
            else
            {
                Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition);
                flag = (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f);
            }
            bool     flag2              = pawn.needs.food.CurCategory == HungerCategory.Starving;
            bool     desperate          = flag2;
            bool     canRefillDispenser = true;
            bool     canUseInventory    = true;
            bool     allowCorpse        = flag;
            bool     flag3              = forceScanWholeMap;
            Thing    foodSource         = default(Thing);
            ThingDef foodDef            = default(ThingDef);

            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out foodSource, out foodDef, canRefillDispenser, canUseInventory, allowForbidden: false, allowCorpse, allowSociallyImproper: false, pawn.IsWildMan(), flag3))
            {
                return(null);
            }
            Pawn pawn2 = foodSource as Pawn;

            if (pawn2 != null)
            {
                Job job = new Job(JobDefOf.PredatorHunt, pawn2);
                job.killIncappedTarget = true;
                return(job);
            }
            if (foodSource is Plant && foodSource.def.plant.harvestedThingDef == foodDef)
            {
                return(new Job(JobDefOf.Harvest, foodSource));
            }
            Building_NutrientPasteDispenser building_NutrientPasteDispenser = foodSource as Building_NutrientPasteDispenser;

            if (building_NutrientPasteDispenser != null && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers())
            {
                Building building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn);
                if (building != null)
                {
                    ISlotGroupParent hopperSgp = building as ISlotGroupParent;
                    Job job2 = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp);
                    if (job2 != null)
                    {
                        return(job2);
                    }
                }
                foodSource = FoodUtility.BestFoodSourceOnMap(pawn, pawn, flag2, out foodDef, FoodPreferability.MealLavish, allowPlant: false, !pawn.IsTeetotaler(), allowCorpse: false, allowDispenserFull: false, allowDispenserEmpty: false, allowForbidden: false, allowSociallyImproper: false, allowHarvest: false, forceScanWholeMap);
                if (foodSource == null)
                {
                    return(null);
                }
            }
            float nutrition = FoodUtility.GetNutrition(foodSource, foodDef);
            Job   job3      = new Job(JobDefOf.Ingest, foodSource);

            job3.count = FoodUtility.WillIngestStackCountOf(pawn, foodDef, nutrition);
            return(job3);
        }
예제 #25
0
        public static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp)
        {
            Building building = hopperSgp as Building;

            if (!pawn.CanReserveAndReach(building.Position, PathEndMode.Touch, pawn.NormalMaxDanger(), 1, -1, null, false))
            {
                return(null);
            }
            ThingDef thingDef  = null;
            Thing    firstItem = building.Position.GetFirstItem(building.Map);

            if (firstItem != null)
            {
                if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(firstItem.def))
                {
                    thingDef = firstItem.def;
                }
                else
                {
                    if (firstItem.IsForbidden(pawn))
                    {
                        return(null);
                    }
                    return(HaulAIUtility.HaulAsideJobFor(pawn, firstItem));
                }
            }
            List <Thing> list;

            if (thingDef == null)
            {
                list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree);
            }
            else
            {
                list = pawn.Map.listerThings.ThingsOfDef(thingDef);
            }
            bool flag = false;

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.IsNutritionGivingIngestible)
                {
                    if (thing.def.ingestible.preferability == FoodPreferability.RawBad || thing.def.ingestible.preferability == FoodPreferability.RawTasty)
                    {
                        if (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, thing, false))
                        {
                            if (pawn.Map.slotGroupManager.SlotGroupAt(building.Position).Settings.AllowedToAccept(thing))
                            {
                                StoragePriority storagePriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing);
                                if (storagePriority >= hopperSgp.GetSlotGroup().Settings.Priority)
                                {
                                    flag = true;
                                    JobFailReason.Is(WorkGiver_CookFillHopper.TheOnlyAvailableFoodIsInStorageOfHigherPriorityTrans);
                                }
                                else
                                {
                                    Job job = HaulAIUtility.HaulMaxNumToCellJob(pawn, thing, building.Position, true);
                                    if (job != null)
                                    {
                                        return(job);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (!flag)
            {
                JobFailReason.Is(WorkGiver_CookFillHopper.NoFoodToFillHopperTrans);
            }
            return(null);
        }
예제 #26
0
        public static void InsertUrgentRefillGizmos(ref IEnumerable <Gizmo> __result, Map map, ISlotGroupParent parent)
        {
            if (!UrgentRefill.active)
            {
                return;
            }
            SlotGroup group = parent.GetSlotGroup();

            __result = __result.Add(new Command_Toggle()
            {
                defaultLabel = "TD.GizmoUrgentRefill".Translate(),
                defaultDesc  = "TD.GizmoUrgentRefillDesc".Translate(),
                icon         = haulUrgentlyIcon,
                isActive     = () => group.IsMarkedForRefill(map),
                toggleAction = delegate
                {
                    group.MarkForRefill(map, !group.IsMarkedForRefill(map));
                }
            });
        }