public static void removeAllUnwantedVehicles() { for (ushort lineId = 1; lineId < Singleton <TransportManager> .instance.m_lines.m_size; lineId++) { if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].m_flags & TransportLine.Flags.Created) != TransportLine.Flags.None) { if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode) { TLMUtils.doLog("removeAllUnwantedVehicles: line #{0}", lineId); } TransportLine tl = Singleton <TransportManager> .instance.m_lines.m_buffer[lineId]; uint prefix = 0; if (TLMConfigWarehouse.getCurrentConfigInt(TLMConfigWarehouse.getConfigIndexForTransportInfo(tl.Info) | TLMConfigWarehouse.ConfigIndex.PREFIX) != (int)ModoNomenclatura.Nenhum) { prefix = tl.m_lineNumber / 1000u; } VehicleManager instance3 = Singleton <VehicleManager> .instance; VehicleInfo info = instance3.m_vehicles.m_buffer[Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].GetVehicle(0)].Info; if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode) { TLMUtils.doLog("removeAllUnwantedVehicles: pre model list; type = {0}", info.GetAI()); } var def = TransportSystemDefinition.from(info); if (def == default(TransportSystemDefinition)) { if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode) { TLMUtils.doLog("NULL TSysDef! {0}+{1}+{2}", info.GetAI().GetType(), info.m_class.m_subService, info.m_vehicleType); } continue; } var modelList = BasicTransportExtensionSingleton.instance(def).getAssetListForPrefix(prefix); if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode) { TLMUtils.doLog("removeAllUnwantedVehicles: models found: {0}", modelList == null ? "?!?" : modelList.Count.ToString()); } if (modelList.Count > 0) { Dictionary <ushort, VehicleInfo> vehiclesToRemove = new Dictionary <ushort, VehicleInfo>(); for (int i = 0; i < tl.CountVehicles(lineId); i++) { var vehicle = tl.GetVehicle(i); if (vehicle != 0) { VehicleInfo info2 = instance3.m_vehicles.m_buffer[(int)vehicle].Info; if (!modelList.Contains(info2.name)) { vehiclesToRemove[vehicle] = info2; } } } foreach (var item in vehiclesToRemove) { item.Value.m_vehicleAI.SetTransportLine(item.Key, ref instance3.m_vehicles.m_buffer[item.Key], 0); } } } } }
public static void RemoveAllUnwantedVehicles() { for (ushort lineId = 1; lineId < Singleton <TransportManager> .instance.m_lines.m_size; lineId++) { if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].m_flags & TransportLine.Flags.Created) != TransportLine.Flags.None) { uint idx; IAssetSelectorExtension extension; if (TLMTransportLineExtension.instance.IsUsingCustomConfig(lineId)) { idx = lineId; extension = TLMTransportLineExtension.instance; } else { idx = TLMLineUtils.getPrefix(lineId); var def = TransportSystemDefinition.from(lineId); extension = def.GetTransportExtension(); } TransportLine tl = Singleton <TransportManager> .instance.m_lines.m_buffer[lineId]; var modelList = extension.GetAssetList(idx); VehicleManager vm = Singleton <VehicleManager> .instance; VehicleInfo info = vm.m_vehicles.m_buffer[Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].GetVehicle(0)].Info; if (TLMSingleton.instance != null && TLMSingleton.debugMode) { TLMUtils.doLog("removeAllUnwantedVehicles: models found: {0}", modelList == null ? "?!?" : modelList.Count.ToString()); } if (modelList.Count > 0) { Dictionary <ushort, VehicleInfo> vehiclesToRemove = new Dictionary <ushort, VehicleInfo>(); for (int i = 0; i < tl.CountVehicles(lineId); i++) { var vehicle = tl.GetVehicle(i); if (vehicle != 0) { VehicleInfo info2 = vm.m_vehicles.m_buffer[(int)vehicle].Info; if (!modelList.Contains(info2.name)) { vehiclesToRemove[vehicle] = info2; } } } foreach (var item in vehiclesToRemove) { item.Value.m_vehicleAI.SetTransportLine(item.Key, ref vm.m_vehicles.m_buffer[item.Key], 0); } } } } }
public static void RemoveAllUnwantedVehicles() { VehicleManager vm = Singleton <VehicleManager> .instance; for (ushort lineId = 1; lineId < Singleton <TransportManager> .instance.m_lines.m_size; lineId++) { if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].m_flags & TransportLine.Flags.Created) != TransportLine.Flags.None) { IBasicExtension extension = TLMLineUtils.GetEffectiveExtensionForLine(lineId); ref TransportLine tl = ref Singleton <TransportManager> .instance.m_lines.m_buffer[lineId]; List <string> modelList = extension.GetAssetListForLine(lineId); if (TransportLinesManagerMod.DebugMode) { LogUtils.DoLog("removeAllUnwantedVehicles: models found: {0}", modelList == null ? "?!?" : modelList.Count.ToString()); } if (modelList.Count > 0) { var vehiclesToRemove = new Dictionary <ushort, VehicleInfo>(); for (int i = 0; i < tl.CountVehicles(lineId); i++) { ushort vehicle = tl.GetVehicle(i); if (vehicle != 0) { VehicleInfo info2 = vm.m_vehicles.m_buffer[vehicle].Info; if (!modelList.Contains(info2.name)) { vehiclesToRemove[vehicle] = info2; } } } foreach (KeyValuePair <ushort, VehicleInfo> item in vehiclesToRemove) { if (item.Value.m_vehicleAI is BusAI) { VehicleUtils.ReplaceVehicleModel(item.Key, extension.GetAModel(lineId)); } else { item.Value.m_vehicleAI.SetTransportLine(item.Key, ref vm.m_vehicles.m_buffer[item.Key], 0); } } } } }
public void updateBidings() { if (showExtraStopInfo) { foreach (var resLabel in residentCounters) { TLMLineUtils.GetQuantityPassengerWaiting(resLabel.Key, out int residents, out int tourists, out int ttb); resLabel.Value.text = residents.ToString(); touristCounters[resLabel.Key].text = tourists.ToString(); ttbTimers[resLabel.Key].text = ttb.ToString(); ttbTimers[resLabel.Key].color = getColorForTTB(ttb); } ushort lineID = parent.CurrentSelectedId; TransportLine t = TLMController.instance.tm.m_lines.m_buffer[(int)lineID]; Color lineColor = TLMController.instance.tm.GetLineColor(lineID); int vehicleCount = t.CountVehicles(lineID); List <ushort> oldItems = lineVehicles.Keys.ToList(); vehiclesOnStation.Clear(); for (int v = 0; v < vehicleCount; v++) { ushort vehicleId = t.GetVehicle(v); UILabel vehicleLabel = null; if (oldItems.Contains(vehicleId)) { vehicleLabel = lineVehicles[vehicleId]; TLMLineUtils.GetVehicleCapacityAndFill(vehicleId, Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId], out int fill, out int cap); vehicleLabel.text = string.Format("{0}/{1}", fill, cap); var labelStation = residentCounters[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_targetBuilding]; updateVehiclePosition(vehicleLabel); oldItems.Remove(vehicleId); } else { AddVehicleToLinearMap(lineColor, vehicleId); } } foreach (ushort dead in oldItems) { GameObject.Destroy(lineVehicles[dead].gameObject); lineVehicles.Remove(dead); } } }
public static ushort GetPreviousVehicle(ushort lineID, ushort vehicleID) { TransportLine transportLine = Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID]; int num1 = transportLine.CountVehicles(lineID); ushort num2 = 0; for (int index = 0; index < num1; ++index) { ushort vehicle = transportLine.GetVehicle(index); if ((int)vehicle == (int)vehicleID) { if ((int)num2 == 0) { return(transportLine.GetVehicle(num1 - 1)); } return(num2); } num2 = vehicle; } return(transportLine.m_vehicles); }
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 RemoveRandomVehicle(ushort lineID, bool descreaseVehicleCount = true) { TransportLine transportLine = Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID]; int index = Singleton <SimulationManager> .instance.m_randomizer.Int32((uint)transportLine.CountVehicles(lineID)); TransportLineMod.RemoveVehicle(lineID, transportLine.GetVehicle(index), descreaseVehicleCount); }
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 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); } } }