// duplicated to make changes (added container support) public Job HaulMaxNumToCellJob(Pawn hauler, Thing haulable, IntVec3 storeCell, bool fitInStoreCell) { Job job = new Job(JobDefOf.HaulToCell, haulable, storeCell); job.maxNumToCarry = 0; if (Find.SlotGroupManager.SlotGroupAt(storeCell) != null) { // container code part // list of things on potential cell with container List <Thing> list = Find.ThingGrid.ThingsListAt(storeCell); if (list.Exists(storage => storage.def.thingClass == typeof(Building_Storage) && storage.TryGetComp <CompContainer>() != null)) { CompContainer container = list.Find(thing => thing.def.thingClass == typeof(Building_Storage) && thing.TryGetComp <CompContainer>() != null).TryGetComp <CompContainer>(); // if container has free slot if (container.itemsCount < container.compProps.itemsCap) { // haul maximum possible, excess will be stored in new slot job.maxNumToCarry = haulable.def.stackLimit; } // all slots occupied, find incomplete stacks else { foreach (Thing item in container.itemsList) { // same thing type in container found if (item.def == haulable.def) { // and it's stack is not full if (item.stackCount < item.def.stackLimit) { // carry what's left job.maxNumToCarry = item.def.stackLimit - item.stackCount; } } } } } // vanilla code part else { Thing thing = Find.ThingGrid.ThingAt(storeCell, haulable.def); if (thing != null) { job.maxNumToCarry = haulable.def.stackLimit; if (fitInStoreCell) { job.maxNumToCarry -= thing.stackCount; } } else { job.maxNumToCarry = 99999; } } } // no storage on target cell else { job.maxNumToCarry = 99999; } // check for scattered stacks to pick up too on the move job.haulOpportunisticDuplicates = true; job.haulMode = HaulMode.ToCellStorage; return(job); }
protected override void FillTab() { Building_Storage storage = this.SelThing as Building_Storage; this.container = storage.TryGetComp <CompContainer>(); if (container == null) { Log.Error("No CompContainer included for this Building_Storage"); return; } List <Thing> list = container.itemsList; float fieldHeight = 30.0f; this.size = new Vector2(300f, 55f + container.compProps.itemsCap * fieldHeight); ConceptDatabase.KnowledgeDemonstrated(ConceptDefOf.PrisonerTab, KnowledgeAmount.GuiFrame); Text.Font = GameFont.Small; Rect innerRect = GenUI.ContractedBy(new Rect(0.0f, 0.0f, this.size.x, this.size.y), 10f); float innerRectX = innerRect.x; GUI.BeginGroup(innerRect); { Widgets.TextField(new Rect(0.0f, 0.0f, this.size.x - 40f, fieldHeight), GetTitle()); Rect thingIconRect = new Rect(10f, fieldHeight + 5f, 30f, fieldHeight); Rect thingLabelRect = new Rect(thingIconRect.x + 35f, thingIconRect.y + 5.0f, innerRect.width - 35f, fieldHeight); Rect thingButtonRect = new Rect(thingIconRect.x, thingIconRect.y, innerRect.width, fieldHeight); //float startY = 0.0f; //Widgets.ListSeparator(ref startY, innerRect.width, GetTitle()); foreach (var thing in list) { Widgets.ThingIcon(thingIconRect, thing); Widgets.Label(thingLabelRect, thing.Label); if (Widgets.InvisibleButton(thingButtonRect)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); options.Add(new FloatMenuOption("Container_Info".Translate(), () => { // NOTE ? Find.WindowStack.Add(new Dialog_InfoCard(thing)); })); options.Add(new FloatMenuOption("Container_Drop".Translate(), () => { IntVec3 bestSpot = IntVec3.Invalid; if (JobDriver_HaulToCell.TryFindPlaceSpotNear(storage.Position, thing, out bestSpot)) { thing.Position = bestSpot; } else { Log.Error("No free spot for " + thing); } })); Find.WindowStack.Add(new FloatMenu(options, "", false, false)); } thingIconRect.y += fieldHeight; thingLabelRect.y += fieldHeight; thingButtonRect.y += fieldHeight; } } GUI.EndGroup(); }
// duplicated to make changes (added container support) public static bool NoStorageBlockersIn(IntVec3 targetCell, Thing haulable) { List <Thing> list = Find.ThingGrid.ThingsListAt(targetCell); for (int i = 0; i < list.Count; i++) { Thing currentThing = list[i]; // container code part if (currentThing.def.thingClass == typeof(Building_Storage) && currentThing.TryGetComp <CompContainer>() != null) { CompContainer container = list.Find(thing => thing.def.thingClass == typeof(Building_Storage) && thing.TryGetComp <CompContainer>() != null).TryGetComp <CompContainer>(); // if has free slots, no blocking if (container.itemsCount < container.compProps.itemsCap) { return(true); } // if no slots else { foreach (Thing item in container.itemsList) { // and same thing in container found if (item.def == haulable.def) { // and it's stack is not full if (item.stackCount < item.def.stackLimit) { // no blocking return(true); } } } // and no matches, block return(false); } } // vanilla code part // no incopmlete stacks of the same thing if (currentThing.def.EverStoreable) { if (currentThing.def != haulable.def) { return(false); } if (currentThing.stackCount >= haulable.def.stackLimit) { return(false); } } // placed blueprint not standable if (currentThing.def.entityDefToBuild != null && currentThing.def.entityDefToBuild.passability != Traversability.Standable) { return(false); } // terrain not standable if (currentThing.def.surfaceType == SurfaceType.None && currentThing.def.passability != Traversability.Standable) { return(false); } } return(true); }
protected override void FillTab() { Building_Storage storage = this.SelThing as Building_Storage; this.container = storage.TryGetComp<CompContainer>(); if (container == null) { Log.Error("No CompContainer included for this Building_Storage"); return; } List<Thing> list = container.itemsList; float fieldHeight = 30.0f; this.size = new Vector2(300f, 55f + container.compProps.itemsCap * fieldHeight); ConceptDatabase.KnowledgeDemonstrated(ConceptDefOf.PrisonerTab, KnowledgeAmount.GuiFrame); Text.Font = GameFont.Small; Rect innerRect = GenUI.ContractedBy(new Rect(0.0f, 0.0f, this.size.x, this.size.y), 10f); float innerRectX = innerRect.x; GUI.BeginGroup(innerRect); { Widgets.TextField(new Rect(0.0f, 0.0f, this.size.x - 40f, fieldHeight), GetTitle()); Rect thingIconRect = new Rect(10f, fieldHeight + 5f, 30f, fieldHeight); Rect thingLabelRect = new Rect(thingIconRect.x + 35f, thingIconRect.y + 5.0f, innerRect.width - 35f, fieldHeight); Rect thingButtonRect = new Rect(thingIconRect.x, thingIconRect.y, innerRect.width, fieldHeight); //float startY = 0.0f; //Widgets.ListSeparator(ref startY, innerRect.width, GetTitle()); foreach (var thing in list) { Widgets.ThingIcon(thingIconRect, thing); Widgets.Label(thingLabelRect, thing.Label); if (Widgets.InvisibleButton(thingButtonRect)) { List<FloatMenuOption> options = new List<FloatMenuOption>(); options.Add(new FloatMenuOption("Container_Info".Translate(), () => { // NOTE ? Find.WindowStack.Add(new Dialog_InfoCard(thing)); })); options.Add(new FloatMenuOption("Container_Drop".Translate(), () => { IntVec3 bestSpot = IntVec3.Invalid; if (JobDriver_HaulToCell.TryFindPlaceSpotNear(storage.Position, thing, out bestSpot)) { thing.Position = bestSpot; } else { Log.Error("No free spot for " + thing); } })); Find.WindowStack.Add(new FloatMenu(options, "", false, false)); } thingIconRect.y += fieldHeight; thingLabelRect.y += fieldHeight; thingButtonRect.y += fieldHeight; } } GUI.EndGroup(); }