private void EnsureCitizenUnits() { Vehicle[] buffer = Singleton <VehicleManager> .instance.m_vehicles.m_buffer; for (int index = 0; index < buffer.Length; ++index) { if (buffer[index].m_flags != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive)) { VehicleInfo info = buffer[index].Info; if (!((UnityEngine.Object)info == (UnityEngine.Object)null) && info.m_prefabDataIndex == this.PrefabDataIndex) { PrefabData.EnsureCitizenUnits((ushort)index, ref buffer[index], this.Capacity); } } } }
public void AddItem(PrefabData data, ushort vehicleID = 0) { VehicleListBoxRow[] vehicleListBoxRowArray = new VehicleListBoxRow[this._items.Length + 1]; Array.Copy((Array)this._items, (Array)vehicleListBoxRowArray, this._items.Length); VehicleListBoxRow vehicleListBoxRow = this._scrollablePanel.AddUIComponent <VehicleListBoxRow>(); if ((UnityEngine.Object) this.Font != (UnityEngine.Object)null) { vehicleListBoxRow.Font = this.Font; } vehicleListBoxRow.Prefab = data; vehicleListBoxRow.VehicleID = vehicleID; vehicleListBoxRow.eventMouseDown += new MouseEventHandler(this.OnMouseDown); vehicleListBoxRowArray[this._items.Length] = vehicleListBoxRow; this._items = vehicleListBoxRowArray; }
public static VehicleInfo GetVehicleInfo(ref Randomizer randomizer, ItemClass m_class, ushort lineID, string prefabName) { PrefabData prefabData = Array.Find <PrefabData>(VehiclePrefabs.instance.GetPrefabs(m_class.m_subService), (Predicate <PrefabData>)(item => item.ObjectName == prefabName)); if (prefabData != null) { return(PrefabCollection <VehicleInfo> .GetPrefab((uint)prefabData.PrefabDataIndex)); } Utils.LogWarning((object)("Unknown prefab: " + prefabName)); VehicleManager instance = Singleton <VehicleManager> .instance; instance.RefreshTransferVehicles(); // ISSUE: explicit reference operation // ISSUE: variable of a reference type Randomizer& r = @randomizer; int service = (int)m_class.m_service; int subService = (int)m_class.m_subService; int level = (int)m_class.m_level; return(instance.GetRandomVehicleInfo(r, (ItemClass.Service)service, (ItemClass.SubService)subService, (ItemClass.Level)level)); }
private void OnApplyButtonClick(UIComponent component, UIMouseEventParameter eventParam) { if (this._selectedIndex <= -1) { return; } UITextField uiTextField1 = this._rightSidePanel.Find <UITextField>("Capacity"); UITextField uiTextField2 = this._rightSidePanel.Find <UITextField>("MaintenanceCost"); UITextField uiTextField3 = this._rightSidePanel.Find <UITextField>("TicketPrice"); UITextField uiTextField4 = this._rightSidePanel.Find <UITextField>("MaxSpeed"); UICheckBox uiCheckBox = this._rightSidePanel.Find <UICheckBox>("EngineOnBothEnds"); PrefabData prefab = VehiclePrefabs.instance.GetPrefabs(this._selectedSubService)[this._selectedIndex]; int capacity = Utils.ToInt32(uiTextField1.text) / prefab.CarCount; int int32_1 = Utils.ToInt32(uiTextField2.text); int int32_2 = Utils.ToInt32(uiTextField3.text); int int32_3 = Utils.ToInt32(uiTextField4.text); bool isChecked = uiCheckBox.isChecked; prefab.SetValues(capacity, int32_1, int32_2, int32_3, isChecked); this.UpdateBindings(); }
private void Update() { if (!this._initialized) { this._cityServiceWorldInfoPanel = GameObject.Find("(Library) CityServiceWorldInfoPanel").GetComponent <CityServiceWorldInfoPanel>(); if (!((UnityEngine.Object) this._cityServiceWorldInfoPanel != (UnityEngine.Object)null)) { return; } this.CreateStopsPanel(); this._initialized = true; } else { if (!this._initialized || !this._cityServiceWorldInfoPanel.component.isVisible) { return; } BuildingManager instance1 = Singleton <BuildingManager> .instance; ushort building = Utils.GetPrivate <InstanceID>((object)this._cityServiceWorldInfoPanel, "m_InstanceID").Building; ItemClass.SubService subService = instance1.m_buildings.m_buffer[(int)building].Info.GetSubService(); switch (subService) { case ItemClass.SubService.PublicTransportBus: case ItemClass.SubService.PublicTransportMetro: case ItemClass.SubService.PublicTransportTrain: case ItemClass.SubService.PublicTransportShip: case ItemClass.SubService.PublicTransportPlane: this._vehicleListBox.Hide(); this._stopsListBox.Show(); ushort[] numArray = PanelExtenderCityService.GetStationStops(building); BuildingInfo.SubInfo[] subBuildings = instance1.m_buildings.m_buffer[(int)building].Info.m_subBuildings; if (subBuildings != null && subBuildings.Length != 0) { Vector3 position = instance1.m_buildings.m_buffer[(int)building].m_position; building = instance1.FindBuilding(position, 100f, ItemClass.Service.PublicTransport, ItemClass.SubService.None, Building.Flags.Untouchable, Building.Flags.None); if ((int)building != 0) { ushort[] stationStops = PanelExtenderCityService.GetStationStops(building); if (stationStops.Length != 0) { numArray = ((IEnumerable <ushort>)numArray).Concat <ushort>((IEnumerable <ushort>)stationStops).ToArray <ushort>(); } } } int length = numArray.Length; if (length > 0) { this._titleLabel.text = Localization.Get("CITY_SERVICE_PANEL_TITLE_STATION_STOPS"); this._listBoxPanel.relativePosition = new Vector3(this._listBoxPanel.parent.width + 1f, 0.0f); this._listBoxPanel.Show(); if ((int)this._cachedBuildingID != (int)building || this._cachedStopCount != length) { this._stopsListBox.ClearItems(); for (int index = 0; index < length; ++index) { this._stopsListBox.AddItem(numArray[index], -1); } } } else { this._listBoxPanel.Hide(); } this._cachedStopCount = length; break; case ItemClass.SubService.PublicTransportTaxi: this._vehicleListBox.Show(); this._stopsListBox.Hide(); UIPanel uiPanel = this._cityServiceWorldInfoPanel.Find <UIPanel>("SvsVehicleTypes"); if ((UnityEngine.Object)uiPanel != (UnityEngine.Object)null) { this._listBoxPanel.relativePosition = new Vector3((float)((double)this._listBoxPanel.parent.width + (double)uiPanel.width + 2.0), 0.0f); } List <ushort> depotVehicles = PanelExtenderCityService.GetDepotVehicles(building); int count = depotVehicles.Count; if (count > 0) { this._titleLabel.text = Localization.Get("CITY_SERVICE_PANEL_TITLE_DEPOT_VEHICLES"); this._listBoxPanel.Show(); if ((int)this._cachedBuildingID != (int)building || this._cachedVehicleCount != count) { this._vehicleListBox.ClearItems(); PrefabData[] prefabs = VehiclePrefabs.instance.GetPrefabs(subService); VehicleManager instance2 = Singleton <VehicleManager> .instance; foreach (ushort vehicleID in depotVehicles) { VehicleInfo info = instance2.m_vehicles.m_buffer[(int)vehicleID].Info; for (int index = 0; index < prefabs.Length; ++index) { PrefabData data = prefabs[index]; if (info.name == data.ObjectName) { this._vehicleListBox.AddItem(data, vehicleID); break; } } } } } else { this._listBoxPanel.Hide(); } this._cachedVehicleCount = count; break; default: this._listBoxPanel.Hide(); break; } this._cachedBuildingID = building; } }
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); }
private void UpdateBindings() { ushort vehicleID = 0; ushort lineId = this.GetLineID(out vehicleID); if ((int)lineId == 0) { this._passengerPanel.Hide(); this._statsPanel.Hide(); this._buttonPanel.Hide(); this._publicTransportVehicleWorldInfoPanel.component.height = 229f; } else { this._publicTransportVehicleWorldInfoPanel.component.height = 332f; this._editType.isVisible = !ImprovedPublicTransportMod.Settings.HideVehicleEditor; ItemClass.SubService subService = Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineId].Info.m_class.m_subService; switch (subService) { case ItemClass.SubService.PublicTransportBus: case ItemClass.SubService.PublicTransportMetro: case ItemClass.SubService.PublicTransportTrain: case ItemClass.SubService.PublicTransportTram: case ItemClass.SubService.PublicTransportShip: case ItemClass.SubService.PublicTransportPlane: this._passengerPanel.Show(); if ((int)vehicleID != 0) { this._lastStopExchange.text = string.Format(Localization.Get("VEHICLE_PANEL_LAST_STOP_EXCHANGE"), (object)VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].LastStopGonePassengers, (object)VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].LastStopNewPassengers); break; } break; default: this._passengerPanel.Hide(); break; } this._distanceTraveled.parent.Show(); this._distanceProgress.parent.Show(); VehicleManager vm = Singleton <VehicleManager> .instance; if ((vm.m_vehicles.m_buffer[(int)vehicleID].m_flags & Vehicle.Flags.Stopped) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive)) { if (VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].IsUnbunchingInProgress) { this._status.text = Localization.Get("VEHICLE_PANEL_STATUS_UNBUNCHING"); } this._distance.text = this._status.text; float num = (float)vm.m_vehicles.m_buffer[(int)vehicleID].m_waitCounter / 12f; int p = Mathf.RoundToInt(num * 100f); this._distanceTraveled.value = num; this._distanceTraveled.progressColor = (Color32)Color.green; this._distanceProgress.text = LocaleFormatter.FormatPercentage(p); } else { bool flag = true; string text = Localization.Get("VEHICLE_PANEL_STATUS_NEXT_STOP"); if (subService == ItemClass.SubService.PublicTransportShip) { this.UpdateProgress(); } else if (subService == ItemClass.SubService.PublicTransportPlane) { if ((vm.m_vehicles.m_buffer[(int)vehicleID].m_flags & Vehicle.Flags.Landing) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive) || (vm.m_vehicles.m_buffer[(int)vehicleID].m_flags & Vehicle.Flags.TakingOff) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive) || (vm.m_vehicles.m_buffer[(int)vehicleID].m_flags & Vehicle.Flags.Flying) == ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive)) { text = this._status.text; flag = false; } this.UpdateProgress(); } this._status.text = text; if (flag) { ushort targetBuilding = vm.m_vehicles.m_buffer[(int)vehicleID].m_targetBuilding; InstanceID id = new InstanceID(); id.NetNode = targetBuilding; string name = Singleton <InstanceManager> .instance.GetName(id); this._target.objectUserData = (object)id; this._target.text = name == null?string.Format(Localization.Get("STOP_LIST_BOX_ROW_STOP"), (object)(TransportLineMod.GetStopIndex(lineId, targetBuilding) + 1)) : name; this._target.Enable(); this._target.Show(); } this._distance.text = ColossalFramework.Globalization.Locale.Get(this._distance.localeID); this._distanceTraveled.progressColor = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); } this._statsPanel.Show(); this._passengersCurrentWeek.text = VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].PassengersThisWeek.ToString(); this._passengersLastWeek.text = VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].PassengersLastWeek.ToString(); this._passengersAverage.text = VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].PassengersAverage.ToString(); PrefabData prefabData = Array.Find <PrefabData>(VehiclePrefabs.instance.GetPrefabs(subService), (Predicate <PrefabData>)(item => item.PrefabDataIndex == vm.m_vehicles.m_buffer[(int)vehicleID].Info.m_prefabDataIndex)); int num1 = VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].IncomeThisWeek - prefabData.MaintenanceCost; UILabel earningsCurrentWeek = this._earningsCurrentWeek; float num2 = (float)num1 * 0.01f; string str1 = num2.ToString(ColossalFramework.Globalization.Locale.Get("MONEY_FORMAT"), (IFormatProvider)LocaleManager.cultureInfo); earningsCurrentWeek.text = str1; this._earningsCurrentWeek.textColor = (Color32)this.GetColor((float)num1); int incomeLastWeek = VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].IncomeLastWeek; UILabel earningsLastWeek = this._earningsLastWeek; num2 = (float)incomeLastWeek * 0.01f; string str2 = num2.ToString(ColossalFramework.Globalization.Locale.Get("MONEY_FORMAT"), (IFormatProvider)LocaleManager.cultureInfo); earningsLastWeek.text = str2; this._earningsLastWeek.textColor = (Color32)this.GetColor((float)incomeLastWeek); int incomeAverage = VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].IncomeAverage; UILabel earningsAverage = this._earningsAverage; num2 = (float)incomeAverage * 0.01f; string str3 = num2.ToString(ColossalFramework.Globalization.Locale.Get("MONEY_FORMAT"), (IFormatProvider)LocaleManager.cultureInfo); earningsAverage.text = str3; this._earningsAverage.textColor = (Color32)this.GetColor((float)incomeAverage); this._buttonPanel.Show(); } }