public static bool IsGoodStoreCell(IntVec3 c, Map map, Thing t, Pawn carrier, Faction faction) { if (carrier != null && c.IsForbidden(carrier)) { return(false); } if (!StoreUtility.NoStorageBlockersIn(c, map, t)) { return(false); } if (carrier != null) { if (!carrier.CanReserveNew(c)) { return(false); } } else if (faction != null && map.reservationManager.IsReservedByAnyoneOf(c, faction)) { return(false); } if (c.ContainsStaticFire(map)) { return(false); } if (carrier != null && !carrier.Map.reachability.CanReach((!t.SpawnedOrAnyParentSpawned) ? carrier.PositionHeld : t.PositionHeld, c, PathEndMode.ClosestTouch, TraverseParms.For(carrier, Danger.Deadly, TraverseMode.ByPawn, false))) { return(false); } return(true); }
public static bool TryFindBestBetterStoreCellFor(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction, out IntVec3 foundCell, bool needAccurateResult = true) { List <SlotGroup> allGroupsListInPriorityOrder = map.haulDestinationManager.AllGroupsListInPriorityOrder; if (allGroupsListInPriorityOrder.Count == 0) { foundCell = IntVec3.Invalid; return(false); } StoragePriority storagePriority = currentPriority; float num = 2.14748365E+09f; IntVec3 invalid = IntVec3.Invalid; int count = allGroupsListInPriorityOrder.Count; for (int i = 0; i < count; i++) { SlotGroup slotGroup = allGroupsListInPriorityOrder[i]; StoragePriority priority = slotGroup.Settings.Priority; if (priority < storagePriority || priority <= currentPriority) { break; } StoreUtility.TryFindBestBetterStoreCellForWorker(t, carrier, map, faction, slotGroup, needAccurateResult, ref invalid, ref num, ref storagePriority); } if (!invalid.IsValid) { foundCell = IntVec3.Invalid; return(false); } foundCell = invalid; return(true); }
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 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 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 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 TryFindBestBetterStoreCellForIn(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction, SlotGroup slotGroup, out IntVec3 foundCell, bool needAccurateResult = true) { foundCell = IntVec3.Invalid; float num = 2.14748365E+09f; StoreUtility.TryFindBestBetterStoreCellForWorker(t, carrier, map, faction, slotGroup, needAccurateResult, ref foundCell, ref num, ref currentPriority); return(foundCell.IsValid); }
public static bool IsInValidBestStorage(this Thing t) { IHaulDestination haulDestination = StoreUtility.CurrentHaulDestinationOf(t); IntVec3 intVec; IHaulDestination haulDestination2; return(haulDestination != null && haulDestination.Accepts(t) && !StoreUtility.TryFindBestBetterStorageFor(t, null, t.Map, haulDestination.GetStoreSettings().Priority, Faction.OfPlayer, out intVec, out haulDestination2, false)); }
public static bool TryFindBestBetterStoreCellFor(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction, out IntVec3 foundCell, bool needAccurateResult = true) { List <SlotGroup> allGroupsListInPriorityOrder = map.slotGroupManager.AllGroupsListInPriorityOrder; if (allGroupsListInPriorityOrder.Count == 0) { foundCell = IntVec3.Invalid; return(false); } IntVec3 a = (!t.SpawnedOrAnyParentSpawned) ? carrier.PositionHeld : t.PositionHeld; StoragePriority storagePriority = currentPriority; float num = 2.14748365E+09f; IntVec3 intVec = default(IntVec3); bool flag = false; int count = allGroupsListInPriorityOrder.Count; int num2 = 0; while (num2 < count) { SlotGroup slotGroup = allGroupsListInPriorityOrder[num2]; StoragePriority priority = slotGroup.Settings.Priority; if ((int)priority >= (int)storagePriority && (int)priority > (int)currentPriority) { if (slotGroup.Settings.AllowedToAccept(t)) { List <IntVec3> cellsList = slotGroup.CellsList; int count2 = cellsList.Count; int num3 = needAccurateResult ? Mathf.FloorToInt((float)count2 * Rand.Range(0.005f, 0.018f)) : 0; for (int i = 0; i < count2; i++) { IntVec3 intVec2 = cellsList[i]; float num4 = (float)(a - intVec2).LengthHorizontalSquared; if (!(num4 > num) && StoreUtility.IsGoodStoreCell(intVec2, map, t, carrier, faction)) { flag = true; intVec = intVec2; num = num4; storagePriority = priority; if (i >= num3) { break; } } } } num2++; continue; } break; } if (!flag) { foundCell = IntVec3.Invalid; return(false); } foundCell = intVec; return(true); }
public static bool IsValidStorageFor(this IntVec3 c, Map map, Thing storable) { if (!StoreUtility.NoStorageBlockersIn(c, map, storable)) { return(false); } SlotGroup slotGroup = c.GetSlotGroup(map); return(slotGroup != null && slotGroup.parent.Accepts(storable)); }
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)); }
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 bool IsValidStorageFor(this IntVec3 c, Map map, Thing storable) { if (!StoreUtility.NoStorageBlockersIn(c, map, storable)) { return(false); } SlotGroup slotGroup = c.GetSlotGroup(map); if (slotGroup != null && slotGroup.Settings.AllowedToAccept(storable)) { return(true); } return(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)); }
public static bool IsGoodStoreCell(IntVec3 c, Map map, Thing t, Pawn carrier, Faction faction) { bool result; if (carrier != null && c.IsForbidden(carrier)) { result = false; } else if (!StoreUtility.NoStorageBlockersIn(c, map, t)) { result = false; } else { if (carrier != null) { if (!carrier.CanReserveNew(c)) { return(false); } } else if (faction != null && map.reservationManager.IsReservedByAnyoneOf(c, faction)) { return(false); } if (c.ContainsStaticFire(map)) { result = false; } else { List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i] is IConstructible && GenConstruct.BlocksConstruction(thingList[i], t)) { return(false); } } result = (carrier == null || carrier.Map.reachability.CanReach((!t.SpawnedOrAnyParentSpawned) ? carrier.PositionHeld : t.PositionHeld, c, PathEndMode.ClosestTouch, TraverseParms.For(carrier, Danger.Deadly, TraverseMode.ByPawn, false))); } } return(result); }
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); }
private static void TryFindBestBetterStoreCellForWorker(Thing t, Pawn carrier, Map map, Faction faction, SlotGroup slotGroup, bool needAccurateResult, ref IntVec3 closestSlot, ref float closestDistSquared, ref StoragePriority foundPriority) { if (!slotGroup.parent.Accepts(t)) { return; } IntVec3 a = (!t.SpawnedOrAnyParentSpawned) ? carrier.PositionHeld : t.PositionHeld; List <IntVec3> cellsList = slotGroup.CellsList; int count = cellsList.Count; int num; if (needAccurateResult) { num = Mathf.FloorToInt((float)count * Rand.Range(0.005f, 0.018f)); } else { num = 0; } for (int i = 0; i < count; i++) { IntVec3 intVec = cellsList[i]; float num2 = (float)(a - intVec).LengthHorizontalSquared; if (num2 <= closestDistSquared) { if (StoreUtility.IsGoodStoreCell(intVec, map, t, carrier, faction)) { closestSlot = intVec; closestDistSquared = num2; foundPriority = slotGroup.Settings.Priority; if (i >= num) { break; } } } } }
private IntVec3 FindRandomDropCell(Pawn pawn, Pawn downedPawn) { IntVec3 cell = pawn.mindState.duty.focusSecond.Cell; return(CellFinder.RandomClosewalkCellNear(cell, pawn.Map, 6, (IntVec3 x) => x.Standable(pawn.Map) && StoreUtility.IsGoodStoreCell(x, pawn.Map, downedPawn, pawn, pawn.Faction))); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_General.Wait(10, TargetIndex.None)); yield return(new Toil { initAction = delegate() { if (!this.pawn.inventory.UnloadEverything) { base.EndJobWith(JobCondition.Succeeded); } else { ThingCount firstUnloadableThing = this.pawn.inventory.FirstUnloadableThing; IntVec3 c; if (!StoreUtility.TryFindStoreCellNearColonyDesperate(firstUnloadableThing.Thing, this.pawn, out c)) { Thing thing; this.pawn.inventory.innerContainer.TryDrop(firstUnloadableThing.Thing, ThingPlaceMode.Near, firstUnloadableThing.Count, out thing, null, null); base.EndJobWith(JobCondition.Succeeded); } else { this.job.SetTarget(TargetIndex.A, firstUnloadableThing.Thing); this.job.SetTarget(TargetIndex.B, c); this.countToDrop = firstUnloadableThing.Count; } } } }); yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null)); yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.Touch)); yield return(new Toil { initAction = delegate() { Thing thing = this.job.GetTarget(TargetIndex.A).Thing; if (thing == null || !this.pawn.inventory.innerContainer.Contains(thing)) { base.EndJobWith(JobCondition.Incompletable); return; } if (!this.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !thing.def.EverStorable(false)) { this.pawn.inventory.innerContainer.TryDrop(thing, ThingPlaceMode.Near, this.countToDrop, out thing, null, null); base.EndJobWith(JobCondition.Succeeded); } else { this.pawn.inventory.innerContainer.TryTransferToContainer(thing, this.pawn.carryTracker.innerContainer, this.countToDrop, out thing, true); this.job.count = this.countToDrop; this.job.SetTarget(TargetIndex.A, thing); } thing.SetForbidden(false, false); } }); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true)); yield break; }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.$current = Toils_General.Wait(10, TargetIndex.None); if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: { Toil pickItem = new Toil(); pickItem.initAction = delegate() { if (!this.pawn.inventory.UnloadEverything) { base.EndJobWith(JobCondition.Succeeded); } else { ThingCount firstUnloadableThing = this.pawn.inventory.FirstUnloadableThing; IntVec3 c; if (!StoreUtility.TryFindStoreCellNearColonyDesperate(firstUnloadableThing.Thing, this.pawn, out c)) { Thing thing; this.pawn.inventory.innerContainer.TryDrop(firstUnloadableThing.Thing, ThingPlaceMode.Near, firstUnloadableThing.Count, out thing, null, null); base.EndJobWith(JobCondition.Succeeded); } else { this.job.SetTarget(TargetIndex.A, firstUnloadableThing.Thing); this.job.SetTarget(TargetIndex.B, c); this.countToDrop = firstUnloadableThing.Count; } } }; this.$current = pickItem; if (!this.$disposing) { this.$PC = 2; } return(true); } case 2u: this.$current = Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null); if (!this.$disposing) { this.$PC = 3; } return(true); case 3u: this.$current = Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.Touch); if (!this.$disposing) { this.$PC = 4; } return(true); case 4u: { Toil dropOrStartCarrying = new Toil(); dropOrStartCarrying.initAction = delegate() { Thing thing = this.job.GetTarget(TargetIndex.A).Thing; if (thing == null || !this.pawn.inventory.innerContainer.Contains(thing)) { base.EndJobWith(JobCondition.Incompletable); return; } if (!this.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !thing.def.EverStorable(false)) { this.pawn.inventory.innerContainer.TryDrop(thing, ThingPlaceMode.Near, this.countToDrop, out thing, null, null); base.EndJobWith(JobCondition.Succeeded); } else { this.pawn.inventory.innerContainer.TryTransferToContainer(thing, this.pawn.carryTracker.innerContainer, this.countToDrop, out thing, true); this.job.count = this.countToDrop; this.job.SetTarget(TargetIndex.A, thing); } thing.SetForbidden(false, false); }; this.$current = dropOrStartCarrying; 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: this.$PC = -1; break; } return(false); }
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 static bool IsInValidStorage(this Thing t) { IHaulDestination haulDestination = StoreUtility.CurrentHaulDestinationOf(t); return(haulDestination != null && haulDestination.Accepts(t)); }
public static bool IsInAnyStorage(this Thing t) { return(StoreUtility.CurrentHaulDestinationOf(t) != null); }
public static StoragePriority StoragePriorityAtFor(IntVec3 c, Thing t) { return(StoreUtility.StoragePriorityAtFor(t.Map.haulDestinationManager.SlotGroupParentAt(c), t)); }
public static Thing StoringThing(this Thing t) { return(StoreUtility.CurrentHaulDestinationOf(t) as Thing); }
public static StoragePriority CurrentStoragePriorityOf(Thing t) { return(StoreUtility.StoragePriorityAtFor(StoreUtility.CurrentHaulDestinationOf(t), t)); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_General.Wait(10)); Toil toil = new Toil(); toil.initAction = delegate { if (!pawn.inventory.UnloadEverything) { EndJobWith(JobCondition.Succeeded); } else { ThingCount firstUnloadableThing = pawn.inventory.FirstUnloadableThing; if (!StoreUtility.TryFindStoreCellNearColonyDesperate(firstUnloadableThing.Thing, pawn, out var storeCell)) { pawn.inventory.innerContainer.TryDrop(firstUnloadableThing.Thing, ThingPlaceMode.Near, firstUnloadableThing.Count, out var _); EndJobWith(JobCondition.Succeeded); } else { job.SetTarget(TargetIndex.A, firstUnloadableThing.Thing); job.SetTarget(TargetIndex.B, storeCell); countToDrop = firstUnloadableThing.Count; } } }; yield return(toil); yield return(Toils_Reserve.Reserve(TargetIndex.B)); yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.Touch)); Toil toil2 = new Toil(); toil2.initAction = delegate { Thing lastResultingThing = job.GetTarget(TargetIndex.A).Thing; if (lastResultingThing == null || !pawn.inventory.innerContainer.Contains(lastResultingThing)) { EndJobWith(JobCondition.Incompletable); } else { if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !lastResultingThing.def.EverStorable(willMinifyIfPossible: false)) { pawn.inventory.innerContainer.TryDrop(lastResultingThing, ThingPlaceMode.Near, countToDrop, out lastResultingThing); EndJobWith(JobCondition.Succeeded); } else { pawn.inventory.innerContainer.TryTransferToContainer(lastResultingThing, pawn.carryTracker.innerContainer, countToDrop, out lastResultingThing); job.count = countToDrop; job.SetTarget(TargetIndex.A, lastResultingThing); } lastResultingThing.SetForbidden(value: false, warnOnFail: false); } }; yield return(toil2); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, storageMode: true)); }