This is what I've come up with.
Vehicle has a path to take which is a series of Intersections
-At each intersection it will look for a LaneConnection that connects it's lane to a lane that connects to the next Intersection it wants
-If it can't find one (it means the graph has changed), so recalculate the path
-The path finder should maybe have a priority queue to process stuck cars first so that they're not blocking traffic
-Needs to check if this intersection has lights
-If it does have lights, will only proceed on a green light to enter LaneConnection
-Needs to check if any of the blocking lanes have a vehicle in them. If it does, then it is blocked and will not be able to move forward into this LaneConnection
Intersections:
-Process Lanes in a round-robin way so that every lane gets a chance to inject a car into the LaneConnections
-Each lane is checked to see if there's a Vehicle there, and it's logic is processed.
-Then every other vehicle in that lane is processed
Vehicles travel down roads by measuring the delta distance between it and the car in front / end of lane.
-If the distance is getting larger, we can speed up at acceleration rate until no more than speedLimit or drivers speed limit
-If the distance is getting smaller AND the distance is less than the breaking threshold for this driver, we will calculate brake rate to match drivers speed before hitting them or 0 for end of lane
-d = distance between vehicle and leading vehicle / end of lane
-s1 = vehicle speed
-s2 = leading vehicle speed or end of lane (0 speed)
-sd = s1^2 - s2^2
-dr = sd / (2 * d)
-dr is the deacceleration rate to apply
-Vehicles should be processed from front of lane to back of lane
Vehicles will change lanes when:
-The current lane has reached a threshold of speed. I.e. some drivers will change if it's 10% slower than speed limit, others will if it's 50% lower than speed limit
-Check the lanes to the left and/or right and ensure they exist
-For the lanes found, check to see if they also connect to a LaneConnection at the next Intersection, that leads to a Lane that connects to the next Intersection in the path queue. I.e., they won't change lanes if that lane won't get them where they want. This means there's no one who will be overtaking or anything like that.
Lane Connections are setup to:
-Have the left-most lane or two leftmost lanes to be turning lanes etc
-Vehicles should naturally move into available space
Some drivers:
-Are slower or faster than others
-Will brake earlier or later than others
-Will change lanes more readily than others
-This should hopefully allow the roads to look natural as cars are travelling through them.
What do you think, Anon?