Yuuzantar, you're idea is well thought out and for that I thank you. It's wonderful to see community members being constructively critical and trying to help the game be better.
The logic you present is solid, but the unfortunate matter is that what you are suggesting is so extraordinarily difficult to program. What seems like simple traffic logic to you, is very hard to put into mathematical formulas and call functions that don't use up all your computers memory. That's one big reason why vehicles have to choose their routes early on. Can you imagine the strain on your system if they were constantly calculating every other vehicle sharing a road with them, plus all the vehicles past the next intersection?
I'm not trying to shoot you down, you really have given great ideas that I've taken note of. But I ask that you trust that CO is doing the best they can to simulate traffic, which is an extremely difficult thing to do. We want to improve, you want improvements, but at the end of the day we need to accept that the traffic AI will never be perfect.
Hope that makes sense and doesn't come off too blunt! =)
Just to make sure I understand, does It mean that the path of any car is calculate either at the beginning normally or when you destroy a road ?
well for a computer performance point of view it makes sense (less calculus means less RAM taken)
I guess you already thought about it and my input is probably useless, but the possibilities I would explore would be:
- to take into account the traffic in the original path calculus: same as what google maps does, sometimes a national is better than a crowded highway (the macro Algorithm of Yuuzantar I guess)
- Pros: a bit closer to reality (same as following a GPS path), should take care of some major traffic congestion
- Cons: need to find a way to quantify the waste of time implied by the traffic congestion, still a few lines that are useless
- Plus: maybe randomize between to paths that are close enough in time ?
- to teach them to use the other lines: As shown by Yuuzantar right now only one lane is used. What I would like to see is for the pathfinding to make the car cross the lines.
Let's say that you have ndirlanes lanes that allow you to go in the direction you want to go before the next intersection. d is the distance you're driving straight before making the direction change. Let's take a minimal distance for changing line equal to the walking distance (10 squares if I'm right), dwalk. The next direction you want to go to is dirNext(i)=(-1=right, 0=straight, 1=left) i being the step you're at
Let's numerate the lanes 1:ndirlanes, the lane 1 being the one on the right (movement direction) and the lane ndirlanes being the one on the left.
To be more clear, when you arrive at you intersection, you should have a matrix:
0 1 1 1 -1 -1 -1 0 The direction of the road (-1 incoming traffic at the intersection, 1 exiting traffic, 0 well the limit)
0 1 0 0 0 0 1 0 indicates which lane allows to turn right (>0 indicates that the arrow will be towards the right) or that cars will turn right into
0 0 1 2 3 2 1 0 indicates which lane goes straight
0 0 0 1 1 0 0 0 indicates which lane goes left (here the left lane allows to go straight and left)
another example, the 6 lane one direction street that with all arrow straight and left:
0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 0
0 1 2 3 4 5 6 0
We will call this matrix intersection.
Now for a simple street intersection:
0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 0
0 1 2 3 4 5 6 0
[---------------------0 0 0 0
[---------------------6 0 0 -1
[---------------------5 0 0 -1
[---------------------4 0 0 -1
[---------------------3 0 0 -1
[---------------------2 0 0 -1
[---------------------1 0 0 -1
[---------------------0 0 0 0
0 1 2 3 4 5 6 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 -1 -1 -1 -1 -1 -1 0
Now the rules for turning are -if I'm not wrong- if you have two lanes to turn right, you have two lanes to turn right into.
The rule here is the same: you are on line 5 to turn left, you go on line 5 to turn left into.
So, the car just spawned on a street (let's say our 6 lane one direction one), on lane 4.
It wants to go left next ( dirNext(1)=1 ) then left again ( dirNext(2)=1 ) because pathfinder said so.
you have chosen left, so you go to intersection(4+1,dirNext+3) and get lane=4
ndirlanes=max(intersection(find(intersection(1,

==1),dirNext+3)=6;
LaneChange(i)=min(int(d/dwalk),ndirlanes-lane); the number of possible lane change before the intersection.
ideally it would go from lane 4 to lane 6 before the first intersection. (ndirlanes-lanes=2)
But if we have only d=1.5*dwalk, then LaneChange=1;
Now we just have to change line.
So basically, instead of having just a direction vector to decide the path of the car, we add a change of line one.
for i intersection, we have dir(1,i)=dirNext(i)=-1, 0 ou 1 et dir(2,i)=LaneChange(i).
dirNext(i)*LaneChange(i) gives how you move through the lanes (+1 lane, no movement (going straight), -2 lanes,...)
Well that was a part of my two cents but at some point I should probably go to sleep ^^
Then again, I don't have access to your code and what I propose may be incompatible with it. But I think that by putting the lane change at the same time as pathfinding, we should not burden the computer too much.
Well what I did was most probably useless but it was a fun intellectual exercise

In the scenario where you may like what I propose but don't quite understand, feel free to ask.
@Azurespecter, like I said I am conscious of the fact that I don't have access to your code, your past tries and that you guys are much more experimented at traffic simulating that I will ever be. But if you have some feedback that would be nice.
I anyway have more proposals and I will post them anyway

but my level of abstraction will probably depend if the devs find this kind of input useful or not