public static void Postfix(ref Rect rect) { ITab_Storage tab = ITab_StorageFillTabsPatcher.currentTab; if (tab == null) { return; } IStoreSettingsParent storeSettingsParent = (IStoreSettingsParent)typeof(ITab_Storage).GetProperty("SelStoreSettingsParent", BindingFlags.NonPublic | BindingFlags.Instance).GetGetMethod(true).Invoke(tab, new object[0]); StorageSettings settings = storeSettingsParent.GetStoreSettings(); int limit = Limits.GetLimit(settings); bool hasLimit = limit != -1; Widgets.CheckboxLabeled(new Rect(rect.xMin, rect.yMin - 24f - 3f - 32f, rect.width / 2, 24f), "Total stack limit", ref hasLimit); if (hasLimit) { if (oldSettings != settings) { buffer = limit.ToString(); } Widgets.TextFieldNumeric <int>(new Rect(rect.xMin + (rect.width / 2) + 60f, rect.yMin - 24f - 3f - 32f, rect.width / 2 - 60f, 24f), ref limit, ref buffer, 0, max); } Limits.SetLimit(settings, hasLimit ? limit : -1); oldSettings = settings; }
public static void Postfix(StorageSettings __instance) { if (Scribe.mode == LoadSaveMode.Saving) { Scribe.saver.WriteElement("stacklimit", Limits.GetLimit(__instance).ToString()); } else if (Scribe.mode == LoadSaveMode.LoadingVars) { Limits.SetLimit(__instance, ScribeExtractor.ValueFromNode(Scribe.loader.curXmlParent["stacklimit"], -1)); } }
public static void Prefix(Thing t, Pawn carrier, Map map, ref StoragePriority currentPriority, Faction faction) { var slotGroup0 = t.GetSlotGroup(); if (slotGroup0 != null && Limits.HasLimit(slotGroup0.Settings)) { int stockpileMax = Limits.GetLimit(slotGroup0.Settings); if (slotGroup0.TotalPrecalculatedItemsStack(false) > stockpileMax) { currentPriority = StoragePriority.Unstored; } } }
public static void Postfix(ref List <IHaulDestination> __result) { int HeldItems(IHaulDestination x) => StoreUtility.GetSlotGroup(x.Position, x.Map).TotalPrecalculatedItemsStack(); __result = __result.Where(x => { if (!Limits.HasLimit(x.GetStoreSettings())) { return(true); } int limit = Limits.GetLimit(x.GetStoreSettings()); if (limit < 0) { limit = int.MaxValue; } return(HeldItems(x) < limit); }) .OrderByDescending(x => x.GetStoreSettings().Priority) .ThenByDescending(x => { if (!Limits.HasLimit(x.GetStoreSettings())) { return(0); } int limit = Limits.GetLimit(x.GetStoreSettings()); if (limit < 0) { limit = int.MaxValue; } return(limit - HeldItems(x)); }) /*.ThenByDescending(x => * { * int limit = Limits.GetLimit(x.GetStoreSettings()); * if (limit < 0) * return int.MaxValue; * else * { * int heldItems = HeldItems(x); * int spaceLeft = limit - heldItems; * return spaceLeft; * } * })*/ .ToList(); }
public static void Postfix(ref List <SlotGroup> __result) { __result = __result.Where(x => { if (!Limits.HasLimit(x.Settings)) { return(true); } int limit = Limits.GetLimit(x.Settings); if (limit < 0) { limit = int.MaxValue; } return(x.TotalPrecalculatedItemsStack() < limit); }) .OrderByDescending(x => x.Settings.Priority) .ThenByDescending(x => { if (!Limits.HasLimit(x.Settings)) { return(0); } int limit = Limits.GetLimit(x.Settings); if (limit < 0) { limit = int.MaxValue; } return(limit - x.TotalPrecalculatedItemsStack()); }) /*.ThenByDescending(x => * { * int limit = Limits.GetLimit(x.Settings); * if (limit < 0) * return int.MaxValue; * else * { * int heldItems = x.TotalItemsStack(); * int spaceLeft = limit - heldItems; * return spaceLeft; * } * })*/ .ToList(); }
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); }
public static void Postfix(StorageSettings s) { clipboardLimit = Limits.GetLimit(s); }
public static void Postfix(StorageSettings __instance) { Scribe_Values.Look <int>(ref Limits.GetLimit(__instance), "stacklimit", -1, false); }
public static void SetCountLimit(Pawn p, Thing t, ref Job __result, IntVec3 storeCell) { SlotGroup toSlotGroup = p.Map.haulDestinationManager.SlotGroupAt(storeCell); // ?? __result.targetB.Thing?.GetSlotGroup(); if (toSlotGroup == null) { //It is a haul destination without a SlotGroup, e.g. a grave return; } int toLimit = Limits.GetLimit(toSlotGroup.Settings); //int currentStack = __result.count < 0 ? t.stackCount : __result.count; int stackCount = __result.targetA.Thing.stackCount; if (stackCount < 1) { stackCount = int.MaxValue; } int currentStack = Math.Min(__result.count, stackCount); currentStack = Math.Min(currentStack, p.carryTracker.AvailableStackSpace(__result.targetA.Thing.def)); bool hasSetFirstLimit = false; SlotGroup fromSlotGroup = StoreUtility.GetSlotGroup(t.Position, t.Map); if (fromSlotGroup != null) { int fromLimit = Limits.GetLimit(fromSlotGroup.Settings); if (fromLimit > 0 && StoreUtility.CurrentStoragePriorityOf(t) > StoreUtility.StoragePriorityAtFor(storeCell, t)) { //Hauling from limited high priority to low priority. Only haul the minimum necessary to go to exact limit. int stockpileStack1 = fromSlotGroup.TotalPrecalculatedItemsStack(); __result.count = stockpileStack1 - fromLimit; hasSetFirstLimit = true; } } if (toLimit < 0) { return; } int stockpileStack = toSlotGroup.TotalPrecalculatedItemsStack(); if (stockpileStack >= toLimit) { //Say no spot availible JobFailReason.Is(GetNoEmptyPlaceLowerTransString(), null); __result = null; } else if (stockpileStack + currentStack > toLimit) //It will go over the limit { int newLimit = toLimit - stockpileStack; __result.count = hasSetFirstLimit ? Math.Min(newLimit, __result.count < 0 ? int.MaxValue : __result.count) : newLimit; } if (__result != null && __result.count <= 0) { JobFailReason.Is(GetNoEmptyPlaceLowerTransString(), null); __result = null; } }