예제 #1
0
        Toil Store()
        {
            return(new Toil()
            {
                initAction = delegate {
                    var objectThing = job.GetTarget(objectTI).Thing;

                    if (job.bill.GetStoreMode() != BillStoreModeDefOf.DropOnFloor)
                    {
                        IntVec3 vec;
                        if (StoreUtility.TryFindBestBetterStoreCellFor(objectThing, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out vec, true))
                        {
                            pawn.carryTracker.TryStartCarry(objectThing, objectThing.stackCount);
                            job.SetTarget(haulTI, vec);
                            job.count = 99999;
                            return;
                        }
                    }
                    pawn.carryTracker.TryStartCarry(objectThing, objectThing.stackCount);
                    pawn.carryTracker.TryDropCarriedThing(pawn.Position, ThingPlaceMode.Near, out objectThing);

                    pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                }
            });
        }
        public static bool Prefix(Pawn pawn, Thing thing, WorkGiver_HaulToInventory __instance, bool forced, ref bool __result)
        {
            #region PickUpAndHaul code
            //bulky gear (power armor + minigun) so don't bother.
            if (MassUtility.GearMass(pawn) / MassUtility.Capacity(pawn) >= 0.8f)
            {
                return(false);
            }

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

            StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);
            bool            foundCell       = StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true);
            #endregion

            if (!foundCell)
            {
                __result = false;
            }
            else
            {
                SlotGroup slotGroup = pawn.Map.haulDestinationManager.SlotGroupAt(storeCell);
                __result = !(slotGroup != null && Limits.HasLimit(slotGroup.Settings) && Limits.GetLimit(slotGroup.Settings) >= slotGroup.TotalPrecalculatedItemsStack());
            }

            return(false);
        }
예제 #3
0
        private static bool AllowToolHaulUrgentlyJobOnThing_PreFix(ref Job __result, Pawn pawn, Thing t, bool forced = false)
        {
            if (ModCompatibilityCheck.AllowToolIsActive)
            {
                //allowTool HaulUrgently
                CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>();

                if (pawn.RaceProps.Humanlike &&
                    pawn.Faction == Faction.OfPlayer &&
                    t is Corpse == false &&
                    takenToInventory != null &&
                    !(t.def.defName.Contains("Chunk"))    //most of the time we don't have space for it
                    )
                {
                    StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(t.Position, t);
                    if (!StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
                    {
                        JobFailReason.Is("NoEmptyPlaceLower".Translate());
                        return(false);
                    }

                    Job haul = new Job(PickUpAndHaulJobDefOf.HaulToInventory, t)
                    {
                        count = t.stackCount
                    };
                    __result = haul;
                    return(false);
                }
            }
            return(true);
        }
예제 #4
0
        private Toil Store()
        {
            Toil toil = new Toil();

            toil.initAction = delegate {
                Pawn  actor       = toil.actor;
                Job   curJob      = actor.jobs.curJob;
                Thing objectThing = curJob.GetTarget(objectTI).Thing;

                if (curJob.bill.GetStoreMode() != BillStoreMode.DropOnFloor)
                {
                    IntVec3 vec;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(objectThing, actor, actor.Map, StoragePriority.Unstored, actor.Faction, out vec, true))
                    {
                        actor.carryTracker.TryStartCarry(objectThing);
                        curJob.SetTarget(haulTI, vec);
                        curJob.count = 99999;
                        return;
                    }
                }

                actor.carryTracker.TryStartCarry(objectThing);
                actor.carryTracker.TryDropCarriedThing(actor.Position, ThingPlaceMode.Near, out objectThing);

                actor.jobs.EndCurrentJob(JobCondition.Succeeded);
            };
            return(toil);
        }
예제 #5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(200, TargetIndex.None).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).FailOn(() => !this.OniWineBarrel.Fermented).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Thing thing = this.OniWineBarrel.TakeOutAOniWine();
                    GenPlace.TryPlaceThing(thing, this.pawn.Position, base.Map, ThingPlaceMode.Near, null, null, default);
                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing, this.pawn, base.Map, currentPriority, this.pawn.Faction, out IntVec3 c, true))
                    {
                        this.job.SetTarget(TargetIndex.C, c);
                        this.job.SetTarget(TargetIndex.B, thing);
                        this.job.count = thing.stackCount;
                        return;
                    }
                    base.EndJobWith(JobCondition.Incompletable);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
예제 #6
0
        private static bool AllowToolHaulUrgentlyJobOnThing_PreFix(ref Job __result, Pawn pawn, Thing t, bool forced = false)
        {
            if (ModCompatibilityCheck.AllowToolIsActive)
            {
                //allowTool HaulUrgently
                CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>();

                if (pawn.RaceProps.Humanlike &&
                    pawn.Faction == Faction.OfPlayer &&
                    t is Corpse == false &&
                    takenToInventory != null &&
                    !(t.def.defName.Contains("Chunk"))    //most of the time we don't have space for it
                    )
                {
                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(t);
                    if (!StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
                    {
                        JobFailReason.Is("NoEmptyPlaceLower".Translate());
                        return(false);
                    }

                    WorkGiver_HaulToInventory haulWG = (WorkGiver_HaulToInventory)pawn.workSettings.WorkGiversInOrderNormal.Find(wg => wg is WorkGiver_HaulToInventory);

                    Job haul = haulWG.JobOnThing(pawn, t, forced);
                    __result = haul;
                    return(false);
                }
            }
            return(true);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Building_AquacultureBasin aquacultureBasin = this.TargetThingA as Building_AquacultureBasin;

            yield return(Toils_Goto.GotoThing(aquacultureBasinIndex, PathEndMode.InteractionCell));

            yield return(Toils_General.Wait(120).WithProgressBarToilDelay(aquacultureBasinIndex));

            Toil getAquacultureBasinProduction = new Toil()
            {
                initAction = () =>
                {
                    Job curJob = this.pawn.jobs.curJob;

                    Thing product = aquacultureBasin.GetProduction();
                    if (product == null)
                    {
                        this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                    else
                    {
                        while (product.stackCount > product.def.stackLimit)
                        {
                            Thing meatStack = ThingMaker.MakeThing(product.def);
                            meatStack.stackCount = product.def.stackLimit;
                            GenPlace.TryPlaceThing(meatStack, this.GetActor().Position, this.Map, ThingPlaceMode.Near);
                            product.stackCount -= product.def.stackLimit;
                        }
                        GenSpawn.Spawn(product, aquacultureBasin.InteractionCell, this.Map);

                        IntVec3 storageCell;
                        if (StoreUtility.TryFindBestBetterStoreCellFor(product, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true))
                        {
                            this.pawn.Reserve(product, this.job);
                            this.pawn.Reserve(storageCell, this.job, 1);
                            this.pawn.CurJob.SetTarget(TargetIndex.B, storageCell);
                            this.pawn.CurJob.SetTarget(TargetIndex.A, product);
                            this.pawn.CurJob.count    = 99999;
                            this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;
                        }
                        else
                        {
                            this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                        }
                    }
                }
            };

            yield return(getAquacultureBasinProduction);

            yield return(Toils_Reserve.Release(aquacultureBasinIndex));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true));
        }
예제 #8
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(1400).WithProgressBarToilDelay(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    var thing = ThingMaker.MakeThing(ThingDef.Named("RawCompost"));
                    thing.stackCount = SewageProcessing.EmptySewage();
                    GenPlace.TryPlaceThing(thing, pawn.Position, Map, ThingPlaceMode.Near);
                    //StoragePriority currentPriority = StoreUtility.StoragePriorityAtFor(thing.Position, thing);
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, Map, StoragePriority.Normal,
                                                                   pawn.Faction, out var c))
                    {
                        job.SetTarget(TargetIndex.C, c);
                        job.SetTarget(TargetIndex.B, thing);
                        job.count = thing.stackCount;
                    }
                    else
                    {
                        EndJobWith(JobCondition.Incompletable);
                    }
                },
예제 #9
0
        public static Job SmartBuild(Pawn p, Job job)
        {
            if (p.story.WorkTagIsDisabled(WorkTags.Hauling))
            {
                return(job);
            }
            var carryCapacity   = p.GetStatValue(StatDefOf.CarryingCapacity);
            var itemCount       = job.count;
            var thing           = job.targetA.Thing;
            var storagePriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing);


            IntVec3 storePos;

            if (StoreUtility.TryFindBestBetterStoreCellFor(thing, p, thing.Map, storagePriority, p.Faction, out storePos) && carryCapacity >= itemCount)
            {
                var targetPos = thing.Position;
                var destPos   = job.targetB.Thing.Position;
                if ((targetPos - destPos).LengthHorizontalSquared > (targetPos - storePos).LengthHorizontalSquared)
                {
                    return(HaulAIUtility.HaulMaxNumToCellJob(p, thing, storePos, false));
                }
            }

            return(job);
        }
예제 #10
0
            public static Job HaulBeforeCarry(Pawn pawn, IntVec3 dest, Thing th)
            {
                if (th.IsInValidStorage())
                {
                    return(null);
                }
                if (!StoreUtility.TryFindBestBetterStoreCellFor(th, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out var storeCell, false))
                {
                    return(null);
                }

                var supplyFromHereDist  = th.Position.DistanceTo(dest);
                var supplyFromStoreDist = storeCell.DistanceTo(dest);

                Debug.WriteLine($"Carry from here: {supplyFromHereDist}; carry from store: {supplyFromStoreDist}");

                // [KV] Infinite Storage https://steamcommunity.com/sharedfiles/filedetails/?id=1233893175
                // infinite storage has an interaction spot 1 tile away from itself
                if (supplyFromStoreDist + 1 < supplyFromHereDist)
                {
                    Debug.WriteLine($"'{pawn}' prefixed job with storage haul for '{th.Label}' because '{storeCell.GetSlotGroup(pawn.Map)}' is closer to original destination '{dest}'.");
                    return(PuahJob(pawn, dest, th, storeCell) ?? HaulAIUtility.HaulToCellStorageJob(pawn, th, storeCell, false));
                }

                return(null);
            }
예제 #11
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(BuildingInd);
            this.FailOnBurningImmobile(BuildingInd);
            yield return(Toils_Goto.GotoThing(BuildingInd, PathEndMode.Touch));

            yield return(Toils_General.Wait(Duration).FailOnDestroyedNullOrForbidden(BuildingInd).FailOnCannotTouch(BuildingInd, PathEndMode.Touch).FailOn(() => !Building.Completed).WithProgressBarToilDelay(BuildingInd));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing product = Building.TakeOutProduct();
                    GenPlace.TryPlaceThing(product, pawn.Position, Map, ThingPlaceMode.Near);
                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(product);
                    if (StoreUtility.TryFindBestBetterStoreCellFor(product, pawn, Map, currentPriority, pawn.Faction, out IntVec3 cell))
                    {
                        job.SetTarget(StorageCellInd, cell);
                        job.SetTarget(ProductInd, product);
                        job.count = product.stackCount;
                    }
                    else
                    {
                        EndJobWith(JobCondition.Incompletable);
                    }
                },
예제 #12
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(BarrelInd);
            this.FailOnBurningImmobile(BarrelInd);
            yield return(Toils_Goto.GotoThing(BarrelInd, PathEndMode.Touch));

            yield return(Toils_General.Wait(Duration).FailOnDestroyedNullOrForbidden(BarrelInd)
                         .FailOnCannotTouch(BarrelInd, PathEndMode.Touch).FailOn(() => !MeadBarrel.Fermented)
                         .WithProgressBarToilDelay(BarrelInd));

            yield return(new Toil
            {
                initAction = delegate
                {
                    var thing = MeadBarrel.TakeOutMead();
                    GenPlace.TryPlaceThing(thing, pawn.Position, Map, ThingPlaceMode.Near);
                    var currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing,
                                                                   pawn, Map, currentPriority, pawn.Faction, out var c))
                    {
                        job.SetTarget(TargetIndex.C, c);
                        job.SetTarget(TargetIndex.B, thing);
                        job.count = thing.stackCount;
                    }
                    else
                    {
                        EndJobWith(JobCondition.Incompletable);
                    }
                },
예제 #13
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Log.Message("I am inside the job now, with "+pawn.ToString(), false);
            Building_ItemProcessor building_processor = (Building_ItemProcessor)this.job.GetTarget(TargetIndex.A).Thing;

            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_General.DoAtomic(delegate
            {
                this.job.count = 1;
            }));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(240).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing newProduct;
                    if (building_processor.productsToTurnInto != null && building_processor.productsToTurnInto.Count > 0)
                    {
                        newProduct = ThingMaker.MakeThing(ThingDef.Named(building_processor.productsToTurnInto[(int)building_processor.qualityNow]));
                    }
                    else
                    {
                        newProduct = ThingMaker.MakeThing(ThingDef.Named(building_processor.productToTurnInto));
                    }

                    newProduct.stackCount = building_processor.amount;

                    if ((newProduct.TryGetComp <CompIngredients>() is CompIngredients ingredientComp) && !building_processor.compItemProcessor.Props.ignoresIngredientLists)
                    {
                        ingredientComp.ingredients = building_processor.ingredients;
                    }
                    if (building_processor.usingQualityIncreasing && newProduct.TryGetComp <CompQuality>() is CompQuality qualityComp)
                    {
                        qualityComp.SetQuality(building_processor.qualityNow, ArtGenerationContext.Colony);
                    }

                    GenSpawn.Spawn(newProduct, building_processor.InteractionCell, building_processor.Map);
                    building_processor.processorStage = ProcessorStage.ProductRemoved;
                    building_processor.ResetEverything();
                    building_processor.DestroyIngredients();

                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(newProduct);
                    IntVec3 c;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(newProduct, this.pawn, this.Map, currentPriority, this.pawn.Faction, out c, true))
                    {
                        this.job.SetTarget(TargetIndex.C, c);
                        this.job.SetTarget(TargetIndex.B, newProduct);
                        this.job.count = newProduct.stackCount;
                    }
                    else
                    {
                        this.EndJobWith(JobCondition.Incompletable);
                    }
                },
예제 #14
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Log.Message(pawn + " JobGiver_StockUp");
            if (pawn.StockUpIsFull())
            {
                return(null);
            }

            Log.Message("Skip need tend?");
            if (pawn.Map.mapPawns.AllPawnsSpawned.Any(p => HealthAIUtility.ShouldBeTendedNow(p) && pawn.CanReserveAndReach(p, PathEndMode.ClosestTouch, Danger.Deadly)))
            {
                return(null);
            }

            Log.Message("any things?");
            IEnumerable <Thing> things    = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableEver);
            Predicate <Thing>   validator = (Thing t) => pawn.StockingUpOn(t) && pawn.StockUpNeeds(t) > 0 && pawn.CanReserve(t, FindBestMedicine.maxPawns, 1) && !t.IsForbidden(pawn);
            Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999, validator);

            if (thing != null)
            {
                int pickupCount = Math.Min(pawn.StockUpNeeds(thing), MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing));
                Log.Message(pawn + " stock thing is " + thing + ", count " + pickupCount);
                if (pickupCount > 0)
                {
                    return new Job(SmartMedicineJobDefOf.StockUp, thing)
                           {
                               count = pickupCount
                           }
                }
                ;
            }

            Log.Message(pawn + " looking to return");
            Thing toReturn = pawn.StockUpThingToReturn();

            if (toReturn == null)
            {
                return(null);
            }
            Log.Message("returning " + toReturn);

            int dropCount = -pawn.StockUpNeeds(toReturn);

            Log.Message("dropping " + dropCount);
            if (StoreUtility.TryFindBestBetterStoreCellFor(toReturn, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out IntVec3 dropLoc, true))
            {
                return new Job(SmartMedicineJobDefOf.StockDown, toReturn, dropLoc)
                       {
                           count = dropCount
                       }
            }
            ;
            Log.Message("nowhere to store");
            return(null);
        }
    }
}
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.StockUpIsFull())
            {
                return(null);
            }
            Log.Message($"{pawn} needs stocking up");

            if (Skip(pawn))
            {
                return(null);
            }

            Log.Message($"any things?");
            Predicate <Thing> validator = (Thing t) => pawn.StockingUpOn(t) && pawn.StockUpNeeds(t) > 0 && pawn.CanReserve(t, FindBestMedicine.maxPawns, 1) && !t.IsForbidden(pawn);
            Thing             thing     = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999, validator);

            if (thing != null)
            {
                int pickupCount = Math.Min(pawn.StockUpNeeds(thing), MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing));
                Log.Message($"{pawn} stock thing is {thing}, count {pickupCount}");
                if (pickupCount > 0)
                {
                    return new Job(SmartMedicineJobDefOf.StockUp, thing)
                           {
                               count = pickupCount
                           }
                }
                ;
            }

            Log.Message($"{pawn} looking to return");
            Thing toReturn = pawn.StockUpThingToReturn();

            if (toReturn == null)
            {
                return(null);
            }
            Log.Message($"returning {toReturn}");

            int dropCount = -pawn.StockUpNeeds(toReturn);

            Log.Message($"dropping {dropCount}");
            if (StoreUtility.TryFindBestBetterStoreCellFor(toReturn, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out IntVec3 dropLoc, true))
            {
                return new Job(SmartMedicineJobDefOf.StockDown, toReturn, dropLoc)
                       {
                           count = dropCount
                       }
            }
            ;
            Log.Message($"nowhere to store");
            return(null);
        }
    }
}
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Reserve.Reserve(aquacultureBasinIndex));

            Building_AquacultureBasin aquacultureBasin = this.TargetThingA as Building_AquacultureBasin;

            yield return(Toils_Goto.GotoThing(aquacultureBasinIndex, PathEndMode.InteractionCell));

            yield return(Toils_General.Wait(120).WithProgressBarToilDelay(aquacultureBasinIndex));

            Toil getAquacultureBasinProduction = new Toil()
            {
                initAction = () =>
                {
                    Job curJob = this.pawn.jobs.curJob;

                    Thing product = aquacultureBasin.GetProduction();
                    if (product == null)
                    {
                        this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                    else
                    {
                        GenSpawn.Spawn(product, aquacultureBasin.InteractionCell, this.Map);

                        IntVec3 storageCell;
                        if (StoreUtility.TryFindBestBetterStoreCellFor(product, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true))
                        {
                            this.pawn.carryTracker.TryStartCarry(product);
                            curJob.targetB = storageCell;
                            curJob.targetC = product;
                            curJob.count   = 99999;
                        }
                        else
                        {
                            this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                        }
                    }
                }
            };

            yield return(getAquacultureBasinProduction);

            // Reserve the product and storage cell.
            yield return(Toils_Reserve.Reserve(TargetIndex.B));

            yield return(Toils_Reserve.Reserve(TargetIndex.C));

            yield return(Toils_Reserve.Release(aquacultureBasinIndex));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true));
        }
예제 #17
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);
		}
예제 #18
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);
        }
예제 #19
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));
                            }
                        }
                    }
                }
            }
                static bool RejectTooFar(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction, out IntVec3 foundCell, bool needAccurateResult = true)
                {
                    // again, why not use our cache
                    var isFound = Hauling.cachedStoreCell.TryGetValue(t, out foundCell);

                    if (!isFound)
                    {
                        isFound = StoreUtility.TryFindBestBetterStoreCellFor(t, carrier, map, currentPriority, faction, out foundCell, needAccurateResult);
                    }

                    WorkGiver_HaulToInventory_TryFindBestBetterStoreCellFor_Patch.RejectTooFar(ref isFound, t, carrier, ref foundCell);
                    return(isFound);
                }
예제 #21
0
        public static bool TryGiveJob(ref Job __result, Pawn pawn)
        {
            int validationChecks        = 0;
            int validatorFalses1        = 0;
            int validatorFalses2        = 0;
            int validatorFalses3        = 0;
            int validatorFalses4        = 0;
            Predicate <Thing> validator = delegate(Thing t)
            {
                validationChecks++;
                if (t.IsForbidden(pawn))
                {
                    validatorFalses1++;
                    return(false);
                }

                if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, forced: false))
                {
                    validatorFalses2++;
                    return(false);
                }

                if (pawn.carryTracker.MaxStackSpaceEver(t.def) <= 0)
                {
                    validatorFalses3++;
                    return(false);
                }

                IntVec3 foundCell;
                bool    tryFindBestBetterStoreCellFor = StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, StoreUtility.CurrentStoragePriorityOf(t), pawn.Faction, out foundCell) ? true : false;
                if (!tryFindBestBetterStoreCellFor)
                {
                    validatorFalses4++;
                }
                return(tryFindBestBetterStoreCellFor);
            };
            //Log.Error(pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling().Count.ToString());
            Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling(), PathEndMode.OnCell, TraverseParms.For(pawn), 9999f, validator);

            if (validationChecks > 10)
            {
                Log.Error("Validator Checks: " + validationChecks.ToString() + " " + validatorFalses1.ToString() + " " + validatorFalses2.ToString() + " " + validatorFalses3.ToString() + " " + validatorFalses4.ToString() + " ");
            }
            if (thing != null)
            {
                __result = HaulAIUtility.HaulToStorageJob(pawn, thing);
                return(false);
            }
            __result = null;
            return(false);
        }
        //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));
                            }
                        }
                    }
                }
            }
예제 #23
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(240).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Building_Beehouse buildingbeehouse = (Building_Beehouse)this.job.GetTarget(TargetIndex.A).Thing;
                    buildingbeehouse.BeehouseIsFull = false;
                    Thing newComb = ThingMaker.MakeThing(DecideRandomComb());
                    GenSpawn.Spawn(newComb, buildingbeehouse.Position - GenAdj.CardinalDirections[0], buildingbeehouse.Map);

                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(newComb);
                    IntVec3 c;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(newComb, this.pawn, this.Map, currentPriority, this.pawn.Faction, out c, true))
                    {
                        this.job.SetTarget(TargetIndex.C, c);
                        this.job.SetTarget(TargetIndex.B, newComb);
                        this.job.count = newComb.stackCount;
                        buildingbeehouse.tickCounter = 0;
                    }
                    else
                    {
                        this.EndJobWith(JobCondition.Incompletable);
                        buildingbeehouse.BeehouseIsFull = false;
                        buildingbeehouse.tickCounter = 0;
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null));

            yield return(Toils_Reserve.Reserve(TargetIndex.C, 1, -1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.C);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.C, carryToCell, true));
        }
예제 #24
0
                static bool UseTryFindBestBetterStoreCellFor_ClosestToDestCell(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction,
                                                                               out IntVec3 foundCell,
                                                                               bool needAccurateResult)
                {
                    if (!haulToInventory.Value || !enabled.Value)
                    {
                        return(StoreUtility.TryFindBestBetterStoreCellFor(t, carrier, map, currentPriority, faction, out foundCell, needAccurateResult));
                    }

                    var haulTracker = haulTrackers.GetValueSafe(carrier);

                    return(JooStoreUtility.TryFindBestBetterStoreCellFor_ClosestToDestCell(
                               t, haulTracker?.destCell ?? IntVec3.Invalid, carrier, map, currentPriority, faction, out foundCell, haulTracker?.destCell.IsValid ?? false));
                }
예제 #25
0
        // Token: 0x0600000B RID: 11 RVA: 0x000029EC File Offset: 0x00000BEC
        private Toil StartCollectCorpseToil()
        {
            var toil = new Toil();

            toil.initAction = delegate
            {
                if (Victim == null)
                {
                    toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable);
                }
                else
                {
                    TaleRecorder.RecordTale(TaleDefOf.Hunted, pawn, Victim);
                    var corpse = Victim.Corpse;
                    if (corpse == null || !pawn.CanReserveAndReach(corpse, PathEndMode.ClosestTouch, Danger.Deadly))
                    {
                        pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                    }
                    else
                    {
                        corpse.SetForbidden(false);
                        if (corpse.InnerPawn.RaceProps.deathActionWorkerClass != null &&
                            !Hunting_Loader.settings.shouldCollectExplodables)
                        {
                            pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                        }
                        else
                        {
                            if (StoreUtility.TryFindBestBetterStoreCellFor(corpse, pawn, Map, StoragePriority.Unstored,
                                                                           pawn.Faction, out var c))
                            {
                                pawn.Reserve(corpse, job);
                                pawn.Reserve(c, job);
                                job.SetTarget(TargetIndex.B, c);
                                job.SetTarget(TargetIndex.A, corpse);
                                job.count    = 1;
                                job.haulMode = HaulMode.ToCellStorage;
                            }
                            else
                            {
                                pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                            }
                        }
                    }
                }
            };
            return(toil);
        }
예제 #26
0
        // Token: 0x0600002E RID: 46 RVA: 0x000035B0 File Offset: 0x000025B0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(200, TargetIndex.None).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOn(() => !this.Barrel.Distilled).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Thing thing = this.Barrel.TakeOutrawlucibatch();
                    GenPlace.TryPlaceThing(thing, this.pawn.Position, base.Map, ThingPlaceMode.Near, null, null);
                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);
                    IntVec3 c;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing, this.pawn, base.Map, currentPriority, this.pawn.Faction, out c, true))
                    {
                        this.job.SetTarget(TargetIndex.C, c);
                        this.job.SetTarget(TargetIndex.B, thing);
                        this.job.count = thing.stackCount;
                    }
                    else
                    {
                        base.EndJobWith(JobCondition.Incompletable);
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null));

            yield return(Toils_Reserve.Reserve(TargetIndex.C, 1, -1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false));

            Toil toil = Toils_Haul.CarryHauledThingToCell(TargetIndex.C);

            yield return(toil);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.C, toil, true));

            yield break;
        }
        // Token: 0x06000030 RID: 48 RVA: 0x00002C83 File Offset: 0x00000E83
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = ThingCompUtility.TryGetComp <CompUniversalFermenter>(this.Fermenter);

            ToilFailConditions.FailOn <JobDriver_TakeProductOutOfUniversalFermenter>(this, () => !comp.Fermented);
            ToilFailConditions.FailOnDestroyedNullOrForbidden <JobDriver_TakeProductOutOfUniversalFermenter>(this, (TargetIndex)1);
            yield return(Toils_Reserve.Reserve((TargetIndex)1, 1, -1, null));

            yield return(Toils_Goto.GotoThing((TargetIndex)1, (PathEndMode)3));

            yield return(ToilEffects.WithProgressBarToilDelay(ToilFailConditions.FailOnDestroyedNullOrForbidden <Toil>(Toils_General.Wait(200, 0), (TargetIndex)1), (TargetIndex)1, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Thing thing = comp.TakeOutProduct();
                    GenPlace.TryPlaceThing(thing, this.pawn.Position, this.Map, (ThingPlaceMode)1, null, null);
                    StoragePriority storagePriority = StoreUtility.CurrentStoragePriorityOf(thing);
                    IntVec3 intVec;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing, this.pawn, this.Map, storagePriority, this.pawn.Faction, out intVec, true))
                    {
                        this.job.SetTarget((TargetIndex)2, thing);
                        this.job.count = thing.stackCount;
                        this.job.SetTarget((TargetIndex)3, intVec);
                        return;
                    }
                    this.EndJobWith((JobCondition)3);
                },
                defaultCompleteMode = (ToilCompleteMode)1
            });

            yield return(Toils_Reserve.Reserve((TargetIndex)2, 1, -1, null));

            yield return(Toils_Reserve.Reserve((TargetIndex)3, 1, -1, null));

            yield return(Toils_Goto.GotoThing((TargetIndex)2, (PathEndMode)3));

            yield return(Toils_Haul.StartCarryThing((TargetIndex)2, false, false, false));

            Toil carry = Toils_Haul.CarryHauledThingToCell((TargetIndex)3);

            yield return(carry);

            yield return(Toils_Haul.PlaceHauledThingInCell((TargetIndex)3, carry, true));

            yield break;
        }
        public static bool Prefix(Pawn pawn, Thing thing, ref Job __result)
        {
            StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);

            if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
            {
                SlotGroup slotGroup = StoreUtility.GetSlotGroup(storeCell, thing.Map);
                if (Limits.HasLimit(slotGroup.Settings))
                {
                    __result = HaulAIUtility.HaulToStorageJob(pawn, thing);
                    return(false);
                }
            }

            return(true);
        }
        public override bool HasJobOnThing(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(false);
            }

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

            StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);

            return(StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 _));
        }
예제 #30
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)
        {
            //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);

            //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);
                        for (int i = 0; i < thingList.Count; i++)
                        {
                            if (thingList[i].def == ThingDefOf.Hopper)
                            {
                                return(HaulAIUtility.HaulToStorageJob(pawn, thing));
                            }
                        }
                    }
                }
            }