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")); }