Esempio n. 1
0
        /// <summary>
        /// Creates a the road between 2 intersections
        /// </summary>
        /// <param name="source">Source intersection</param>
        /// <param name="target">Target intersection</param>
        /// <param name="numInLanes">Numlanes along negative orientation</param>
        /// <param name="numOutLanes">Numlanes along positive orientation</param>
        /// <param name="speedLimit">Speed limit</param>
        public Road(
            ref FourWayIntersection source, ref FourWayIntersection target,
            int numInLanes, int numOutLanes,
            float speedLimit)
        {
            this.SpeedLimit = speedLimit;

            SourceIntersection = source;
            TargetIntersection = target;

            this.NumInLanes  = numInLanes;
            this.NumOutLanes = numOutLanes;
            InLanes          = InitLanes(numInLanes, SourceIntersection);
            OutLanes         = InitLanes(numOutLanes, TargetIntersection);

            SourceIntersection.AddRoad(this);
            TargetIntersection.AddRoad(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize lanes heading the same direction, supply neighbor information, and target intersection info
        /// </summary>
        /// <param name="numLanes">Number of lanes</param>
        /// <param name="laneTargetIntersection">Target intersection</param>
        /// <returns></returns>
        private Lane[] InitLanes(int numLanes, FourWayIntersection laneTargetIntersection)
        {
            // Create the lanes
            Lane[] lanes = new Lane[numLanes];
            for (int i = 0; i < numLanes; i++)
            {
                lanes[i] = new Lane(i, SpeedLimit, laneTargetIntersection);
            }

            // Setup lane neighbors
            for (int i = 0; i < numLanes; i++)
            {
                // Get lane neighbors
                Lane[] neighboringLanes;
                if (0 < i && i < numLanes - 1)
                {
                    neighboringLanes = new Lane[] {
                        lanes[i - 1],
                        lanes[i + 1]
                    };
                }
                else if (numLanes > 1)
                {
                    neighboringLanes = new Lane[] {
                        i == 0 ? lanes[i + 1] : lanes[i - 1]
                    };
                }
                else
                {
                    // no neighboring lanes -> empty array
                    neighboringLanes = new Lane[0];
                }

                lanes[i].NeighboringLanes = neighboringLanes;
            }

            return(lanes);
        }