diff --git a/Source/PickUpAndHaul/ExtendedStorage_Support.cs b/Source/PickUpAndHaul/ExtendedStorage_Support.cs new file mode 100644 index 0000000..24900cb --- /dev/null +++ b/Source/PickUpAndHaul/ExtendedStorage_Support.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Verse; +using RimWorld; +using UnityEngine; + +namespace PickUpAndHaul +{ + class ExtendedStorage_Support + { + public static bool CapacityAt(ThingDef def, IntVec3 storeCell, Map map, out int capacity) + { + if (ModCompatibilityCheck.ExtendedStorageIsActive) + { + try + { + return CapacityAtEx(def, storeCell, map, out capacity); + } + catch (Exception e) + { + Verse.Log.Warning($"Pick Up And Haul tried to get Extended Storage capacity but it failed: {e}"); + } + } + capacity = 0; + return false; + } + + public static bool CapacityAtEx(ThingDef def, IntVec3 storeCell, Map map, out int capacity) + { + foreach (Thing thing in storeCell.GetThingList(map)) + { + //thing.Position seems to be the input cell, which can just be handled normally + if (thing.Position == storeCell) continue; + + ExtendedStorage.Building_ExtendedStorage storage = thing as ExtendedStorage.Building_ExtendedStorage; + + if(storage.StoredThingTotal == 0) + capacity = (int)(def.stackLimit * storage.GetStatValue(ExtendedStorage.DefReferences.Stat_ES_StorageFactor)); + else + capacity = storage.ApparentMaxStorage - storage.StoredThingTotal; + Log.Message($"AT {storeCell} ES: {capacity} = {storage.ApparentMaxStorage} - {storage.StoredThingTotal}"); + return true; + } + capacity = 0; + return false; + } + } +} diff --git a/Source/PickUpAndHaul/JobDriver_HaulToInventory.cs b/Source/PickUpAndHaul/JobDriver_HaulToInventory.cs index 7d6000b..aa7cfdc 100644 --- a/Source/PickUpAndHaul/JobDriver_HaulToInventory.cs +++ b/Source/PickUpAndHaul/JobDriver_HaulToInventory.cs @@ -104,6 +104,34 @@ protected override IEnumerable MakeNewToils() yield return takeThing; yield return Toils_Jump.JumpIf(nextTarget, () => !job.targetQueueA.NullOrEmpty()); + //Find more to haul, in case things spawned while this was in progess + yield return new Toil() + { + initAction = () => + { + Pawn actor = pawn; + Job curJob = actor.jobs.curJob; + LocalTargetInfo storeCell = curJob.targetB; + + List haulables = actor.Map.listerHaulables.ThingsPotentiallyNeedingHauling(); + WorkGiver_HaulToInventory haulMoreWork = actor.workSettings.WorkGiversInOrderNormal.First(wg => wg is WorkGiver_HaulToInventory) as WorkGiver_HaulToInventory; + Thing haulMoreThing = GenClosest.ClosestThing_Global(actor.Position, haulables, 12, t => haulMoreWork.HasJobOnThing(actor, t, false)); + + //WorkGiver_HaulToInventory found more work nearby + if (haulMoreThing != null) + { + Log.Message($"{actor} hauling again : {haulMoreThing}"); + Job haulMoreJob = haulMoreWork.JobOnThing(actor, haulMoreThing); + + if (haulMoreJob.TryMakePreToilReservations(actor, false)) + { + actor.jobs.jobQueue.EnqueueFirst(haulMoreJob, new JobTag?(JobTag.Misc)); + this.EndJobWith(JobCondition.Succeeded); + } + } + } + }; + //maintain cell reservations on the trip back //TODO: do that when we carry things //I guess that means TODO: implement carrying the rest of the items in this job instead of falling back on HaulToStorageJob diff --git a/Source/PickUpAndHaul/ModCompatibilityCheck.cs b/Source/PickUpAndHaul/ModCompatibilityCheck.cs index d5e1230..90be73d 100644 --- a/Source/PickUpAndHaul/ModCompatibilityCheck.cs +++ b/Source/PickUpAndHaul/ModCompatibilityCheck.cs @@ -30,7 +30,9 @@ public static bool ExtendedStorageIsActive { get { - return (ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == "ExtendedStorageFluffyHarmonised") || ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == "Core SK")); + return (ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == "ExtendedStorageFluffyHarmonised") + || ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == "Extended Storage") + || ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == "Core SK")); } } diff --git a/Source/PickUpAndHaul/PickUpAndHaul.csproj b/Source/PickUpAndHaul/PickUpAndHaul.csproj index 634a810..8c2bbf5 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul.csproj +++ b/Source/PickUpAndHaul/PickUpAndHaul.csproj @@ -16,7 +16,7 @@ false none true - ..\..\..\Assemblies\ + ..\..\Assemblies\ DEBUG;TRACE prompt 4 @@ -24,7 +24,7 @@ none true - ..\..\..\Assemblies\ + ..\..\Assemblies\ TRACE prompt 4 @@ -35,7 +35,11 @@ ..\..\..\..\..\..\..\..\..\..\Users\Maniak\Documents\RimWorld Mods\0Harmony.dll - ..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll + False + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\workshop\content\294100\731732064\Assemblies\ExtendedStorage.dll False @@ -45,13 +49,14 @@ - ..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll False + diff --git a/Source/PickUpAndHaul/WorkGiver_HaulToInventory.cs b/Source/PickUpAndHaul/WorkGiver_HaulToInventory.cs index afebaab..042cd0f 100644 --- a/Source/PickUpAndHaul/WorkGiver_HaulToInventory.cs +++ b/Source/PickUpAndHaul/WorkGiver_HaulToInventory.cs @@ -218,6 +218,9 @@ public CellAllocation(Thing a, int c) public static int CapacityAt(ThingDef def, IntVec3 storeCell, Map map) { + if (ExtendedStorage_Support.CapacityAt(def, storeCell, map, out int cap)) + return cap; + int capacity = def.stackLimit; Thing preExistingThing = map.thingGrid.ThingAt(storeCell, def);