private static Job HopperFillJob(Pawn pawn, ISlotGroupParent hopperSgp, Thing resource) { Building building = hopperSgp as Building; // Get a sorted list (by distance) of matching resources List <Thing> resources = null; if (resource != null) { resources = Find.Map.listerThings.ThingsOfDef(resource.def) .Where(t => ( (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t)) && (hopperSgp.GetStoreSettings().AllowedToAccept(t)) && (HaulAIUtility.StoragePriorityAtFor(t.Position, t) < hopperSgp.GetSlotGroup().Settings.Priority) )).ToList(); } else { resources = Find.Map.listerThings.AllThings .Where(t => ( (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t)) && (hopperSgp.GetStoreSettings().AllowedToAccept(t)) && (HaulAIUtility.StoragePriorityAtFor(t.Position, t) < hopperSgp.GetSlotGroup().Settings.Priority) )).ToList(); } if (resources.NullOrEmpty()) { return((Job)null); } // Sort by distance (closest first) resources.Sort((Thing x, Thing y) => (Gen.ManhattanDistanceFlat(x.Position, building.Position) < Gen.ManhattanDistanceFlat(y.Position, building.Position)) ? -1 : 1); var grabResource = resources.First(); if (grabResource != null) { // Try to haul the first (closest) resource found var job = HaulAIUtility.HaulMaxNumToCellJob(pawn, grabResource, building.Position, true); if (job != null) { return(job); } } return((Job)null); }
private static Thing HopperGetCurrentResource(IntVec3 position, ISlotGroupParent hopperSgp) { var list = Find.ThingGrid.ThingsListAt(position).Where(t => ( (!HopperDefs.Contains(t.def)) && (hopperSgp.GetStoreSettings().AllowedToAccept(t)) )).ToList(); if (list.NullOrEmpty()) { return((Thing)null); } return(list.First()); }
private static Job HopperFillJob( Pawn pawn, ISlotGroupParent hopperSgp, Thing resource ) { Building building = hopperSgp as Building; // Get a sorted list (by distance) of matching resources List< Thing > resources = null; if( resource != null ) { resources = Find.Map.listerThings.ThingsOfDef( resource.def ) .Where( t => ( ( HaulAIUtility.PawnCanAutomaticallyHaul( pawn, t ) )&& ( hopperSgp.GetStoreSettings().AllowedToAccept( t ) )&& ( HaulAIUtility.StoragePriorityAtFor( t.Position, t ) < hopperSgp.GetSlotGroup().Settings.Priority ) ) ).ToList(); } else { resources = Find.Map.listerThings.AllThings .Where( t => ( ( HaulAIUtility.PawnCanAutomaticallyHaul( pawn, t ) )&& ( hopperSgp.GetStoreSettings().AllowedToAccept( t ) )&& ( HaulAIUtility.StoragePriorityAtFor( t.Position, t ) < hopperSgp.GetSlotGroup().Settings.Priority ) ) ).ToList(); } if( resources.NullOrEmpty() ) { return (Job) null; } // Sort by distance (closest first) resources.Sort( ( Thing x, Thing y ) => ( Gen.ManhattanDistanceFlat( x.Position, building.Position ) < Gen.ManhattanDistanceFlat( y.Position, building.Position ) ) ? -1 : 1 ); var grabResource = resources.First(); if( grabResource != null ) { // Try to haul the first (closest) resource found var job = HaulAIUtility.HaulMaxNumToCellJob( pawn, grabResource, building.Position, true ); if( job != null ) { return job; } } return (Job) null; }
private static Thing HopperGetCurrentResource( IntVec3 position, ISlotGroupParent hopperSgp ) { var list = Find.ThingGrid.ThingsListAt( position ).Where( t => ( ( !HopperDefs.Contains( t.def ) )&& ( hopperSgp.GetStoreSettings().AllowedToAccept( t ) ) ) ).ToList(); if( list.NullOrEmpty() ) { return (Thing) null; } return list.First(); }
public static void Postfix(ref Rect rect) { if (selected == null) { return; } if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.Escape)) { UI.UnfocusCurrentControl(); Event.current.Use(); } var settings = selected.GetStoreSettings(); var limit = settings.GetStacklimit(); Rect drawArea = new Rect(rect.xMin, rect.yMin - 48f - 3f - 90f, rect.width, 24f); drawArea.SplitVertically(70f, out Rect labelArea, out drawArea, 5f); drawArea.SplitVertically(100f, out Rect buttonArea, out drawArea, 5f); Rect inputArea = drawArea.LeftPartPixels(50f); Widgets.Label(labelArea, "Set limit"); TooltipHandler.TipRegion(labelArea, "Set an upper limit for each tile in this stockpile. The limit is strictly in effect for pawns. Pawns will not haul items exceeding the upper limit."); if (limittooltip.ContainsKey(limit)) { TooltipHandler.TipRegion(buttonArea, limittooltip[limit]); } if (Widgets.ButtonText(buttonArea, limitmenu.ContainsKey(limit) ? limitmenu[limit] : otherlimit_text)) { var options = new List <FloatMenuOption>(limitmenu.Select(p => new FloatMenuOption(p.Value, () => settings.SetStacklimitAndNotifyChange(p.Key)))); Find.WindowStack.Add(new FloatMenu(options)); } //if (prev_settings != settings) buffer = null; var new_limit = limit; Widgets.TextFieldNumeric(inputArea, ref new_limit, ref buffer, -1, AdditionalStorageSettings.max_limit); if (new_limit != limit) { settings.SetStacklimitAndNotifyChange(new_limit); } //prev_settings = settings; var refillpercent = settings.GetRefillPercent(); drawArea = new Rect(rect.xMin, rect.yMin - 48f - 3f - 60f, rect.width, 24f); drawArea.SplitVertically(70f, out labelArea, out drawArea, 5f); drawArea.SplitVertically(100f, out buttonArea, out drawArea, 5f); drawArea.SplitVertically(50f, out inputArea, out drawArea, 5f); Widgets.Label(labelArea, "Refill at"); TooltipHandler.TipRegion(labelArea, "Set the refill threshold of *each tile* in this stockpile.This can be considered as the lower limit"); if (refilltooltip.ContainsKey(refillpercent)) { TooltipHandler.TipRegion(buttonArea, refilltooltip[refillpercent]); } if (Widgets.ButtonText(buttonArea, refillmenu.ContainsKey(refillpercent) ? refillmenu[refillpercent] : otherrefill_text)) { var options = new List <FloatMenuOption>(refillmenu.Select(p => new FloatMenuOption(p.Value, () => settings.SetRefillPercent(p.Key)))); Find.WindowStack.Add(new FloatMenu(options)); } buffer = null; var new_refillpercent = refillpercent; Widgets.TextFieldNumeric(inputArea, ref new_refillpercent, ref buffer, 0, 100); if (new_refillpercent != refillpercent) { settings.SetRefillPercent(new_refillpercent); } Widgets.Label(drawArea, "%"); drawArea = new Rect(rect.xMin, rect.yMin - 48f - 3f - 30f, rect.width, 24f); var checkOn = settings.IsRefillingDisabled(); var new_checkOn = checkOn; TooltipHandler.TipRegion(drawArea, "Temporarily disable refilling for all tiles in this stockpile. It is just a handy functionality, not a part of storage settings."); Widgets.CheckboxLabeled(drawArea, "Pause refilling", ref new_checkOn, placeCheckboxNearText: true); if (new_checkOn != checkOn) { if (new_checkOn) { settings.SetRefillingDisabled(); } else { settings.UnsetRefillingDisabled(); } } }