static Job TryHaulStage(Pawn pawn, IntVec3 jobCell, ProximityCheck proximityCheck) { foreach (var thing in pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling()) { if (thingProximityStage.TryGetValue(thing, out var proximityStage) && proximityStage == ProximityStage.Fail) { continue; } var newProximityStage = CanHaul(proximityStage, pawn, thing, jobCell, proximityCheck, out var storeCell); // Debug.WriteLine($"{pawn} for {thing} proximity stage: {proximityStage} -> {newProximityStage}"); thingProximityStage.SetOrAdd(thing, newProximityStage); if (newProximityStage != ProximityStage.Success) { continue; } #if RELEASE if (DebugViewSettings.drawOpportunisticJobs) { #endif pawn.Map.debugDrawer.FlashLine(pawn.Position, jobCell, 600, SimpleColor.Red); pawn.Map.debugDrawer.FlashLine(pawn.Position, thing.Position, 600, SimpleColor.Green); pawn.Map.debugDrawer.FlashLine(thing.Position, storeCell, 600, SimpleColor.Green); pawn.Map.debugDrawer.FlashLine(storeCell, jobCell, 600, SimpleColor.Green); #if RELEASE } #endif var haulTracker = HaulTracker.CreateAndAdd(SpecialHaulType.Opportunity, pawn, jobCell); return(PuahJob(haulTracker, pawn, thing, storeCell) ?? HaulAIUtility.HaulToCellStorageJob(pawn, thing, storeCell, false)); } return(null); }
static Job PuahJob(HaulTracker haulTracker, Pawn pawn, Thing thing, IntVec3 storeCell) { if (!havePuah || !haulToInventory.Value || !enabled.Value) { return(null); } haulTracker.Add(thing, storeCell); return((Job)PuahJobOnThing.Invoke(puahWorkGiver, new object[] { pawn, thing, false })); }
// "Optimize hauling" public static Job HaulBeforeCarry(Pawn pawn, IntVec3 destCell, Thing thing) { if (thing.ParentHolder is Pawn_InventoryTracker) { return(null); } if (!JooStoreUtility.TryFindBestBetterStoreCellFor_ClosestToDestCell( thing, destCell, pawn, pawn.Map, StoreUtility.CurrentStoragePriorityOf(thing), pawn.Faction, out var storeCell, true)) { return(null); } var supplyFromHereDist = thing.Position.DistanceTo(destCell); var supplyFromStoreDist = storeCell.DistanceTo(destCell); // Debug.WriteLine($"Carry from here: {supplyFromHereDist}; carry from store: {supplyFromStoreDist}"); // [KV] Infinite Storage https://steamcommunity.com/sharedfiles/filedetails/?id=1233893175 // infinite storage has an interaction spot 1 tile away from itself if (supplyFromStoreDist + 1 < supplyFromHereDist) { // Debug.WriteLine( // $"'{pawn}' prefixed job with haul for '{thing.Label}' because '{storeCell.GetSlotGroup(pawn.Map)}' is closer to original destination '{destCell}'."); #if RELEASE if (DebugViewSettings.drawOpportunisticJobs) { #endif pawn.Map.debugDrawer.FlashLine(pawn.Position, thing.Position, 600, SimpleColor.White); // unchanged pawn.Map.debugDrawer.FlashLine(thing.Position, destCell, 600, SimpleColor.Magenta); pawn.Map.debugDrawer.FlashLine(thing.Position, storeCell, 600, SimpleColor.Cyan); pawn.Map.debugDrawer.FlashLine(storeCell, destCell, 600, SimpleColor.Cyan); #if RELEASE } #endif var haulTracker = HaulTracker.CreateAndAdd(SpecialHaulType.HaulBeforeCarry, pawn, destCell); return(PuahJob(haulTracker, pawn, thing, storeCell) ?? HaulAIUtility.HaulToCellStorageJob(pawn, thing, storeCell, false)); } return(null); }
static void AddFirstRegularHaulToTracker(WorkGiver_Scanner __instance, bool __state, Job __result, Pawn pawn, Thing thing) { // restore storage priority if (__state) { StoreUtility.CurrentHaulDestinationOf(thing).GetStoreSettings().Priority += 1; } if (__result == null) { return; } if (!haulToInventory.Value || !enabled.Value) { return; } // JobOnThing() can run additional times (e.g. haulMoreWork toil) so don't assume this is already added if there's a jobCell or destCell var haulTracker = haulTrackers.GetValueSafe(pawn) ?? HaulTracker.CreateAndAdd(SpecialHaulType.None, pawn, IntVec3.Invalid); // thing from parameter because targetA is null because things are in queues instead // https://github.com/Mehni/PickUpAndHaul/blob/af50a05a8ae5ca64d9b95fee8f593cf91f13be3d/Source/PickUpAndHaul/WorkGiver_HaulToInventory.cs#L98 haulTracker.Add(thing, __result.targetB.Cell, false); }