Esempio n. 1
0
        private Crossing(PointD location, CrossingData crossingdata, params RoadConnection[] roadconnections)
        {
            cornerpoints = new PointD[2*roadconnections.Length];
            lanelist = new List<CrossingLane>();
            linewidth = crossingdata.LineWidth;
            this.location = location;
            roadlist = new List<Road>();
            trafficlightsystem = new TrafficLightSystem(this);

            #region SortRoads

            List<RoadConnection> roadconnectionlist = roadconnections.ToList();
            // Bepaal het SortingPoint van elke Road. Dit is het uiteinde van de Road dat bij de Crossing uitkomt.
            foreach (RoadConnection t in roadconnectionlist)
                t.Road.SortPoint = t.Road.GetTowardCoordinate(location);

            // Sorteer de Roads die op de Crossing samenkomen tegen de klik in.
            roadconnectionlist.Sort(
                (r1, r2) => Math.Atan2(r2.Road.SortPoint.Y - location.Y, r2.Road.SortPoint.X - location.X).CompareTo(
                    Math.Atan2(r1.Road.SortPoint.Y - location.Y, r1.Road.SortPoint.X - location.X)));

            #endregion

            #region MakeCrossingLanes

            for (int i = 0; i < roadconnectionlist.Count; i++)
            {
                Road road = roadconnectionlist[i].Road;
                roadlist.Add(road);

                // Bepaal de hoekpunten van de Crossing bij elke Road.
                if (road.IsToward(location))
                {
                    cornerpoints[2*i] = road.GetLastCoordinate() +
                                        road.GetLastDirection().GetLeftHandNormal()*road.Width/2;
                    cornerpoints[2*i + 1] = road.GetLastCoordinate() +
                                            road.GetLastDirection().GetRightHandNormal()*road.Width/2;
                    road.SetNext(this);
                }
                else
                {
                    cornerpoints[2*i] = road.GetFirstCoordinate() +
                                        road.GetFirstDirection().GetRightHandNormal()*road.Width/2;
                    cornerpoints[2*i + 1] = road.GetFirstCoordinate() +
                                            road.GetFirstDirection().GetLeftHandNormal()*road.Width/2;
                    road.SetPrevious(this);
                }

                Dictionary<int, HashSet<RoadLaneIndex>> connectiondictionary =
                    roadconnectionlist[i].ConnectionDictionary;
                List<RoadLane> road1lanelist = roadconnectionlist[i].Road.GetTowardLanes(location);

                // Verbind de Lanes van de Roads met elkaar zoals beschreven in de PDF
                foreach (int lane1 in connectiondictionary.Keys)
                {
                    var vehiclelist = new List<Vehicle>();
                    HashSet<RoadLaneIndex> roadlaneindexhashset = connectiondictionary[lane1];
                    var trafficlight = new TrafficLight(road1lanelist[lane1], road1lanelist[lane1].GetLastCoordinate());

                    foreach (RoadLaneIndex roadlaneindex in roadlaneindexhashset)
                    {
                        int road2index = (i + roadlaneindex.Road)%roadconnectionlist.Count;
                        List<RoadLane> road2lanelist = roadconnectionlist[road2index].Road.GetOffwardLanes(location);

                        trafficlight.AddExitLane(road2lanelist[roadlaneindex.Lane]);

                        lanelist.Add(new CrossingLane(this, road1lanelist[lane1], road2lanelist[roadlaneindex.Lane],
                                                      road1lanelist[lane1].Width, vehiclelist));
                    }

                    if (road1lanelist[lane1].LaneType == LaneType.Shoulder) continue;
                    trafficlightsystem.AddTrafficLight(road, trafficlight);
                    road1lanelist[lane1].TrafficLight = trafficlight;
                }
            }

            #endregion

            MakeCrossingGraphicsPath();
        }
Esempio n. 2
0
        private void makemap()
        {
            var speeddictionary = new Dictionary<string, double>();

            var crossingdata = new CrossingData(0.15);

            // Snelheden van Vehicle typen
            speeddictionary.Add("Bus", 80/3.6);
            speeddictionary.Add("Car", 120/3.6);
            speeddictionary.Add("Motorcycle", 120/3.6);
            speeddictionary.Add("Truck", 80/3.6);
            speeddictionary.Add("Vehicle", 120/3.6);
            var roaddata = new RoadData(RoadType.Highway, speeddictionary, Color.Gray, Color.White, 4, 4, true, true,
                                        3.5, 3, 0.15, 9);

            // Bepaal via welke Lane je waarheen mag zoals beschreven in de PDF voor symmetrische Crossings

            var connectiondictionary1 = new Dictionary<int, HashSet<RoadLaneIndex>>();

            var roadlaneindexhashset = new HashSet<RoadLaneIndex>
                {new RoadLaneIndex(3, 0), new RoadLaneIndex(3, 1), new RoadLaneIndex(3, 2)};
            connectiondictionary1.Add(0, roadlaneindexhashset);

            roadlaneindexhashset = new HashSet<RoadLaneIndex>
                {new RoadLaneIndex(2, 0), new RoadLaneIndex(2, 1), new RoadLaneIndex(2, 2)};
            connectiondictionary1.Add(1, roadlaneindexhashset);

            roadlaneindexhashset = new HashSet<RoadLaneIndex>
                {new RoadLaneIndex(1, 0), new RoadLaneIndex(1, 1), new RoadLaneIndex(1, 2)};
            connectiondictionary1.Add(2, roadlaneindexhashset);

            roadlaneindexhashset = new HashSet<RoadLaneIndex> {new RoadLaneIndex(1, 3)};
            connectiondictionary1.Add(3, roadlaneindexhashset);

            // Leg de Roads neer.

            if (!buggedmap)
            {
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-1450, -500, -550, -500)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-450, -500, 450, -500)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(550, -500, 1500, -500)}));

                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-1450, 500, -550, 500)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-450, 500, 450, 500)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(550, 500, 1500, 500)}));

                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-500, -1500, -500, -550)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-500, -450, -500, 450)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-500, 550, -500, 1500)}));

                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(500, -1500, 500, -550)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(500, -450, 500, 450)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(500, 550, 500, 1500)}));

                roadlist.Add(new Road(roaddata,
                                      new Bezier[]
                                          {
                                              new CubicBezier(-3500, -2500, -3000, -2500, -2500, -2000, -2000, -2000),
                                              new CircularBezier(-2000, -2000, -2000, -1500, -1500, -1500),
                                              new LinearBezier(-1500, -1500, -1500, -550)
                                          })); // 12
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-1500, -450, -1500, 450)}));
                roadlist.Add(new Road(roaddata,
                                      new Bezier[]
                                          {
                                              new LinearBezier(-1500, 550, -1500, 1500),
                                              new CircularBezier(-1500, 1500, -2000, 1500, -2000, 2000),
                                              new QuadraticBezier(-2000, 2000, -2500, 2000, -2500, 1500)
                                          }));

                // Voeg de Crossings toe.

                crossinglist.Add(new Crossing(-500, -500, crossingdata,
                                              new RoadConnection(roadlist[0], connectiondictionary1),
                                              new RoadConnection(roadlist[1], connectiondictionary1),
                                              new RoadConnection(roadlist[6], connectiondictionary1),
                                              new RoadConnection(roadlist[7], connectiondictionary1)));
                crossinglist.Add(new Crossing(500, -500, crossingdata,
                                              new RoadConnection(roadlist[1], connectiondictionary1),
                                              new RoadConnection(roadlist[2], connectiondictionary1),
                                              new RoadConnection(roadlist[9], connectiondictionary1),
                                              new RoadConnection(roadlist[10], connectiondictionary1)));
                crossinglist.Add(new Crossing(-500, 500, crossingdata,
                                              new RoadConnection(roadlist[3], connectiondictionary1),
                                              new RoadConnection(roadlist[4], connectiondictionary1),
                                              new RoadConnection(roadlist[7], connectiondictionary1),
                                              new RoadConnection(roadlist[8], connectiondictionary1)));
                crossinglist.Add(new Crossing(500, 500, crossingdata,
                                              new RoadConnection(roadlist[4], connectiondictionary1),
                                              new RoadConnection(roadlist[5], connectiondictionary1),
                                              new RoadConnection(roadlist[10], connectiondictionary1),
                                              new RoadConnection(roadlist[11], connectiondictionary1)));
            }

            else
            {
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-600, -500, -600, -50)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-600, 50, -600, 250)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-950, 0, -650, 0)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(-550, 0, -50, 0)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(50, 0, 350, 0)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(0, -250, 0, -50)}));
                roadlist.Add(new Road(roaddata, new Bezier[] {new LinearBezier(0, 50, 0, 600)}));

                crossinglist.Add(new Crossing(-600, 0, crossingdata,
                                              new RoadConnection(roadlist[0], connectiondictionary1),
                                              new RoadConnection(roadlist[1], connectiondictionary1),
                                              new RoadConnection(roadlist[2], connectiondictionary1),
                                              new RoadConnection(roadlist[3], connectiondictionary1)));
                crossinglist.Add(new Crossing(0, 0, crossingdata, new RoadConnection(roadlist[3], connectiondictionary1),
                                              new RoadConnection(roadlist[4], connectiondictionary1),
                                              new RoadConnection(roadlist[5], connectiondictionary1),
                                              new RoadConnection(roadlist[6], connectiondictionary1)));
            }

            if (!buggedmap)
            {
                //Bepaal via welke Lane je waarheen mag zoals beschreven in de PDF voor T Crossings.
                connectiondictionary1 = new Dictionary<int, HashSet<RoadLaneIndex>>();
                var connectiondictionary2 = new Dictionary<int, HashSet<RoadLaneIndex>>();
                var connectiondictionary3 = new Dictionary<int, HashSet<RoadLaneIndex>>();

                roadlaneindexhashset = new HashSet<RoadLaneIndex>
                    {new RoadLaneIndex(2, 0), new RoadLaneIndex(2, 1), new RoadLaneIndex(2, 2)};
                connectiondictionary1.Add(0, roadlaneindexhashset);
                connectiondictionary2.Add(0, roadlaneindexhashset);

                roadlaneindexhashset = new HashSet<RoadLaneIndex> {new RoadLaneIndex(1, 0), new RoadLaneIndex(1, 1)};
                connectiondictionary1.Add(1, roadlaneindexhashset);
                connectiondictionary2.Add(1, roadlaneindexhashset);

                roadlaneindexhashset = new HashSet<RoadLaneIndex> {new RoadLaneIndex(1, 2)};
                connectiondictionary1.Add(2, roadlaneindexhashset);
                connectiondictionary2.Add(2, roadlaneindexhashset);

                roadlaneindexhashset = new HashSet<RoadLaneIndex> {new RoadLaneIndex(1, 3)};
                connectiondictionary1.Add(3, roadlaneindexhashset);
                connectiondictionary2.Add(3, roadlaneindexhashset);
                connectiondictionary3.Add(3, roadlaneindexhashset);

                roadlaneindexhashset = new HashSet<RoadLaneIndex> {new RoadLaneIndex(2, 0)};
                connectiondictionary3.Add(0, roadlaneindexhashset);

                roadlaneindexhashset = new HashSet<RoadLaneIndex> {new RoadLaneIndex(2, 1), new RoadLaneIndex(2, 2)};
                connectiondictionary3.Add(1, roadlaneindexhashset);

                roadlaneindexhashset = new HashSet<RoadLaneIndex>
                    {new RoadLaneIndex(1, 0), new RoadLaneIndex(1, 1), new RoadLaneIndex(1, 2)};
                connectiondictionary3.Add(2, roadlaneindexhashset);

                crossinglist.Add(new Crossing(-1500, -500, crossingdata,
                                              new RoadConnection(roadlist[12], connectiondictionary1),
                                              new RoadConnection(roadlist[0], connectiondictionary2),
                                              new RoadConnection(roadlist[13], connectiondictionary3)));
                crossinglist.Add(new Crossing(-1500, 500, crossingdata,
                                              new RoadConnection(roadlist[13], connectiondictionary1),
                                              new RoadConnection(roadlist[3], connectiondictionary2),
                                              new RoadConnection(roadlist[14], connectiondictionary3)));
            }
            //bool dreamscametrue = false;
            //if (dreamscametrue)
            //{
            //    roadlist = (List<Road>)Serializer.Deserialize(Global.HomeFolder + "\\Maps\\Default_roadlist.xml", false);
            //    crossinglist = new List<Crossing>();
            //    foreach (Crossing crossing in (List<Crossing>)Serializer.Deserialize(Global.HomeFolder + "\\Maps\\Default_crossinglist.xml", false))
            //    {
            //        crossing.DeserializationRepopulation();
            //        crossinglist.Add(crossing);
            //    }
            //}

            // Voeg Buildings toe.

            #region LegacyBuildingConstruction

            /*
             * LEGACY
             *
            buildinglist.Add(new Building(Color.Beige, -450, -300, -400, -300, -425, -100, -450, -100));
            buildinglist.Add(new Building(Color.Chocolate, -450, -50, -400, -50, -400, 0, -425, 0, -425, -25, -450, -25));\
             *
             */

            #endregion

            foreach (
                Building building in
                    (List<Building>)
                    Serializer.Deserialize(Global.HomeFolder + "\\Maps\\Default_buildinglist.xml", false))
            {
                building.DeserializationRepopulation();
                buildinglist.Add(building);
            }
        }
Esempio n. 3
0
 public Crossing(double x, double y, CrossingData crossingdata, params RoadConnection[] roadconnections)
     : this(new PointD(x, y), crossingdata, roadconnections)
 {
 }