//If cell to checked for storage blockers is a shelf, return enhanced stackLimits static int TransformStacklimitIfCellIsAShelf(int stackLimit, Thing thing, IntVec3 cell) { Map map = thing.MapHeld; if (map == null) //Is occasionally called on newly created items before they get a map ... { return(stackLimit); } return(cell.GetShelf(map)?.GetStackLimit(thing, cell) ?? stackLimit); }
static public void AddReservationActionsIfOnlySingleItem(IntVec3 cell, Map map, List<FloatMenuOption> opts) { var shelf = cell.GetShelf(map); if(shelf == null) return; var itemsAtCell = cell.GetThingList(map).Where(thing => thing.def.category == ThingCategory.Item).ToList(); if(itemsAtCell.Count == 1) { var item = itemsAtCell[0]; ThingDef reservedItem = shelf.GetReservationAt(cell); if(reservedItem == null) opts.Add(new FloatMenuOption("AS.AddReservation.FloatOption".Translate(item.def.LabelCap) , () => shelf.AddReservation(item))); else if(reservedItem == item.def) opts.Add(new FloatMenuOption("AS.RemoveReservation.FloatOption".Translate(item.def.LabelCap) , () => shelf.RemoveReservation(item))); else opts.Add(new FloatMenuOption("AS.AddReservation.AlreadyReserved.FloatOption".Translate(item.def.LabelCap, reservedItem.LabelCap), null)); } }
//Have the map, might as well save the lookup ... public static int TransformStacklimitIfDestIsShelf(int stackLimit, Thing thing, IntVec3 cell, Map map) { return(cell.GetShelf(map)?.GetStackLimit(thing, cell) ?? stackLimit); }