Ejemplo n.º 1
0
        public static void Init()
        {
            if (!TryLoadData(out _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 (ushort index = 0; index < length; ++index)
                {
                    if (instance2.m_lines.m_buffer[index].Complete)
                    {
                        _lineData[index].TargetVehicleCount = TransportLineDetour.CountLineActiveVehicles(index, out int _);
                    }
                    else
                    {
                        _lineData[index].TargetVehicleCount =
                            OptionsWrapper <Settings> .Options.DefaultVehicleCount;
                    }
                    _lineData[index].BudgetControl = OptionsWrapper <Settings> .Options.BudgetControl;
                    _lineData[index].Depot         = DepotUtil.GetClosestDepot((ushort)index,
                                                                               instance1.m_nodes.m_buffer[(int)instance2.m_lines.m_buffer[index].GetStop(0)].m_position);
                    _lineData[index].Unbunching = OptionsWrapper <Settings> .Options.Unbunching;
                }
            }
            SerializableDataExtension.instance.EventSaveData +=
                new SerializableDataExtension.SaveDataEventHandler(OnSaveData);

            _init = true;
        }
Ejemplo n.º 2
0
        public static ushort[] GetDepots(ItemClass.Service service, ItemClass.SubService subService, ItemClass.Level level)
        {
            HashSet <ushort> source;
            TransportInfo    info = null;

            return(_depotMap.TryGetValue(new ItemClassTriplet(service, subService, level), out source) ?
                   source.Where(d => DepotUtil.IsValidDepot(ref BuildingManager.instance.m_buildings.m_buffer[d], ref info, out _, out _, out _)).ToArray() :
                   new ushort[] {}); //we validate here to be compatible with MOM (if MOM sets max vehicle count later than this mod loads)
        }
Ejemplo n.º 3
0
        public static ushort[] GetDepots(TransportInfo transportInfo)
        {
            if (transportInfo == null)
            {
                return(new ushort[0]);
            }

            return(_depotMap.TryGetValue(
                       new ItemClassTriplet(transportInfo.GetService(), transportInfo.GetSubService(),
                                            transportInfo.GetClassLevel()),
                       out HashSet <ushort> source)
                ? source.Where(d => DepotUtil.IsValidDepot(d, transportInfo))
                   .ToArray()
                : new ushort [0]);
            //we validate here to be compatible with MOM (if MOM sets max vehicle count later than this mod loads)
        }
Ejemplo n.º 4
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))
             {
                 CachedTransportLineData.SetLineDefaults(lineID);
                 DepotUtil.AutoAssignLineDepot(lineID, out var position);
                 if (OptionsWrapper <Settings> .Options.ShowLineInfo &&
                     lines.m_buffer[(int)lineID].Info?.m_class?.m_service != ItemClass.Service.Disaster)
                 {
                     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 lineID = 0; (uint)lineID < lines.m_size; ++lineID)
         {
             if (!LineWatcher.IsValid(ref lines.m_buffer[(int)lineID]))
             {
                 this._knownLines.Remove(lineID);
             }
         }
     }
 }
        private static void ObserveForInfo(ushort buildingId, TransportInfo transportInfo)
        {
            if (transportInfo == null || !DepotUtil.IsValidDepot(ref BuildingManager.instance.m_buildings.m_buffer[buildingId], transportInfo))
            {
                return;
            }
            var itemClassTriplet = new ItemClassTriplet(transportInfo.GetService(), transportInfo.GetSubService(),
                                                        transportInfo.GetClassLevel());

            if (!_depotMap.TryGetValue(itemClassTriplet, out HashSet <ushort> depots))
            {
                depots = new HashSet <ushort>();
                _depotMap.Add(itemClassTriplet, depots);
            }
            if (depots.Contains(buildingId))
            {
                return;
            }
            depots.Add(buildingId);
            OnDepotAdded?.Invoke(itemClassTriplet.Service, itemClassTriplet.SubService, itemClassTriplet.Level);
        }
Ejemplo n.º 6
0
        public static bool TryLoadData(out LineData[] data)
        {
            data = new LineData[256];
            byte[] data1 = SerializableDataExtension.instance.SerializableData.LoadData(_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)OptionsWrapper <Settings> .Options.SpawnTimeInterval);
                    if ((double)num > 0.0)
                    {
                        data[(int)lineID].NextSpawnTime = SimHelper.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
                        : DepotUtil.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"
                        ? OptionsWrapper <Settings> .Options.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);
            }
        }