Beispiel #1
0
        public void Show(Vector3 worldMousePosition, InstanceID instanceID)
        {
            this.m_WorldMousePosition = worldMousePosition;
            this.m_InstanceID         = instanceID;
            if (InstanceManager.IsValid(this.m_InstanceID))
            {
                WorldInfoPanel.HideAllWorldInfoPanels();
                NetManager instance      = Singleton <NetManager> .instance;
                ushort     transportLine = instance.m_nodes.m_buffer[(int)this.m_InstanceID.NetNode].m_transportLine;
                this.m_VehicleType.spriteName = PublicTransportWorldInfoPanel.GetVehicleTypeIcon(Singleton <TransportManager> .instance.m_lines.m_buffer[(int)transportLine].Info.m_transportType);
                this.m_StopIndex     = TransportLineMod.GetStopIndex(transportLine, this.m_InstanceID.NetNode);
                this.m_StopName.text = Singleton <InstanceManager> .instance.GetName(this.m_InstanceID) ?? string.Format(Localization.Get("STOP_LIST_BOX_ROW_STOP"), (object)(this.m_StopIndex + 1));

                this.m_SuggestedNames.ClearItems();
                this.m_SuggestedNames.AddItems(this.FindBuildings(instance.m_nodes.m_buffer[(int)this.m_InstanceID.NetNode].m_position), new Func <ushort, string>(this.IDToName));
                this.m_Line.text = Singleton <TransportManager> .instance.GetLineName(transportLine);

                this.Show();
                this.LateUpdate();
            }
            else
            {
                this.Hide();
            }
        }
        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 void SimulationStep(ushort lineID)
 {
     if (!TransportLineMod._init)
     {
         return;
     }
     TransportLineMod.SimulationStepImpl(ref Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID], lineID);
 }
 public static void DequeueVehicle(ushort lineID)
 {
     if (TransportLineMod._lineData[(int)lineID].QueuedVehicles == null)
     {
         return;
     }
     TransportLineMod.DecreaseTargetVehicleCount(lineID);
     TransportLineMod.Dequeue(lineID);
 }
Beispiel #5
0
        private void OnResetButtonClick(UIComponent component, UIMouseEventParameter eventParam)
        {
            int length = Singleton <TransportManager> .instance.m_lines.m_buffer.Length;

            for (int index = 0; index < length; ++index)
            {
                TransportLineMod.SetNextSpawnTime((ushort)index, 0.0f);
            }
        }
        public static void RemoveVehicle(ushort lineID, ushort vehicleID, bool descreaseVehicleCount = true)
        {
            if (descreaseVehicleCount)
            {
                TransportLineMod.DecreaseTargetVehicleCount(lineID);
            }
            VehicleManager instance = Singleton <VehicleManager> .instance;

            instance.m_vehicles.m_buffer[(int)vehicleID].Info.m_vehicleAI.SetTransportLine(vehicleID, ref instance.m_vehicles.m_buffer[(int)vehicleID], (ushort)0);
        }
        private void OnRemoveVehicleClick(UIComponent component, UIMouseEventParameter eventParam)
        {
            ushort firstVehicle = 0;
            ushort lineId       = this.GetLineID(out firstVehicle);

            if ((int)lineId == 0 || (int)firstVehicle == 0)
            {
                return;
            }
            TransportLineMod.SetBudgetControlState(lineId, false);
            TransportLineMod.RemoveVehicle(lineId, firstVehicle, true);
        }
 public static float GetLength(ushort lineID)
 {
     if (ImprovedPublicTransportMod.Settings.CompatibilityMode)
     {
         return(TransportLineMod.CalculateLineLength(lineID));
     }
     if ((double)TransportLineMod._lineData[(int)lineID].Length == 0.0)
     {
         Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID].UpdateMeshData(lineID);
     }
     return(TransportLineMod._lineData[(int)lineID].Length);
 }
 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();
     }
 }
Beispiel #10
0
        private void OnUpdateButtonClick(UIComponent component, UIMouseEventParameter eventParam)
        {
            int length = Singleton <TransportManager> .instance.m_lines.m_buffer.Length;

            for (int index = 0; index < length; ++index)
            {
                TransportLineMod.SetBudgetControlState((ushort)index, this._budgetControl.isChecked);
                if (this._budgetControl.isChecked)
                {
                    TransportLineMod.ClearEnqueuedVehicles((ushort)index);
                }
            }
        }
 public static void EnqueueVehicle(ushort lineID, string prefabName, bool inscreaseVehicleCount = true)
 {
     if (TransportLineMod._lineData[(int)lineID].QueuedVehicles == null)
     {
         TransportLineMod._lineData[(int)lineID].QueuedVehicles = new Queue <string>();
     }
     if (inscreaseVehicleCount)
     {
         TransportLineMod.IncreaseTargetVehicleCount(lineID);
     }
     lock (TransportLineMod._lineData[(int)lineID].QueuedVehicles)
         TransportLineMod._lineData[(int)lineID].QueuedVehicles.Enqueue(prefabName);
 }
 public static bool IsLineDepotStillValid(ushort lineID, ref ushort depotID)
 {
     ItemClass.SubService subService;
     if ((int)depotID == 0 || !BuildingWatcher.IsValidDepot(ref Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)depotID], out subService))
     {
         depotID = TransportLineMod.GetClosestDepot(lineID, Singleton <NetManager> .instance.m_nodes.m_buffer[(int)Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID].GetStop(0)].m_position);
         TransportLineMod._lineData[(int)lineID].Depot = depotID;
         if ((int)depotID == 0)
         {
             TransportLineMod.ClearEnqueuedVehicles(lineID);
             return(false);
         }
     }
     return(true);
 }
 public static void DequeueVehicles(ushort lineID, int[] indexes, bool descreaseVehicleCount = true)
 {
     lock (TransportLineMod._lineData[(int)lineID].QueuedVehicles)
     {
         List <string> stringList = new List <string>((IEnumerable <string>)TransportLineMod._lineData[(int)lineID].QueuedVehicles);
         for (int index = indexes.Length - 1; index >= 0; --index)
         {
             stringList.RemoveAt(indexes[index]);
             if (descreaseVehicleCount)
             {
                 TransportLineMod.DecreaseTargetVehicleCount(lineID);
             }
         }
         TransportLineMod._lineData[(int)lineID].QueuedVehicles = new Queue <string>((IEnumerable <string>)stringList);
     }
 }
Beispiel #14
0
        private void OnDefaultVehicleCountSubmitted(UIComponent component, string text)
        {
            int int32 = Utils.ToInt32(text);

            ImprovedPublicTransportMod.Settings.DefaultVehicleCount = int32;
            TransportManager instance = Singleton <TransportManager> .instance;
            int length = instance.m_lines.m_buffer.Length;

            for (int index = 0; index < length; ++index)
            {
                if (!instance.m_lines.m_buffer[index].Complete)
                {
                    TransportLineMod.SetTargetVehicleCount((ushort)index, int32);
                }
            }
        }
        private static void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteString(TransportLineMod._dataVersion, data);
                for (ushort lineID = 0; (int)lineID < 256; ++lineID)
                {
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(TransportLineMod.GetTargetVehicleCount(lineID)), data);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(Mathf.Max(TransportLineMod.GetNextSpawnTime(lineID) - SimHelper.instance.SimulationTime, 0.0f)), data);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(TransportLineMod.GetBudgetControlState(lineID)), data);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(TransportLineMod.GetDepot(lineID)), data);
                    int num = 0;
                    HashSet <string> prefabs = TransportLineMod.GetPrefabs(lineID);
                    if (prefabs != null)
                    {
                        num = prefabs.Count;
                    }
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(num), data);
                    if (num > 0)
                    {
                        foreach (string s in prefabs)
                        {
                            SerializableDataExtension.WriteString(s, data);
                        }
                    }
                    string[] enqueuedVehicles = TransportLineMod.GetEnqueuedVehicles(lineID);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(enqueuedVehicles.Length), data);
                    if (enqueuedVehicles.Length != 0)
                    {
                        foreach (string s in enqueuedVehicles)
                        {
                            SerializableDataExtension.WriteString(s, data);
                        }
                    }
                    SerializableDataExtension.WriteBool(TransportLineMod.GetUnbunchingState(lineID), data);
                }
                SerializableDataExtension.instance.SerializableData.SaveData(TransportLineMod._dataID, data.ToArray());
            }
            catch (Exception ex)
            {
                string msg = "Error while saving transport line data! " + ex.Message + " " + (object)ex.InnerException;
                Utils.LogError((object)msg);
                CODebugBase <LogChannel> .Log(LogChannel.Modding, msg, ErrorLevel.Error);
            }
        }
Beispiel #16
0
 private void Update()
 {
     if (!this._initialized)
     {
         return;
     }
     if (this.SimulationLineCount > this.KnownLineCount)
     {
         Array16 <TransportLine> lines = Singleton <TransportManager> .instance.m_lines;
         for (ushort lineID = 0; (uint)lineID < lines.m_size; ++lineID)
         {
             if (LineWatcher.IsValid(ref lines.m_buffer[(int)lineID]) && this._knownLines.Add(lineID))
             {
                 TransportLineMod.SetLineDefaults(lineID);
                 Vector3 position     = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)lines.m_buffer[(int)lineID].GetStop(0)].m_position;
                 ushort  closestDepot = TransportLineMod.GetClosestDepot(lineID, position);
                 if ((int)closestDepot != 0)
                 {
                     TransportLineMod.SetDepot(lineID, closestDepot);
                 }
                 if (ImprovedPublicTransportMod.Settings.ShowLineInfo)
                 {
                     WorldInfoPanel.Show <PublicTransportWorldInfoPanel>(position, new InstanceID()
                     {
                         TransportLine = lineID
                     });
                 }
             }
         }
     }
     else
     {
         if (this.SimulationLineCount >= this.KnownLineCount)
         {
             return;
         }
         Array16 <TransportLine> lines = Singleton <TransportManager> .instance.m_lines;
         for (ushort index = 0; (uint)index < lines.m_size; ++index)
         {
             if (!LineWatcher.IsValid(ref lines.m_buffer[(int)index]))
             {
                 this._knownLines.Remove(index);
             }
         }
     }
 }
 public static void Deinit()
 {
     if (TransportLineMod._isDeployed)
     {
         TransportLineMod._redirectionSimulationStep.Revert();
         TransportLineMod._redirectionSimulationStep = (Redirection <TransportLine, TransportLineMod>)null;
         if (!ImprovedPublicTransportMod.Settings.CompatibilityMode)
         {
             TransportLineMod.RevertDetourUpdateMeshData();
         }
         TransportLineMod._redirectionUpdateMeshData = (Redirection <TransportLine, TransportLineMod>)null;
         TransportLineMod._isDeployed = false;
     }
     TransportLineMod._lineData = (LineData[])null;
     SerializableDataExtension.instance.EventSaveData -= new SerializableDataExtension.SaveDataEventHandler(TransportLineMod.OnSaveData);
     TransportLineMod._init = false;
 }
Beispiel #18
0
 private void OnCompatibilityModeChanged(UIComponent component, bool isChecked)
 {
     if (ImprovedPublicTransportMod.Settings.CompatibilityMode == isChecked)
     {
         return;
     }
     Utils.Log((object)("Changing compatibility mode: " + (isChecked ? "on" : "off")));
     ImprovedPublicTransportMod.Settings.CompatibilityMode = isChecked;
     if (isChecked)
     {
         TransportLineMod.RevertDetourUpdateMeshData();
     }
     else
     {
         TransportLineMod.DetourUpdateMeshData();
     }
 }
Beispiel #19
0
        private void OnBudgetCheckChanged(UIComponent component, bool isChecked)
        {
            if (ImprovedPublicTransportMod.Settings.BudgetControl == isChecked)
            {
                return;
            }
            ImprovedPublicTransportMod.Settings.BudgetControl = isChecked;
            TransportManager instance = Singleton <TransportManager> .instance;
            int length = instance.m_lines.m_buffer.Length;

            for (int index = 0; index < length; ++index)
            {
                if (!instance.m_lines.m_buffer[index].Complete)
                {
                    TransportLineMod.SetBudgetControlState((ushort)index, isChecked);
                }
            }
        }
        private void OnChangeVehicleClick(UIComponent component, UIMouseEventParameter eventParam)
        {
            ushort firstVehicle = 0;
            ushort lineId       = this.GetLineID(out firstVehicle);

            if ((int)lineId == 0)
            {
                return;
            }
            ushort num = !(component.name == "PreviousVehicle") ? TransportLineMod.GetNextVehicle(lineId, firstVehicle) : TransportLineMod.GetPreviousVehicle(lineId, firstVehicle);

            if ((int)firstVehicle == (int)num)
            {
                return;
            }
            InstanceID instanceId = new InstanceID();

            instanceId.Vehicle = num;
            WorldInfoPanel.ChangeInstanceID(WorldInfoPanel.GetCurrentInstanceID(), instanceId);
            ToolsModifierControl.cameraController.SetTarget(instanceId, ToolsModifierControl.cameraController.transform.position, Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift));
        }
 public static void Init()
 {
     if (!TransportLineMod.TryLoadData(out TransportLineMod._lineData))
     {
         Utils.Log((object)"Loading default transport line data.");
         NetManager       instance1 = Singleton <NetManager> .instance;
         TransportManager instance2 = Singleton <TransportManager> .instance;
         int length = instance2.m_lines.m_buffer.Length;
         for (int index = 0; index < length; ++index)
         {
             if (instance2.m_lines.m_buffer[index].Complete)
             {
                 int num = instance2.m_lines.m_buffer[index].CountVehicles((ushort)index);
                 TransportLineMod._lineData[index].TargetVehicleCount = num;
             }
             else
             {
                 TransportLineMod._lineData[index].TargetVehicleCount = ImprovedPublicTransportMod.Settings.DefaultVehicleCount;
             }
             TransportLineMod._lineData[index].BudgetControl = ImprovedPublicTransportMod.Settings.BudgetControl;
             TransportLineMod._lineData[index].Depot         = TransportLineMod.GetClosestDepot((ushort)index, instance1.m_nodes.m_buffer[(int)instance2.m_lines.m_buffer[index].GetStop(0)].m_position);
             TransportLineMod._lineData[index].Unbunching    = ImprovedPublicTransportMod.Settings.Unbunching;
         }
     }
     SerializableDataExtension.instance.EventSaveData += new SerializableDataExtension.SaveDataEventHandler(TransportLineMod.OnSaveData);
     if (!TransportLineMod._isDeployed)
     {
         TransportLineMod._redirectionSimulationStep = new Redirection <TransportLine, TransportLineMod>("SimulationStep");
         TransportLineMod._redirectionUpdateMeshData = new Redirection <TransportLine, TransportLineMod>("UpdateMeshData", false);
         if (!ImprovedPublicTransportMod.Settings.CompatibilityMode)
         {
             TransportLineMod.DetourUpdateMeshData();
         }
         TransportLineMod._isDeployed = true;
     }
     TransportLineMod._init = 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);
 }
Beispiel #23
0
        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);
        }
        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();
            }
        }
        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 bool UpdateMeshData(ushort lineID)
 {
     return(TransportLineMod.UpdateMeshDataImpl(ref Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID], lineID));
 }
        public static bool TryLoadData(out LineData[] data)
        {
            data = new LineData[256];
            byte[] data1 = SerializableDataExtension.instance.SerializableData.LoadData(TransportLineMod._dataID);
            if (data1 == null)
            {
                return(false);
            }
            int    index1 = 0;
            ushort lineID = 0;
            string empty  = string.Empty;

            try
            {
                Utils.Log((object)"Try to load transport line data.");
                string str = SerializableDataExtension.ReadString(data1, ref index1);
                if (string.IsNullOrEmpty(str) || str.Length != 4)
                {
                    Utils.LogWarning((object)"Unknown data found.");
                    return(false);
                }
                Utils.Log((object)("Found transport line data version: " + str));
                NetManager       instance1 = Singleton <NetManager> .instance;
                TransportManager instance2 = Singleton <TransportManager> .instance;
                while (index1 < data1.Length)
                {
                    if (instance2.m_lines.m_buffer[(int)lineID].Complete)
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        data[(int)lineID].TargetVehicleCount = int32;
                    }
                    index1 += 4;
                    float num = Mathf.Min(BitConverter.ToSingle(data1, index1), (float)ImprovedPublicTransportMod.Settings.SpawnTimeInterval);
                    if ((double)num > 0.0)
                    {
                        data[(int)lineID].NextSpawnTime = SimHelper.instance.SimulationTime + num;
                    }
                    index1 += 4;
                    bool boolean = BitConverter.ToBoolean(data1, index1);
                    data[(int)lineID].BudgetControl = boolean;
                    ++index1;
                    ushort uint16 = BitConverter.ToUInt16(data1, index1);
                    data[(int)lineID].Depot = (int)uint16 != 0 ? uint16 : TransportLineMod.GetClosestDepot(lineID, instance1.m_nodes.m_buffer[(int)instance2.m_lines.m_buffer[(int)lineID].GetStop(0)].m_position);
                    index1 += 2;
                    if (str == "v001")
                    {
                        string name = SerializableDataExtension.ReadString(data1, ref index1);
                        if (name != "Random")
                        {
                            if (data[(int)lineID].Prefabs == null)
                            {
                                data[(int)lineID].Prefabs = new HashSet <string>();
                            }
                            if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) != (UnityEngine.Object)null)
                            {
                                data[(int)lineID].Prefabs.Add(name);
                            }
                        }
                    }
                    else
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        index1 += 4;
                        for (int index2 = 0; index2 < int32; ++index2)
                        {
                            string name = SerializableDataExtension.ReadString(data1, ref index1);
                            if (data[(int)lineID].Prefabs == null)
                            {
                                data[(int)lineID].Prefabs = new HashSet <string>();
                            }
                            if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) != (UnityEngine.Object)null)
                            {
                                data[(int)lineID].Prefabs.Add(name);
                            }
                        }
                    }
                    if (str != "v001")
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        index1 += 4;
                        for (int index2 = 0; index2 < int32; ++index2)
                        {
                            string name = SerializableDataExtension.ReadString(data1, ref index1);
                            if (!boolean)
                            {
                                if (data[(int)lineID].QueuedVehicles == null)
                                {
                                    data[(int)lineID].QueuedVehicles = new Queue <string>();
                                }
                                if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) != (UnityEngine.Object)null)
                                {
                                    lock (data[(int)lineID].QueuedVehicles)
                                        data[(int)lineID].QueuedVehicles.Enqueue(name);
                                }
                            }
                        }
                    }
                    if (str == "v003")
                    {
                        ++index1;
                    }
                    data[(int)lineID].Unbunching = !(str == "v004") ? ImprovedPublicTransportMod.Settings.Unbunching : SerializableDataExtension.ReadBool(data1, ref index1);
                    ++lineID;
                }
                return(true);
            }
            catch (Exception ex)
            {
                Utils.LogWarning((object)("Could not load transport line data. " + ex.Message));
                data = new LineData[256];
                return(false);
            }
        }
Beispiel #28
0
        private string GenerateStopName(string name)
        {
            string str;

            if (string.IsNullOrEmpty(name))
            {
                if (this.StopIndex == -1)
                {
                    ushort transportLine = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)this._instanceID.NetNode].m_transportLine;
                    str = string.Format("{0} #{1}", (object)Singleton <TransportManager> .instance.GetLineName(transportLine), (object)(TransportLineMod.GetStopIndex(transportLine, this._instanceID.NetNode) + 1));
                }
                else
                {
                    str = string.Format(Localization.Get("STOP_LIST_BOX_ROW_STOP"), (object)this.StopIndex);
                }
            }
            else
            {
                str = name;
            }
            return(str);
        }