Beispiel #1
0
 public CardinalPoint getDirectionForStation(Station s)
 {
     return(stationConnections.FirstOrDefault(x => x.Value.stopId == s.stopId).Key);
 }
Beispiel #2
0
 public void addStation(ref Station s)
 {
     stations.Add(s);
     s.addLine(lineId);
 }
Beispiel #3
0
        public static void drawCityMap()
        {
            TLMController controller = TLMController.instance;
            Dictionary <TransportInfo.TransportType, List <ushort> > linesByType = new Dictionary <TransportInfo.TransportType, List <ushort> >();

            linesByType[TransportInfo.TransportType.Metro] = new List <ushort>();
            linesByType[TransportInfo.TransportType.Train] = new List <ushort>();
            linesByType[TransportInfo.TransportType.Tram]  = new List <ushort>();
            linesByType[TransportInfo.TransportType.Ship]  = new List <ushort>();

            //			List<int> usedX = new List<int> ();
            //			List<int> usedY = new List<int> ();
            int nextStationId = 1;

            for (ushort lineId = 0; lineId < controller.tm.m_lines.m_size; lineId++)
            {
                TransportLine t = controller.tm.m_lines.m_buffer[(int)lineId];
                if (t.m_lineNumber > 0 && (t.Info.m_transportType == TransportInfo.TransportType.Metro ||
                                           t.Info.m_transportType == TransportInfo.TransportType.Train ||
                                           t.Info.m_transportType == TransportInfo.TransportType.Tram ||
                                           t.Info.m_transportType == TransportInfo.TransportType.Ship))
                {
                    switch (t.Info.m_transportType)
                    {
                    case TransportInfo.TransportType.Ship:
                    case TransportInfo.TransportType.Train:
                    case TransportInfo.TransportType.Metro:
                    case TransportInfo.TransportType.Tram:
                        linesByType[t.Info.m_transportType].Add(lineId);
                        break;
                    }
                }
            }

            CalculateCoords calc         = TLMLineUtils.gridPosition81Tiles;
            NetManager      nm           = NetManager.instance;
            float           invPrecision = 32;
            //Restart:
            Dictionary <int, List <int> > positions = new Dictionary <int, List <int> >();
            List <Station> stations = new List <Station>();
            Dictionary <Segment2, Color32>        svgLines       = new Dictionary <Segment2, Color32>();
            Dictionary <ushort, MapTransportLine> transportLines = new Dictionary <ushort, MapTransportLine>();

            foreach (TransportInfo.TransportType tt in new TransportInfo.TransportType[] { TransportInfo.TransportType.Ship, TransportInfo.TransportType.Train, TransportInfo.TransportType.Metro, TransportInfo.TransportType.Tram })
            {
                foreach (ushort lineId in linesByType[tt])
                {
                    TransportLine t     = controller.tm.m_lines.m_buffer[(int)lineId];
                    float         range = 75f;
                    switch (tt)
                    {
                    case TransportInfo.TransportType.Ship:
                        range = 150f;
                        break;

                    case TransportInfo.TransportType.Metro:
                    case TransportInfo.TransportType.Train:
                        range = 100f;
                        break;
                    }


                    int stopsCount = t.CountStops(lineId);
                    if (stopsCount == 0)
                    {
                        continue;
                    }
                    Color   color = t.m_color;
                    Vector2 ultPos = Vector2.zero;
                    bool    day, night;
                    t.GetActive(out day, out night);
                    transportLines[lineId] = new MapTransportLine(color, day, night, lineId);
                    int startStop = 0;
                    int finalStop = stopsCount;

                    for (int j = startStop; j < finalStop; j++)
                    {
                        //						Debug.Log ("ULT POS:" + ultPos);
                        ushort               nextStop = t.GetStop(j % stopsCount);
                        ItemClass.Service    service;
                        ItemClass.SubService nil2;
                        string               prefix;
                        ushort               buildingId;
                        string               name = TLMUtils.getStationName(nextStop, lineId, t.Info.m_stationSubService, out service, out nil2, out prefix, out buildingId);

                        Vector3 worldPos = TLMUtils.getStationBuildingPosition(nextStop, t.Info.m_stationSubService);
                        Vector2 pos2D    = calc(worldPos, invPrecision);
                        Vector2 gridAdd  = Vector2.zero;


                        var idx = stations.FirstOrDefault(x => x.stops.Contains(nextStop) || x.centralPos == pos2D);
                        if (idx != null)
                        {
                            transportLines[lineId].addStation(ref idx);
                        }
                        else
                        {
                            //if (positions.containskey((int)pos2d.x) && positions[(int)pos2d.x].contains((int)pos2d.y))
                            //{
                            //    float exp = (float)(math.log(invprecision) / math.log(2)) - 1;
                            //    invprecision = (float)math.pow(2, exp);
                            //    goto restart;
                            //}
                            List <ushort> nearStops = new List <ushort>();
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportShip }, 10);
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportTrain, ItemClass.SubService.PublicTransportMetro }, 10);
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportTram }, 10);
                            TLMUtils.doLog("Station: ${0}; nearStops: ${1}", name, string.Join(",", nearStops.Select(x => x.ToString()).ToArray()));
                            Station thisStation = new Station(name, pos2D, nearStops, nextStationId++, service, nextStop);
                            stations.Add(thisStation);
                            transportLines[lineId].addStation(ref thisStation);
                        }
                        if (!positions.ContainsKey((int)pos2D.x))
                        {
                            positions[(int)pos2D.x] = new List <int>();
                        }
                        positions[(int)pos2D.x].Add((int)pos2D.y);
                        //						Debug.Log ("POS:" + pos);
                        ultPos = pos2D;
                    }
                }
            }
            printToSVG(stations, transportLines, Singleton <SimulationManager> .instance.m_metaData.m_CityName + "_" + Singleton <SimulationManager> .instance.m_currentGameTime.ToString("yyyy.MM.dd"));
        }