public static bool TryFindBestBetterStorageFor(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction, out IntVec3 foundCell, out IHaulDestination haulDestination, bool needAccurateResult = true) { IntVec3 invalid = IntVec3.Invalid; StoragePriority storagePriority = StoragePriority.Unstored; if (StoreUtility.TryFindBestBetterStoreCellFor(t, carrier, map, currentPriority, faction, out invalid, needAccurateResult)) { storagePriority = invalid.GetSlotGroup(map).Settings.Priority; } IHaulDestination haulDestination2; if (!StoreUtility.TryFindBestBetterNonSlotGroupStorageFor(t, carrier, map, currentPriority, faction, out haulDestination2)) { haulDestination2 = null; } if (storagePriority == StoragePriority.Unstored && haulDestination2 == null) { foundCell = IntVec3.Invalid; haulDestination = null; return(false); } if (haulDestination2 != null && (storagePriority == StoragePriority.Unstored || haulDestination2.GetStoreSettings().Priority > storagePriority)) { foundCell = IntVec3.Invalid; haulDestination = haulDestination2; return(true); } foundCell = invalid; haulDestination = invalid.GetSlotGroup(map).parent; return(true); }
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); }
public static bool TryFindStoreCellNearColonyDesperate(Thing item, Pawn carrier, out IntVec3 storeCell) { bool result; if (StoreUtility.TryFindBestBetterStoreCellFor(item, carrier, carrier.Map, StoragePriority.Unstored, carrier.Faction, out storeCell, true)) { result = true; } else { for (int i = -4; i < 20; i++) { int num = (i >= 0) ? i : Rand.RangeInclusive(0, 4); IntVec3 intVec = carrier.Position + GenRadial.RadialPattern[num]; if (intVec.InBounds(carrier.Map) && carrier.Map.areaManager.Home[intVec] && carrier.CanReach(intVec, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn) && intVec.GetSlotGroup(carrier.Map) == null && StoreUtility.IsGoodStoreCell(intVec, carrier.Map, item, carrier, carrier.Faction)) { storeCell = intVec; return(true); } } if (RCellFinder.TryFindRandomSpotJustOutsideColony(carrier.Position, carrier.Map, carrier, out storeCell, (IntVec3 x) => x.GetSlotGroup(carrier.Map) == null && StoreUtility.IsGoodStoreCell(x, carrier.Map, item, carrier, carrier.Faction))) { result = true; } else { storeCell = IntVec3.Invalid; result = false; } } return(result); }
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 bool IsInValidBestStorage(this Thing t) { if (!t.Spawned) { return(false); } SlotGroup slotGroup = t.GetSlotGroup(); IntVec3 intVec; return(slotGroup != null && slotGroup.Settings.AllowedToAccept(t) && !StoreUtility.TryFindBestBetterStoreCellFor(t, null, t.Map, slotGroup.Settings.Priority, Faction.OfPlayer, out intVec, false)); }
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)); }
private Toil StartCollectCorpseToil() { Toil toil = new Toil(); toil.initAction = delegate() { if (this.Victim == null) { toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); } else { TaleRecorder.RecordTale(TaleDefOf.Hunted, new object[] { this.pawn, this.Victim }); Corpse corpse = this.Victim.Corpse; if (corpse == null || !this.pawn.CanReserveAndReach(corpse, PathEndMode.ClosestTouch, Danger.Deadly, 1, -1, null, false)) { this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true); } else { corpse.SetForbidden(false, true); IntVec3 c; if (StoreUtility.TryFindBestBetterStoreCellFor(corpse, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out c, true)) { this.pawn.Reserve(corpse, this.job, 1, -1, null); this.pawn.Reserve(c, this.job, 1, -1, null); this.job.SetTarget(TargetIndex.B, c); this.job.SetTarget(TargetIndex.A, corpse); this.job.count = 1; this.job.haulMode = HaulMode.ToCellStorage; } else { this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded, true); } } } }; return(toil); }
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); } }));
private Toil StartCollectCorpseToil() { Toil toil = new Toil(); toil.initAction = delegate { if (Victim == null) { toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable); } else { TaleRecorder.RecordTale(TaleDefOf.Hunted, pawn, Victim); Corpse corpse = Victim.Corpse; if (corpse == null || !pawn.CanReserveAndReach(corpse, PathEndMode.ClosestTouch, Danger.Deadly)) { pawn.jobs.EndCurrentJob(JobCondition.Incompletable); } else { corpse.SetForbidden(value: false); if (StoreUtility.TryFindBestBetterStoreCellFor(corpse, pawn, base.Map, StoragePriority.Unstored, pawn.Faction, out IntVec3 foundCell)) { pawn.Reserve(corpse, job); pawn.Reserve(foundCell, job); job.SetTarget(TargetIndex.B, foundCell); job.SetTarget(TargetIndex.A, corpse); job.count = 1; job.haulMode = HaulMode.ToCellStorage; } else { pawn.jobs.EndCurrentJob(JobCondition.Succeeded); } } } }; return(toil); }
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, HaulAIUtility.StoragePriorityAtFor(t.Position, 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); if (thing != null) { return(HaulAIUtility.HaulToStorageJob(pawn, thing)); } return(null); }
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); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); yield return(new Toil { initAction = delegate { this.$this.pawn.pather.StopDead(); }, defaultCompleteMode = ToilCompleteMode.Delay, defaultDuration = 60 }); yield return(new Toil { initAction = delegate { if (this.$this.pawn.apparel.WornApparel.Contains(this.$this.TargetApparel)) { Apparel apparel; if (this.$this.pawn.apparel.TryDrop(this.$this.TargetApparel, out apparel)) { this.$this.job.targetA = apparel; if (this.$this.job.haulDroppedApparel) { apparel.SetForbidden(false, false); StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(apparel.Position, apparel); IntVec3 c; if (StoreUtility.TryFindBestBetterStoreCellFor(apparel, this.$this.pawn, this.$this.Map, currentPriority, this.$this.pawn.Faction, out c, true)) { this.$this.job.count = apparel.stackCount; this.$this.job.targetB = c; } else { this.$this.EndJobWith(JobCondition.Incompletable); } } else { this.$this.EndJobWith(JobCondition.Succeeded); } } else { this.$this.EndJobWith(JobCondition.Incompletable); } } else { this.$this.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.$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)); } }
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)); }