ubergarm / RimWorld-KanbanStockpile

RimWorld mod adding `Stack Refill Threshold` and `Similar Stack Limit` to stockpiles and deep storage inspired by kanban logistic control systems.
https://steamcommunity.com/sharedfiles/filedetails/?id=2287142613
MIT License
2 stars 3 forks source link

Reduce redundant haul jobs when used with PickupAndHaul #11

Closed ubergarm closed 3 years ago

ubergarm commented 4 years ago

Probably have to check for both PickUpAndHaul mods folks mostly use right now:

Assuming PUAH properly reserves all the items that get hauled to inventory, might be able to just check for that specific job def like I'm doing already.

ubergarm commented 4 years ago

Possibly could prefix patch WorkGiver_HaulToInventory.AllocateThingAtCell() to check for kanbanstockpile settings before blindly sucking it up into inventory...

it only checks if the slotGroup.Accepts(nextThing) but doesn't check NoStorageBlockersIn... hrmm... will play around and see...

ubergarm commented 4 years ago

Could also possibly look at public static int CapacityAt(Thing thing, IntVec3 storeCell, Map map) too as it is probably reporting more capacity that is actually available (due to KanbanStockpile)

ubergarm commented 3 years ago

Okay, some thoughts after sleeping:

PUAH's WorkGiver_HaulToInventory makes a new HaulToInventory job then calls AllocateThingAtCell() on everything nearby the pawn. The call tree goes through AllocateThingAtCell() -> StoreUtility.TryFindBestBetterStoreCellFor() -> StoreUtility.TryFindBestBetterStoreCellForWorker() -> StoreUtility.IsGoodStoreCell() -> StoreUtility.NoStorageBlockersIn(). This is good as this mod mainly patches NoStorageBlockersIn().

The issue that arises is that the Work Giver does not make reservation on things as it goes along allocating, only after it has allocated as much as possible will it pass the job to the JobDriver at which point it tries to reserve everything that it can in the queue.

So it is impossible for me to say "don't Allocate that thing it is already reserved" because the reservations happen too late.

So next best option is to directly patch PUAH's CapacityAt() with a postfix that looks at what PUAH thinks the capacity is in storage and reduces it if this mod is set to do so.

So hopefully that will prevent the first pawn that does a PUAH job from grabbing way too much stuff, and then if another pawn tries to haul something by that time it will have been properly reserved as a PUAH job - still have to write some code to scan the entire queue of that job reservation or what not.. hah

ubergarm commented 3 years ago

Oh man... 3 days deep into fussing around with it.. hah.. I ended up removing KanbanStockpile from my test loadout just to see how PUAH handles on its own, and it exhibits similar "overhauling" or perhaps some call it "unloading madness" or whatever on its own. Likely because the two jobs it adds don't quite do all the reservations at the right times or just doesn't reserve items to be hauled at all depending on how the sequence plays out.

So I'll back-off on "fixing it" as i'd have to redo PUAH and that is out of scope for today lol.

I think I can keep the CapacityAt() patch so at least deep storage won't immediately overhaul, and there may be a little more that i can do...