private List <OSMNode> CreateTransportLine(int index, TransportLine line) { List <OSMNode> returnNodes = new List <OSMNode>(); TransportManager transportManager = Singleton <TransportManager> .instance; int numberOfStops = line.CountStops(line.m_stops); var transportType = line.Info.m_transportType; if (line.m_stops != 0 && numberOfStops > 0) { for (int stopIndex = 0; stopIndex < numberOfStops; ++stopIndex) { ushort stopId = line.GetStop(stopIndex); NetNode stop = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stopId]; Vector3 position = stop.m_position; ushort transportLine = stop.m_transportLine; string transportLineName = transportLineName = transportManager.GetLineName(transportLine);; decimal lon, lat; Translations.VectorToLonLat(position, out lon, out lat); List <OSMNodeTag> tags = new List <OSMNodeTag>(); if (transportType == TransportInfo.TransportType.Bus) { tags.Add(new OSMNodeTag { k = "highway", v = "bus_stop" }); } else if (transportType == TransportInfo.TransportType.Train) { bool tramLine = transportLineName != null && (transportLineName.Contains("[t]") || transportLineName.ToLower().Contains("tram")); tags.Add(new OSMNodeTag { k = "public_transport", v = "platform" }); tags.Add(new OSMNodeTag { k = "railway", v = tramLine ? "tram_stop" : "station" }); } else if (transportType == TransportInfo.TransportType.Tram) { tags.Add(new OSMNodeTag { k = "public_transport", v = "platform" }); tags.Add(new OSMNodeTag { k = "railway", v = "tram_stop" }); } returnNodes.Add(new OSMNode { changeset = 50000000, id = (uint)unindexedNodeOffset++, version = 1, timestamp = DateTime.Now, user = "******", lon = lon, lat = lat, tag = tags.ToArray() }); } } return(returnNodes); }
public static string[] GetAllStopsFromLine(ushort lineID) { TransportLine t = TransportManager.instance.m_lines.m_buffer[lineID]; int stopsCount = t.CountStops(lineID); string[] result = new string[stopsCount]; ItemClass.SubService ss = TransportSystemDefinition.GetDefinitionForLine(lineID).SubService; for (int i = 0; i < stopsCount; i++) { ushort stationId = t.GetStop(i); result[i] = TLMStationUtils.GetFullStationName(stationId, lineID, ss); } return(result); }
private bool GetStopIndex(TransportLine line, int stopCount, ushort stopId, out int stopIndex) { for (int i = 0; i < stopCount; i++) { if (stopId == line.GetStop(i)) { stopIndex = i; return(true); } } stopIndex = -1; return(false); }
private List<OSMNode> CreateTransportLine(int index, TransportLine line) { List<OSMNode> returnNodes = new List<OSMNode>(); TransportManager transportManager = Singleton<TransportManager>.instance; int numberOfStops = line.CountStops(line.m_stops); var transportType = line.Info.m_transportType; if (line.m_stops != 0 && numberOfStops > 0) { for (int stopIndex = 0; stopIndex < numberOfStops; ++stopIndex) { ushort stopId = line.GetStop(stopIndex); NetNode stop = Singleton<NetManager>.instance.m_nodes.m_buffer[(int)stopId]; Vector3 position = stop.m_position; ushort transportLine = stop.m_transportLine; string transportLineName = transportLineName = transportManager.GetLineName(transportLine); ; decimal lon, lat; Translations.VectorToLonLat(position, out lon, out lat); List<OSMNodeTag> tags = new List<OSMNodeTag>(); if (transportType == TransportInfo.TransportType.Bus) { tags.Add(new OSMNodeTag { k = "highway", v = "bus_stop" }); } else if (transportType == TransportInfo.TransportType.Train) { bool tramLine = transportLineName != null && (transportLineName.Contains("[t]") || transportLineName.ToLower().Contains("tram")); tags.Add(new OSMNodeTag { k = "public_transport", v = "platform" }); tags.Add(new OSMNodeTag { k = "railway", v = tramLine ? "tram_stop" : "station" }); } else if (transportType == TransportInfo.TransportType.Tram) { tags.Add(new OSMNodeTag { k = "public_transport", v = "platform" }); tags.Add(new OSMNodeTag { k = "railway", v = "tram_stop" }); } returnNodes.Add(new OSMNode { changeset = 50000000, id = (uint)unindexedNodeOffset++, version = 1, timestamp = DateTime.Now, user = "******", lon = lon, lat = lat, tag = tags.ToArray() }); } } return returnNodes; }
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")); }
public void redrawLine() { ushort lineID = parent.CurrentSelectedId; TransportLine t = TLMController.instance.tm.m_lines.m_buffer[(int)lineID]; int stopsCount = t.CountStops(lineID); int vehicleCount = t.CountVehicles(lineID); Color lineColor = TLMController.instance.tm.GetLineColor(lineID); setLinearMapColor(lineColor); clearStations(); updateSubIconLayer(); setLineNumberCircle(lineID); if (lineID == 0) { var tsd = TransportSystemDefinition.from(parent.CurrentTransportInfo); if (tsd != default(TransportSystemDefinition)) { linearMapLineNumberFormat.backgroundSprite = TLMLineUtils.GetIconForIndex(tsd.toConfigIndex()); } lineStationsPanel.width = 0; return; } ItemClass.SubService ss = TLMCW.getDefinitionForLine(lineID).subService; linearMapLineNumberFormat.backgroundSprite = TLMLineUtils.getIconForLine(lineID); m_autoName = TLMLineUtils.calculateAutoName(lineID, true); linearMapLineNumber.tooltip = m_autoName; string stationName; Vector3 local; string airport, taxi, harbor, regionalStation, cableCarStation; string namePrefix; bool isComplete = (Singleton <TransportManager> .instance.m_lines.m_buffer[TLMController.instance.CurrentSelectedId].m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None; bool simmetric = TLMLineUtils.CalculateSimmetry(ss, stopsCount, t, out int middle); float addedWidth = 0; lineStationsPanel.width = 0; if (t.Info.m_transportType != TransportInfo.TransportType.Bus && t.Info.m_transportType != TransportInfo.TransportType.Tram && simmetric && !showExtraStopInfo) { int maxIt = middle + stopsCount / 2; for (int j = middle; j <= maxIt; j++) { ushort stationId = t.GetStop(j); local = getStation(lineID, stationId, ss, out stationName, out List <ushort> intersections, out airport, out harbor, out taxi, out regionalStation, out cableCarStation, out namePrefix); addedWidth = addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, cableCarStation, stationId, ss, lineColor, false) + (j == middle + stopsCount / 2 ? 5 : 0); lineStationsPanel.width += addedWidth; } } else { int minI = 0, maxI = stopsCount; if (simmetric) { minI = middle + 1; maxI = stopsCount + middle + 1; } if (showExtraStopInfo) { int j = (minI - 1 + stopsCount) % stopsCount; ushort stationId = t.GetStop(j); local = getStation(lineID, stationId, ss, out stationName, out List <ushort> intersections, out airport, out harbor, out taxi, out regionalStation, out cableCarStation, out namePrefix); lineStationsPanel.width += addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, cableCarStation, stationId, ss, lineColor, true); } else if (TLMSingleton.showDistanceInLinearMap || parent.ForceShowStopsDistances) { minI--; } for (int i = minI; i < maxI; i++) { int j = (i + stopsCount) % stopsCount; ushort stationId = t.GetStop(j); local = getStation(lineID, stationId, ss, out stationName, out List <ushort> intersections, out airport, out harbor, out taxi, out regionalStation, out cableCarStation, out namePrefix); addedWidth = addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, cableCarStation, stationId, ss, lineColor, false); lineStationsPanel.width += addedWidth; } } lineStationsPanel.width -= addedWidth; if (showExtraStopInfo) { vehiclesOnStation.Clear(); for (int v = 0; v < vehicleCount; v++) { ushort vehicleId = t.GetVehicle(v); AddVehicleToLinearMap(lineColor, vehicleId); } } }
public static void SimulationStep(ref TransportLine thisLine, ushort lineID) { //begin mod(+): change for initialization if (!TransportLineMod._init) { return; } //end mod TransportInfo info = thisLine.Info; if (thisLine.Complete) { //begin mod(*): moved this section to a separate method int num2 = CountLineActiveVehicles(lineID); //end mod bool flag1 = !Singleton <SimulationManager> .instance.m_isNightTime ? (thisLine.m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None : (thisLine.m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None; uint range = 0; float num5 = 0.0f; int num6 = 0; bool flag2 = false; if ((int)thisLine.m_stops != 0) { NetManager instance = Singleton <NetManager> .instance; ushort stops = thisLine.m_stops; ushort num3 = stops; int num4 = 0; while ((int)num3 != 0) { ushort num7 = 0; if (flag1) { instance.m_nodes.m_buffer[(int)num3].m_flags &= NetNode.Flags.OneWayOutTrafficLights | NetNode.Flags.UndergroundTransition | NetNode.Flags.Created | NetNode.Flags.Deleted | NetNode.Flags.Original | NetNode.Flags.End | NetNode.Flags.Middle | NetNode.Flags.Bend | NetNode.Flags.Junction | NetNode.Flags.Moveable | NetNode.Flags.Untouchable | NetNode.Flags.Outside | NetNode.Flags.Temporary | NetNode.Flags.Double | NetNode.Flags.Fixed | NetNode.Flags.OnGround | NetNode.Flags.Ambiguous | NetNode.Flags.Water | NetNode.Flags.Sewage | NetNode.Flags.ForbidLaneConnection | NetNode.Flags.LevelCrossing | NetNode.Flags.OneWayIn | NetNode.Flags.Heating | NetNode.Flags.Electricity | NetNode.Flags.Collapsed | NetNode.Flags.DisableOnlyMiddle | NetNode.Flags.AsymForward | NetNode.Flags.AsymBackward | NetNode.Flags.CustomTrafficLights; } else { instance.m_nodes.m_buffer[(int)num3].m_flags |= NetNode.Flags.Disabled; } for (int index = 0; index < 8; ++index) { ushort segment = instance.m_nodes.m_buffer[(int)num3].GetSegment(index); if ((int)segment != 0 && (int)instance.m_segments.m_buffer[(int)segment].m_startNode == (int)num3) { num6 += Mathf.Max((int)instance.m_segments.m_buffer[(int)segment].m_trafficLightState0, (int)instance.m_segments.m_buffer[(int)segment].m_trafficLightState1); num5 += instance.m_segments.m_buffer[(int)segment].m_averageLength; num7 = instance.m_segments.m_buffer[(int)segment].m_endNode; if ((instance.m_segments.m_buffer[(int)segment].m_flags & NetSegment.Flags.PathLength) == NetSegment.Flags.None) { flag2 = true; break; } break; } } ++range; num3 = num7; if ((int)num3 != (int)stops) { if (++num4 >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace); break; } } else { break; } } } if (!flag2) { thisLine.m_totalLength = num5; } if ((int)range != 0) { thisLine.m_averageInterval = (byte)Mathf.Min((float)byte.MaxValue, (float)(((long)num6 + (long)(range >> 1)) / (long)range)); } //begin mod(-): let's count maintenance once a week //end mod TransferManager.TransferReason vehicleReason = info.m_vehicleReason; if (vehicleReason != TransferManager.TransferReason.None) { //begin mod: calculate target vehicle count or read saved value int num3 = 0; if (TransportLineMod._lineData[(int)lineID].BudgetControl || info.m_class.m_service == ItemClass.Service.Disaster) { num3 = !flag1 ? 0 : (!flag2 ? thisLine.CalculateTargetVehicleCount() : num2); TransportLineMod._lineData[(int)lineID].TargetVehicleCount = num3; } else if (flag1) { num3 = TransportLineMod._lineData[(int)lineID].TargetVehicleCount; } //end mod if (range != 0 && num2 < num3) { ushort stop = thisLine.GetStop(Singleton <SimulationManager> .instance.m_randomizer .Int32((uint)thisLine.CountStops(lineID))); if (info.m_vehicleReason != TransferManager.TransferReason.None && (int)stop != 0) { //begin mod(+): save offer as variable and directly invoke spawn if it's not evac line TransferManager.TransferOffer offer = new TransferManager.TransferOffer { Priority = num3 - num2 + 1, TransportLine = lineID, Position = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stop] .m_position, Amount = 1, Active = false }; if (info.m_class.m_service == ItemClass.Service.Disaster) { Singleton <TransferManager> .instance.AddIncomingOffer(vehicleReason, offer); } else { HandleVehicleSpawn(lineID, info, num3, num2, offer); } //end mod } } else if (num2 > num3) { //begin mod(*): encapsulate into method TransportLineMod.RemoveActiveVehicle(lineID, false, num2); //end mod } } } if ((Singleton <SimulationManager> .instance.m_currentFrameIndex & 4095U) < 3840U) { return; } thisLine.m_passengers.Update(); Singleton <TransportManager> .instance.m_passengers[(int)info.m_transportType].Add(ref thisLine.m_passengers); thisLine.m_passengers.Reset(); //begin mod(+): update statistics + fetch maintenance costs if (thisLine.Complete) { ushort stops1 = thisLine.m_stops; ushort stop1 = stops1; do { NetManagerMod.m_cachedNodeData[(int)stop1].StartNewWeek(); stop1 = TransportLine.GetNextStop(stop1); } while ((int)stops1 != (int)stop1 && (int)stop1 != 0); var itemClass = info.m_class; PrefabData[] prefabs = VehiclePrefabs.instance.GetPrefabs(itemClass.m_service, itemClass.m_subService, itemClass.m_level); int amount = 0; CountLineActiveVehicles(lineID, (num3) => { Vehicle vehicle = VehicleManager.instance.m_vehicles.m_buffer[num3]; PrefabData prefabData = Array.Find(prefabs, item => item.PrefabDataIndex == vehicle.Info.m_prefabDataIndex); if (prefabData != null) { amount += prefabData.MaintenanceCost; VehicleManagerMod.m_cachedVehicleData[num3].StartNewWeek(prefabData.MaintenanceCost); } }); if (amount != 0) { Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Maintenance, amount, info.m_class); } //end mod } }
public static void SimulationStepImpl(ref TransportLine line, ushort lineID) { if (!line.Complete) { return; } TransportInfo info = line.Info; SimulationManager instance1 = Singleton <SimulationManager> .instance; bool isLineEnabled = !instance1.m_isNightTime ? (line.m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None : (line.m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None; bool flag = TransportLineMod.SetLineStatus(lineID, isLineEnabled); int num1 = line.CountVehicles(lineID); int num2 = 0; if (TransportLineMod._lineData[(int)lineID].BudgetControl) { num2 = !isLineEnabled ? 0 : (!flag ? Mathf.CeilToInt((float)((double)TransportLineMod.GetBudget(lineID, instance1.m_isNightTime, info.m_class) * (double)TransportLineMod.GetLength(lineID) / ((double)info.m_defaultVehicleDistance * 100.0))) : num1); TransportLineMod._lineData[(int)lineID].TargetVehicleCount = num2; } else if (isLineEnabled) { num2 = TransportLineMod._lineData[(int)lineID].TargetVehicleCount; } if (num1 < num2) { if ((double)SimHelper.instance.SimulationTime >= (double)TransportLineMod._lineData[(int)lineID].NextSpawnTime) { int index1 = instance1.m_randomizer.Int32((uint)line.CountStops(lineID)); ushort stop = line.GetStop(index1); if (info.m_vehicleReason != TransferManager.TransferReason.None && (int)stop != 0) { TransferManager.TransferOffer offer = new TransferManager.TransferOffer(); offer.Priority = num2 - num1 + 1; offer.TransportLine = lineID; offer.Position = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stop].m_position; offer.Amount = 1; offer.Active = false; ushort depot = TransportLineMod._lineData[(int)lineID].Depot; if (TransportLineMod.IsLineDepotStillValid(lineID, ref depot)) { BuildingManager instance2 = Singleton <BuildingManager> .instance; if (TransportLineMod.CanAddVehicle(depot, ref instance2.m_buildings.m_buffer[(int)depot])) { string prefabName; if (TransportLineMod.EnqueuedVehiclesCount(lineID) > 0) { prefabName = TransportLineMod.Dequeue(lineID); } else { int num3 = num2 - num1; for (int index2 = 0; index2 < num3; ++index2) { TransportLineMod.EnqueueVehicle(lineID, TransportLineMod.GetRandomPrefab(lineID), false); } prefabName = TransportLineMod.Dequeue(lineID); } if (prefabName != "") { int num4 = (int)DepotAIMod.StartTransfer(depot, ref instance2.m_buildings.m_buffer[(int)depot], info.m_vehicleReason, offer, prefabName); } else { instance2.m_buildings.m_buffer[(int)depot].Info.m_buildingAI.StartTransfer(depot, ref instance2.m_buildings.m_buffer[(int)depot], info.m_vehicleReason, offer); } TransportLineMod._lineData[(int)lineID].NextSpawnTime = SimHelper.instance.SimulationTime + (float)ImprovedPublicTransportMod.Settings.SpawnTimeInterval; } else { TransportLineMod.ClearEnqueuedVehicles(lineID); } } } } } else if (num1 > num2) { TransportLineMod.RemoveRandomVehicle(lineID, false); } if ((instance1.m_currentFrameIndex & 4095U) < 3840U) { return; } line.m_passengers.Update(); Singleton <TransportManager> .instance.m_passengers[(int)info.m_transportType].Add(ref line.m_passengers); line.m_passengers.Reset(); ushort stops = line.m_stops; ushort stop1 = stops; do { NetManagerMod.m_cachedNodeData[(int)stop1].StartNewWeek(); stop1 = TransportLine.GetNextStop(stop1); }while ((int)stops != (int)stop1 && (int)stop1 != 0); VehicleManager instance3 = Singleton <VehicleManager> .instance; PrefabData[] prefabs = VehiclePrefabs.instance.GetPrefabs(info.m_class.m_subService); int amount = 0; for (ushort index = line.m_vehicles; (int)index != 0; index = instance3.m_vehicles.m_buffer[(int)index].m_nextLineVehicle) { Vehicle vehicle = instance3.m_vehicles.m_buffer[(int)index]; PrefabData prefabData = Array.Find <PrefabData>(prefabs, (Predicate <PrefabData>)(item => item.PrefabDataIndex == vehicle.Info.m_prefabDataIndex)); if (prefabData != null) { amount += prefabData.MaintenanceCost; VehicleManagerMod.m_cachedVehicleData[(int)index].StartNewWeek(prefabData.MaintenanceCost); } } if (amount == 0) { return; } Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Maintenance, amount, info.m_class); }
public static void SimulationStep(ref TransportLine thisLine, ushort lineID) { //begin mod(+): change for initialization if (!CachedTransportLineData._init) { return; } //end mod TransportInfo info = thisLine.Info; NetManager instance1 = Singleton <NetManager> .instance; SimulationManager instance2 = Singleton <SimulationManager> .instance; Notification.Problem problems1 = Notification.Problem.None; Notification.Problem problem1 = Notification.Problem.None; Notification.Problem problem2 = Notification.Problem.None; Notification.Problem problems2 = Notification.Problem.TooLong | Notification.Problem.MajorProblem; if ((int)thisLine.m_stops != 0) { problem1 = instance1.m_nodes.m_buffer[(int)thisLine.m_stops].m_problems; problems1 = problem1; } bool flag1 = (instance2.m_currentFrameIndex & 4095U) >= 3840U; float num1 = 0.0f; bool flag2 = false; if (thisLine.Complete) { //begin mod(*): moved this section to a separate method int num3 = CountLineActiveVehicles(lineID, out int num2); //end mod bool flag3 = !instance2.m_isNightTime ? (thisLine.m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None : (thisLine.m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None; uint range = 0; int num6 = 0; int num7 = 0; int num8 = 0; if ((int)thisLine.m_stops != 0) { CitizenManager instance3 = Singleton <CitizenManager> .instance; ushort stops = thisLine.m_stops; ushort num4 = stops; int num5 = 0; while ((int)num4 != 0) { ushort num9 = 0; if (flag3) { instance1.m_nodes.m_buffer[(int)num4].m_flags &= NetNode.Flags.OneWayOutTrafficLights | NetNode.Flags.UndergroundTransition | NetNode.Flags.Created | NetNode.Flags.Deleted | NetNode.Flags.Original | NetNode.Flags.End | NetNode.Flags.Middle | NetNode.Flags.Bend | NetNode.Flags.Junction | NetNode.Flags.Moveable | NetNode.Flags.Untouchable | NetNode.Flags.Outside | NetNode.Flags.Temporary | NetNode.Flags.Double | NetNode.Flags.Fixed | NetNode.Flags.OnGround | NetNode.Flags.Ambiguous | NetNode.Flags.Water | NetNode.Flags.Sewage | NetNode.Flags.ForbidLaneConnection | NetNode.Flags.LevelCrossing | NetNode.Flags.OneWayIn | NetNode.Flags.Heating | NetNode.Flags.Electricity | NetNode.Flags.Collapsed | NetNode.Flags.DisableOnlyMiddle | NetNode.Flags.AsymForward | NetNode.Flags.AsymBackward | NetNode.Flags.CustomTrafficLights; } else { instance1.m_nodes.m_buffer[(int)num4].m_flags |= NetNode.Flags.Disabled; } problem2 |= (instance1.m_nodes.m_buffer[(int)num4].m_problems ^ problem1) & problems2; for (int index = 0; index < 8; ++index) { ushort segment = instance1.m_nodes.m_buffer[(int)num4].GetSegment(index); if ((int)segment != 0 && (int)instance1.m_segments.m_buffer[(int)segment].m_startNode == (int)num4) { num6 += Mathf.Max((int)instance1.m_segments.m_buffer[(int)segment].m_trafficLightState0, (int)instance1.m_segments.m_buffer[(int)segment].m_trafficLightState1); num1 += instance1.m_segments.m_buffer[(int)segment].m_averageLength; num7 += (int)instance1.m_segments.m_buffer[(int)segment].m_trafficBuffer; num9 = instance1.m_segments.m_buffer[(int)segment].m_endNode; if ((instance1.m_segments.m_buffer[(int)segment].m_flags & NetSegment.Flags.PathLength) == NetSegment.Flags.None) { flag2 = true; break; } break; } } ushort num10 = instance1.m_nodes.m_buffer[(int)num4].m_targetCitizens; int num11 = 0; while ((int)num10 != 0) { ++num8; num10 = instance3.m_instances.m_buffer[(int)num10].m_nextTargetInstance; if (++num11 >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace); break; } } ++range; num4 = num9; if ((int)num4 != (int)stops) { if (++num5 >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace); break; } } else { break; } } } if (!flag2) { thisLine.m_totalLength = num1; } if ((int)range != 0) { thisLine.m_averageInterval = (byte)Mathf.Min((float)byte.MaxValue, (float)(((long)num6 + (long)(range >> 1)) / (long)range)); } //begin mod(-): let's count maintenance once a week //end mod TransferManager.TransferReason vehicleReason = info.m_vehicleReason; if (vehicleReason != TransferManager.TransferReason.None) { //begin mod: calculate target vehicle count or read saved value int num4 = 0; if (CachedTransportLineData._lineData[(int)lineID].BudgetControl || info.m_class.m_service == ItemClass.Service.Disaster) { num4 = !flag3 ? 0 : (!flag2 ? thisLine.CalculateTargetVehicleCount() : num3); CachedTransportLineData._lineData[(int)lineID].TargetVehicleCount = num4; } else if (flag3) { num4 = CachedTransportLineData._lineData[(int)lineID].TargetVehicleCount; } //end mod if (range != 0U && num2 < num4) { ushort stop = thisLine.GetStop(instance2.m_randomizer.Int32(range)); if (stop != (ushort)0) { Singleton <TransferManager> .instance.AddIncomingOffer(vehicleReason, new TransferManager.TransferOffer() { Priority = num4 - num2 + 1, TransportLine = lineID, Position = instance1.m_nodes.m_buffer[(int)stop].m_position, Amount = 1, Active = false }); } } else if (num3 > num4) { //begin mod(*): encapsulate into method TransportLineDetour.RemoveActiveVehicle(lineID, false, num3); //end mod } } TransferManager.TransferReason material = info.m_citizenReason; switch (material) { case TransferManager.TransferReason.None: goto label_99; case TransferManager.TransferReason.Entertainment: switch (instance2.m_randomizer.Int32(4U)) { case 0: material = TransferManager.TransferReason.Entertainment; break; case 1: material = TransferManager.TransferReason.EntertainmentB; break; case 2: material = TransferManager.TransferReason.EntertainmentC; break; case 3: material = TransferManager.TransferReason.EntertainmentD; break; } //begin mod: to shut up compiler break; //end mod case TransferManager.TransferReason.TouristA: switch (instance2.m_randomizer.Int32(20U)) { case 0: case 1: case 2: case 3: material = TransferManager.TransferReason.TouristA; break; case 4: case 5: case 6: case 7: material = TransferManager.TransferReason.TouristB; break; case 8: case 9: case 10: case 11: material = TransferManager.TransferReason.TouristC; break; case 12: case 13: case 14: case 15: material = TransferManager.TransferReason.TouristD; break; case 16: material = TransferManager.TransferReason.Entertainment; break; case 17: material = TransferManager.TransferReason.EntertainmentB; break; case 18: material = TransferManager.TransferReason.EntertainmentC; break; case 19: material = TransferManager.TransferReason.EntertainmentD; break; } //begin mod: to shut up compiler break; //end mod } if (vehicleReason == TransferManager.TransferReason.None) { if ((double)thisLine.m_totalLength <= 1920.0) { if (!flag2) { problems1 = Notification.RemoveProblems(problems1, Notification.Problem.TooLong); } } else if ((double)thisLine.m_totalLength <= 3840.0) { if (!flag2) { problems1 = Notification.RemoveProblems(problems1, Notification.Problem.TooLong); } num7 = (num7 * 17 + 10) / 20; } else if ((double)thisLine.m_totalLength <= 5760.0) { if (!flag2) { problems1 = Notification.AddProblems( Notification.RemoveProblems(problems1, Notification.Problem.TooLong), Notification.Problem.TooLong); } num7 = (num7 * 14 + 10) / 20; } else { if (!flag2) { problems1 = Notification.AddProblems(problems1, Notification.Problem.TooLong | Notification.Problem.MajorProblem); } num7 = (num7 * 8 + 10) / 20; } if (flag1) { Singleton <StatisticsManager> .instance.Acquire <StatisticInt32>(StatisticType.WalkingTourLength) .Add(Mathf.RoundToInt(thisLine.m_totalLength)); } } else { num7 = Mathf.Max(0, num7 + 50 - (int)thisLine.m_ticketPrice * 50 / Mathf.Max(1, info.m_ticketPrice)); } int num12; if (flag3) { if (flag2) { num12 = num8; } else { int num4 = Mathf.Max(1, info.m_citizenPullRequirement); num12 = (num7 + num4 - 1) / num4; } } else { num12 = 0; } if ((int)range != 0 && num8 < num12) { ushort stop = thisLine.GetStop(instance2.m_randomizer.Int32(range)); if ((int)stop != 0) { Singleton <TransferManager> .instance.AddOutgoingOffer(material, new TransferManager.TransferOffer() { Priority = Mathf.Max(1, (num12 - num8) * 8 / num12), TransportLine = lineID, Position = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stop].m_position, Amount = 1, Active = false }); } } } else { if ((int)thisLine.m_stops != 0) { ushort stops = thisLine.m_stops; ushort num2 = stops; int num3 = 0; while ((int)num2 != 0) { ushort num4 = 0; problem2 |= (instance1.m_nodes.m_buffer[(int)num2].m_problems ^ problem1) & problems2; for (int index = 0; index < 8; ++index) { ushort segment = instance1.m_nodes.m_buffer[(int)num2].GetSegment(index); if ((int)segment != 0 && (int)instance1.m_segments.m_buffer[(int)segment].m_startNode == (int)num2) { num1 += instance1.m_segments.m_buffer[(int)segment].m_averageLength; num4 = instance1.m_segments.m_buffer[(int)segment].m_endNode; if ((instance1.m_segments.m_buffer[(int)segment].m_flags & NetSegment.Flags.PathLength) == NetSegment.Flags.None) { flag2 = true; break; } break; } } num2 = num4; if ((int)num2 != (int)stops) { if (++num3 >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace); break; } } else { break; } } } if (!flag2) { thisLine.m_totalLength = num1; if (info.m_citizenReason != TransferManager.TransferReason.None && info.m_vehicleReason == TransferManager.TransferReason.None) { problems1 = (double)thisLine.m_totalLength > 1920.0 ? ((double)thisLine.m_totalLength > 3840.0 ? ((double)thisLine.m_totalLength > 5760.0 ? Notification.AddProblems(problems1, Notification.Problem.TooLong | Notification.Problem.MajorProblem) : Notification.AddProblems( Notification.RemoveProblems(problems1, Notification.Problem.TooLong), Notification.Problem.TooLong)) : Notification.RemoveProblems(problems1, Notification.Problem.TooLong)) : Notification.RemoveProblems(problems1, Notification.Problem.TooLong); } } } label_99: if ((int)thisLine.m_stops != 0 && (problem2 | problems1 ^ problem1) != Notification.Problem.None) { ushort stops = thisLine.m_stops; ushort num2 = stops; int num3 = 0; while ((int)num2 != 0) { Notification.Problem problems = instance1.m_nodes.m_buffer[(int)num2].m_problems; Notification.Problem problem3 = Notification.RemoveProblems(problems, problems2); if ((problems1 & problems2 & ~(Notification.Problem.MajorProblem | Notification.Problem.FatalProblem)) != Notification.Problem.None) { problem3 = Notification.AddProblems(problem3, problems1 & problems2); } if (problems != problem3) { instance1.m_nodes.m_buffer[(int)num2].m_problems = problem3; instance1.UpdateNodeNotifications(num2, problems, problem3); } num2 = TransportLine.GetNextStop(num2); if ((int)num2 != (int)stops) { if (++num3 >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace); break; } } else { break; } } } if (!flag1) { return; } thisLine.m_passengers.Update(); Singleton <TransportManager> .instance.m_passengers[(int)info.m_transportType] .Add(ref thisLine.m_passengers); thisLine.m_passengers.Reset(); //begin mod(+): update statistics + fetch maintenance costs if (thisLine.Complete) { ushort stops1 = thisLine.m_stops; ushort stop1 = stops1; do { CachedNodeData.m_cachedNodeData[(int)stop1].StartNewWeek(); stop1 = TransportLine.GetNextStop(stop1); } while ((int)stops1 != (int)stop1 && (int)stop1 != 0); var itemClass = info.m_class; PrefabData[] prefabs = VehiclePrefabs.instance.GetPrefabs(itemClass.m_service, itemClass.m_subService, itemClass.m_level); int amount = 0; CountLineActiveVehicles(lineID, out int _, (num3) => { Vehicle vehicle = VehicleManager.instance.m_vehicles.m_buffer[num3]; PrefabData prefabData = Array.Find(prefabs, item => item.PrefabDataIndex == vehicle.Info.m_prefabDataIndex); if (prefabData != null) { amount += prefabData.MaintenanceCost; CachedVehicleData.m_cachedVehicleData[num3].StartNewWeek(prefabData.MaintenanceCost); } }); if (amount != 0) { Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Maintenance, amount, info.m_class); } //end mod } }
public void redrawLine() { ushort lineID = lineInfoPanel.lineIdSelecionado.TransportLine; TransportLine t = lineInfoPanel.controller.tm.m_lines.m_buffer[(int)lineID]; int stopsCount = t.CountStops(lineID); int vehicleCount = t.CountVehicles(lineID); Color lineColor = lineInfoPanel.controller.tm.GetLineColor(lineID); setLinearMapColor(lineColor); clearStations(); String bgSprite; ItemClass.SubService ss = TLMLineUtils.getLineNamingParameters(lineID, out prefix, out sep, out suffix, out nonPrefix, out zerosEsquerda, out invertPrefixSuffix, out bgSprite).subService; linearMapLineNumberFormat.backgroundSprite = bgSprite; bool day, night, zeroed; TLMLineUtils.getLineActive(ref t, out day, out night, out zeroed); if (zeroed) { linearMapLineTime.backgroundSprite = "NoBudgetIcon"; } else { if (!day || !night) { linearMapLineTime.backgroundSprite = day ? "DayIcon" : night ? "NightIcon" : "DisabledIcon"; } else { linearMapLineTime.backgroundSprite = ""; } } setLineNumberCircle(t.m_lineNumber, prefix, sep, suffix, nonPrefix, zerosEsquerda, invertPrefixSuffix); m_autoName = TLMUtils.calculateAutoName(lineID); string stationName = null; Vector3 local; string airport, taxi, harbor, regionalStation; int middle; string namePrefix; bool simmetric = TLMUtils.CalculateSimmetry(ss, stopsCount, t, out middle); if (t.Info.m_transportType != TransportInfo.TransportType.Bus && t.Info.m_transportType != TransportInfo.TransportType.Tram && simmetric && !showExtraStopInfo) { lineStationsPanel.width = 5; for (int j = middle; j <= middle + stopsCount / 2; j++) { List <ushort> intersections; ushort stationId = t.GetStop(j); local = getStation(lineID, stationId, ss, out stationName, out intersections, out airport, out harbor, out taxi, out regionalStation, out namePrefix); lineStationsPanel.width += addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, stationId, ss) + (j == middle + stopsCount / 2 ? 5 : 0); } } else { lineStationsPanel.width = 5; int minI = 0, maxI = stopsCount; if (simmetric) { minI = middle + 1; maxI = stopsCount + middle + 1; } if (showExtraStopInfo) { int j = (minI - 1 + stopsCount) % stopsCount; ushort stationId = t.GetStop(j); List <ushort> intersections; local = getStation(lineID, stationId, ss, out stationName, out intersections, out airport, out harbor, out taxi, out regionalStation, out namePrefix); lineStationsPanel.width += addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, stationId, ss, true); } for (int i = minI; i < maxI; i++) { int j = i % stopsCount; List <ushort> intersections; ushort stationId = t.GetStop(j); local = getStation(lineID, stationId, ss, out stationName, out intersections, out airport, out harbor, out taxi, out regionalStation, out namePrefix); lineStationsPanel.width += addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, stationId, ss) + (j == stopsCount - (showExtraStopInfo ? 0 : 1) ? 5 : 0); } } if (showExtraStopInfo) { vehiclesOnStation.Clear(); for (int v = 0; v < vehicleCount; v++) { ushort vehicleId = t.GetVehicle(v); AddVehicleToLinearMap(lineColor, vehicleId); } } }