Issue description
When a vehicle fails to reach a destination, it will sit idle for a couple of seconds, then try to reach the same destination again. This can lead to an infinite loop.
Example:
- Dump truck full
- Dump truck gets destination with highest priority
- Pathfinding cannot find a path, because conveyors are in the way
- Dump truck waits x seconds and tries again
- If the priorities are unchanged, goto 3
Expected behavior
When a destination is unreachable for a vehicle, that vehicle should put that destination on a per-vehicle blacklist for a certain time. When the vehicle gets a new job, it should evict items on the blacklist that are past ttl and otherwise only consider destinations that are not on the blacklist.
Example code:
ORDERED_DESTINATIONS = {
"ore": ["id1", "id2"]
}
class Vehicle:
def __init__(self):
# might be faster to use two arrays here instead of a hashmap
self.blacklist_destinations = []
self.blacklist_timestamps = []
self.load = "ore"
self.ttl = 60
def pathfind_to_destination(self, destination):
path = a_star(destination)
if not path:
self.blacklist_destinations.append(destination)
self.blacklist_timestamps.append(time.time())
return None
return path
def get_job(self):
if self.blacklist_destinations:
for i in range(len(self.blacklist_destinations)):
if time.time() - self.blacklist_timestamps[i] > self.ttl:
self.blacklist_destinations.pop(i)
self.blacklist_timestamps.pop(i)
break
for destination in ORDERED_DESTINATIONS[self.load]:
if destination not in self.blacklist_destinations:
path = self.pathfind_to_destination(destination)
if not path: continue
self.do_job(path)
return
return None
Reproduction steps
- Have dump truck full of product
- Have high-priority destination for product behind raised conveyors
- Have low-priority destination somewhere else
Game version
v0.4.14B