Beispiel #1
0
        /// <summary>
        /// separates turning lanes for all segments attached to nodeId,
        /// </summary>
        public static void SeparateNode(ushort nodeId, out SetLaneArrow_Result res, bool alternativeMode = true) {
            NetNode node = Singleton<NetManager>.instance.m_nodes.m_buffer[nodeId];
            if (nodeId == 0) {
                res = SetLaneArrow_Result.Invalid;
                return;
            }
            if ((node.m_flags & NetNode.Flags.Created) == NetNode.Flags.None) {
                res = SetLaneArrow_Result.Invalid;
                return;
            }
            if (LaneConnectionManager.Instance.HasNodeConnections(nodeId)) {
                res = SetLaneArrow_Result.LaneConnection;
                return;
            }
            if (Options.highwayRules && ExtNodeManager.JunctionHasHighwayRules(nodeId)) {
                res = SetLaneArrow_Result.HighwayArrows;
                return;
            }
            res = SetLaneArrow_Result.Success;

            for (int i = 0; i < 8; i++) {
                ushort segmentId = Singleton<NetManager>.instance.m_nodes.m_buffer[nodeId].GetSegment(i);
                if (segmentId == 0) {
                    continue;
                }
                SeparateSegmentLanes(segmentId, nodeId, out res, alternativeMode);
            }
            Debug.Assert(res == SetLaneArrow_Result.Success);
        }
        /// <summary>
        /// separates turning lanes for the input segment on the input node.
        /// <param name="alt2">alternativ mode for two lanes(dedicated near turn)</param>
        /// <param name="alt3">alternative mode for 3+ lanes(favour forward)</param>
        /// <param name="altBus">alternative mode for roads with bs lanes(mixed VS separate caluclations)</param>
        /// </summary>
        public static void SeparateSegmentLanes(
            ushort segmentId,
            ushort nodeId,
            out SetLaneArrow_Result res,
            bool alternativeMode = true)
        {
            bool alt2        = alternativeMode; // alt mode for 2 lanes
            bool alt3        = alternativeMode; // alt mode for 3+ lanes
            bool altBus      = alternativeMode; // alt mode if lanes include bus lane[s].
            bool hasBusLanes = CountBusLanes(segmentId, nodeId) > 0;

            LaneArrowManager.Instance.ResetLaneArrows(segmentId, netService.IsStartNode(segmentId, nodeId));

            if (!hasBusLanes)
            {
                SeparateSegmentLanes(
                    segmentId,
                    nodeId,
                    out res,
                    LaneArrowManager.LANE_TYPES,
                    LaneArrowManager.VEHICLE_TYPES,
                    alt2,
                    alt3);
            }
            else
            {
                if (altBus)
                {
                    SeparateSegmentLanes(
                        segmentId,
                        nodeId,
                        out res,
                        LaneArrowManager.LANE_TYPES,
                        LaneArrowManager.VEHICLE_TYPES);
                }
                else
                {
                    SeparateSegmentLanes(
                        segmentId,
                        nodeId,
                        out res,
                        NetInfo.LaneType.Vehicle,
                        LaneArrowManager.VEHICLE_TYPES);
                    SeparateSegmentLanes(
                        segmentId,
                        nodeId,
                        out res,
                        NetInfo.LaneType.TransportVehicle,
                        LaneArrowManager.VEHICLE_TYPES);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Toggles a lane arrows (user or default) on and off for the directions where flag is set.
        /// overrides default settings for the arrows that change.
        /// default arrows may change as user connects or remove more segments to the junction but
        /// the user arrows stay the same no matter what.
        /// </summary>
        public bool ToggleLaneArrows(uint laneId,
                                     bool startNode,
                                     LaneArrows flags,
                                     out SetLaneArrow_Result res)
        {
            if (Flags.ToggleLaneArrowFlags(laneId, startNode, flags, out res))
            {
                OnLaneChange(laneId);
                return(true);
            }

            return(false);
        }
Beispiel #4
0
        private static void SeparateSegmentLanes(
            ushort segmentId,
            ushort nodeId,
            out SetLaneArrow_Result res,
            NetInfo.LaneType laneType,
            VehicleInfo.VehicleType vehicleType,
            bool alt2 = false,
            bool alt3 = false) {
            res = CanChangeLanes(segmentId, nodeId);
            if (res != SetLaneArrow_Result.Success) {
                return;
            }
            res = SetLaneArrow_Result.Success;

            ref NetSegment seg = ref segmentId.ToSegment();
Beispiel #5
0
        public static bool ToggleLaneArrowFlags(uint laneId,
                                                bool startNode,
                                                LaneArrows flags,
                                                out SetLaneArrow_Result res)
        {
            if (!CanHaveLaneArrows(laneId))
            {
                RemoveLaneArrowFlags(laneId);
                res = SetLaneArrow_Result.Invalid;
                return(false);
            }

            if (highwayLaneArrowFlags[laneId] != null)
            {
                res = SetLaneArrow_Result.HighwayArrows;
                return(false); // disallow custom lane arrows in highway rule mode
            }

            if (LaneConnectionManager.Instance.HasConnections(laneId, startNode))
            {
                // TODO refactor
                res = SetLaneArrow_Result.LaneConnection;
                return(false); // custom lane connection present
            }

            LaneArrows?arrows = laneArrowFlags[laneId];

            if (arrows == null)
            {
                // read currently defined arrows
                uint laneFlags = Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_flags;
                laneFlags &= lfr; // filter arrows
                arrows     = (LaneArrows)laneFlags;
            }

            arrows ^= flags;
            laneArrowFlags[laneId] = arrows;
            if (ApplyLaneArrowFlags(laneId, false))
            {
                res = SetLaneArrow_Result.Success;
                return(true);
            }

            res = SetLaneArrow_Result.Invalid;
            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// If Lane Arrow operation ended with failure, pop up a guide box with an explanation.
        /// </summary>
        /// <param name="result">Result coming out of LaneArrowManager function call.</param>
        internal void InformUserAboutPossibleFailure(SetLaneArrow_Result result)
        {
            switch (result)
            {
            case SetLaneArrow_Result.HighwayArrows: {
                MainTool.Guide.Activate("LaneArrowTool_Disabled due to highway rules");
                break;
            }

            case SetLaneArrow_Result.LaneConnection: {
                MainTool.Guide.Activate("LaneArrowTool_Disabled due to lane connections");
                break;
            }

            case SetLaneArrow_Result.Success:
                MainTool.Guide.Deactivate("LaneArrowTool_Disabled due to highway rules");
                MainTool.Guide.Deactivate("LaneArrowTool_Disabled due to lane connections");
                break;
            }
        }