From eefc44b23bafbcd1f0e1daac52fe5440424ace78 Mon Sep 17 00:00:00 2001 From: Alex Tearse-Doyle Date: Thu, 25 Oct 2018 00:53:41 -0700 Subject: [PATCH 1/4] Following up the project folder change with making sure it builds to the correct spot --- Source/PickUpAndHaul/PickUpAndHaul.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/PickUpAndHaul/PickUpAndHaul.csproj b/Source/PickUpAndHaul/PickUpAndHaul.csproj index 634a810..359e575 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,7 @@ ..\..\..\..\..\..\..\..\..\..\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 @@ -45,7 +45,7 @@ - ..\..\..\..\..\..\..\..\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 From 74fd63182a0821c15a63d85b4307963d6c25379e Mon Sep 17 00:00:00 2001 From: Alex Tearse-Doyle Date: Thu, 25 Oct 2018 01:41:00 -0700 Subject: [PATCH 2/4] adding simple "Extended Storage" to compatibility check --- Source/PickUpAndHaul/ModCompatibilityCheck.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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")); } } From 28bd9323156d8f9eaeeb6431a5a3788f490f6996 Mon Sep 17 00:00:00 2001 From: Alex Tearse-Doyle Date: Thu, 25 Oct 2018 02:19:06 -0700 Subject: [PATCH 3/4] The Queued WorkGiver supports Extended Storage cell capacities --- .../PickUpAndHaul/ExtendedStorage_Support.cs | 50 +++++++++++++++++++ Source/PickUpAndHaul/PickUpAndHaul.csproj | 5 ++ .../WorkGiver_HaulToInventory.cs | 3 ++ 3 files changed, 58 insertions(+) create mode 100644 Source/PickUpAndHaul/ExtendedStorage_Support.cs 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/PickUpAndHaul.csproj b/Source/PickUpAndHaul/PickUpAndHaul.csproj index 359e575..8c2bbf5 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul.csproj +++ b/Source/PickUpAndHaul/PickUpAndHaul.csproj @@ -38,6 +38,10 @@ ..\..\..\..\..\..\..\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 + @@ -52,6 +56,7 @@ + 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); From be98072925ddbc003fe39e55bace109fdf19d88f Mon Sep 17 00:00:00 2001 From: Alex Tearse-Doyle Date: Thu, 25 Oct 2018 17:51:27 -0700 Subject: [PATCH 4/4] After Hauling the Queue to Inventory, do another local search for more haulables (e.g. someone else harvested more crops while he was picking up crops) Once inventory is full, Carrying items in hand is already handled by HaulToStorageJob --- .../JobDriver_HaulToInventory.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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