private void UpdateProgress() { VehicleManager instance = Singleton <VehicleManager> .instance; ushort vehicle = WorldInfoPanel.GetCurrentInstanceID().Vehicle; ushort firstVehicle = instance.m_vehicles.m_buffer[(int)vehicle].GetFirstVehicle(vehicle); float current; float max; if (BusAIMod.GetProgressStatus(firstVehicle, ref instance.m_vehicles.m_buffer[(int)firstVehicle], out current, out max) || (int)firstVehicle != (int)(ushort)this._cachedProgressVehicle.GetValue((object)this._publicTransportVehicleWorldInfoPanel)) { this._cachedCurrentProgress.SetValue((object)this._publicTransportVehicleWorldInfoPanel, (object)current); this._cachedTotalProgress.SetValue((object)this._publicTransportVehicleWorldInfoPanel, (object)max); this._cachedProgressVehicle.SetValue((object)this._publicTransportVehicleWorldInfoPanel, (object)firstVehicle); } else { current = (float)this._cachedCurrentProgress.GetValue((object)this._publicTransportVehicleWorldInfoPanel); max = (float)this._cachedTotalProgress.GetValue((object)this._publicTransportVehicleWorldInfoPanel); } if ((double)max == 0.0) { return; } this._distanceTraveled.parent.Show(); this._distanceProgress.parent.Show(); float num = current / max; int p = Mathf.RoundToInt(num * 100f); this._distanceTraveled.value = num; this._distanceProgress.text = LocaleFormatter.FormatPercentage(p); }
private bool ArriveAtTarget(ushort vehicleID, ref Vehicle data) { if ((int)data.m_targetBuilding == 0) { Singleton <VehicleManager> .instance.ReleaseVehicle(vehicleID); return(true); } ushort nextStop = 0; if ((int)data.m_transportLine != 0) { nextStop = TransportLine.GetNextStop(data.m_targetBuilding); } ushort targetBuilding = data.m_targetBuilding; ushort transferSize1 = data.m_transferSize; BusAIMod.UnloadPassengers((BusAI)this, vehicleID, ref data, targetBuilding, nextStop); ushort num1 = (ushort)((uint)transferSize1 - (uint)data.m_transferSize); VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].LastStopGonePassengers = (int)num1; VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].CurrentStop = targetBuilding; NetManagerMod.m_cachedNodeData[(int)targetBuilding].PassengersOut += (int)num1; if ((int)nextStop == 0) { data.m_flags |= Vehicle.Flags.GoingBack; if (!this.StartPathFind(vehicleID, ref data)) { return(true); } data.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.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; data.m_flags |= Vehicle.Flags.Stopped; data.m_waitCounter = (byte)0; } else { data.m_targetBuilding = nextStop; if (!this.StartPathFind(vehicleID, ref data)) { return(true); } ushort transferSize2 = data.m_transferSize; BusAIMod.LoadPassengers((BusAI)this, vehicleID, ref data, targetBuilding, nextStop); ushort num2 = (ushort)((uint)data.m_transferSize - (uint)transferSize2); int ticketPrice = data.Info.m_vehicleAI.GetTicketPrice(vehicleID, ref data); VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].Add((int)num2, ticketPrice); NetManagerMod.m_cachedNodeData[(int)targetBuilding].PassengersIn += (int)num2; data.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.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; data.m_flags |= Vehicle.Flags.Stopped; data.m_waitCounter = (byte)0; } return(false); }
public new bool CanLeave(ushort vehicleID, ref Vehicle vehicleData) { if ((int)vehicleData.m_leadingVehicle != 0) { return(true); } if ((int)vehicleData.m_waitCounter >= 12 && BusAIMod.IsBoardingDone(vehicleID, ref vehicleData)) { return(BusAIMod.IsUnbunchingDone(vehicleID, ref vehicleData)); } return(false); }
public void OnLevelLoaded(LoadMode mode) { this._loadMode = mode; if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame) { return; } try { Utils.Log((object)"Begin init version: 3.8.10"); ImprovedPublicTransportMod.Settings.LogSettings(); this.ReleaseUnusedCitizenUnits(); UIView objectOfType = UnityEngine.Object.FindObjectOfType <UIView>(); if ((UnityEngine.Object)objectOfType != (UnityEngine.Object)null) { this._iptGameObject = new GameObject("IptGameObject"); this._iptGameObject.transform.parent = objectOfType.transform; this._iptGameObject.AddComponent <VehicleEditor>(); this._iptGameObject.AddComponent <PanelExtenderLine>(); this._iptGameObject.AddComponent <PanelExtenderVehicle>(); this._iptGameObject.AddComponent <PanelExtenderCityService>(); this._iptGameObject.AddComponent <SimHelper>(); this._iptGameObject.AddComponent <LineWatcher>(); this._worldInfoPanel = new GameObject("PublicTransportStopWorldInfoPanel"); this._worldInfoPanel.transform.parent = objectOfType.transform; this._worldInfoPanel.AddComponent <PublicTransportStopWorldInfoPanel>().Show(); NetManagerMod.Init(); VehicleManagerMod.Init(); BusAIMod.Init(); PassengerTrainAIMod.Init(); PassengerShipAIMod.Init(); PassengerPlaneAIMod.Init(); TramAIMod.Init(); BuildingWatcher.instance.Init(); LineWatcher.instance.Init(); TransportLineMod.Init(); VehiclePrefabs.Init(); SerializableDataExtension.instance.Loaded = true; LocaleModifier.Init(); Utils.Log((object)"Loading done!"); } else { Utils.LogError((object)"UIView not found, aborting!"); } } catch (Exception ex) { Utils.LogError((object)("Error during initialization, IPT disables itself." + System.Environment.NewLine + "Please try again without any other mod." + System.Environment.NewLine + "Please upload your log file and post the link here if that didn't help:" + System.Environment.NewLine + "http://steamcommunity.com/workshop/filedetails/discussion/424106600/615086038663282271/" + System.Environment.NewLine + ex.Message + System.Environment.NewLine + (object)ex.InnerException + System.Environment.NewLine + ex.StackTrace)); this.Deinit(); } }
private static bool IsBoardingDone(ushort vehicleID, ref Vehicle vehicleData) { CitizenManager instance1 = Singleton <CitizenManager> .instance; bool flag = false; ushort firstVehicle = vehicleData.GetFirstVehicle(vehicleID); if ((int)Singleton <VehicleManager> .instance.m_vehicles.m_buffer[(int)firstVehicle].m_waitCounter >= 60) { flag = true; } uint num1 = vehicleData.m_citizenUnits; int num2 = 0; while ((int)num1 != 0) { uint nextUnit = instance1.m_units.m_buffer[(int)num1].m_nextUnit; for (int index = 0; index < 5; ++index) { uint citizen = instance1.m_units.m_buffer[(int)num1].GetCitizen(index); if ((int)citizen != 0) { ushort instance2 = instance1.m_citizens.m_buffer[(int)citizen].m_instance; if ((int)instance2 != 0 && (instance1.m_instances.m_buffer[(int)instance2].m_flags & CitizenInstance.Flags.EnteringVehicle) != CitizenInstance.Flags.None) { if (!flag) { return(false); } BusAIMod.EnterVehicle(firstVehicle, instance2, ref instance1.m_instances.m_buffer[(int)instance2]); } } } num1 = nextUnit; if (++num2 > 524288) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace); break; } } return(true); }
private void Deinit() { TramAIMod.Deinit(); PassengerTrainAIMod.Deinit(); PassengerShipAIMod.Deinit(); PassengerPlaneAIMod.Deinit(); BusAIMod.Deinit(); TransportLineMod.Deinit(); BuildingWatcher.instance.Deinit(); NetManagerMod.Deinit(); VehicleManagerMod.Deinit(); VehiclePrefabs.Deinit(); SerializableDataExtension.instance.Loaded = false; LocaleModifier.Deinit(); if ((UnityEngine.Object) this._iptGameObject != (UnityEngine.Object)null) { UnityEngine.Object.Destroy((UnityEngine.Object) this._iptGameObject); } if (!((UnityEngine.Object) this._worldInfoPanel != (UnityEngine.Object)null)) { return; } UnityEngine.Object.Destroy((UnityEngine.Object) this._worldInfoPanel); }
private static bool IsUnbunchingDone(ushort vehicleID, ref Vehicle vehicleData) { bool flag; try { if ((int)vehicleData.m_transportLine == 0 || (int)ImprovedPublicTransportMod.Settings.IntervalAggressionFactor == 0 || (!TransportLineMod.GetUnbunchingState(vehicleData.m_transportLine) || (int)vehicleData.m_waitCounter >= (int)(byte)Mathf.Min((int)ImprovedPublicTransportMod.Settings.IntervalAggressionFactor * 6 + 12, (int)byte.MaxValue))) { flag = true; } else { TransportManager instance1 = Singleton <TransportManager> .instance; int length = instance1.m_lines.m_buffer[(int)vehicleData.m_transportLine].CountVehicles(vehicleData.m_transportLine); if (length == 1) { flag = true; } else { ushort currentStop = VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].CurrentStop; if ((int)currentStop != 0 && !NetManagerMod.m_cachedNodeData[(int)currentStop].Unbunching) { flag = true; } else if ((int)vehicleData.m_lastFrame != 0) { flag = false; } else { ushort vehicleID1 = instance1.m_lines.m_buffer[(int)vehicleData.m_transportLine].m_vehicles; VehicleManager instance2 = Singleton <VehicleManager> .instance; float max = 0.0f; ushort[] numArray = new ushort[length]; float[] keys = new float[length]; for (int index = 0; index < length; ++index) { float current; BusAIMod.GetProgressStatus(vehicleID1, ref instance2.m_vehicles.m_buffer[(int)vehicleID1], out current, out max); numArray[index] = vehicleID1; keys[index] = current; vehicleID1 = instance2.m_vehicles.m_buffer[(int)vehicleID1].m_nextLineVehicle; } Array.Sort <float, ushort>(keys, numArray); int index1 = Array.IndexOf <ushort>(numArray, vehicleID); if (index1 == -1) { flag = true; } else { int index2 = index1 + 1; if (index2 == length) { index2 = 0; } float num = keys[index2] - keys[index1]; if ((double)num < 0.0) { num += max; } flag = (double)num > (double)max / (double)length * 0.899999976158142; } } } } } catch (Exception ex) { if (BusAIMod._isDeployed) { Utils.Log((object)(ex.Message + System.Environment.NewLine + System.Environment.StackTrace)); } flag = true; } VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].IsUnbunchingInProgress = !flag; return(flag); }