public static void RemoveAllUnwantedVehicles() { var r = new Randomizer(); for (ushort vehicleId = 1; vehicleId < Singleton <VehicleManager> .instance.m_vehicles.m_size; vehicleId++) { if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Created) != 0) { ref Vehicle vehicle = ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId]; VehicleInfo vehicleInfo = vehicle.Info; if (vehicleInfo != null && !VehicleUtils.IsTrailer(vehicleInfo) && vehicle.m_transportLine == 0 && vehicle.m_sourceBuilding > 0) { var buildingSsd = ServiceSystemDefinition.from(vehicleInfo); if (buildingSsd != null) { if (!ExtensionStaticExtensionMethods.IsModelCompatible(vehicle.m_sourceBuilding, vehicleInfo, ref buildingSsd)) { if (vehicleInfo.m_vehicleAI is CarAI) { var model = buildingSsd.GetAModel(ref r, vehicle.m_sourceBuilding); VehicleUtils.ReplaceVehicleModel(vehicleId, model); } else { Singleton <VehicleManager> .instance.ReleaseVehicle(vehicleId); } } } } } }
public void SetVehicleCapacity(string assetName, int newCapacity) { VehicleInfo vehicle = PrefabCollection <VehicleInfo> .FindLoaded(assetName); if (vehicle != null && !VehicleUtils.IsTrailer(vehicle)) { Dictionary <string, MutableTuple <float, int> > assetsCapacitiesPercentagePerTrailer = GetCapacityRelative(vehicle); int capacityUsed = 0; foreach (KeyValuePair <string, MutableTuple <float, int> > entry in assetsCapacitiesPercentagePerTrailer) { SafeGetAsset(entry.Key).Capacity = Mathf.RoundToInt(newCapacity <= 0 ? -1f : entry.Value.First *newCapacity); capacityUsed += SafeGetAsset(entry.Key).Capacity *entry.Value.Second; } if (newCapacity > 0 && capacityUsed != newCapacity) { SafeGetAsset(assetsCapacitiesPercentagePerTrailer.Keys.ElementAt(0)).Capacity += (newCapacity - capacityUsed) / assetsCapacitiesPercentagePerTrailer[assetsCapacitiesPercentagePerTrailer.Keys.ElementAt(0)].Second; } foreach (string entry in assetsCapacitiesPercentagePerTrailer.Keys) { VehicleAI vai = PrefabCollection <VehicleInfo> .FindLoaded(entry).m_vehicleAI; SetVehicleCapacity(vai, SafeGetAsset(entry).Capacity); } SimulationManager.instance.StartCoroutine(TLMVehicleUtils.UpdateCapacityUnitsFromTSD()); } }
// public static void RemoveAllUnwantedVehicles() { using var x = new EnumerableActionThread(new Func<ThreadBase, IEnumerator>(RemoveAllUnwantedVehicles)); } public static IEnumerator RemoveAllUnwantedVehicles(ThreadBase t) { ushort num = 0; while (num < Singleton <VehicleManager> .instance.m_vehicles.m_size) { VehicleInfo vehicleInfo = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].Info; if (vehicleInfo != null && !VehicleUtils.IsTrailer(vehicleInfo) && Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].m_transportLine == 0 && Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].m_sourceBuilding > 0) { BuildingInfo buildingInfo = Singleton <BuildingManager> .instance.m_buildings.m_buffer[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].m_sourceBuilding].Info; var buildingSsd = ServiceSystemDefinition.from(buildingInfo, vehicleInfo.m_vehicleType); if (buildingSsd != null) { if (!ExtensionStaticExtensionMethods.IsModelCompatible(Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].m_sourceBuilding, vehicleInfo, ref buildingSsd)) { Singleton <VehicleManager> .instance.ReleaseVehicle(num); } } } if (num % 256 == 255) { yield return(num); } num++; } yield break; }
public static IEnumerator RemoveAllUnwantedVehicles(ThreadBase t) { ushort vehId = 1; while (vehId < Singleton <VehicleManager> .instance.m_vehicles.m_size) { Vehicle vehicle = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehId]; VehicleInfo vehicleInfo = vehicle.Info; if (vehicleInfo != null && !VehicleUtils.IsTrailer(vehicleInfo) && vehicle.m_transportLine == 0) { uint citizenOwner = vehicle.Info.m_vehicleAI.GetOwnerID(vehId, ref vehicle).Citizen; if (citizenOwner > 0) { var ownerWealth = CitizenWealthDefinition.from(CitizenManager.instance.m_citizens.m_buffer[citizenOwner].WealthLevel); if (ownerWealth != null) { var ext = ownerWealth.GetVehicleExtension(); if (!ext.IsModelCompatible(vehicleInfo)) { Singleton <VehicleManager> .instance.ReleaseVehicle(vehId); } } } } if (vehId % 256 == 255) { yield return(vehId); } vehId++; } vehId = 1; while (vehId < Singleton <VehicleManager> .instance.m_parkedVehicles.m_size) { VehicleParked vehicle = Singleton <VehicleManager> .instance.m_parkedVehicles.m_buffer[vehId]; VehicleInfo vehicleInfo = vehicle.Info; if (vehicleInfo != null && !VehicleUtils.IsTrailer(vehicleInfo)) { uint citizenOwner = vehicle.m_ownerCitizen; if (citizenOwner > 0) { var ownerWealth = CitizenWealthDefinition.from(CitizenManager.instance.m_citizens.m_buffer[citizenOwner].WealthLevel); if (ownerWealth != null) { if (!ownerWealth.GetVehicleExtension().IsModelCompatible(vehicleInfo)) { Singleton <VehicleManager> .instance.m_parkedVehicles.m_buffer[vehId].Info = ownerWealth.GetVehicleExtension().GetAModel(); } } } } if (vehId % 256 == 255) { yield return(vehId); } vehId++; } yield break; }
private int UpdateDefaultCapacity <AI>(AI ai) where AI : VehicleAI { if (!m_defaultCapacities.ContainsKey(ai.m_info.name)) { m_defaultCapacities[ai.m_info.name] = (int)VehicleUtils.GetVehicleCapacityField(ai).GetValue(ai); if (CommonProperties.DebugMode) { LogUtils.DoLog($"STORED DEFAULT VEHICLE CAPACITY {m_defaultCapacities[ai.m_info.name] } for {ai.m_info.name}"); } } return(m_defaultCapacities[ai.m_info.name]); }
private void SetVehicleCapacity <AI>(AI ai, int newCapacity) where AI : VehicleAI { int defaultCapacity = UpdateDefaultCapacity(ai); if (newCapacity <= 0) { newCapacity = defaultCapacity; } VehicleUtils.GetVehicleCapacityField(ai).SetValue(ai, newCapacity); if (CommonProperties.DebugMode) { LogUtils.DoLog($"SET VEHICLE CAPACITY {newCapacity} at {ai.m_info.name}"); } }
internal static List <string> LoadBasicAssets(CitizenWealthDefinition definition) { var basicAssetsList = new List <string>(); for (uint num = 0u; num < (ulong)PrefabCollection <VehicleInfo> .PrefabCount(); num += 1u) { VehicleInfo prefab = PrefabCollection <VehicleInfo> .GetPrefab(num); if (!(prefab == null) && definition.isFromSystem(prefab) && !VehicleUtils.IsTrailer(prefab)) { basicAssetsList.Add(prefab.name); } } return(basicAssetsList); }
private void CapacityEditor_eventTextSubmitted(UIComponent x, string y) { if (m_isLoading || !int.TryParse(y.IsNullOrWhiteSpace() ? "0" : y, out int value)) { return; } var capacityEditor = x as UITextField; string assetName = x.parent.GetComponentInChildren <UICheckBox>().objectUserData.ToString(); VehicleInfo info = PrefabCollection <VehicleInfo> .FindLoaded(assetName); TransportSystemDefinition.From(info).GetTransportExtension().SetVehicleCapacity(assetName, value); m_isLoading = true; capacityEditor.text = VehicleUtils.GetCapacity(info).ToString("0"); m_isLoading = false; }
public VehicleInfo GetAModel(ushort lineID) { VehicleInfo info = null; List <string> assetList = ExtensionStaticExtensionMethods.GetAssetListForLine(this, lineID); while (info == null && assetList.Count > 0) { info = VehicleUtils.GetRandomModel(assetList, out string modelName); if (info == null) { ExtensionStaticExtensionMethods.RemoveAssetFromLine(this, lineID, modelName); assetList = ExtensionStaticExtensionMethods.GetAssetListForLine(this, lineID); } } return(info); }
internal static List <string> LoadBasicAssets(ref TransportSystemDefinition definition) { var basicAssetsList = new List <string>(); TLMUtils.doLog("LoadBasicAssets: pre prefab read"); for (uint num = 0u; num < (ulong)PrefabCollection <VehicleInfo> .PrefabCount(); num += 1u) { VehicleInfo prefab = PrefabCollection <VehicleInfo> .GetPrefab(num); if (!(prefab == null) && definition.IsFromSystem(prefab) && !VehicleUtils.IsTrailer(prefab)) { basicAssetsList.Add(prefab.name); } } return(basicAssetsList); }
public VehicleInfo GetAModel() { LogUtils.DoLog("[{0}] GetAModel", typeof(W).Name); IEnumerable <string> assetList = GetEffectiveAssetList(); VehicleInfo info = null; while (info == null && assetList.Count() > 0) { info = VehicleUtils.GetRandomModel(assetList, out string modelName); if (info == null) { RemoveAsset(modelName); assetList = GetEffectiveAssetList(); } } return(info); }
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); } } } } }
private void ProcessExteriorSound() { if (SourceEntity is Vehicle is false) { return; } if (IsExteriorSound is false) { return; } // If player is in the source vehicle and use 3rd person mode we use original sound volume if (Main.PlayerVehicle == SourceEntity == false || CameraUtils.IsPlayerUseFirstPerson() == false) { SoundInstances.ForEach(x => x.Volume = _originalVolume); return; } // Define volume based on is car doors open / closed SoundInstances.ForEach(x => x.Volume = VehicleUtils.IsAnyOfFrontDoorsOpen((Vehicle)SourceEntity) ? _originalVolume : _originalVolume / 2); }
private void ProcessInteriorSound() { if (SourceEntity is Vehicle is false) { return; } if (IsInteriorSound is false) { return; } // If player is in the source vehicle we use original sound volume if (Main.PlayerVehicle == SourceEntity) { SoundInstances.ForEach(x => x.Volume = _originalVolume); return; } // Define volume based on is car doors open / closed SoundInstances.ForEach(x => x.Volume = VehicleUtils.IsAnyOfFrontDoorsOpen((Vehicle)SourceEntity) ? _originalVolume : _originalVolume / 4); }
public static Dictionary <string, string> GetSelectedBasicAssetsForLine <T>(this T it, ushort lineId) where T : IAssetSelectorExtension => it.GetAssetListForLine(lineId).Intersect(it.GetBasicAssetListForLine(lineId)).ToDictionary(x => x, x => string.Format("[Cap={0}] {1}", VehicleUtils.GetCapacity(PrefabCollection <VehicleInfo> .FindLoaded(x)), Locale.Get("VEHICLE_TITLE", x)));
public void OnSetTarget(Type source) { if (source == GetType()) { return; } TransportSystemDefinition tsd = TransportSystem; if (!tsd.HasVehicles()) { MainPanel.isVisible = false; return; } m_isLoading = true; LogUtils.DoLog("tsd = {0}", tsd); IBasicExtension config = TLMLineUtils.GetEffectiveExtensionForLine(GetLineID()); if (TransportSystem != m_lastSystem) { m_defaultAssets = tsd.GetTransportExtension().GetAllBasicAssetsForLine(0); UIPanel[] depotChecks = m_checkboxTemplateList.SetItemCount(m_defaultAssets.Count); LogUtils.DoLog("m_defaultAssets Size = {0} ({1})", m_defaultAssets?.Count, string.Join(",", m_defaultAssets.Keys?.ToArray() ?? new string[0])); for (int i = 0; i < m_defaultAssets.Count; i++) { string assetName = m_defaultAssets.Keys.ElementAt(i); UICheckBox checkbox = depotChecks[i].GetComponentInChildren <UICheckBox>(); checkbox.objectUserData = assetName; UITextField capacityEditor = depotChecks[i].GetComponentInChildren <UITextField>(); capacityEditor.text = VehicleUtils.GetCapacity(PrefabCollection <VehicleInfo> .FindLoaded(assetName)).ToString("0"); if (checkbox.label.objectUserData == null) { checkbox.eventCheckChanged += (x, y) => { if (m_isLoading) { return; } ushort lineId = GetLineID(); IBasicExtension extension = TLMLineUtils.GetEffectiveExtensionForLine(lineId); LogUtils.DoLog($"checkbox event: {x.objectUserData} => {y} at {extension}[{lineId}]"); if (y) { extension.AddAssetToLine(lineId, x.objectUserData.ToString()); } else { extension.RemoveAssetFromLine(lineId, x.objectUserData.ToString()); } }; CreateModelCheckBox(checkbox); KlyteMonoUtils.LimitWidthAndBox(checkbox.label, 280); capacityEditor.eventTextSubmitted += CapacityEditor_eventTextSubmitted;; capacityEditor.eventMouseEnter += (x, y) => { m_lastInfo = PrefabCollection <VehicleInfo> .FindLoaded(checkbox.objectUserData.ToString()); RedrawModel(); }; checkbox.label.objectUserData = true; } checkbox.text = m_defaultAssets[assetName]; } m_lastSystem = TransportSystem; } else { List <string> allowedAssets = config.GetAssetListForLine(GetLineID()); for (int i = 0; i < m_checkboxTemplateList.items.Count; i++) { UICheckBox checkbox = m_checkboxTemplateList.items[i].GetComponentInChildren <UICheckBox>(); checkbox.isChecked = allowedAssets.Contains(checkbox.objectUserData.ToString()); } } if (TransportLinesManagerMod.DebugMode) { List <string> allowedAssets = config.GetAssetListForLine(GetLineID()); LogUtils.DoLog($"selectedAssets Size = {allowedAssets?.Count} ({ string.Join(",", allowedAssets?.ToArray() ?? new string[0])}) {config?.GetType()}"); } if (config is TLMTransportLineConfiguration) { m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE"), TLMLineUtils.GetLineStringId(GetLineID())); } else { int prefix = (int)TLMPrefixesUtils.GetPrefix(GetLineID()); m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE_PREFIX"), prefix > 0 ? NumberingUtils.GetStringFromNumber(TLMPrefixesUtils.GetStringOptionsForPrefix(tsd), prefix + 1) : Locale.Get("K45_TLM_UNPREFIXED"), tsd.GetTransportName()); } m_isLoading = false; }