Haul opportunistically at every job/activity switch.

Started by fritzgryphon, February 23, 2020, 03:08:07 PM

Previous topic - Next topic

fritzgryphon

My most desperately wanted quality of life addition.  I'm sure there's a mod for it, but it's something so common and universal that it would be nice in the base game.  So many QoL mods have been integrated that I can almost completely play vanilla now, and avoid the mod version pain.

Let's say Bob is mining steel.  He mines and mines, steel piles up around him.  Then he decides to go sleep.

He walks toward his bed, leaving the steel he mined sitting on the ground.  He walks right through a stockpile that accepts steel before getting into bed.  He could have hauled that steel to the stockpile effectively for free, but now it will take another complete round trip to do it. 

This potentially happens every time a colonist changes activities.  From job to job, job to recreation, recreation to sleep, etc.  The only vanilla bandaid for this is to micromanage every colonist that is doing a job that creates carryables, or is near carryables, to make sure they take the carryables with them when they switch tasks.  It would be nice if they did this automatically.

I get that it's basically travelling salesman, but a rough implementation of this could actually be really simple and fast. The below algorithm would only run once per task switch, and task switches happen only once every multiple seconds per colonist.  The algorithm will sometimes fail to haul, or won't haul the optimal thing, or to the highest priority stockpile.  On the upside, it's practically free performance wise, and covers almost all of the desired cases, with almost no additional pathing cost, and all hauled items end up in a better place than before (better to be in a low priority stockpile, to be moved later, than left in the wilderness).

Quoteon switch from task A to B:

if (carryable, allowed item is adjacent to me, not already in a stockpile)
   {
    for (each type of item) 
      {
       for (each stockpile within X cells of my destination, but only stockpiles closer to me than destination B) 
      {
       if (this stockpile accepts the item and there is room for it) 
       then {queue hauling job of this item to that stockpile before doing task B;  return;}  else {keep looking through items}
      }
   }
}

The function would only run about once a second in a busy colony, could terminate as soon as it found the first valid haul job, and it could use distance squared or even manhattan for the distance checks.  Super light, and would eliminate so much tedious micro.