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);
        }
        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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
        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));
                }
            });
        }
Esempio n. 7
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));
                }
            });
        }
        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));
                }
            });
        }
        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;
        }
Esempio n. 10
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);
        }
 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;
 }
Esempio n. 12
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);
        }
        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);
        }