CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
569 stars 85 forks source link

RoutingManager lane grouping enhancements #1593

Open Elesbaan70 opened 2 years ago

Elesbaan70 commented 2 years ago

This issue depends on #1589.

Basic Non-Highway Routing Strategy

RoutingManager's logic for car lanes (non-highway rules) will be revised as follows:

  1. Outgoing lanes will be grouped first by lane group then by arrow direction. These are routing groups. For each outgoing routing group, the valid outgoing lane groups on all segments on the node will be identified.
  2. Incoming lane connections will be explicitly honored, then ignored by the remaining logic, as is done in the current code. However, this ought to be improved in the future.
  3. The lanes of the incoming routing group will be assigned to an outgoing lane group, proportionally according to the outgoing groups' lane counts. However, outgoing Standard and Express lane groups on the same segment will be treated as one for this operation.
  4. If the incoming routing group has at least as many lanes as the number of outgoing lane groups, an incoming lane will never be assigned to more than one outgoing lane group.
  5. Lane transitions will be defined from the incoming lanes into their assigned outgoing groups in a manner to avoid conflicts, or at least minimize them if there are more incoming than outgoing lanes.

The code will be structured to allow for node-based routing in the future. This will allow the routing of incoming segments to adapt to each other. Such an enhancement will also improve highway rules.

Valid Outgoing Lane Groups

A DisplacedInner lane group is exclusive if m_allowConnect is false and m_laneType is Vehicle. This excludes both Airports DLC cargo roads and TransportVehicle lanes from special CFI rules for displaced lanes.

Far Turn

An outgoing lane group is valid for far turns if its relative arrow direction is Left (RHT) or Right (LHT) and any one of the following conditions are met:

  1. It is a DisplacedOuter lane group on the nearest segment with incoming lanes in the clockwise (RHT) or counter-clockwise (LHT) direction.
  2. It is a DisplacedInner lane group.
  3. It is an Express or Standard lane group and there is no exclusive DisplacedInner lane group on the same segment. (The presence of an exclusive DisplacedInner lane group triggers the CFI rule.)

Near Turn

An outgoing lane group is valid for near turns if its relative arrow direction is Right (RHT) or Left (LHT) and any of the following conditions are met:

  1. It is a Standard or Express lane group.
  2. It is a DisplacedInner lane group that is not exclusive.

Forward, Standard Rule

  1. If the incoming routing group is DisplacedOuter and there is no DisplacedOuter outgoing lane group, it is handled as if it were DisplacedInner.
  2. If a segment contains the same type of outgoing lane group as the incoming routing group, then that is the valid outgoing lane group for the segment.
  3. Otherwise, if the incoming routing group is Express, then outgoing DisplacedInner and Standard lane groups are both valid.
  4. Otherwise, if the incoming routing group is DisplacedInner and an Express outgoing lane group is available, then that the valid outgoing lane group.
  5. Otherwise, the outgoing Standard lane group is selected as valid.

Forward, CFI Rule

When the incoming and outgoing segments both have exclusive DisplacedInner lanes and there are valid outgoing lane groups for far turns, the only valid outgoing lane group is DisplacedInner.

Highway Rules

When all segments on a node are highways, the existing code will be used for lane routing. Since highways do not have in-segment medians, they are beyond the scope of this project.