public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.stackCount == t.def.stackLimit)
            {
                return(null);
            }
            if (!HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t, forced))
            {
                return(null);
            }
            SlotGroup slotGroup = t.GetSlotGroup();

            if (slotGroup == null)
            {
                return(null);
            }
            if (!pawn.CanReserve(t.Position, 1, -1, null, forced))
            {
                return(null);
            }
            foreach (Thing heldThing in slotGroup.HeldThings)
            {
                if (heldThing != t && heldThing.CanStackWith(t) && (forced || heldThing.stackCount >= t.stackCount) && heldThing.stackCount < heldThing.def.stackLimit && pawn.CanReserve(heldThing.Position, 1, -1, null, forced) && pawn.CanReserve(heldThing) && heldThing.Position.IsValidStorageFor(heldThing.Map, t))
                {
                    Job job = JobMaker.MakeJob(JobDefOf.HaulToCell, t, heldThing.Position);
                    job.count    = Mathf.Min(heldThing.def.stackLimit - heldThing.stackCount, t.stackCount);
                    job.haulMode = HaulMode.ToCellStorage;
                    return(job);
                }
            }
            JobFailReason.Is("NoMergeTarget".Translate());
            return(null);
        }
 private Action RestoreRemainingThings(Thing t, int amount)
 {
     return(delegate
     {
         pawn.jobs.TryTakeOrderedJob(HaulAIUtility.HaulToStorageJob(pawn, t));
     });
 }
        public static Job HandleBlockingThingJob(Thing constructible, Pawn worker, bool forced = false)
        {
            Thing thing = GenConstruct.FirstBlockingThing(constructible, worker);
            Job   result;

            if (thing == null)
            {
                result = null;
            }
            else
            {
                if (thing.def.category == ThingCategory.Plant)
                {
                    LocalTargetInfo target    = thing;
                    PathEndMode     peMode    = PathEndMode.ClosestTouch;
                    Danger          maxDanger = worker.NormalMaxDanger();
                    if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.CutPlant, thing));
                    }
                }
                else if (thing.def.category == ThingCategory.Item)
                {
                    if (thing.def.EverHaulable)
                    {
                        return(HaulAIUtility.HaulAsideJobFor(worker, thing));
                    }
                    Log.ErrorOnce(string.Concat(new object[]
                    {
                        "Never haulable ",
                        thing,
                        " blocking ",
                        constructible.ToStringSafe <Thing>(),
                        " at ",
                        constructible.Position
                    }), 6429262, false);
                }
                else if (thing.def.category == ThingCategory.Building)
                {
                    if (worker.story != null && worker.story.WorkTypeIsDisabled(WorkTypeDefOf.Construction))
                    {
                        JobFailReason.Is(GenConstruct.IncapableOfDeconstruction, null);
                        return(null);
                    }
                    LocalTargetInfo target    = thing;
                    PathEndMode     peMode    = PathEndMode.Touch;
                    Danger          maxDanger = worker.NormalMaxDanger();
                    if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.Deconstruct, thing)
                        {
                            ignoreDesignations = true
                        });
                    }
                }
                result = null;
            }
            return(result);
        }
 public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
 {
     if (!HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t, forced))
     {
         return(null);
     }
     return(HaulAIUtility.HaulToStorageJob(pawn, t));
 }
Exemple #5
0
        //Private, you say?
        //public static MethodInfo FindInfo = AccessTools.Method(typeof(HaulAIUtility), "TryFindSpotToPlaceHaulableCloseTo");
        public static bool TryFindSpotToPlaceHaulableCloseTo(Thing haulable, Pawn worker, IntVec3 center, out IntVec3 spot)
        {
            //object[] args = new object[] { haulable, worker, center, null};
            bool result = HaulAIUtility.TryFindSpotToPlaceHaulableCloseTo(haulable, worker, center, out spot);//(bool) FindInfo.Invoke(null, args);

            //spot = (IntVec3)args[3];
            return(result);
        }
        // Token: 0x06000003 RID: 3 RVA: 0x0000210C File Offset: 0x0000030C
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            var result = !HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, forced)
                ? null
                : HaulOuttaHere.HaulOuttaHereJobFor(pawn, t);

            return(result);
        }
Exemple #7
0
        public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            var job = base.JobOnCell(pawn, c, forced);

            // plant has seeds, if there is a seed return a job, otherwise prevent it.
            if (job != null && job.plantDefToSow != null && job.plantDefToSow.blueprintDef != null)
            {
                // Clear the area some...
                var zone = c.GetZone(pawn.Map);
                if (zone != null)
                {
                    foreach (var corner in GenAdj.AdjacentCells8WayRandomized())
                    {
                        var cell = c + corner;
                        if (zone.ContainsCell(cell))
                        {
                            foreach (var thing in pawn.Map.thingGrid.ThingsAt(cell))
                            {
                                if (thing.def != job.plantDefToSow && thing.def.BlockPlanting && pawn.CanReserve(thing) && !thing.IsForbidden(pawn))
                                {
                                    if (thing.def.category == ThingCategory.Plant)
                                    {
                                        return(new Job(JobDefOf.CutPlant, thing));
                                    }
                                    if (thing.def.EverHaulable)
                                    {
                                        return(HaulAIUtility.HaulAsideJobFor(pawn, thing));
                                    }
                                }
                            }
                        }
                    }
                }

                Predicate <Thing> predicate = (Thing tempThing) =>
                                              !ForbidUtility.IsForbidden(tempThing, pawn.Faction) &&
                                              ForbidUtility.InAllowedArea(tempThing.Position, pawn) &&
                                              PawnLocalAwareness.AnimalAwareOf(pawn, tempThing) &&
                                              ReservationUtility.CanReserve(pawn, tempThing, 1);

                Thing bestSeedThingForSowing = GenClosest.ClosestThingReachable(
                    c, pawn.Map, ThingRequest.ForDef(job.plantDefToSow.blueprintDef),
                    PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999,
                    predicate);

                if (bestSeedThingForSowing != null)
                {
                    return(new Job(ResourceBank.JobDefOf.SowWithSeeds, c, bestSeedThingForSowing)
                    {
                        plantDefToSow = job.plantDefToSow,
                        count = SEEDS_TO_CARRY
                    });
                }
                return(null);
            }

            return(job);
        }
 public override Job JobOnThing(Pawn pawn, Thing t)
 {
     if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t))
     {
         return(null);
     }
     // call duplicated to make changes
     return(HaulToStorageJob(pawn, t));
 }
Exemple #9
0
        // Token: 0x060000EB RID: 235 RVA: 0x000083A0 File Offset: 0x000065A0
        public static void HandleBlockingThingJob_Prefix(ref Job __result, Thing constructible, Pawn worker, bool forced = false)
        {
            Thing thing = GenConstruct.FirstBlockingThing(constructible, worker);
            bool  flag  = thing == null;

            if (flag)
            {
                __result = null;
            }
            bool flag2 = thing.def.category == ThingCategory.Plant && worker.RaceProps.Animal;

            if (flag2)
            {
                bool flag3 = worker.CanReserveAndReach(thing, PathEndMode.ClosestTouch, worker.NormalMaxDanger(), 1, -1, null, forced);
                if (flag3)
                {
                    __result = new Job(JobDefOf.CutPlant, thing);
                }
            }
            else
            {
                bool flag4 = thing.def.category == ThingCategory.Item && worker.RaceProps.Animal;
                if (flag4)
                {
                    bool everHaulable = thing.def.EverHaulable;
                    if (everHaulable)
                    {
                        __result = HaulAIUtility.HaulAsideJobFor(worker, thing);
                    }
                    Log.ErrorOnce(string.Concat(new object[]
                    {
                        "Never haulable ",
                        thing,
                        " blocking ",
                        constructible.ToStringSafe <Thing>(),
                        " at ",
                        constructible.Position
                    }), 6429262, false);
                }
                else
                {
                    bool flag5 = thing.def.category == ThingCategory.Building && worker.RaceProps.Animal;
                    if (flag5)
                    {
                        bool flag6 = worker.CanReserveAndReach(thing, PathEndMode.Touch, worker.NormalMaxDanger(), 1, -1, null, forced);
                        if (flag6)
                        {
                            __result = new Job(WPJobDefOf.WPDeconstruct, thing)
                            {
                                ignoreDesignations = true
                            };
                        }
                    }
                }
            }
            __result = null;
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced)
        {
            if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, forced))
            {
                return(null);
            }

            return(HaulOuttaHere.HaulOuttaHereJobFor(pawn, t));
        }
Exemple #11
0
        public static Job HandleBlockingThingJob(Thing constructible, Pawn worker, bool forced = false)
        {
            Thing thing = FirstBlockingThing(constructible, worker);

            if (thing == null)
            {
                return(null);
            }
            if (thing.def.category == ThingCategory.Plant)
            {
                if (worker.CanReserveAndReach(thing, PathEndMode.ClosestTouch, worker.NormalMaxDanger(), 1, -1, null, forced))
                {
                    return(JobMaker.MakeJob(JobDefOf.CutPlant, thing));
                }
            }
            else if (thing.def.category == ThingCategory.Item)
            {
                if (thing.def.EverHaulable)
                {
                    return(HaulAIUtility.HaulAsideJobFor(worker, thing));
                }
                Log.ErrorOnce("Never haulable " + thing + " blocking " + constructible.ToStringSafe() + " at " + constructible.Position, 6429262);
            }
            else if (thing.def.category == ThingCategory.Building)
            {
                if (((Building)thing).DeconstructibleBy(worker.Faction))
                {
                    if (worker.WorkTypeIsDisabled(WorkTypeDefOf.Construction))
                    {
                        JobFailReason.Is(IncapableOfDeconstruction);
                        return(null);
                    }
                    if (worker.CanReserveAndReach(thing, PathEndMode.Touch, worker.NormalMaxDanger(), 1, -1, null, forced))
                    {
                        Job job = JobMaker.MakeJob(JobDefOf.Deconstruct, thing);
                        job.ignoreDesignations = true;
                        return(job);
                    }
                }
                if (thing.def.mineable)
                {
                    if (worker.WorkTypeIsDisabled(WorkTypeDefOf.Mining))
                    {
                        JobFailReason.Is(IncapableOfMining);
                        return(null);
                    }
                    if (worker.CanReserveAndReach(thing, PathEndMode.Touch, worker.NormalMaxDanger(), 1, -1, null, forced))
                    {
                        Job job2 = JobMaker.MakeJob(JobDefOf.Mine, thing);
                        job2.ignoreDesignations = true;
                        return(job2);
                    }
                }
            }
            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            var info = CarnUtils.Info;

            if (!info.Active ||
                !info.ShouldHaulTrash ||
                !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) ||
                pawn.story.WorkTagIsDisabled(WorkTags.Hauling))
            {
                return(null);
            }

            var lord = info.currentLord;

            if (lord.LordJob is LordJob_EntertainColony)
            {
                if (info.thingsToHaul.Any())
                {
                    var haulable = info.thingsToHaul.LastOrDefault(t =>
                                                                   pawn.carryTracker.MaxStackSpaceEver(t.def) > 0 &&
                                                                   HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, false)
                                                                   );

                    if (haulable != null)
                    {
                        if (!haulable.IsForbidden(Faction.OfPlayer))
                        {
                            if (Prefs.DevMode)
                            {
                                Log.Warning("[Carnivale] " + haulable + " from CarnivalInfo.thingsToHaul was claimed by the player. Removing from list.");
                            }

                            info.thingsToHaul.Remove(haulable);

                            return(null);
                        }

                        if (!info.AnyCarriersCanCarry(haulable))
                        {
                            Log.Error("No carriers have space for " + haulable + ". If they are packing up crates, they may never leave.");
                            return(null);
                        }

                        pawn.Reserve(haulable);

                        return(new Job(_DefOf.Job_HaulToCarrierOrTrash, haulable)
                        {
                            lord = lord
                        });
                    }
                }
            }

            return(null);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.stackCount == t.def.stackLimit)
            {
                return(null);
            }
            if (!HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t, forced))
            {
                return(null);
            }
            SlotGroup slotGroup = t.GetSlotGroup();

            if (slotGroup == null)
            {
                return(null);
            }
            LocalTargetInfo target = t.Position;

            if (!pawn.CanReserve(target, 1, -1, null, forced))
            {
                return(null);
            }
            foreach (Thing current in slotGroup.HeldThings)
            {
                if (current != t)
                {
                    if (current.def == t.def)
                    {
                        if (forced || current.stackCount >= t.stackCount)
                        {
                            if (current.stackCount < current.def.stackLimit)
                            {
                                target = current.Position;
                                if (pawn.CanReserve(target, 1, -1, null, forced))
                                {
                                    if (pawn.CanReserve(current, 1, -1, null, false))
                                    {
                                        if (current.Position.IsValidStorageFor(current.Map, t))
                                        {
                                            return(new Job(JobDefOf.HaulToCell, t, current.Position)
                                            {
                                                count = Mathf.Min(current.def.stackLimit - current.stackCount, t.stackCount),
                                                haulMode = HaulMode.ToCellStorage
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            JobFailReason.Is("NoMergeTarget".Translate(), null);
            return(null);
        }
Exemple #14
0
 public static Job PutAwayTool(this Pawn pawn, ThingWithComps tool, bool bestLoc = true)
 {
     if (bestLoc)
     {
         return(HaulAIUtility.HaulToStorageJob(pawn, tool));
     }
     else
     {
         return(HaulAIUtility.HaulToStorageJob(pawn, tool));
     }
 }
Exemple #15
0
		public static Job HaulToStorageJob(Pawn p, Thing t)
		{
			var currentPriority = HaulAIUtility.StoragePriorityAtFor(t.Position, t);
			IntVec3 storeCell;
			if (!StoreUtility.TryFindBestBetterStoreCellFor(t, p, p.Map, currentPriority, p.Faction, out storeCell, true))
			{
				JobFailReason.Is(NoEmptyPlaceLowerTrans);
				return null;
			}
			return TestHaulMaxNumToCellJob(p, t, storeCell, false);
		}
Exemple #16
0
        public static Job TryGiveJob(this JobGiver_Haul @this, Pawn pawn)
        {
            Predicate <Thing> validator = t => !t.IsForbidden(pawn) && HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t) && IsPlaceToPutThing(pawn, t);
            Thing             thing     = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling(), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, null);

            if (thing != null)
            {
                return(HaulAIUtility.HaulToStorageJob(pawn, thing));
            }
            return(null);
        }
Exemple #17
0
        private static bool IsPlaceToPutThing(Pawn p, Thing t)
        {
            StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(t.Position, t);
            IntVec3         storeCell;

            if (!StoreUtility.TryFindBestBetterStoreCellFor(t, p, p.Map, currentPriority, p.Faction, out storeCell))
            {
                return(false);
            }
            return(true);
        }
Exemple #18
0
 public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
 {
     if (HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, forced) && t is MechSuit mechSuit && mechSuit.AssignedStation != null &&
         mechSuit.Position != mechSuit.AssignedStation.InteractionCell)
     {
         Job job = JobMaker.MakeJob(JobDefOf.HaulToCell, t, mechSuit.AssignedStation.InteractionCell);
         job.count = 1;
         return(job);
     }
     return(null);
 }
Exemple #19
0
 private void Haul()
 {
     if (HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, Silver, false))
     {
         pawn.jobs.StartJob(HaulAIUtility.HaulToStorageJob(pawn, Silver), JobCondition.Succeeded);
     }
     else
     {
         pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
     }
 }
        public override IEnumerable <Thing> PotentialWorkThingsGlobal(Pawn pawn)
        {
            List <SlotGroup> needRefill = pawn.Map.haulDestinationManager.AllGroupsListForReading
                                          .FindAll(group => AllowToolController.Instance.WorldSettings.IsMarkedForRefill(pawn.Map, group) &&
                                                   group.CellsList.Any(c => NeedsRefill(c, pawn.Map)));

            return(pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableEver)
                   .FindAll(t => !t.IsInValidBestStorage() &&
                            HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, false) &&
                            needRefill.Any(g => g.Settings.AllowedToAccept(t))));
        }
Exemple #21
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 Job HaulStuffOffBillGiverJob(Pawn pawn, IBillGiver giver, Thing thingToIgnore)
 {
     foreach (IntVec3 ingredientStackCell in giver.IngredientStackCells)
     {
         Thing thing = pawn.Map.thingGrid.ThingAt(ingredientStackCell, ThingCategory.Item);
         if (thing != null && thing != thingToIgnore)
         {
             return(HaulAIUtility.HaulAsideJobFor(pawn, thing));
         }
     }
     return(null);
 }
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (pawn.Map == null)
     {
         return(null);
     }
     if (!pawn.story.WorkTagIsDisabled(WorkTags.Cleaning) && pawn.Map.listerFilthInHomeArea.FilthInHomeArea.Count > 0)
     {
         Thing closestFilth = pawn.Map.listerFilthInHomeArea.FilthInHomeArea.RandomElement();
         if (closestFilth != null && pawn.CanReserveAndReach(closestFilth, PathEndMode.Touch, Danger.Some))
         {
             Job job = new Job(JobDefOf.Clean);
             job.AddQueuedTarget(TargetIndex.A, closestFilth);
             int  num  = 15;
             Map  map  = closestFilth.Map;
             Room room = closestFilth.GetRoom(RegionType.Set_Passable);
             for (int i = 0; i < 100; i++)
             {
                 IntVec3 intVec = closestFilth.Position + GenRadial.RadialPattern[i];
                 if (intVec.InBounds(map) && intVec.GetRoom(map, RegionType.Set_Passable) == room)
                 {
                     List <Thing> thingList = intVec.GetThingList(map);
                     for (int j = 0; j < thingList.Count; j++)
                     {
                         Thing thing = thingList[j];
                         if (thing != closestFilth && IsValidFilth(pawn, thing))
                         {
                             job.AddQueuedTarget(TargetIndex.A, thing);
                         }
                     }
                     if (job.GetTargetQueue(TargetIndex.A).Count >= num)
                     {
                         break;
                     }
                 }
             }
             if (job.targetQueueA != null && job.targetQueueA.Count >= 5)
             {
                 job.targetQueueA.SortBy((LocalTargetInfo targ) => targ.Cell.DistanceToSquared(pawn.Position));
             }
             return(job);
         }
     }
     if (!pawn.story.WorkTagIsDisabled(WorkTags.Hauling) && pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling().Count > 0)
     {
         Thing thing = pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling().RandomElement();
         if (thing != null && HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, thing, true) && pawn.CanReserveAndReach(thing, PathEndMode.Touch, Danger.Some))
         {
             return(HaulAIUtility.HaulToStorageJob(pawn, thing));
         }
     }
     return(null);
 }
Exemple #24
0
        public static IntVec3 FindStorageCell(Pawn pawn, Thing haulable, Map map, List <LocalTargetInfo> targetQueue = null)
        {
            // Find closest cell in queue.
            if (!targetQueue.NullOrEmpty())
            {
                foreach (LocalTargetInfo target in targetQueue)
                {
                    foreach (IntVec3 adjCell in GenAdjFast.AdjacentCells8Way(target))
                    {
                        if (!targetQueue.Contains(adjCell) && adjCell.IsValidStorageFor(map, haulable))
                        {
                            if (pawn.CanReserveAndReach(adjCell, PathEndMode.ClosestTouch, Danger.Some))
                            {
                                return(adjCell);
                            }
                        }
                    }
                }
            }

            /*
             *          StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(closestHaulable.Position, closestHaulable);
             *          IntVec3 foundCell;
             *          if (StoreUtility.TryFindBestBetterStoreCellFor(closestHaulable, pawn, currentPriority, pawn.Faction, out foundCell, true))
             *              return foundCell;
             */
            // Vanilla code is not worked item on container.
            StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(haulable.Position, haulable);

            foreach (SlotGroup slotGroup in map.slotGroupManager.AllGroupsListInPriorityOrder)
            {
                if (slotGroup.Settings.Priority < currentPriority)
                {
                    break;
                }
                {
                    foreach (IntVec3 cell in slotGroup.CellsList)
                    {
                        if ((!targetQueue.NullOrEmpty() && !targetQueue.Contains(cell)) || targetQueue.NullOrEmpty())
                        {
                            if (cell.GetStorable(map) == null)
                            {
                                if (slotGroup.Settings.AllowedToAccept(haulable) && pawn.CanReserveAndReach(cell, PathEndMode.ClosestTouch, Danger.Deadly))
                                {
                                    return(cell);
                                }
                            }
                        }
                    }
                }
            }
            return(IntVec3.Invalid);
        }
Exemple #25
0
        public Job ReturnTool(Pawn pawn)
        {
            // NOTE: temporary solution using default jobs, need future improvement
            ThingWithComps tool;

            // drops primary equipment (weapon) as forbidden
            pawn.equipment.TryDropEquipment(pawn.equipment.Primary, out tool, pawn.Position);
            // making it non forbidden
            tool.SetForbidden(false);
            // vanilla haul to best stockpile job
            return(HaulAIUtility.HaulToStorageJob(pawn, tool));
        }
Exemple #26
0
        // drop tool and haul it to stockpile, if necessary
        public Job TryReturnTool(Pawn pawn)
        {
            ThingWithComps tool;

            // drops primary equipment (weapon) as forbidden
            pawn.equipment.TryDropEquipment(pawn.equipment.Primary, out tool, pawn.Position);
            // making it non forbidden
            tool.SetForbidden(false);

            // tr to haul to the stockpile
            return(HaulAIUtility.HaulToStorageJob(pawn, tool));
        }
Exemple #27
0
 private static Job HaulStuffOffBillGiverJob(Pawn pawn, Building_ReligiousBuildingFacility giver, Thing thingToIgnore)
 {
     foreach (IntVec3 ingredientStackCell in giver.IngredientStackCells)
     {
         Thing t = pawn.Map.thingGrid.ThingAt(ingredientStackCell, ThingCategory.Item);
         if (t != null && t != thingToIgnore)
         {
             return(HaulAIUtility.HaulAsideJobFor(pawn, t));
         }
     }
     return((Job)null);
 }
Exemple #28
0
        public override IEnumerable <Thing> PotentialWorkThingsGlobal(Pawn pawn)
        {
            var things = GetHaulablesForPawn(pawn);

            for (int i = 0; i < things.Count; i++)
            {
                if (HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, things[i], false))
                {
                    yield return(things[i]);
                }
            }
        }
Exemple #29
0
        //pick up stuff until you can't anymore,
        //while you're up and about, pick up something and haul it
        //before you go out, empty your pockets

        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>();

            if (takenToInventory == null)
            {
                return(null);
            }

            if (thing is Corpse)
            {
                return(null);
            }

            if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, thing, forced))
            {
                return(null);
            }

            if (thing.IsForbidden(pawn) || StoreUtility.IsInValidBestStorage(thing))
            {
                return(null);
            }

            //bulky gear (power armor + minigun) so don't bother.
            if (MassUtility.GearMass(pawn) / MassUtility.Capacity(pawn) >= 0.8f)
            {
                return(null);
            }

            StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing);

            if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
            {
                //since we've gone through all the effort of getting the loc, might as well use it.
                //Don't multi-haul food to hoppers.
                if (thing.def.IsNutritionGivingIngestible)
                {
                    if (thing.def.ingestible.preferability == FoodPreferability.RawBad || thing.def.ingestible.preferability == FoodPreferability.RawTasty)
                    {
                        List <Thing> thingList = storeCell.GetThingList(thing.Map);
                        for (int i = 0; i < thingList.Count; i++)
                        {
                            Thing thingAtCell = thingList[i];
                            if (thingAtCell.def == ThingDefOf.Hopper)
                            {
                                return(HaulAIUtility.HaulToStorageJob(pawn, thing));
                            }
                        }
                    }
                }
            }
        //pick up stuff until you can't anymore,
        //while you're up and about, pick up something and haul it
        //before you go out, empty your pockets

        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            //bulky gear (power armor + minigun) so don't bother.
            if (MassUtility.GearMass(pawn) / MassUtility.Capacity(pawn) >= 0.8f)
            {
                return(null);
            }

            DesignationDef haulUrgentlyDesignation = DefDatabase <DesignationDef> .GetNamed("HaulUrgentlyDesignation", false);

            // Misc. Robots compatibility
            // See https://github.com/catgirlfighter/RimWorld_CommonSense/blob/master/Source/CommonSense11/CommonSense/OpportunisticTasks.cs#L129-L140
            if (pawn.TryGetComp <CompHauledToInventory>() == null)
            {
                return(null);
            }

            //This WorkGiver gets hijacked by AllowTool and expects us to urgently haul corpses.
            if (ModCompatibilityCheck.AllowToolIsActive && thing is Corpse &&
                pawn.Map.designationManager.DesignationOn(thing)?.def == haulUrgentlyDesignation && HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, thing, forced))
            {
                return(HaulAIUtility.HaulToStorageJob(pawn, thing));
            }

            if (!GoodThingToHaul(thing, pawn) || !HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, thing, forced))
            {
                return(null);
            }

            StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);

            if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
            {
                //since we've gone through all the effort of getting the loc, might as well use it.
                //Don't multi-haul food to hoppers.
                if (thing.def.IsNutritionGivingIngestible)
                {
                    if (thing.def.ingestible.preferability == FoodPreferability.RawBad || thing.def.ingestible.preferability == FoodPreferability.RawTasty)
                    {
                        List <Thing> thingList = storeCell.GetThingList(thing.Map);

                        foreach (Thing t in thingList)
                        {
                            if (t.def == ThingDefOf.Hopper)
                            {
                                return(HaulAIUtility.HaulToStorageJob(pawn, thing));
                            }
                        }
                    }
                }
            }