@@ -60,6 +60,8 @@ public class CustomPathFind : PathFind {
6060 private readonly TrafficMeasurementManager trafficMeasurementManager =
6161 TrafficMeasurementManager . Instance ;
6262#endif
63+ //Cached value (vanilla uses property to access it)
64+ private VehicleInfo . VehicleCategory vehicleCategory_ ;
6365
6466 private GlobalConfig globalConf_ ;
6567
@@ -256,6 +258,7 @@ private void PathFindImplementation(uint unit, ref PathUnit data) {
256258
257259 laneTypes_ = ( NetInfo . LaneType ) pathUnits_ . m_buffer [ unit ] . m_laneTypes ;
258260 vehicleTypes_ = ( VehicleInfo . VehicleType ) pathUnits_ . m_buffer [ unit ] . m_vehicleTypes ;
261+ vehicleCategory_ = ( VehicleInfo . VehicleCategory ) pathUnits_ . m_buffer [ unit ] . m_vehicleCategories ;
259262 maxLength_ = pathUnits_ . m_buffer [ unit ] . m_length ;
260263 pathFindIndex_ = pathFindIndex_ + 1 & 0x7FFF ;
261264 pathRandomizer_ = new Randomizer ( unit ) ;
@@ -1031,6 +1034,7 @@ ref nextSegmentId.ToSegment(),
10311034 } else if ( prevIsPedestrianLane ) {
10321035 // we are going to a pedestrian lane
10331036 if ( ! prevIsElevated ) {
1037+ bool isPedZoneRoad = prevSegmentInfo . IsPedestrianZoneOrPublicTransportRoad ( ) ;
10341038 if ( nextNode . Info . m_class . m_service != ItemClass . Service . Beautification ) {
10351039 bool canCrossStreet =
10361040 ( nextNode . m_flags &
@@ -1047,6 +1051,7 @@ ref nextSegmentId.ToSegment(),
10471051 nextNodeId ,
10481052 NetInfo . LaneType . Pedestrian ,
10491053 VehicleInfo . VehicleType . None ,
1054+ VehicleInfo . VehicleCategory . None ,
10501055 prevLaneIndex ,
10511056 isOnCenterPlatform ,
10521057 out int leftLaneIndex ,
@@ -1068,6 +1073,7 @@ ref nextSegmentId.ToSegment(),
10681073 nextNodeId ,
10691074 NetInfo . LaneType . Pedestrian ,
10701075 VehicleInfo . VehicleType . None ,
1076+ VehicleInfo . VehicleCategory . None ,
10711077 - 1 ,
10721078 isOnCenterPlatform ,
10731079 out _ ,
@@ -1106,6 +1112,7 @@ ref nextSegmentId.ToSegment(),
11061112 nextNodeId ,
11071113 NetInfo . LaneType . Pedestrian ,
11081114 VehicleInfo . VehicleType . None ,
1115+ VehicleInfo . VehicleCategory . None ,
11091116 - 1 ,
11101117 isOnCenterPlatform ,
11111118 out int someLeftLaneIndex ,
@@ -1138,8 +1145,8 @@ ref nextSegmentId.ToSegment(),
11381145 }
11391146
11401147 if ( leftLaneId != 0 &&
1141- ( nextLeftSegmentId != prevSegmentId || canCrossStreet ||
1142- isOnCenterPlatform ) ) {
1148+ ( nextLeftSegmentId != prevSegmentId || canCrossStreet || isOnCenterPlatform ) &&
1149+ ( ! isPedZoneRoad || ! netManager . m_segments . m_buffer [ nextLeftSegmentId ] . Info . IsPedestrianZoneOrPublicTransportRoad ( ) ) ) {
11431150 if ( isLogEnabled ) {
11441151 DebugLog (
11451152 unitId ,
@@ -1174,8 +1181,8 @@ ref leftLaneId.ToLane(),
11741181 }
11751182
11761183 if ( rightLaneId != 0 && rightLaneId != leftLaneId &&
1177- ( nextRightSegmentId != prevSegmentId || canCrossStreet ||
1178- isOnCenterPlatform ) ) {
1184+ ( nextRightSegmentId != prevSegmentId || canCrossStreet || isOnCenterPlatform ) &&
1185+ ( ! isPedZoneRoad || ! netManager . m_segments . m_buffer [ nextRightSegmentId ] . Info . IsPedestrianZoneOrPublicTransportRoad ( ) ) ) {
11791186 if ( isLogEnabled ) {
11801187 DebugLog (
11811188 unitId ,
@@ -1217,6 +1224,7 @@ ref rightLaneId.ToLane(),
12171224 item . Position . m_lane ,
12181225 NetInfo . LaneType . Vehicle ,
12191226 VehicleInfo . VehicleType . Bicycle ,
1227+ VehicleInfo . VehicleCategory . All ,
12201228 out int nextLaneIndex ,
12211229 out uint nextLaneId ) ) {
12221230 if ( isLogEnabled ) {
@@ -1251,6 +1259,35 @@ ref nextLaneId.ToLane(),
12511259 connectOffset ,
12521260 connectOffset ) ;
12531261 }
1262+
1263+ if ( isPedZoneRoad ) {
1264+ bool isPrevSegmentPedZoneRoad = prevSegmentInfo . IsPedestrianZoneOrPublicTransportRoad ( ) ;
1265+ for ( int i = 0 ; i < 8 ; i ++ )
1266+ {
1267+ ushort nextPedZoneSegmentId = nextNode . GetSegment ( i ) ;
1268+ if ( nextPedZoneSegmentId != 0 && nextPedZoneSegmentId != prevSegmentId && isPrevSegmentPedZoneRoad ) {
1269+ ProcessItemCosts (
1270+ #if DEBUG
1271+ isLogEnabled ,
1272+ unitId ,
1273+ #endif
1274+ item ,
1275+ ref prevSegment ,
1276+ ref prevLane ,
1277+ prevMaxSpeed ,
1278+ prevLaneSpeed ,
1279+ nextNodeId ,
1280+ ref nextNode ,
1281+ false ,
1282+ nextPedZoneSegmentId ,
1283+ ref nextPedZoneSegmentId . ToSegment ( ) ,
1284+ ref prevRelSimilarLaneIndex ,
1285+ connectOffset ,
1286+ false ,
1287+ true ) ;
1288+ }
1289+ }
1290+ }
12541291 } else {
12551292 if ( isLogEnabled ) {
12561293 DebugLog (
@@ -1374,6 +1411,7 @@ ref nextSegmentId.ToSegment(),
13741411 prevLaneIndex ,
13751412 nextLaneType ,
13761413 nextVehicleType ,
1414+ vehicleCategory_ ,
13771415 out int sameSegLaneIndex ,
13781416 out uint sameSegLaneId ) )
13791417 {
@@ -1660,6 +1698,8 @@ ref nextSegmentId.ToSegment(),
16601698 }
16611699 }
16621700
1701+ VehicleInfo . VehicleCategory currentVehicleCategories = VehicleInfo . VehicleCategory . None ;
1702+
16631703 if ( allowBicycle || ! prevIsRouted ) {
16641704 // pedestrian to bicycle lane switch or no routing information available:
16651705 // if pedestrian lanes should be explored (allowBicycle == true): do this here
@@ -1733,6 +1773,7 @@ ref nextSegmentId.ToSegment(),
17331773#endif
17341774 }
17351775
1776+ currentVehicleCategories |= ( netManager . m_segments . m_buffer [ nextSegmentId ] . Info . m_vehicleCategories & VehicleInfo . VehicleCategory . RoadTransport ) ;
17361777 nextSegmentId = nextSegmentId . ToSegment ( ) . GetRightSegment ( nextNodeId ) ;
17371778 }
17381779#if ROUTING
@@ -1874,6 +1915,14 @@ ref nextSegmentId.ToSegment(),
18741915 }
18751916 }
18761917#endif
1918+ VehicleInfo . VehicleCategory segmentVehicleCategories = netManager . m_segments . m_buffer [ item . Position . m_segment ] . Info . m_vehicleCategories & VehicleInfo . VehicleCategory . RoadTransport ;
1919+ if ( ! prevIsRouted && ( currentVehicleCategories & segmentVehicleCategories ) != segmentVehicleCategories ) {
1920+ DebugLog (
1921+ unitId ,
1922+ item ,
1923+ $ "ProcessItemMain: Different segment vehicle categories. Force explore U-turn. Previous value: { exploreUturn } ") ;
1924+ exploreUturn = true ;
1925+ }
18771926
18781927 if ( exploreUturn
18791928 && ( vehicleTypes_ & ( VehicleInfo . VehicleType . Tram | VehicleInfo . VehicleType . Trolleybus ) ) == VehicleInfo . VehicleType . None )
@@ -1922,6 +1971,7 @@ ref nextSegmentId.ToSegment(),
19221971 item . Position . m_lane ,
19231972 NetInfo . LaneType . Pedestrian ,
19241973 vehicleTypes_ ,
1974+ vehicleCategory_ ,
19251975 out int nextLaneIndex ,
19261976 out uint nextLaneId ) ) {
19271977 if ( isLogEnabled ) {
@@ -2141,7 +2191,7 @@ private void ProcessItemPublicTransport(
21412191 }
21422192
21432193 NetInfo . Lane nextLaneInfo = nextSegmentInfo . m_lanes [ nextLaneIndex ] ;
2144- if ( ! nextLaneInfo . CheckType ( laneTypes_ , vehicleTypes_ ) ) {
2194+ if ( ! nextLaneInfo . CheckType ( laneTypes_ , vehicleTypes_ , vehicleCategory_ ) ) {
21452195 return ;
21462196 }
21472197
@@ -2460,11 +2510,13 @@ private bool ProcessItemCosts(
24602510 // float prevLaneSpeed = 1f; // stock code commented
24612511 NetInfo . LaneType prevLaneType = NetInfo . LaneType . None ;
24622512 VehicleInfo . VehicleType prevVehicleType = VehicleInfo . VehicleType . None ;
2513+ VehicleInfo . VehicleCategory prevVehicleCategory = VehicleInfo . VehicleCategory . None ;
24632514
24642515 if ( item . Position . m_lane < prevSegmentInfo . m_lanes . Length ) {
24652516 NetInfo . Lane prevLaneInfo = prevSegmentInfo . m_lanes [ item . Position . m_lane ] ;
24662517 prevLaneType = prevLaneInfo . m_laneType ;
24672518 prevVehicleType = prevLaneInfo . m_vehicleType ;
2519+ prevVehicleCategory = prevLaneInfo . vehicleCategory ;
24682520 // prevMaxSpeed = prevLaneInfo.m_speedLimit; // stock code commented
24692521 // prevLaneSpeed = CalculateLaneSpeed(prevMaxSpeed, connectOffset,
24702522 // item.Position.m_offset, ref prevSegment, prevLaneInfo); // stock code commented
@@ -2697,11 +2749,12 @@ private bool ProcessItemCosts(
26972749 }
26982750#endif
26992751
2752+ var currentVehicleCategory = vehicleCategory_ ;
27002753 // NON-STOCK CODE END
27012754 for ( ; nextLaneIndex <= maxNextLaneIndex && nextLaneId != 0 ; nextLaneIndex ++ ) {
27022755 NetInfo . Lane nextLaneInfo = nextSegmentInfo . m_lanes [ nextLaneIndex ] ;
27032756 if ( ( nextLaneInfo . m_finalDirection & nextFinalDir ) != NetInfo . Direction . None ) {
2704- if ( nextLaneInfo . CheckType ( allowedLaneTypes , allowedVehicleTypes ) &&
2757+ if ( nextLaneInfo . CheckType ( allowedLaneTypes , allowedVehicleTypes , currentVehicleCategory ) &&
27052758 ( nextSegmentId != item . Position . m_segment ||
27062759 nextLaneIndex != item . Position . m_lane ) ) {
27072760 if ( acuteTurningAngle &&
@@ -3015,8 +3068,9 @@ private bool ProcessItemCosts(
30153068#endif
30163069
30173070 if ( ( nextLaneInfo . m_laneType & prevLaneType ) != NetInfo . LaneType . None &&
3018- ( nextLaneInfo . m_vehicleType & vehicleTypes_ ) !=
3019- VehicleInfo . VehicleType . None ) {
3071+ ( nextLaneInfo . m_vehicleType & vehicleTypes_ ) != VehicleInfo . VehicleType . None &&
3072+ ( nextLaneInfo . vehicleCategory & vehicleCategory_ ) != VehicleInfo . VehicleCategory . None ) {
3073+
30203074#if ADVANCEDAI && ROUTING
30213075 if ( ! enableAdvancedAI ) {
30223076#endif
@@ -3052,6 +3106,12 @@ private bool ProcessItemCosts(
30523106 }
30533107 }
30543108
3109+ if ( ( nextLaneInfo . vehicleCategory & VehicleInfo . VehicleCategory . PublicTransportRoad ) != 0 &&
3110+ ( nextLaneInfo . vehicleCategory & ~ ( VehicleInfo . VehicleCategory . Bus | VehicleInfo . VehicleCategory . Trolleybus | VehicleInfo . VehicleCategory . Taxi ) ) == 0 )
3111+ {
3112+ nextItem . ComparisonValue /= 100f ;
3113+ }
3114+
30553115 if ( isLogEnabled ) {
30563116 DebugLog (
30573117 unitId ,
@@ -3096,8 +3156,8 @@ private bool ProcessItemCosts(
30963156 }
30973157
30983158 if ( ( nextLaneInfo . m_laneType & prevLaneType ) != NetInfo . LaneType . None &&
3099- ( nextLaneInfo . m_vehicleType & prevVehicleType ) !=
3100- VehicleInfo . VehicleType . None ) {
3159+ ( nextLaneInfo . m_vehicleType & prevVehicleType ) != VehicleInfo . VehicleType . None &&
3160+ ( nextLaneInfo . vehicleCategory & prevVehicleCategory ) != VehicleInfo . VehicleCategory . None ) {
31013161 newLaneIndexFromInner ++ ;
31023162 }
31033163 }
@@ -3309,7 +3369,7 @@ private void ProcessItemPedBicycle(
33093369 if ( ( nextLaneInfo . m_laneType & prevLaneType ) == NetInfo . LaneType . None ) {
33103370 nextItem . MethodDistance = 0f ;
33113371 } else {
3312- if ( item . MethodDistance == 0f ) { // TODO fixme: Float comparison to 0
3372+ if ( FloatUtil . IsZero ( item . MethodDistance ) ) {
33133373 comparisonValue += 100f / ( 0.25f * maxLength_ ) ;
33143374 }
33153375
0 commit comments