public void AddHaulDestination(IHaulDestination haulDestination) { if (this.allHaulDestinationsInOrder.Contains(haulDestination)) { Log.Error("Double-added haul destination " + haulDestination.ToStringSafe <IHaulDestination>(), false); return; } this.allHaulDestinationsInOrder.Add(haulDestination); this.allHaulDestinationsInOrder.InsertionSort(new Comparison <IHaulDestination>(HaulDestinationManager.CompareHaulDestinationPrioritiesDescending)); ISlotGroupParent slotGroupParent = haulDestination as ISlotGroupParent; if (slotGroupParent != null) { SlotGroup slotGroup = slotGroupParent.GetSlotGroup(); if (slotGroup == null) { Log.Error("ISlotGroupParent gave null slot group: " + slotGroupParent.ToStringSafe <ISlotGroupParent>(), false); } else { this.allGroupsInOrder.Add(slotGroup); this.allGroupsInOrder.InsertionSort(new Comparison <SlotGroup>(HaulDestinationManager.CompareSlotGroupPrioritiesDescending)); List <IntVec3> cellsList = slotGroup.CellsList; for (int i = 0; i < cellsList.Count; i++) { this.SetCellFor(cellsList[i], slotGroup); } this.map.listerHaulables.Notify_SlotGroupChanged(slotGroup); this.map.listerMergeables.Notify_SlotGroupChanged(slotGroup); } } }
public void AddHaulDestination(IHaulDestination haulDestination) { if (allHaulDestinationsInOrder.Contains(haulDestination)) { Log.Error("Double-added haul destination " + haulDestination.ToStringSafe()); return; } allHaulDestinationsInOrder.Add(haulDestination); allHaulDestinationsInOrder.InsertionSort(CompareHaulDestinationPrioritiesDescending); ISlotGroupParent slotGroupParent = haulDestination as ISlotGroupParent; if (slotGroupParent == null) { return; } SlotGroup slotGroup = slotGroupParent.GetSlotGroup(); if (slotGroup == null) { Log.Error("ISlotGroupParent gave null slot group: " + slotGroupParent.ToStringSafe()); return; } allGroupsInOrder.Add(slotGroup); allGroupsInOrder.InsertionSort(CompareSlotGroupPrioritiesDescending); List <IntVec3> cellsList = slotGroup.CellsList; for (int i = 0; i < cellsList.Count; i++) { SetCellFor(cellsList[i], slotGroup); } map.listerHaulables.Notify_SlotGroupChanged(slotGroup); map.listerMergeables.Notify_SlotGroupChanged(slotGroup); }
public void RemoveHaulDestination(IHaulDestination haulDestination) { if (!allHaulDestinationsInOrder.Contains(haulDestination)) { Log.Error("Removing haul destination that isn't registered " + haulDestination.ToStringSafe()); return; } allHaulDestinationsInOrder.Remove(haulDestination); ISlotGroupParent slotGroupParent = haulDestination as ISlotGroupParent; if (slotGroupParent == null) { return; } SlotGroup slotGroup = slotGroupParent.GetSlotGroup(); if (slotGroup == null) { Log.Error("ISlotGroupParent gave null slot group: " + slotGroupParent.ToStringSafe()); return; } allGroupsInOrder.Remove(slotGroup); List <IntVec3> cellsList = slotGroup.CellsList; for (int i = 0; i < cellsList.Count; i++) { IntVec3 intVec = cellsList[i]; groupGrid[intVec.x, intVec.y, intVec.z] = null; } map.listerHaulables.Notify_SlotGroupChanged(slotGroup); map.listerMergeables.Notify_SlotGroupChanged(slotGroup); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnDestroyedNullOrForbidden(TargetIndex.B); this.FailOn(() => TransporterUtility.WasLoadingCanceled(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0065: stateMachine*/)._0024this.Container)); this.FailOn(delegate { ThingOwner thingOwner = ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_007d: stateMachine*/)._0024this.Container.TryGetInnerInteractableThingOwner(); if (thingOwner != null && !thingOwner.CanAcceptAnyOf(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_007d: stateMachine*/)._0024this.ThingToCarry)) { return(true); } IHaulDestination haulDestination = ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_007d: stateMachine*/)._0024this.Container as IHaulDestination; if (haulDestination != null && !haulDestination.Accepts(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_007d: stateMachine*/)._0024this.ThingToCarry)) { return(true); } return(false); }); Toil getToHaulTarget = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(TargetIndex.A); yield return(getToHaulTarget); /*Error: Unable to find new state assignment for yield return*/; }
public static bool CurrentHaulDestinationOf(ref IHaulDestination __result, Thing t) { __result = null; if (t == null) { return(false); } if (!t.Spawned) { __result = t.ParentHolder as IHaulDestination; return(false); } Map map = t.Map; if (map == null) { return(false); } HaulDestinationManager haulDestinationManager = map.haulDestinationManager; if (haulDestinationManager == null) { return(false); } __result = haulDestinationManager.SlotGroupParentAt(t.Position); return(false); }
//public void RemoveHaulDestination(IHaulDestination haulDestination) public static void Postfix(IHaulDestination haulDestination) { if (haulDestination is ISlotGroupParent slotGroupParent && slotGroupParent.GetSlotGroup() is SlotGroup slotGroup) { AllowToolController.Instance.WorldSettings.MarkForRefill(haulDestination.Map, slotGroup, false); } }
public static StoragePriority StoragePriorityAtFor(IHaulDestination at, Thing t) { if (at == null || !at.Accepts(t)) { return(StoragePriority.Unstored); } return(at.GetStoreSettings().Priority); }
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 void RemoveHaulDestination(IHaulDestination haulDestination) public static void Postfix(Map ___map, IHaulDestination haulDestination) { if (haulDestination is ISlotGroupParent slotGroupParent && slotGroupParent.GetSlotGroup() is SlotGroup slotGroup) { slotGroup.MarkForRefill(___map, false); } }
public virtual void PostDeregister() { IHaulDestination haulDestination = this as IHaulDestination; if (haulDestination != null) { Map.haulDestinationManager.RemoveHaulDestination(haulDestination); } }
private void CheckAddHaulDestination() { IHaulDestination haulDestination = this as IHaulDestination; if (haulDestination != null) { Map.haulDestinationManager.AddHaulDestination(haulDestination); } }
public static bool IsInValidBestStorage(this Thing t) { IHaulDestination haulDestination = CurrentHaulDestinationOf(t); if (haulDestination == null || !haulDestination.Accepts(t)) { return(false); } if (TryFindBestBetterStorageFor(t, null, t.Map, haulDestination.GetStoreSettings().Priority, Faction.OfPlayer, out var _, out var _, needAccurateResult: false)) { return(false); } return(true); }
public static StoragePriority StoragePriorityAtFor(IHaulDestination at, Thing t) { StoragePriority result; if (at == null || !at.Accepts(t)) { result = StoragePriority.Unstored; } else { result = at.GetStoreSettings().Priority; } return(result); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnDestroyedNullOrForbidden(TargetIndex.B); this.FailOn(() => TransporterUtility.WasLoadingCanceled(this.Container)); this.FailOn(delegate() { ThingOwner thingOwner = this.Container.TryGetInnerInteractableThingOwner(); bool result; if (thingOwner != null && !thingOwner.CanAcceptAnyOf(this.ThingToCarry, true)) { result = true; } else { IHaulDestination haulDestination = this.Container as IHaulDestination; result = (haulDestination != null && !haulDestination.Accepts(this.ThingToCarry)); } return(result); }); Toil getToHaulTarget = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(TargetIndex.A); yield return(getToHaulTarget); yield return(Toils_Construct.UninstallIfMinifiable(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A)); yield return(Toils_Haul.StartCarryThing(TargetIndex.A, false, true, false)); yield return(Toils_Haul.JumpIfAlsoCollectingNextTargetInQueue(getToHaulTarget, TargetIndex.A)); Toil carryToContainer = Toils_Haul.CarryHauledThingToContainer(); yield return(carryToContainer); yield return(Toils_Goto.MoveOffTargetBlueprint(TargetIndex.B)); Toil prepare = Toils_General.Wait(this.Duration, TargetIndex.B); prepare.WithProgressBarToilDelay(TargetIndex.B, false, -0.5f); yield return(prepare); yield return(Toils_Construct.MakeSolidThingFromBlueprintIfNecessary(TargetIndex.B, TargetIndex.C)); yield return(Toils_Haul.DepositHauledThingInContainer(TargetIndex.B, TargetIndex.C)); yield return(Toils_Haul.JumpToCarryToNextContainerIfPossible(carryToContainer, TargetIndex.C)); yield break; }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnDestroyedNullOrForbidden(TargetIndex.B); this.FailOn(() => TransporterUtility.WasLoadingCanceled(Container)); this.FailOn(delegate { ThingOwner thingOwner = Container.TryGetInnerInteractableThingOwner(); if (thingOwner != null && !thingOwner.CanAcceptAnyOf(ThingToCarry)) { return(true); } IHaulDestination haulDestination = Container as IHaulDestination; return((haulDestination != null && !haulDestination.Accepts(ThingToCarry)) ? true : false); }); Toil getToHaulTarget = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(TargetIndex.A); yield return(getToHaulTarget); yield return(Toils_Construct.UninstallIfMinifiable(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A)); yield return(Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true)); yield return(Toils_Haul.JumpIfAlsoCollectingNextTargetInQueue(getToHaulTarget, TargetIndex.A)); Toil carryToContainer = Toils_Haul.CarryHauledThingToContainer(); yield return(carryToContainer); yield return(Toils_Goto.MoveOffTargetBlueprint(TargetIndex.B)); Toil toil = Toils_General.Wait(Duration, TargetIndex.B); toil.WithProgressBarToilDelay(TargetIndex.B); yield return(toil); yield return(Toils_Construct.MakeSolidThingFromBlueprintIfNecessary(TargetIndex.B, TargetIndex.C)); yield return(Toils_Haul.DepositHauledThingInContainer(TargetIndex.B, TargetIndex.C)); yield return(Toils_Haul.JumpToCarryToNextContainerIfPossible(carryToContainer, TargetIndex.C)); }
public static void DrawKanbanSettings(ITab_Storage tab) { IHaulDestination haulDestination = SelStoreInfo.GetValue(tab, null) as IHaulDestination; if (haulDestination == null) { return; } StorageSettings settings = haulDestination.GetStoreSettings(); if (settings == null) { return; } //ITab_Storage.WinSize = 300 float buttonMargin = ITab_Storage_TopAreaHeight_Patch.extraHeight + 4; Rect rect = new Rect(0f, (float)GetTopAreaHeight.Invoke(tab, new object[] { }) - ITab_Storage_TopAreaHeight_Patch.extraHeight - 2, 280, ITab_Storage_TopAreaHeight_Patch.extraHeight); // if Stockpile Ranking is installed, scootch these widgets up so it doesn't overlap // https://github.com/alextd/RimWorld-StockpileRanking/blob/master/Source/RankSelection.cs#L18 if (KanbanStockpileLoader.IsStockpileRankingLoaded) { rect.y -= 26f; } rect.x += buttonMargin; rect.width -= buttonMargin * 3; Text.Font = GameFont.Small; KanbanSettings ks, tmp; ks = State.Get(settings.owner.ToString()); tmp.srt = ks.srt; tmp.ssl = ks.ssl; string stackRefillThresholdLabel = "KS.StackRefillThreshold".Translate(ks.srt); string similarStackLimitLabel; if (ks.ssl > 0) { similarStackLimitLabel = "KS.SimilarStackLimit".Translate(ks.ssl); } else { similarStackLimitLabel = "KS.SimilarStackLimitOff".Translate(); } //Stack Refill Threshold Slider tmp.srt = (int)Widgets.HorizontalSlider(new Rect(0f, rect.yMin + 10f, 150f, 15f), ks.srt, 0f, 100f, false, stackRefillThresholdLabel, null, null, 1f); //Similar Stack Limit Slider tmp.ssl = (int)Widgets.HorizontalSlider(new Rect(155, rect.yMin + 10f, 125f, 15f), ks.ssl, 0f, 8f, false, similarStackLimitLabel, null, null, 1f); if ((ks.srt != tmp.srt) || (ks.ssl != tmp.ssl)) { // Accept slider changes no faster than 4Hz (250ms) to prevent spamming multiplayer sync lag DateTime curTime = DateTime.Now; if ((curTime - lastUpdateTime).TotalMilliseconds < 250) { return; } lastUpdateTime = curTime; KSLog.Message("[KanbanStockpile] Changed Stack Refill Threshold for settings with haulDestination named: " + settings.owner.ToString()); ks.srt = tmp.srt; ks.ssl = tmp.ssl; State.Set(settings.owner.ToString(), ks); } }
public static void DrawRanking(ITab_Storage tab) { IHaulDestination haulDestination = SelStoreInfo.GetValue(tab, null) as IHaulDestination; if (haulDestination == null) { return; } StorageSettings settings = haulDestination.GetStoreSettings(); if (settings == null) { return; } var comp = RankComp.Get(); int count = comp.CountExtraFilters(settings); if (curRank > count) { curRank = count; } float buttonMargin = TopAreaHeight.rankHeight + 4; //ITab_Storage.WinSize = 300 Rect rect = new Rect(0f, (float)GetTopAreaHeight.Invoke(tab, new object[] { }) - TopAreaHeight.rankHeight - 2, 280, TopAreaHeight.rankHeight); //Left Arrow Rect leftButtonRect = rect.LeftPartPixels(TopAreaHeight.rankHeight); if (curRank > 0) { if (Widgets.ButtonImage(leftButtonRect, Tex.ArrowLeft)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); curRank--; } } //Right Arrow Rect rightButtonRect = rect.RightPartPixels(TopAreaHeight.rankHeight); if (curRank == count) { if (Widgets.ButtonImage(rightButtonRect, Tex.Plus)) { SoundDefOf.Click.PlayOneShotOnCamera(); comp.AddFilter(settings); curRank++; } } else { if (Widgets.ButtonImage(rightButtonRect, Tex.ArrowRight)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); curRank++; } } //Delete rank button rightButtonRect.x -= buttonMargin; if (curRank > 0) { if (Widgets.ButtonImage(rightButtonRect, Tex.DeleteX)) { SoundDefOf.Crunch.PlayOneShotOnCamera(); comp.RemoveFilter(settings, curRank--); } } //Label rect.x += buttonMargin; rect.width -= buttonMargin * 3; Text.Font = GameFont.Small; if (count == 0) { Widgets.Label(rect, "TD.AddFilter".Translate()); } else { Widgets.Label(rect, "TD.RankNum".Translate(curRank + 1)); } }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { if (this.Destroyed) { Log.Error(string.Concat(new object[] { "Spawning destroyed thing ", this, " at ", this.Position, ". Correcting." }), false); this.mapIndexOrState = -1; if (this.HitPoints <= 0 && this.def.useHitPoints) { this.HitPoints = 1; } } if (this.Spawned) { Log.Error(string.Concat(new object[] { "Tried to spawn already-spawned thing ", this, " at ", this.Position }), false); return; } int num = Find.Maps.IndexOf(map); if (num < 0) { Log.Error("Tried to spawn thing " + this + ", but the map provided does not exist.", false); return; } if (this.stackCount > this.def.stackLimit) { Log.Error(string.Concat(new object[] { "Spawned ", this, " with stackCount ", this.stackCount, " but stackLimit is ", this.def.stackLimit, ". Truncating." }), false); this.stackCount = this.def.stackLimit; } this.mapIndexOrState = (sbyte)num; RegionListersUpdater.RegisterInRegions(this, map); if (!map.spawnedThings.TryAdd(this, false)) { Log.Error("Couldn't add thing " + this + " to spawned things.", false); } map.listerThings.Add(this); map.thingGrid.Register(this); if (Find.TickManager != null) { Find.TickManager.RegisterAllTickabilityFor(this); } this.DirtyMapMesh(map); if (this.def.drawerType != DrawerType.MapMeshOnly) { map.dynamicDrawManager.RegisterDrawable(this); } map.tooltipGiverList.Notify_ThingSpawned(this); if (this.def.graphicData != null && this.def.graphicData.Linked) { map.linkGrid.Notify_LinkerCreatedOrDestroyed(this); map.mapDrawer.MapMeshDirty(this.Position, MapMeshFlag.Things, true, false); } if (!this.def.CanOverlapZones) { map.zoneManager.Notify_NoZoneOverlapThingSpawned(this); } if (this.def.AffectsRegions) { map.regionDirtyer.Notify_ThingAffectingRegionsSpawned(this); } if (this.def.pathCost != 0 || this.def.passability == Traversability.Impassable) { map.pathGrid.RecalculatePerceivedPathCostUnderThing(this); } if (this.def.AffectsReachability) { map.reachability.ClearCache(); } map.coverGrid.Register(this); if (this.def.category == ThingCategory.Item) { map.listerHaulables.Notify_Spawned(this); map.listerMergeables.Notify_Spawned(this); } map.attackTargetsCache.Notify_ThingSpawned(this); Region validRegionAt_NoRebuild = map.regionGrid.GetValidRegionAt_NoRebuild(this.Position); Room room = (validRegionAt_NoRebuild != null) ? validRegionAt_NoRebuild.Room : null; if (room != null) { room.Notify_ContainedThingSpawnedOrDespawned(this); } StealAIDebugDrawer.Notify_ThingChanged(this); IHaulDestination haulDestination = this as IHaulDestination; if (haulDestination != null) { map.haulDestinationManager.AddHaulDestination(haulDestination); } if (this is IThingHolder && Find.ColonistBar != null) { Find.ColonistBar.MarkColonistsDirty(); } if (this.def.category == ThingCategory.Item) { SlotGroup slotGroup = this.Position.GetSlotGroup(map); if (slotGroup != null && slotGroup.parent != null) { slotGroup.parent.Notify_ReceivedThing(this); } } if (this.def.receivesSignals) { Find.SignalManager.RegisterReceiver(this); } }
private static int CompareHaulDestinationPrioritiesDescending(IHaulDestination a, IHaulDestination b) { return(((int)b.GetStoreSettings().Priority).CompareTo((int)a.GetStoreSettings().Priority)); }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnDestroyedNullOrForbidden(TargetIndex.B); this.FailOn(() => TransporterUtility.WasLoadingCanceled(base.Container)); this.FailOn(delegate() { ThingOwner thingOwner = base.Container.TryGetInnerInteractableThingOwner(); bool result; if (thingOwner != null && !thingOwner.CanAcceptAnyOf(base.ThingToCarry, true)) { result = true; } else { IHaulDestination haulDestination = base.Container as IHaulDestination; result = (haulDestination != null && !haulDestination.Accepts(base.ThingToCarry)); } return(result); }); getToHaulTarget = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(TargetIndex.A); this.$current = getToHaulTarget; if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: this.$current = Toils_Construct.UninstallIfMinifiable(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A); if (!this.$disposing) { this.$PC = 2; } return(true); case 2u: this.$current = Toils_Haul.StartCarryThing(TargetIndex.A, false, true, false); if (!this.$disposing) { this.$PC = 3; } return(true); case 3u: this.$current = Toils_Haul.JumpIfAlsoCollectingNextTargetInQueue(getToHaulTarget, TargetIndex.A); if (!this.$disposing) { this.$PC = 4; } return(true); case 4u: carryToContainer = Toils_Haul.CarryHauledThingToContainer(); this.$current = carryToContainer; if (!this.$disposing) { this.$PC = 5; } return(true); case 5u: this.$current = Toils_Goto.MoveOffTargetBlueprint(TargetIndex.B); if (!this.$disposing) { this.$PC = 6; } return(true); case 6u: prepare = Toils_General.Wait(base.Duration, TargetIndex.B); prepare.WithProgressBarToilDelay(TargetIndex.B, false, -0.5f); this.$current = prepare; if (!this.$disposing) { this.$PC = 7; } return(true); case 7u: this.$current = Toils_Construct.MakeSolidThingFromBlueprintIfNecessary(TargetIndex.B, TargetIndex.C); if (!this.$disposing) { this.$PC = 8; } return(true); case 8u: this.$current = Toils_Haul.DepositHauledThingInContainer(TargetIndex.B, TargetIndex.C); if (!this.$disposing) { this.$PC = 9; } return(true); case 9u: this.$current = Toils_Haul.JumpToCarryToNextContainerIfPossible(carryToContainer, TargetIndex.C); if (!this.$disposing) { this.$PC = 10; } return(true); case 10u: this.$PC = -1; break; } return(false); }
public static bool TryFindBestBetterNonSlotGroupStorageFor(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction, out IHaulDestination haulDestination, bool acceptSamePriority = false) { List <IHaulDestination> allHaulDestinationsListInPriorityOrder = map.haulDestinationManager.AllHaulDestinationsListInPriorityOrder; IntVec3 intVec = (t.SpawnedOrAnyParentSpawned ? t.PositionHeld : carrier.PositionHeld); float num = float.MaxValue; StoragePriority storagePriority = StoragePriority.Unstored; haulDestination = null; for (int i = 0; i < allHaulDestinationsListInPriorityOrder.Count; i++) { if (allHaulDestinationsListInPriorityOrder[i] is ISlotGroupParent) { continue; } StoragePriority priority = allHaulDestinationsListInPriorityOrder[i].GetStoreSettings().Priority; if ((int)priority < (int)storagePriority || (acceptSamePriority && (int)priority < (int)currentPriority) || (!acceptSamePriority && (int)priority <= (int)currentPriority)) { break; } float num2 = intVec.DistanceToSquared(allHaulDestinationsListInPriorityOrder[i].Position); if (num2 > num || !allHaulDestinationsListInPriorityOrder[i].Accepts(t)) { continue; } Thing thing = allHaulDestinationsListInPriorityOrder[i] as Thing; if (thing != null && thing.Faction != faction) { continue; } if (thing != null) { if (carrier != null) { if (thing.IsForbidden(carrier)) { continue; } } else if (faction != null && thing.IsForbidden(faction)) { continue; } } if (thing != null) { if (carrier != null) { if (!carrier.CanReserveNew(thing)) { continue; } } else if (faction != null && map.reservationManager.IsReservedByAnyoneOf(thing, faction)) { continue; } } if (carrier != null) { if (thing != null) { if (!carrier.Map.reachability.CanReach(intVec, thing, PathEndMode.ClosestTouch, TraverseParms.For(carrier))) { continue; } } else if (!carrier.Map.reachability.CanReach(intVec, allHaulDestinationsListInPriorityOrder[i].Position, PathEndMode.ClosestTouch, TraverseParms.For(carrier))) { continue; } } num = num2; storagePriority = priority; haulDestination = allHaulDestinationsListInPriorityOrder[i]; } return(haulDestination != 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); }
public static bool TryFindBestBetterNonSlotGroupStorageFor(Thing t, Pawn carrier, Map map, StoragePriority currentPriority, Faction faction, out IHaulDestination haulDestination) { List <IHaulDestination> allHaulDestinationsListInPriorityOrder = map.haulDestinationManager.AllHaulDestinationsListInPriorityOrder; IntVec3 intVec = (!t.SpawnedOrAnyParentSpawned) ? carrier.PositionHeld : t.PositionHeld; float num = 3.40282347E+38f; StoragePriority storagePriority = StoragePriority.Unstored; haulDestination = null; for (int i = 0; i < allHaulDestinationsListInPriorityOrder.Count; i++) { if (!(allHaulDestinationsListInPriorityOrder[i] is ISlotGroupParent)) { StoragePriority priority = allHaulDestinationsListInPriorityOrder[i].GetStoreSettings().Priority; if (priority < storagePriority || priority <= currentPriority) { break; } float num2 = (float)intVec.DistanceToSquared(allHaulDestinationsListInPriorityOrder[i].Position); if (num2 <= num) { if (allHaulDestinationsListInPriorityOrder[i].Accepts(t)) { Thing thing = allHaulDestinationsListInPriorityOrder[i] as Thing; if (thing == null || thing.Faction == faction) { if (thing != null) { if (carrier != null) { if (thing.IsForbidden(carrier)) { goto IL_1F3; } } else if (faction != null && thing.IsForbidden(faction)) { goto IL_1F3; } } if (thing != null) { if (carrier != null) { if (!carrier.CanReserveNew(thing)) { goto IL_1F3; } } else if (faction != null && map.reservationManager.IsReservedByAnyoneOf(thing, faction)) { goto IL_1F3; } } if (carrier != null) { if (thing != null) { if (!carrier.Map.reachability.CanReach(intVec, thing, PathEndMode.ClosestTouch, TraverseParms.For(carrier, Danger.Deadly, TraverseMode.ByPawn, false))) { goto IL_1F3; } } else if (!carrier.Map.reachability.CanReach(intVec, allHaulDestinationsListInPriorityOrder[i].Position, PathEndMode.ClosestTouch, TraverseParms.For(carrier, Danger.Deadly, TraverseMode.ByPawn, false))) { goto IL_1F3; } } num = num2; storagePriority = priority; haulDestination = allHaulDestinationsListInPriorityOrder[i]; } } } } IL_1F3 :; } return(haulDestination != null); }
public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) { if (this.Destroyed) { Log.Error("Tried to despawn " + this.ToStringSafe <Thing>() + " which is already destroyed.", false); return; } if (!this.Spawned) { Log.Error("Tried to despawn " + this.ToStringSafe <Thing>() + " which is not spawned.", false); return; } Map map = this.Map; RegionListersUpdater.DeregisterInRegions(this, map); map.spawnedThings.Remove(this); map.listerThings.Remove(this); map.thingGrid.Deregister(this, false); map.coverGrid.DeRegister(this); if (this.def.receivesSignals) { Find.SignalManager.DeregisterReceiver(this); } map.tooltipGiverList.Notify_ThingDespawned(this); if (this.def.graphicData != null && this.def.graphicData.Linked) { map.linkGrid.Notify_LinkerCreatedOrDestroyed(this); map.mapDrawer.MapMeshDirty(this.Position, MapMeshFlag.Things, true, false); } Find.Selector.Deselect(this); this.DirtyMapMesh(map); if (this.def.drawerType != DrawerType.MapMeshOnly) { map.dynamicDrawManager.DeRegisterDrawable(this); } Region validRegionAt_NoRebuild = map.regionGrid.GetValidRegionAt_NoRebuild(this.Position); Room room = (validRegionAt_NoRebuild != null) ? validRegionAt_NoRebuild.Room : null; if (room != null) { room.Notify_ContainedThingSpawnedOrDespawned(this); } if (this.def.AffectsRegions) { map.regionDirtyer.Notify_ThingAffectingRegionsDespawned(this); } if (this.def.pathCost != 0 || this.def.passability == Traversability.Impassable) { map.pathGrid.RecalculatePerceivedPathCostUnderThing(this); } if (this.def.AffectsReachability) { map.reachability.ClearCache(); } Find.TickManager.DeRegisterAllTickabilityFor(this); this.mapIndexOrState = -1; if (this.def.category == ThingCategory.Item) { map.listerHaulables.Notify_DeSpawned(this); map.listerMergeables.Notify_DeSpawned(this); } map.attackTargetsCache.Notify_ThingDespawned(this); map.physicalInteractionReservationManager.ReleaseAllForTarget(this); StealAIDebugDrawer.Notify_ThingChanged(this); IHaulDestination haulDestination = this as IHaulDestination; if (haulDestination != null) { map.haulDestinationManager.RemoveHaulDestination(haulDestination); } if (this is IThingHolder && Find.ColonistBar != null) { Find.ColonistBar.MarkColonistsDirty(); } if (this.def.category == ThingCategory.Item) { SlotGroup slotGroup = this.Position.GetSlotGroup(map); if (slotGroup != null && slotGroup.parent != null) { slotGroup.parent.Notify_LostThing(this); } } }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { if (Destroyed) { Log.Error(string.Concat("Spawning destroyed thing ", this, " at ", Position, ". Correcting.")); mapIndexOrState = -1; if (HitPoints <= 0 && def.useHitPoints) { HitPoints = 1; } } if (Spawned) { Log.Error(string.Concat("Tried to spawn already-spawned thing ", this, " at ", Position)); return; } int num = Find.Maps.IndexOf(map); if (num < 0) { Log.Error(string.Concat("Tried to spawn thing ", this, ", but the map provided does not exist.")); return; } if (stackCount > def.stackLimit) { Log.Error(string.Concat("Spawned ", this, " with stackCount ", stackCount, " but stackLimit is ", def.stackLimit, ". Truncating.")); stackCount = def.stackLimit; } mapIndexOrState = (sbyte)num; RegionListersUpdater.RegisterInRegions(this, map); if (!map.spawnedThings.TryAdd(this, canMergeWithExistingStacks: false)) { Log.Error(string.Concat("Couldn't add thing ", this, " to spawned things.")); } map.listerThings.Add(this); map.thingGrid.Register(this); if (Find.TickManager != null) { Find.TickManager.RegisterAllTickabilityFor(this); } DirtyMapMesh(map); if (def.drawerType != DrawerType.MapMeshOnly) { map.dynamicDrawManager.RegisterDrawable(this); } map.tooltipGiverList.Notify_ThingSpawned(this); if (def.graphicData != null && def.graphicData.Linked) { map.linkGrid.Notify_LinkerCreatedOrDestroyed(this); map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Things, regenAdjacentCells: true, regenAdjacentSections: false); } if (!def.CanOverlapZones) { map.zoneManager.Notify_NoZoneOverlapThingSpawned(this); } if (def.AffectsRegions) { map.regionDirtyer.Notify_ThingAffectingRegionsSpawned(this); } if (def.pathCost != 0 || def.passability == Traversability.Impassable) { map.pathGrid.RecalculatePerceivedPathCostUnderThing(this); } if (def.AffectsReachability) { map.reachability.ClearCache(); } map.coverGrid.Register(this); if (def.category == ThingCategory.Item) { map.listerHaulables.Notify_Spawned(this); map.listerMergeables.Notify_Spawned(this); } map.attackTargetsCache.Notify_ThingSpawned(this); (map.regionGrid.GetValidRegionAt_NoRebuild(Position)?.Room)?.Notify_ContainedThingSpawnedOrDespawned(this); StealAIDebugDrawer.Notify_ThingChanged(this); IHaulDestination haulDestination = this as IHaulDestination; if (haulDestination != null) { map.haulDestinationManager.AddHaulDestination(haulDestination); } if (this is IThingHolder && Find.ColonistBar != null) { Find.ColonistBar.MarkColonistsDirty(); } if (def.category == ThingCategory.Item) { SlotGroup slotGroup = Position.GetSlotGroup(map); if (slotGroup != null && slotGroup.parent != null) { slotGroup.parent.Notify_ReceivedThing(this); } } if (def.receivesSignals) { Find.SignalManager.RegisterReceiver(this); } if (!respawningAfterLoad) { QuestUtility.SendQuestTargetSignals(questTags, "Spawned", this.Named("SUBJECT")); } }
public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) { if (Destroyed) { Log.Error("Tried to despawn " + this.ToStringSafe() + " which is already destroyed."); return; } if (!Spawned) { Log.Error("Tried to despawn " + this.ToStringSafe() + " which is not spawned."); return; } Map map = Map; RegionListersUpdater.DeregisterInRegions(this, map); map.spawnedThings.Remove(this); map.listerThings.Remove(this); map.thingGrid.Deregister(this); map.coverGrid.DeRegister(this); if (def.receivesSignals) { Find.SignalManager.DeregisterReceiver(this); } map.tooltipGiverList.Notify_ThingDespawned(this); if (def.graphicData != null && def.graphicData.Linked) { map.linkGrid.Notify_LinkerCreatedOrDestroyed(this); map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Things, regenAdjacentCells: true, regenAdjacentSections: false); } if (Find.Selector.IsSelected(this)) { Find.Selector.Deselect(this); Find.MainButtonsRoot.tabs.Notify_SelectedObjectDespawned(); } DirtyMapMesh(map); if (def.drawerType != DrawerType.MapMeshOnly) { map.dynamicDrawManager.DeRegisterDrawable(this); } (map.regionGrid.GetValidRegionAt_NoRebuild(Position)?.Room)?.Notify_ContainedThingSpawnedOrDespawned(this); if (def.AffectsRegions) { map.regionDirtyer.Notify_ThingAffectingRegionsDespawned(this); } if (def.pathCost != 0 || def.passability == Traversability.Impassable) { map.pathGrid.RecalculatePerceivedPathCostUnderThing(this); } if (def.AffectsReachability) { map.reachability.ClearCache(); } Find.TickManager.DeRegisterAllTickabilityFor(this); mapIndexOrState = -1; if (def.category == ThingCategory.Item) { map.listerHaulables.Notify_DeSpawned(this); map.listerMergeables.Notify_DeSpawned(this); } map.attackTargetsCache.Notify_ThingDespawned(this); map.physicalInteractionReservationManager.ReleaseAllForTarget(this); StealAIDebugDrawer.Notify_ThingChanged(this); IHaulDestination haulDestination = this as IHaulDestination; if (haulDestination != null) { map.haulDestinationManager.RemoveHaulDestination(haulDestination); } if (this is IThingHolder && Find.ColonistBar != null) { Find.ColonistBar.MarkColonistsDirty(); } if (def.category == ThingCategory.Item) { SlotGroup slotGroup = Position.GetSlotGroup(map); if (slotGroup != null && slotGroup.parent != null) { slotGroup.parent.Notify_LostThing(this); } } QuestUtility.SendQuestTargetSignals(questTags, "Despawned", this.Named("SUBJECT")); }
public static bool IsInValidStorage(this Thing t) { IHaulDestination haulDestination = StoreUtility.CurrentHaulDestinationOf(t); return(haulDestination != null && haulDestination.Accepts(t)); }