Current:
- Bot picks job
- Bot reaches low energy
- Bot panics and runs to port
- Bot continues job
- Bot picks job
- Bot measures distance to target
- If ((distance/speed)*energyConsumption>lowEnergy), does pathfinding with ports (and start and destination) as nodes
- Repeat when destination changes
Cheap pathfinding:
Each port is a node. Start and end are also nodes.
Each node has at most 8 edges - in 4 orthogonals and 4 diagonals. Edges are created by picking closest node in that direction, as long as it isn't already an endpoint of other edge.
That way all connected roboports could be reached, but the path wouldn't be optimal.
Perfect pathfinding:
Nodes the same as above.
Each port node is connected to all port nodes reachable by bot with full energy. Start and end nodes are an exception: end needs to be reachable with enough energy to reach a port from it, start can have less energy than full.
That's basically it. Even the perfect pathfinding version should be cheap enough not to be noticeable even on older computers.
There could be many easy improvements to both performance and functionality here, but I'm pretty sure even now it would be easy to implement, fast enough not to be noticed and would solve the tendency of bots with low energy to both overestimate and underestimate their capabilities (and either die in action or change direction 0.3 meters before chest).