@@ -12,6 +12,9 @@ namespace TrafficManager.Manager.Impl {
12
12
using TrafficManager . State . ConfigData ;
13
13
using TrafficManager . State ;
14
14
using TrafficManager . Traffic ;
15
+ using static TrafficManager . Util . Shortcuts ;
16
+ using static CSUtil . Commons . TernaryBoolUtil ;
17
+ using TrafficManager . Util ;
15
18
16
19
public class JunctionRestrictionsManager
17
20
: AbstractGeometryObservingManager ,
@@ -743,6 +746,54 @@ public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) {
743
746
! IsPedestrianCrossingAllowed ( segmentId , startNode ) ) ;
744
747
}
745
748
749
+ public bool SetUturnAllowed ( ushort segmentId , bool startNode , bool value ) {
750
+ return SetUturnAllowed ( segmentId , startNode , ToTernaryBool ( value ) ) ;
751
+ }
752
+
753
+ public bool SetNearTurnOnRedAllowed ( ushort segmentId , bool startNode , bool value ) {
754
+ return SetNearTurnOnRedAllowed ( segmentId , startNode , ToTernaryBool ( value ) ) ;
755
+ }
756
+
757
+ public bool SetFarTurnOnRedAllowed ( ushort segmentId , bool startNode , bool value ) {
758
+ return SetFarTurnOnRedAllowed ( segmentId , startNode , ToTernaryBool ( value ) ) ;
759
+ }
760
+
761
+ public bool SetTurnOnRedAllowed ( bool near , ushort segmentId , bool startNode , bool value ) {
762
+ return SetTurnOnRedAllowed ( near , segmentId , startNode , ToTernaryBool ( value ) ) ;
763
+ }
764
+
765
+ public bool SetLaneChangingAllowedWhenGoingStraight ( ushort segmentId , bool startNode , bool value ) {
766
+ return SetLaneChangingAllowedWhenGoingStraight (
767
+ segmentId ,
768
+ startNode ,
769
+ ToTernaryBool ( value ) ) ;
770
+ }
771
+
772
+ public bool SetEnteringBlockedJunctionAllowed ( ushort segmentId , bool startNode , bool value ) {
773
+ return SetEnteringBlockedJunctionAllowed (
774
+ segmentId ,
775
+ startNode ,
776
+ ToTernaryBool ( value ) ) ;
777
+ }
778
+
779
+ public bool SetPedestrianCrossingAllowed ( ushort segmentId , bool startNode , bool value ) {
780
+ return SetPedestrianCrossingAllowed (
781
+ segmentId ,
782
+ startNode ,
783
+ ToTernaryBool ( value ) ) ;
784
+ }
785
+
786
+ public bool ClearSegmentEnd ( ushort segmentId , bool startNode ) {
787
+ bool ret = true ;
788
+ ret |= SetPedestrianCrossingAllowed ( segmentId , startNode , TernaryBool . Undefined ) ;
789
+ ret |= SetEnteringBlockedJunctionAllowed ( segmentId , startNode , TernaryBool . Undefined ) ;
790
+ ret |= SetLaneChangingAllowedWhenGoingStraight ( segmentId , startNode , TernaryBool . Undefined ) ;
791
+ ret |= SetFarTurnOnRedAllowed ( segmentId , startNode , TernaryBool . Undefined ) ;
792
+ ret |= SetNearTurnOnRedAllowed ( segmentId , startNode , TernaryBool . Undefined ) ;
793
+ ret |= SetUturnAllowed ( segmentId , startNode , TernaryBool . Undefined ) ;
794
+ return ret ;
795
+ }
796
+
746
797
private void SetSegmentEndFlags ( ushort segmentId , bool startNode , SegmentEndFlags flags ) {
747
798
if ( flags . uturnAllowed != TernaryBool . Undefined ) {
748
799
SetUturnAllowed ( segmentId , startNode , flags . IsUturnAllowed ( ) ) ;
@@ -753,7 +804,7 @@ private void SetSegmentEndFlags(ushort segmentId, bool startNode, SegmentEndFlag
753
804
}
754
805
755
806
if ( flags . nearTurnOnRedAllowed != TernaryBool . Undefined ) {
756
- SetFarTurnOnRedAllowed ( segmentId , startNode , flags . IsFarTurnOnRedAllowed ( ) ) ;
807
+ SetFarTurnOnRedAllowed ( segmentId , startNode , flags . IsNearTurnOnRedAllowed ( ) ) ;
757
808
}
758
809
759
810
if ( flags . straightLaneChangingAllowed != TernaryBool . Undefined ) {
@@ -778,12 +829,27 @@ private void SetSegmentEndFlags(ushort segmentId, bool startNode, SegmentEndFlag
778
829
}
779
830
}
780
831
781
- public bool SetUturnAllowed ( ushort segmentId , bool startNode , bool value ) {
832
+
833
+ private static ref NetNode GetNode ( ushort segmentId , bool startNode ) {
834
+ ref NetSegment segment = ref GetSeg ( segmentId ) ;
835
+ ushort nodeId = startNode ? segment . m_startNode : segment . m_endNode ;
836
+ return ref Shortcuts . GetNode ( nodeId ) ;
837
+ }
838
+
839
+ #region Set<Traffic Rule>Allowed: TernaryBool
840
+
841
+ public bool SetUturnAllowed ( ushort segmentId , bool startNode , TernaryBool value ) {
782
842
if ( ! Services . NetService . IsSegmentValid ( segmentId ) ) {
783
843
return false ;
784
844
}
845
+ if ( GetUturnAllowed ( segmentId , startNode ) == value ) {
846
+ return true ;
847
+ }
848
+ if ( ! IsUturnAllowedConfigurable ( segmentId , startNode , ref GetNode ( segmentId , startNode ) ) ) {
849
+ return false ;
850
+ }
785
851
786
- if ( ! value && Constants . ManagerFactory . LaneConnectionManager . HasUturnConnections (
852
+ if ( value == TernaryBool . False && Constants . ManagerFactory . LaneConnectionManager . HasUturnConnections (
787
853
segmentId ,
788
854
startNode ) ) {
789
855
return false ;
@@ -798,18 +864,30 @@ public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) {
798
864
return true ;
799
865
}
800
866
801
- public bool SetNearTurnOnRedAllowed ( ushort segmentId , bool startNode , bool value ) {
867
+ public bool SetNearTurnOnRedAllowed ( ushort segmentId , bool startNode , TernaryBool value ) {
802
868
return SetTurnOnRedAllowed ( true , segmentId , startNode , value ) ;
803
869
}
804
870
805
- public bool SetFarTurnOnRedAllowed ( ushort segmentId , bool startNode , bool value ) {
871
+ public bool SetFarTurnOnRedAllowed ( ushort segmentId , bool startNode , TernaryBool value ) {
806
872
return SetTurnOnRedAllowed ( false , segmentId , startNode , value ) ;
807
873
}
808
874
809
- public bool SetTurnOnRedAllowed ( bool near , ushort segmentId , bool startNode , bool value ) {
875
+ public bool SetTurnOnRedAllowed ( bool near , ushort segmentId , bool startNode , TernaryBool value ) {
810
876
if ( ! Services . NetService . IsSegmentValid ( segmentId ) ) {
811
877
return false ;
812
878
}
879
+ if ( GetTurnOnRedAllowed ( near , segmentId , startNode ) == value ) {
880
+ return true ;
881
+ }
882
+ if ( ! IsTurnOnRedAllowedConfigurable ( near , segmentId , startNode , ref GetNode ( segmentId , startNode ) ) ) {
883
+ return false ;
884
+ }
885
+
886
+ if ( value == TernaryBool . False && Constants . ManagerFactory . LaneConnectionManager . HasUturnConnections (
887
+ segmentId ,
888
+ startNode ) ) {
889
+ return false ;
890
+ }
813
891
814
892
if ( near ) {
815
893
segmentFlags_ [ segmentId ] . SetNearTurnOnRedAllowed ( startNode , value ) ;
@@ -823,10 +901,16 @@ public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, boo
823
901
public bool SetLaneChangingAllowedWhenGoingStraight (
824
902
ushort segmentId ,
825
903
bool startNode ,
826
- bool value ) {
904
+ TernaryBool value ) {
827
905
if ( ! Services . NetService . IsSegmentValid ( segmentId ) ) {
828
906
return false ;
829
907
}
908
+ if ( GetLaneChangingAllowedWhenGoingStraight ( segmentId , startNode ) == value ) {
909
+ return true ;
910
+ }
911
+ if ( ! IsLaneChangingAllowedWhenGoingStraightConfigurable ( segmentId , startNode , ref GetNode ( segmentId , startNode ) ) ) {
912
+ return false ;
913
+ }
830
914
831
915
segmentFlags_ [ segmentId ] . SetLaneChangingAllowedWhenGoingStraight ( startNode , value ) ;
832
916
OnSegmentChange (
@@ -837,11 +921,16 @@ public bool SetLaneChangingAllowedWhenGoingStraight(
837
921
return true ;
838
922
}
839
923
840
- public bool
841
- SetEnteringBlockedJunctionAllowed ( ushort segmentId , bool startNode , bool value ) {
924
+ public bool SetEnteringBlockedJunctionAllowed ( ushort segmentId , bool startNode , TernaryBool value ) {
842
925
if ( ! Services . NetService . IsSegmentValid ( segmentId ) ) {
843
926
return false ;
844
927
}
928
+ if ( GetEnteringBlockedJunctionAllowed ( segmentId , startNode ) == value ) {
929
+ return true ;
930
+ }
931
+ if ( ! IsEnteringBlockedJunctionAllowedConfigurable ( segmentId , startNode , ref GetNode ( segmentId , startNode ) ) ) {
932
+ return false ;
933
+ }
845
934
846
935
segmentFlags_ [ segmentId ] . SetEnteringBlockedJunctionAllowed ( startNode , value ) ;
847
936
@@ -854,10 +943,17 @@ public bool
854
943
return true ;
855
944
}
856
945
857
- public bool SetPedestrianCrossingAllowed ( ushort segmentId , bool startNode , bool value ) {
946
+ public bool SetPedestrianCrossingAllowed ( ushort segmentId , bool startNode , TernaryBool value ) {
858
947
if ( ! Services . NetService . IsSegmentValid ( segmentId ) ) {
859
948
return false ;
860
949
}
950
+ if ( GetPedestrianCrossingAllowed ( segmentId , startNode ) == value ) {
951
+ return true ;
952
+ }
953
+ if ( ! IsPedestrianCrossingAllowedConfigurable ( segmentId , startNode , ref GetNode ( segmentId , startNode ) ) ) {
954
+ return false ;
955
+ }
956
+
861
957
862
958
segmentFlags_ [ segmentId ] . SetPedestrianCrossingAllowed ( startNode , value ) ;
863
959
OnSegmentChange (
@@ -868,6 +964,8 @@ public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool
868
964
return true ;
869
965
}
870
966
967
+ #endregion
968
+
871
969
private void OnSegmentChange ( ushort segmentId ,
872
970
bool startNode ,
873
971
ref ExtSegment seg ,
0 commit comments