/// <summary>Produces list of speed limits to offer user in the palette.</summary>
        /// <param name="unit">What kind of speed limit list is required.</param>
        /// <returns>
        ///     List from smallest to largest speed with the given unit. Zero (no limit) is
        ///     not added to the list. The values are in-game speeds as float.
        /// </returns>
        public static List <SetSpeedLimitAction> AllSpeedLimits(SpeedUnit unit)
        {
            var result = new List <SetSpeedLimitAction>();

            // SpeedLimitTextures textures = TMPELifecycle.Instance.Textures.SpeedLimits;

            switch (unit)
            {
            case SpeedUnit.Kmph:
                for (var km = RoadSignThemes.KMPH_STEP;
                     km <= RoadSignThemes.UPPER_KMPH;
                     km += RoadSignThemes.KMPH_STEP)
                {
                    result.Add(SetSpeedLimitAction.SetOverride(SpeedValue.FromKmph(km)));
                }

                break;

            case SpeedUnit.Mph:
                for (var mi = RoadSignThemes.MPH_STEP;
                     mi <= RoadSignThemes.UPPER_MPH;
                     mi += RoadSignThemes.MPH_STEP)
                {
                    result.Add(SetSpeedLimitAction.SetOverride(SpeedValue.FromMph(mi)));
                }

                break;

            case SpeedUnit.CurrentlyConfigured:
                // Automatically choose from the config
                return(AllSpeedLimits(GlobalConfig.Instance.Main.GetDisplaySpeedUnit()));
            }

            return(result);
        }
Пример #2
0
        private static void FixSegmentRoundabout(ushort segmentId, ushort nextSegmentId) {
            if (OptionsMassEditTab.RoundAboutQuickFix_ParkingBanMainR) {
                ParkingRestrictionsManager.Instance.SetParkingAllowed(segmentId, false);
            }

            if (OptionsMassEditTab.RoundAboutQuickFix_RealisticSpeedLimits) {
                SpeedValue? targetSpeed = CalculatePreferedSpeed(segmentId);
                float defaultSpeed = SpeedLimitManager.Instance.CalculateCustomNetinfoSpeedLimit(segmentId.ToSegment().Info);

                if (targetSpeed != null && targetSpeed.Value.GetKmph() < defaultSpeed) {
                    SpeedLimitManager.Instance.SetSegmentSpeedLimit(
                        segmentId: segmentId,
                        finalDir: NetInfo.Direction.Forward,
                        action: SetSpeedLimitAction.SetOverride(targetSpeed.Value));
                    SpeedLimitManager.Instance.SetSegmentSpeedLimit(
                        segmentId: segmentId,
                        finalDir: NetInfo.Direction.Backward,
                        action: SetSpeedLimitAction.SetOverride(targetSpeed.Value));
                }
            }

            ushort nodeId = ExtSegmentManager.Instance.GetHeadNode(segmentId);

            if (OptionsMassEditTab.RoundAboutQuickFix_StayInLaneMainR && !HasJunctionFlag(nodeId)) {
                StayInLane(nodeId, StayInLaneMode.Both);
            }

            // allocation of dedicated exit lanes is supported only when the roundabout is round
            // in which case the next segment should be straigh ahead.
            bool isStraight = segEndMan.GetDirection(segmentId, nextSegmentId, nodeId) == ArrowDirection.Forward;

            if (OptionsMassEditTab.RoundAboutQuickFix_DedicatedExitLanes &&
                HasJunctionFlag(nodeId) &&
                SeparateTurningLanesUtil.CanChangeLanes(
                    segmentId, nodeId) == SetLaneArrow_Result.Success &&
                    isStraight) {

                bool startNode = (bool)ExtSegmentManager.Instance.IsStartNode(segmentId, nodeId);
                ExtSegmentManager extSegmentManager = ExtSegmentManager.Instance;
                IList<LanePos> laneList =
                    extSegmentManager.GetSortedLanes(
                        segmentId,
                        ref segmentId.ToSegment(),
                        startNode,
                        LaneArrowManager.LANE_TYPES,
                        LaneArrowManager.VEHICLE_TYPES,
                        true);
                int nSrc = laneList.Count;

                // check for exits.
                segEndMan.CalculateOutgoingLeftStraightRightSegments(
                    ref GetSegEnd(segmentId, nodeId),
                    ref nodeId.ToNode(),
                    out bool bLeft,
                    out bool bForward,
                    out bool bRight);

                //Set one dedicated exit lane per exit - if there are enough lanes that is.
                switch (nSrc) {
                    case 0:
                        Debug.LogAssertion("The road is the wrong way around.");
                        break;
                    case 1:
                        break; // not enough lanes Use default settings.
                    case 2:
                        if (bRight && bLeft) {
                            // not enough lanes, use default settings
                        } else if (bRight) {
                            LaneArrowManager.Instance.SetLaneArrows(laneList[0].laneId, LaneArrows.Forward);
                            LaneArrowManager.Instance.SetLaneArrows(laneList[1].laneId, LaneArrows.Right);
                        } else if (bLeft) {
                            LaneArrowManager.Instance.SetLaneArrows(laneList[0].laneId, LaneArrows.Left);
                            LaneArrowManager.Instance.SetLaneArrows(laneList[1].laneId, LaneArrows.Forward);
                        } else {
                            LaneArrowManager.Instance.SetLaneArrows(laneList[0].laneId, LaneArrows.Forward);
                            LaneArrowManager.Instance.SetLaneArrows(laneList[1].laneId, LaneArrows.Forward);
                        }
                        break;
                    default:
                        for (int i = 0; i < laneList.Count; ++i) {
                            LaneArrowManager.Instance.SetLaneArrows(laneList[i].laneId, LaneArrows.Forward);
                        }
                        if (bRight) {
                            LaneArrowManager.Instance.SetLaneArrows(laneList[nSrc - 1].laneId, LaneArrows.Right);
                        }
                        if (bLeft) {
                            LaneArrowManager.Instance.SetLaneArrows(laneList[0].laneId, LaneArrows.Left);
                        }
                        break;
                } // end switch
            } // end if
        }