diff --git a/About/About.xml b/About/About.xml index 70f2b46..27395f2 100644 --- a/About/About.xml +++ b/About/About.xml @@ -2,11 +2,11 @@ Pick Up And Haul Mehni - 0.18.0 + 0.19.0 https://ludeon.com/forums/index.php?topic=35832 "Greatest hauling mod ever" - Chicken Plucker - v0.18.2.0 + v.1.0.3 Colonists will gather stuff in their inventory, then haul it all to a stockpile. @@ -19,6 +19,7 @@ Safe to add to existing games. <size=20>Credits and thanks:</size> - erdelf, Zorba, Why_is_that and Dingo for code and advice (yet again!) - Chicken Plucker, for the preview image +- AlexTD, for his direct contributions - Brrainz, for the amazing Harmony library Ludeon: https://ludeon.com/forums/index.php?topic=35832 diff --git a/About/ModSync.xml b/About/ModSync.xml deleted file mode 100644 index 4b1b1d1..0000000 --- a/About/ModSync.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - ad5b17a5-9e12-43ee-8d22-d43dd3140786 - Pick Up and Haul - v0.18.2.0 - false - diff --git a/Assemblies/0Harmony.dll b/Assemblies/0Harmony.dll index 904f049..6c0dd94 100644 Binary files a/Assemblies/0Harmony.dll and b/Assemblies/0Harmony.dll differ diff --git a/Assemblies/PickUpAndHaul.dll b/Assemblies/PickUpAndHaul.dll index 64e8d0d..e5998ad 100644 Binary files a/Assemblies/PickUpAndHaul.dll and b/Assemblies/PickUpAndHaul.dll differ diff --git a/Patches/PickUpAndHaul.xml b/Patches/PickUpAndHaul.xml index cdcc0a0..5ae65d2 100644 --- a/Patches/PickUpAndHaul.xml +++ b/Patches/PickUpAndHaul.xml @@ -2,7 +2,7 @@ - Defs/ThingDef [@Name ="BasePawn"]/comps + Defs/ThingDef[thingClass="Pawn"]/comps
  • PickUpAndHaul.CompHauledToInventory
  • diff --git a/Source/PickUpAndHaul/PickUpAndHaul/CompHauledToInventory.cs b/Source/PickUpAndHaul/PickUpAndHaul/CompHauledToInventory.cs index 48e4d88..25c8a65 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/CompHauledToInventory.cs +++ b/Source/PickUpAndHaul/PickUpAndHaul/CompHauledToInventory.cs @@ -9,7 +9,7 @@ public class CompHauledToInventory : ThingComp public HashSet GetHashSet() { - TakenToInventory.Remove(null); + TakenToInventory.RemoveWhere(x => x == null); return TakenToInventory; } diff --git a/Source/PickUpAndHaul/PickUpAndHaul/HarmonyPatches.cs b/Source/PickUpAndHaul/PickUpAndHaul/HarmonyPatches.cs index 63fa4d1..ff7297a 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/HarmonyPatches.cs +++ b/Source/PickUpAndHaul/PickUpAndHaul/HarmonyPatches.cs @@ -12,11 +12,9 @@ namespace PickUpAndHaul { - [StaticConstructorOnStartup] static class HarmonyPatches { - static HarmonyPatches() { HarmonyInstance harmony = HarmonyInstance.Create("mehni.rimworld.pickupthatcan.main"); @@ -38,14 +36,14 @@ static HarmonyPatches() harmony.Patch(AccessTools.Method(typeof(JobGiver_Idle), "TryGiveJob"), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(IdleJoy_Postfix)), null); - + try { ((Action)(() => { if (ModCompatibilityCheck.AllowToolIsActive) { - harmony.Patch(AccessTools.Method(typeof(AllowTool.WorkGiver_HaulUrgently), "JobOnThing"), + harmony.Patch(AccessTools.Method(typeof(AllowTool.WorkGiver_HaulUrgently), nameof(AllowTool.WorkGiver_HaulUrgently.JobOnThing)), new HarmonyMethod(typeof(HarmonyPatches), nameof(AllowToolHaulUrgentlyJobOnThing_PreFix)), null, null); } }))(); @@ -66,10 +64,9 @@ static HarmonyPatches() } catch (TypeLoadException) { } - Log.Message("PickUpAndHaul v0.18.2.0 welcomes you to RimWorld with pointless logspam."); + Log.Message("PickUpAndHaul v0.1.0.3 welcomes you to RimWorld with pointless logspam."); } - private static bool AllowToolHaulUrgentlyJobOnThing_PreFix(ref Job __result, Pawn pawn, Thing t, bool forced = false) { if (ModCompatibilityCheck.AllowToolIsActive) @@ -84,14 +81,14 @@ private static bool AllowToolHaulUrgentlyJobOnThing_PreFix(ref Job __result, Paw && !(t.def.defName.Contains("Chunk")) //most of the time we don't have space for it ) { - StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(t.Position, t); + StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(t); if (!StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true)) { JobFailReason.Is("NoEmptyPlaceLower".Translate()); return false; } - Job haul = new Job(PickUpAndHaulJobDefOf.HaulToInventory, t) + Job haul = new Job(PickUpAndHaulJobDefOf.HaulToInventory, t, storeCell) { count = t.stackCount }; @@ -102,7 +99,7 @@ private static bool AllowToolHaulUrgentlyJobOnThing_PreFix(ref Job __result, Paw return true; } - private static bool Drop_Prefix(ref Pawn pawn, ref Thing thing) + private static bool Drop_Prefix(Pawn pawn, Thing thing) { CompHauledToInventory takenToInventory = pawn.TryGetComp(); if (takenToInventory == null) return true; @@ -116,7 +113,7 @@ private static bool Drop_Prefix(ref Pawn pawn, ref Thing thing) return true; } - private static void Pawn_InventoryTracker_PostFix(Pawn_InventoryTracker __instance, ref Thing item) + private static void Pawn_InventoryTracker_PostFix(Pawn_InventoryTracker __instance, Thing item) { CompHauledToInventory takenToInventory = __instance.pawn.TryGetComp(); if (takenToInventory == null) return; @@ -154,12 +151,12 @@ private static void JobDriver_HaulToCell_PostFix(JobDriver_HaulToCell __instance //} } - public static void IdleJoy_Postfix(ref Pawn pawn) + public static void IdleJoy_Postfix(Pawn pawn) { PawnUnloadChecker.CheckIfPawnShouldUnloadInventory(pawn, true); } - public static void DropUnusedInventory_PostFix(ref Pawn pawn) + public static void DropUnusedInventory_PostFix(Pawn pawn) { PawnUnloadChecker.CheckIfPawnShouldUnloadInventory(pawn); } @@ -202,8 +199,7 @@ public static void WhileYoureUpMaybeHaulOtherStuffFirst_PostFix(Pawn pawn, Local { if (__result == null || __result.def != JobDefOf.HaulToCell) return; - WorkGiver_HaulToInventory worker = pawn.workSettings.WorkGiversInOrderNormal.FirstOrDefault(wg => wg is WorkGiver_HaulToInventory) as WorkGiver_HaulToInventory; - if (worker == null) return; + if (!(pawn.workSettings.WorkGiversInOrderNormal.FirstOrDefault(wg => wg is WorkGiver_HaulToInventory) is WorkGiver_HaulToInventory worker)) return; Job myJob = worker.JobOnThing(pawn, __result.targetA.Thing, false); if (myJob == null) return; diff --git a/Source/PickUpAndHaul/PickUpAndHaul/JobDriver_HaulToInventory.cs b/Source/PickUpAndHaul/PickUpAndHaul/JobDriver_HaulToInventory.cs index d97c389..3cfcd9e 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/JobDriver_HaulToInventory.cs +++ b/Source/PickUpAndHaul/PickUpAndHaul/JobDriver_HaulToInventory.cs @@ -1,26 +1,23 @@ using System; using System.Collections.Generic; using RimWorld; +using UnityEngine; using Verse; using Verse.AI; -using UnityEngine; namespace PickUpAndHaul { public class JobDriver_HaulToInventory : JobDriver { - - - public override bool TryMakePreToilReservations() + public override bool TryMakePreToilReservations(bool errorOnFailed) { - return this.pawn.Reserve(this.job.targetA, this.job, 1, -1, null); + return this.pawn.Reserve(this.job.targetA, this.job) && pawn.Reserve(job.targetB, this.job); } //reserve, goto, take, check for more. Branches off to "all over the place" protected override IEnumerable MakeNewToils() { CompHauledToInventory takenToInventory = pawn.TryGetComp(); - HashSet carriedThings = takenToInventory.GetHashSet(); DesignationDef HaulUrgentlyDesignation = DefDatabase.GetNamed("HaulUrgentlyDesignation", false); //Thanks to AlexTD for the more dynamic search range @@ -28,7 +25,7 @@ protected override IEnumerable MakeNewToils() float distanceToOthers = 0f; Toil wait = Toils_General.Wait(2); - Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null); + Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.A); Toil calculateExtraDistanceToGo = new Toil { @@ -40,8 +37,8 @@ protected override IEnumerable MakeNewToils() }; yield return calculateExtraDistanceToGo; - Toil checkForOtherItemsToHaulToInventory = CheckForOtherItemsToHaulToInventory(reserveTargetA, TargetIndex.A, distanceToOthers, null); - Toil checkForOtherItemsToUrgentlyHaulToInventory = CheckForOtherItemsToHaulToInventory(reserveTargetA, TargetIndex.A, distanceToOthers, (Thing x) => pawn.Map.designationManager.DesignationOn(x)?.def == HaulUrgentlyDesignation); + Toil checkForOtherItemsToHaulToInventory = CheckForOtherItemsToHaulToInventory(reserveTargetA, TargetIndex.A, distanceToOthers); + Toil checkForOtherItemsToUrgentlyHaulToInventory = CheckForOtherItemsToHaulToInventory(reserveTargetA, TargetIndex.A, distanceToOthers, x => pawn.Map.designationManager.DesignationOn(x)?.def == HaulUrgentlyDesignation); yield return reserveTargetA; @@ -51,7 +48,7 @@ protected override IEnumerable MakeNewToils() { this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.ClosestTouch); }, - defaultCompleteMode = ToilCompleteMode.PatherArrival, + defaultCompleteMode = ToilCompleteMode.PatherArrival }; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return gotoThing; @@ -65,7 +62,7 @@ protected override IEnumerable MakeNewToils() Toils_Haul.ErrorCheckForCarry(actor, thing); //get max we can pick up - int num = Mathf.Min(thing.stackCount, MassUtility.CountToPickUpUntilOverEncumbered(actor, thing)); + int num = Mathf.Min(thing.stackCount, MassUtility.CountToPickUpUntilOverEncumbered(actor, thing), job.count); // yo dawg, I heard you like delegates so I put delegates in your delegate, so you can delegate your delegates. // because compilers don't respect IF statements in delegates and toils are fully iterated over as soon as the job starts. @@ -76,7 +73,7 @@ protected override IEnumerable MakeNewToils() if (ModCompatibilityCheck.CombatExtendedIsActive) { CombatExtended.CompInventory ceCompInventory = actor.GetComp(); - ceCompInventory.CanFitInInventory(thing, out num, false, false); + ceCompInventory.CanFitInInventory(thing, out num); } }))(); } @@ -86,9 +83,9 @@ protected override IEnumerable MakeNewToils() if (num <= 0) { Job haul = HaulAIUtility.HaulToStorageJob(actor, thing); - if (haul?.TryMakePreToilReservations(actor) ?? false) + if (haul?.TryMakePreToilReservations(actor, false) ?? false) { - actor.jobs.jobQueue.EnqueueFirst(haul, new JobTag?(JobTag.Misc)); + actor.jobs.jobQueue.EnqueueFirst(haul, JobTag.Misc); } actor.jobs.curDriver.JumpToToil(wait); } @@ -104,7 +101,7 @@ protected override IEnumerable MakeNewToils() } } - actor.inventory.GetDirectlyHeldThings().TryAdd(thing.SplitOff(num), true); + actor.inventory.GetDirectlyHeldThings().TryAdd(thing.SplitOff(num)); takenToInventory.RegisterHauledItem(thing); try @@ -145,60 +142,59 @@ public Toil CheckForOtherItemsToHaulToInventory(Toil getHaulTargetToil, TargetIn Job curJob = actor.jobs.curJob; IntVec3 storeCell = IntVec3.Invalid; - Predicate validator = (Thing t) => t.Spawned - && HaulAIUtility.PawnCanAutomaticallyHaulFast(actor, t, false) - && (!t.IsInValidBestStorage()) - && !t.IsForbidden(actor) - && !(t is Corpse) - && (StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, (HaulAIUtility.StoragePriorityAtFor(t.Position, t)), actor.Faction, out storeCell, true)) - && (extraValidator == null || extraValidator (t)) - && actor.CanReserve(t, 1, -1, null, false); + bool Validator(Thing t) => t.Spawned && HaulAIUtility.PawnCanAutomaticallyHaulFast(actor, t, false) + && !t.IsInValidBestStorage() + && !t.IsForbidden(actor) + && !(t is Corpse) + && StoreUtility.TryFindBestBetterStoreCellFor(t, this.pawn, this.pawn.Map, StoreUtility.CurrentStoragePriorityOf(t), actor.Faction, out storeCell) + && (extraValidator == null || extraValidator(t)) + && actor.CanReserve(t); Thing thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableAlways), PathEndMode.ClosestTouch, - TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), Math.Max(distanceToOthers, 12f), validator, null, 0, -1, false, RegionType.Set_Passable, false); - - float usedBulkByPct = 1f; - float usedWeightByPct = 1f; - - try - { - ((Action)(() => - { - if (ModCompatibilityCheck.CombatExtendedIsActive) - { - CombatExtended.CompInventory ceCompInventory = actor.GetComp(); - usedWeightByPct = ceCompInventory.currentWeight / ceCompInventory.capacityWeight; - usedBulkByPct = ceCompInventory.currentBulk / ceCompInventory.capacityBulk; - } - }))(); - } - catch (TypeLoadException) { } - - - if (thing != null && (MassUtility.EncumbrancePercent(actor) <= 0.9f || usedBulkByPct >= 0.7f || usedWeightByPct >= 0.8f)) + TraverseParms.For(actor), Math.Max(distanceToOthers, 12f), Validator); + + //float usedBulkByPct = 1f; + //float usedWeightByPct = 1f; + + //try + //{ + // ((Action)(() => + // { + // if (ModCompatibilityCheck.CombatExtendedIsActive) + // { + // CompInventory ceCompInventory = actor.GetComp(); + // usedWeightByPct = ceCompInventory.currentWeight / ceCompInventory.capacityWeight; + // usedBulkByPct = ceCompInventory.currentBulk / ceCompInventory.capacityBulk; + // } + // }))(); + //} + //catch (TypeLoadException) { } + + + if (thing != null && (MassUtility.EncumbrancePercent(actor) <= 0.9f /*|| usedBulkByPct >= 0.7f || usedWeightByPct >= 0.8f*/)) { curJob.SetTarget(haulableInd, thing); - actor.Reserve(storeCell, this.job, 1, -1, null); + actor.Reserve(storeCell, this.job); + this.job.count = 99999; //done for "num", to solve scenarios like hauling 150 meat to single free spot near stove actor.jobs.curDriver.JumpToToil(getHaulTargetToil); return; } if (thing != null) { Job haul = HaulAIUtility.HaulToStorageJob(actor, thing); - if (haul?.TryMakePreToilReservations(actor) ?? false) + if (haul?.TryMakePreToilReservations(actor, false) ?? false) { - actor.jobs.jobQueue.EnqueueFirst(haul, new JobTag?(JobTag.Misc)); + //note that HaulToStorageJob etc doesn't do opportunistic duplicate hauling for items in valid storage. REEEE + actor.jobs.jobQueue.EnqueueFirst(haul, JobTag.Misc); this.EndJobWith(JobCondition.Succeeded); + return; } } - if (thing == null) + Job unload = new Job(PickUpAndHaulJobDefOf.UnloadYourHauledInventory, storeCell); + if (unload.TryMakePreToilReservations(actor, false)) { - Job job = new Job(PickUpAndHaulJobDefOf.UnloadYourHauledInventory); - if (job.TryMakePreToilReservations(actor)) - { - actor.jobs.jobQueue.EnqueueFirst(job, new JobTag?(JobTag.Misc)); - this.EndJobWith(JobCondition.Succeeded); - } + actor.jobs.jobQueue.EnqueueFirst(unload, JobTag.Misc); + this.EndJobWith(JobCondition.Succeeded); } }; return toil; diff --git a/Source/PickUpAndHaul/PickUpAndHaul/JobDriver_UnloadYourHauledInventory.cs b/Source/PickUpAndHaul/PickUpAndHaul/JobDriver_UnloadYourHauledInventory.cs index d29e5a7..e2f211c 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/JobDriver_UnloadYourHauledInventory.cs +++ b/Source/PickUpAndHaul/PickUpAndHaul/JobDriver_UnloadYourHauledInventory.cs @@ -15,14 +15,14 @@ public class JobDriver_UnloadYourHauledInventory : JobDriver public override void ExposeData() { base.ExposeData(); - Scribe_Values.Look(ref this.countToDrop, "countToDrop", -1, false); + Scribe_Values.Look(ref this.countToDrop, "countToDrop", -1); } - - public override bool TryMakePreToilReservations() + + public override bool TryMakePreToilReservations(bool errorOnFailed) { return true; } - + /// /// Find spot, reserve spot, pull thing out of inventory, go to spot, drop stuff, repeat. /// @@ -46,7 +46,7 @@ protected override IEnumerable MakeNewToils() { initAction = () => { - ThingStackPart unloadableThing = FirstUnloadableThing(pawn); + ThingCount unloadableThing = FirstUnloadableThing(pawn); if (unloadableThing.Count == 0 && carriedThing.Count == 0) { @@ -55,10 +55,10 @@ protected override IEnumerable MakeNewToils() if (unloadableThing.Count != 0) { - StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(pawn.Position, unloadableThing.Thing); + //StoragePriority currentPriority = StoreUtility.StoragePriorityAtFor(pawn.Position, unloadableThing.Thing); if (!StoreUtility.TryFindStoreCellNearColonyDesperate(unloadableThing.Thing, this.pawn, out IntVec3 c)) { - this.pawn.inventory.innerContainer.TryDrop(unloadableThing.Thing, ThingPlaceMode.Near, unloadableThing.Thing.stackCount, out Thing thing, null); + this.pawn.inventory.innerContainer.TryDrop(unloadableThing.Thing, ThingPlaceMode.Near, unloadableThing.Thing.stackCount, out Thing thing); this.EndJobWith(JobCondition.Succeeded); } else @@ -72,7 +72,7 @@ protected override IEnumerable MakeNewToils() }; yield return findSpot; - yield return Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null); + yield return Toils_Reserve.Reserve(TargetIndex.B); yield return new Toil { @@ -85,15 +85,15 @@ protected override IEnumerable MakeNewToils() pawn.jobs.curDriver.JumpToToil(wait); return; } - if (!this.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !thing.def.EverStoreable) + if (!this.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !thing.def.EverStorable(false)) { - this.pawn.inventory.innerContainer.TryDrop(thing, ThingPlaceMode.Near, this.countToDrop, out thing, null); + this.pawn.inventory.innerContainer.TryDrop(thing, ThingPlaceMode.Near, this.countToDrop, out thing); this.EndJobWith(JobCondition.Succeeded); carriedThing.Remove(thing); } else { - this.pawn.inventory.innerContainer.TryTransferToContainer(thing, this.pawn.carryTracker.innerContainer, this.countToDrop, out thing, true); + this.pawn.inventory.innerContainer.TryTransferToContainer(thing, this.pawn.carryTracker.innerContainer, this.countToDrop, out thing); this.job.count = this.countToDrop; this.job.SetTarget(TargetIndex.A, thing); carriedThing.Remove(thing); @@ -136,7 +136,7 @@ protected override IEnumerable MakeNewToils() yield return celebrate; } - static ThingStackPart FirstUnloadableThing(Pawn pawn) + static ThingCount FirstUnloadableThing(Pawn pawn) { CompHauledToInventory itemsTakenToInventory = pawn.TryGetComp(); HashSet carriedThings = itemsTakenToInventory.GetHashSet(); @@ -147,7 +147,7 @@ from t in pawn.inventory.innerContainer where carriedThings.Contains(t) select t; - foreach (Thing thing in carriedThings.OrderBy(t => t.def.FirstThingCategory.index)) + foreach (Thing thing in carriedThings.OrderBy(t => t.def.FirstThingCategory?.index)) { //merged partially picked up stacks get a different thingID in inventory if (!potentialThingsToUnload.Contains(thing)) @@ -163,12 +163,12 @@ from straggler in pawn.inventory.innerContainer foreach (Thing dirtyStraggler in dirtyStragglers) { - return new ThingStackPart(dirtyStraggler, dirtyStraggler.stackCount); + return new ThingCount(dirtyStraggler, dirtyStraggler.stackCount); } } - return new ThingStackPart(thing, thing.stackCount); + return new ThingCount(thing, thing.stackCount); } - return default(ThingStackPart); + return default(ThingCount); } } } \ No newline at end of file diff --git a/Source/PickUpAndHaul/PickUpAndHaul/ModCompatibilityCheck.cs b/Source/PickUpAndHaul/PickUpAndHaul/ModCompatibilityCheck.cs index 5a60154..d5e1230 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/ModCompatibilityCheck.cs +++ b/Source/PickUpAndHaul/PickUpAndHaul/ModCompatibilityCheck.cs @@ -26,14 +26,6 @@ public static bool AllowToolIsActive } } - //public static bool SimplesidearmsIsActive - //{ - // get - // { - // return ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == "Simple sidearms"); - // } - //} - public static bool ExtendedStorageIsActive { get diff --git a/Source/PickUpAndHaul/PickUpAndHaul/PawnUnloadChecker.cs b/Source/PickUpAndHaul/PickUpAndHaul/PawnUnloadChecker.cs index 5f0e907..18df091 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/PawnUnloadChecker.cs +++ b/Source/PickUpAndHaul/PickUpAndHaul/PawnUnloadChecker.cs @@ -13,7 +13,7 @@ public class PawnUnloadChecker public static void CheckIfPawnShouldUnloadInventory(Pawn pawn, bool forced = false) { - Job job = new Job(PickUpAndHaulJobDefOf.UnloadYourHauledInventory); + Job job = new Job(PickUpAndHaulJobDefOf.UnloadYourHauledInventory, pawn); CompHauledToInventory itemsTakenToInventory = pawn.TryGetComp(); if (itemsTakenToInventory == null) return; @@ -23,7 +23,7 @@ public static void CheckIfPawnShouldUnloadInventory(Pawn pawn, bool forced = fal if (pawn.Faction != Faction.OfPlayer || !pawn.RaceProps.Humanlike) return; if (carriedThing?.Count == 0 || pawn.inventory.innerContainer.Count == 0) return; - if (carriedThing.Count != 0) + if (carriedThing?.Count != 0) { try { @@ -39,18 +39,18 @@ public static void CheckIfPawnShouldUnloadInventory(Pawn pawn, bool forced = fal if (forced) { - if (job.TryMakePreToilReservations(pawn)) + if (job.TryMakePreToilReservations(pawn, false)) { - pawn.jobs.jobQueue.EnqueueFirst(job, new JobTag?(JobTag.Misc)); + pawn.jobs.jobQueue.EnqueueFirst(job, JobTag.Misc); return; } } if (MassUtility.EncumbrancePercent(pawn) >= 0.90f || carriedThing.Count >= 1) { - if (job.TryMakePreToilReservations(pawn)) + if (job.TryMakePreToilReservations(pawn, false)) { - pawn.jobs.jobQueue.EnqueueFirst(job, new JobTag?(JobTag.Misc)); + pawn.jobs.jobQueue.EnqueueFirst(job, JobTag.Misc); return; } } @@ -64,7 +64,7 @@ public static void CheckIfPawnShouldUnloadInventory(Pawn pawn, bool forced = fal { if (compRottable.TicksUntilRotAtCurrentTemp < 30000) { - pawn.jobs.jobQueue.EnqueueFirst(job, new JobTag?(JobTag.Misc)); + pawn.jobs.jobQueue.EnqueueFirst(job, JobTag.Misc); return; } } diff --git a/Source/PickUpAndHaul/PickUpAndHaul/PickUpAndHaul.csproj b/Source/PickUpAndHaul/PickUpAndHaul/PickUpAndHaul.csproj index 2941782..17dfcbc 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/PickUpAndHaul.csproj +++ b/Source/PickUpAndHaul/PickUpAndHaul/PickUpAndHaul.csproj @@ -30,9 +30,9 @@ 4 - + + False ..\..\..\..\..\..\..\..\..\..\Users\Maniak\Documents\RimWorld Mods\0Harmony.dll - True ..\..\..\..\..\..\..\workshop\content\294100\761421485\Assemblies\AllowTool.dll @@ -57,7 +57,7 @@ False - ..\..\..\..\..\..\..\workshop\content\294100\1161112205\Assemblies\WhileYoureUp.dll + ..\..\..\..\..\..\..\workshop\content\294100\1428216342\Assemblies\WhileYoureUp.dll False diff --git a/Source/PickUpAndHaul/PickUpAndHaul/Properties/AssemblyInfo.cs b/Source/PickUpAndHaul/PickUpAndHaul/Properties/AssemblyInfo.cs index ae135b6..4c156da 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/Properties/AssemblyInfo.cs +++ b/Source/PickUpAndHaul/PickUpAndHaul/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.18.2.0")] -[assembly: AssemblyFileVersion("1.0.0.569")] +[assembly: AssemblyVersion("0.1.0.3")] +[assembly: AssemblyFileVersion("0.1.0.585")] diff --git a/Source/PickUpAndHaul/PickUpAndHaul/WorkGiver_HaulToInventory.cs b/Source/PickUpAndHaul/PickUpAndHaul/WorkGiver_HaulToInventory.cs index 882dc23..9e683ac 100644 --- a/Source/PickUpAndHaul/PickUpAndHaul/WorkGiver_HaulToInventory.cs +++ b/Source/PickUpAndHaul/PickUpAndHaul/WorkGiver_HaulToInventory.cs @@ -12,7 +12,7 @@ namespace PickUpAndHaul public class WorkGiver_HaulToInventory : WorkGiver_HaulGeneral { - public override bool ShouldSkip(Pawn pawn) + public override bool ShouldSkip(Pawn pawn, bool forced = false) { return base.ShouldSkip(pawn) || pawn.Faction != Faction.OfPlayer || (!pawn.RaceProps.Humanlike); //hospitality check + misc robots & animals } @@ -31,12 +31,12 @@ public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, thing, forced)) return null; - if (thing.IsForbidden(pawn) || StoreUtility.IsInValidBestStorage(thing)) return null; + if (thing.IsForbidden(pawn) || thing.IsInValidBestStorage()) return null; //bulky gear (power armor + minigun) so don't bother. if (MassUtility.GearMass(pawn) / MassUtility.Capacity(pawn) >= 0.8f) return null; - StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing); + StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing); if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true)) { //since we've gone through all the effort of getting the loc, might as well use it. @@ -48,8 +48,7 @@ public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) List thingList = storeCell.GetThingList(thing.Map); for (int i = 0; i < thingList.Count; i++) { - Thing thingAtCell = thingList[i]; - if (thingAtCell.def == ThingDefOf.Hopper) + if (thingList[i].def == ThingDefOf.Hopper) return HaulAIUtility.HaulToStorageJob(pawn, thing); } } @@ -61,7 +60,7 @@ public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) return null; } - if (MassUtility.EncumbrancePercent(pawn) >= 0.80f) + if (MassUtility.EncumbrancePercent(pawn) >= 0.90f) { Job haul = HaulAIUtility.HaulToStorageJob(pawn, thing); return haul; @@ -70,9 +69,13 @@ public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) //credit to Dingo int c = MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing); + Thing preExistingThing = pawn.Map.thingGrid.ThingAt(storeCell, thing.def); + if (preExistingThing != null) + c = thing.def.stackLimit - preExistingThing.stackCount; + if (c == 0) return HaulAIUtility.HaulToStorageJob(pawn, thing); - return new Job(PickUpAndHaulJobDefOf.HaulToInventory, thing) + return new Job(PickUpAndHaulJobDefOf.HaulToInventory, thing, storeCell) { count = c };