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

Multiple pawns try to haul the same type of stack when `Similar Stack Limit` is enabled. #1

Closed ubergarm closed 4 years ago

ubergarm commented 4 years ago

How to Recreate Issue

  1. Setup a 4x4 stockpile, allow all meals, set Similar Stack Limit to 1 and everything else default.
  2. Have say like at least 3 pawns and 3 stacks of packaged survival meals sitting around (not stored).
  3. One pawn will likely start hauling a single stack of packaged survival meals to the new stockpile - great.
  4. Bug: A second pawn may also begin to haul a stack not realizing someone else is already going to fill it up.

This is likely because the stockpile is not "full" until the first pawn drops off their stuff. If the map is small and not much is going on the second pawn will likely be updated and cancel their now unneeded job and drop the carried stack. However, if you are in a bigger game that notification may get delayed and the second pawn will successfully store a duplicate stack.

Proposed Solution

Add an additional check against all outstanding hauling jobs going to that stockpile already around here: https://github.com/ubergarm/RimWorld-KanbanStockpile/blob/master/Source/Patches.cs#L197

I need to research JobGiver_Haul.cs and Pawn.carryTracker etc to figure out most efficient way to get this info. May need to iterate over every pawn and check their job / carried item. May be able to get a list of all items currently being hauled to current stockpile too. brainstorming...

ubergarm commented 4 years ago

I have implemented a patch of one algorithm to fix this. It requires scanning all pawns capable of hauling and checking if a hauling job is already "in-flight" for a similar stack to the same destination stockpile.

At a minimum I want to optimize the existing implementation, as it could become CPU costly as the number of pawns and haulers grows etc...

There may be a better way to perhaps get a list of jobs already pointing at the slotgroup directly instead of scanning for everything explicitly like I'm doing... I'll sleep on it...