Toxe , Yes, I do. But it's difficult when you have got a bunch of vehicles...
I deliberately copied a part of my code. Let me explain the situation:
unitCore.unitCroisement = an array where the unit detect his neighbors, distance = 1.
What this code do:
One unit goes from A to B, there are 5 checkpoints between.
When it reachs a checkpoint, this code is called.
If a neighbor is detected and he has got a path (it moves), the unit must check if this neighbor's position is the next chekpoint to reach. If yes, he must conturn it, if not, he must wait. That's means we can break the loop.
Why it must wait: because the neighbor can be on the way. No need to break the loop, because not necessary.
list's index out of range error, I suspect it's because one neighbor on the way has reachs his final point, but the unit in move doesn't know it.
Here the complete code:
# for loop...
# if...
# elif...
elif myCurrentPath == hisPosMap: # if neighbor on the way
# if neighbor out of fuel or stuck by other unit out of fuel, conturn
if reasonListWait.has(unit.waitReason):
actionToDo = 'conturn'
breakLoop = true
else: # if neighbor not out of fuel but still on the way
var faceToFace = false
for dir in dirOpposite:
if ((myVelo == dir[0] and hisVelo == dir[1]) or\
(myVelo == dir[1] and hisVelo == dir[0])):
faceToFace = true
break
if faceToFace:
actionToDo = 'faceToface'
else:
for neighbor in unitCore.unitCrossed:
if not neighbor.unitPath.empty():
if unitCore.Map.world_to_map(neighbor.unitPath[neighbor.step]) == unitCore.Map.world_to_map(unitCore.position):
actionToDo = 'conturn'
break
else:
actionToDo = 'wait'
breakLoop = true
else:
actionToDo = 'move'