protected override Job TryGiveJob(Pawn pawn) { Predicate <Thing> validator = delegate(Thing t) { if (t.IsForbidden(pawn)) { return(false); } if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, forced: false)) { return(false); } if (pawn.carryTracker.MaxStackSpaceEver(t.def) <= 0) { return(false); } if (!StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, StoreUtility.CurrentStoragePriorityOf(t), pawn.Faction, out IntVec3 _)) { return(false); } return(true); }; Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling(), PathEndMode.OnCell, TraverseParms.For(pawn), 9999f, validator); if (thing != null) { return(HaulAIUtility.HaulToStorageJob(pawn, thing)); } return(null); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); yield return(Toils_General.Wait(this.duration, TargetIndex.None).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f)); yield return(Toils_General.Do(delegate { if (this.pawn.apparel.WornApparel.Contains(this.Apparel)) { Apparel apparel; if (this.pawn.apparel.TryDrop(this.Apparel, out apparel)) { this.job.targetA = apparel; if (this.job.haulDroppedApparel) { apparel.SetForbidden(false, false); StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(apparel); IntVec3 c; if (StoreUtility.TryFindBestBetterStoreCellFor(apparel, this.pawn, base.Map, currentPriority, this.pawn.Faction, out c, true)) { this.job.count = apparel.stackCount; this.job.targetB = c; } else { base.EndJobWith(JobCondition.Incompletable); } } else { base.EndJobWith(JobCondition.Succeeded); } } else { base.EndJobWith(JobCondition.Incompletable); } } else { base.EndJobWith(JobCondition.Incompletable); } })); if (this.job.haulDroppedApparel) { yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null)); yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null)); yield return(Toils_Haul.StartCarryThing(TargetIndex.A, false, false, false).FailOn(() => !this.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true)); } yield break; }
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); }
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.Barrel.Fermented).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f)); yield return(new Toil { initAction = delegate() { Thing thing = this.Barrel.TakeOutBeer(); 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 carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.C); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.C, carryToCell, true)); yield break; }
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).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch) .FailOn(() => !Barrel.Fermented) .WithProgressBarToilDelay(TargetIndex.A)); Toil toil = new Toil(); toil.initAction = delegate { Thing thing = Barrel.TakeOutBeer(); GenPlace.TryPlaceThing(thing, pawn.Position, base.Map, ThingPlaceMode.Near); StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing); if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, base.Map, currentPriority, pawn.Faction, out IntVec3 foundCell)) { job.SetTarget(TargetIndex.C, foundCell); job.SetTarget(TargetIndex.B, thing); job.count = thing.stackCount; } else { EndJobWith(JobCondition.Incompletable); } }; toil.defaultCompleteMode = ToilCompleteMode.Instant; yield return(toil); yield return(Toils_Reserve.Reserve(TargetIndex.B)); yield return(Toils_Reserve.Reserve(TargetIndex.C)); yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch)); yield return(Toils_Haul.StartCarryThing(TargetIndex.B)); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.C); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.C, carryToCell, storageMode: true)); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); yield return(Toils_General.Wait(duration).WithProgressBarToilDelay(TargetIndex.A)); yield return(Toils_General.Do(delegate { if (pawn.apparel.WornApparel.Contains(Apparel)) { if (pawn.apparel.TryDrop(Apparel, out var resultingAp)) { job.targetA = resultingAp; if (job.haulDroppedApparel) { resultingAp.SetForbidden(value: false, warnOnFail: false); StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(resultingAp); if (StoreUtility.TryFindBestBetterStoreCellFor(resultingAp, pawn, base.Map, currentPriority, pawn.Faction, out var foundCell)) { job.count = resultingAp.stackCount; job.targetB = foundCell; } else { EndJobWith(JobCondition.Incompletable); } } else { EndJobWith(JobCondition.Succeeded); } } else { EndJobWith(JobCondition.Incompletable); } } else { EndJobWith(JobCondition.Incompletable); } }));
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.FailOnDespawnedNullOrForbidden(TargetIndex.A); this.FailOnBurningImmobile(TargetIndex.A); this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch); if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: this.$current = Toils_General.Wait(200, TargetIndex.None).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).FailOn(() => !base.Barrel.Fermented).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f); if (!this.$disposing) { this.$PC = 2; } return(true); case 2u: { Toil takeBeer = new Toil(); takeBeer.initAction = delegate() { Thing thing = base.Barrel.TakeOutBeer(); 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); } }; takeBeer.defaultCompleteMode = ToilCompleteMode.Instant; this.$current = takeBeer; if (!this.$disposing) { this.$PC = 3; } return(true); } case 3u: this.$current = Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null); if (!this.$disposing) { this.$PC = 4; } return(true); case 4u: this.$current = Toils_Reserve.Reserve(TargetIndex.C, 1, -1, null); if (!this.$disposing) { this.$PC = 5; } return(true); case 5u: this.$current = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch); if (!this.$disposing) { this.$PC = 6; } return(true); case 6u: this.$current = Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false); if (!this.$disposing) { this.$PC = 7; } return(true); case 7u: carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.C); this.$current = carryToCell; if (!this.$disposing) { this.$PC = 8; } return(true); case 8u: this.$current = Toils_Haul.PlaceHauledThingInCell(TargetIndex.C, carryToCell, true); if (!this.$disposing) { this.$PC = 9; } return(true); case 9u: this.$PC = -1; break; } return(false); }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.FailOnDestroyedOrNull(TargetIndex.A); this.$current = Toils_General.Wait(this.duration, TargetIndex.None).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f); if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: this.$current = Toils_General.Do(delegate { if (this.pawn.apparel.WornApparel.Contains(base.Apparel)) { Apparel apparel; if (this.pawn.apparel.TryDrop(base.Apparel, out apparel)) { this.job.targetA = apparel; if (this.job.haulDroppedApparel) { apparel.SetForbidden(false, false); StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(apparel); IntVec3 c; if (StoreUtility.TryFindBestBetterStoreCellFor(apparel, this.pawn, base.Map, currentPriority, this.pawn.Faction, out c, true)) { this.job.count = apparel.stackCount; this.job.targetB = c; } else { base.EndJobWith(JobCondition.Incompletable); } } else { base.EndJobWith(JobCondition.Succeeded); } } else { base.EndJobWith(JobCondition.Incompletable); } } else { base.EndJobWith(JobCondition.Incompletable); } }); if (!this.$disposing) { this.$PC = 2; } return(true); case 2u: if (this.job.haulDroppedApparel) { this.$current = Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null); if (!this.$disposing) { this.$PC = 3; } return(true); } break; case 3u: this.$current = Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null); if (!this.$disposing) { this.$PC = 4; } return(true); case 4u: this.$current = Toils_Haul.StartCarryThing(TargetIndex.A, false, false, false).FailOn(() => !this.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)); if (!this.$disposing) { this.$PC = 5; } return(true); case 5u: carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B); this.$current = carryToCell; if (!this.$disposing) { this.$PC = 6; } return(true); case 6u: this.$current = Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true); if (!this.$disposing) { this.$PC = 7; } return(true); case 7u: break; default: return(false); } this.$PC = -1; return(false); }
internal bool <> m__0(Thing t) { IntVec3 intVec; return(!t.IsForbidden(this.pawn) && HaulAIUtility.PawnCanAutomaticallyHaulFast(this.pawn, t, false) && this.pawn.carryTracker.MaxStackSpaceEver(t.def) > 0 && StoreUtility.TryFindBestBetterStoreCellFor(t, this.pawn, this.pawn.Map, StoreUtility.CurrentStoragePriorityOf(t), this.pawn.Faction, out intVec, true)); }
protected override Job TryGiveJob(Pawn pawn) { Predicate <Thing> validator = delegate(Thing t) { IntVec3 intVec; return(!t.IsForbidden(pawn) && HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, false) && pawn.carryTracker.MaxStackSpaceEver(t.def) > 0 && StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, StoreUtility.CurrentStoragePriorityOf(t), pawn.Faction, out intVec, true)); }; 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); Job result; if (thing != null) { result = HaulAIUtility.HaulToStorageJob(pawn, thing); } else { result = null; } return(result); }