Ejemplo n.º 1
0
        public void addStation(Station s, Dictionary <ushort, MapTransportLine> lines)
        {
            bool   inverse  = false;
            bool   vertical = false;
            string name     = s.name;
            float  angle    = s.writeAngle;

            switch (CardinalPoint.GetCardinalPoint(angle).Value)
            {
            case CardinalPoint.CardinalInternal.SW:
            case CardinalPoint.CardinalInternal.S:
            case CardinalPoint.CardinalInternal.SE:
                inverse = true;
                break;

            case CardinalPoint.CardinalInternal.E:
            case CardinalPoint.CardinalInternal.W:
                vertical = true;
                break;
            }

            foreach (ushort pos in s.getAllStationOffsetPoints())
            {
                Vector2          point = s.centralPos - offset;// + pos.Key;
                MapTransportLine line  = lines[pos];
                svgPart.Append(getStationPointTemplate(s.getLineIdx(pos), line.lineColor, point.x * multiplier, point.y * multiplier, line.lineId, s.id));
            }
            Vector2 namePoint = s.writePoint - offset;

            htmlStationsPart.Append(vertical ?
                                    getStationNameVerticalTemplate(s.name, s.getAllStationOffsetPoints().Count, s.id, (namePoint.x + 0.5f) * multiplier, ((namePoint.y + 0.5f) * multiplier), angle, s.linesPassing) : inverse ?
                                    getStationNameInverseTemplate(s.name, s.getAllStationOffsetPoints().Count, s.id, (namePoint.x + 0.5f) * multiplier, ((namePoint.y + 0.5f) * multiplier), angle, s.linesPassing) :
                                    getStationNameTemplate(s.name, s.getAllStationOffsetPoints().Count, s.id, (namePoint.x + 0.5f) * multiplier, ((namePoint.y + 0.5f) * multiplier), angle, s.linesPassing));
        }
        public void addTransportLine(MapTransportLine points, ushort transportLineIdx)
        {
            var count = points.stationsCount();

            for (int i = 1; i <= count; i++)
            {
                Station s1 = points[i - 1];
                Station s2 = points[i % count];
                segmentManager.addLine(s1, s2, points, LineSegmentStationsManager.Direction.S1_TO_S2);
            }
        }
 public void addLine(MapTransportLine m, Direction d)
 {
     if (lines.ContainsKey(m))
     {
         lines[m] |= d;
     }
     else
     {
         lines[m] = d;
     }
 }
Ejemplo n.º 4
0
        public void addLine(Station s1, Station s2, MapTransportLine line, Direction d)
        {
            LineSegmentStations lss = getStationsSegment(s1, s2, out bool invert);

            if (invert)
            {
                switch (d)
                {
                case Direction.S1_TO_S2:
                    d = Direction.S2_TO_S1;
                    break;

                case Direction.S2_TO_S1:
                    d = Direction.S1_TO_S2;
                    break;
                }
            }
            lss.addLine(line, d);
        }
        public static void drawCityMap()
        {
            TLMController controller = TLMController.instance;
            Dictionary <TransportInfo.TransportType, List <ushort> > linesByType = new Dictionary <TransportInfo.TransportType, List <ushort> >();

            foreach (var type in Enum.GetValues(typeof(TransportInfo.TransportType)))
            {
                linesByType[(TransportInfo.TransportType)type] = 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.m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None)
                {
                    linesByType[t.Info.m_transportType].Add(lineId);
                }
            }

            CalculateCoords calc         = TLMUtils.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 <ushort, MapTransportLine> transportLines = new Dictionary <ushort, MapTransportLine>();

            foreach (TransportInfo.TransportType tt in linesByType.Keys)
            {
                if (!linesByType.ContainsKey(tt))
                {
                    continue;
                }
                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.Monorail:
                    case TransportInfo.TransportType.Train:
                    case TransportInfo.TransportType.CableCar:
                        range = 100f;
                        break;
                    }


                    int stopsCount = t.CountStops(lineId);
                    if (stopsCount == 0)
                    {
                        continue;
                    }
                    Color   color  = t.m_color;
                    Vector2 ultPos = Vector2.zero;
                    t.GetActive(out bool day, out bool 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);
                        string name     = TLMLineUtils.getStationName(nextStop, lineId, t.Info.m_stationSubService, out ItemClass.Service service, out ItemClass.SubService nil2, out string prefix, out ushort buildingId, out NamingType namingType);

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


                        var idx = stations.FirstOrDefault(x => x.stopsWithWorldPos.ContainsKey(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;
                            //}
                            Dictionary <ushort, Vector3> nearStops = new Dictionary <ushort, Vector3>();
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportShip, ItemClass.SubService.PublicTransportPlane }, 10);
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportTrain, ItemClass.SubService.PublicTransportMonorail, ItemClass.SubService.PublicTransportCableCar, ItemClass.SubService.PublicTransportMetro }, 10);
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportTram, ItemClass.SubService.PublicTransportBus }, 10);
                            TLMUtils.doLog("Station: ${0}; nearStops: ${1}", name, string.Join(",", nearStops.Select(x => x.ToString()).ToArray()));
                            Station thisStation = new Station(name, pos2D, worldPos, 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"));
            printToJson(stations, transportLines, Singleton <SimulationManager> .instance.m_metaData.m_CityName + "_" + Singleton <SimulationManager> .instance.m_currentGameTime.ToString("yyyy.MM.dd"));
        }
Ejemplo n.º 6
0
 private string getLineElement(Vector2[] points, MapTransportLine line, TransportInfo.TransportType tt) => $@"<polyline points=""{string.Join(",", points.Select(x => "" + x.x + "," + x.y).ToArray())}"" class=""path{tt.ToString()} _lid_{line.lineId}"" style='stroke:rgb({ line.lineColor.r},{ line.lineColor.g},{ line.lineColor.b});' stroke-linejoin=""round"" stroke-linecap=""round""/>";