Exemple #1
0
        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.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);
            }
        }
        public override bool CanLeave(ushort vehicleID, ref Vehicle vehicleData)
        {
            if ((int)vehicleData.m_leadingVehicle == 0 && (int)vehicleData.m_waitCounter < 12 ||
                !base.CanLeave(vehicleID, ref vehicleData))
            {
                //begin mod(+): track if unbunching happens
                VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].IsUnbunchingInProgress = false;
                //end mod
                return(false);
            }
            //begin mod(+): no unbunching for evac buses or if only 1 bus on line!
            if (vehicleData.Info?.m_class?.m_service == ItemClass.Service.Disaster || (vehicleData.m_nextLineVehicle == 0 && Singleton <TransportManager> .instance.m_lines
                                                                                       .m_buffer[(int)vehicleData.m_transportLine].m_vehicles == vehicleID))
            {
                VehicleManagerMod.m_cachedVehicleData[vehicleID].IsUnbunchingInProgress = false;
                return(true);
            }
            //end mod

            if ((int)vehicleData.m_leadingVehicle == 0 && (int)vehicleData.m_transportLine != 0)
            {
                //begin mod(+): Check if unbunching enabled for this line & stop. track if unbunching happens. Don't divide m_waitCounter by 2^4
                ushort currentStop = VehicleManagerMod.m_cachedVehicleData[vehicleID].CurrentStop;
                if (currentStop != 0 && NetManagerMod.m_cachedNodeData[currentStop].Unbunching &&
                    TransportLineMod.GetUnbunchingState(vehicleData.m_transportLine))
                {
                    var canLeaveStop = Singleton <TransportManager> .instance.m_lines
                                       .m_buffer[(int)vehicleData.m_transportLine]
                                       .CanLeaveStop(vehicleData.m_targetBuilding, (int)vehicleData.m_waitCounter);
                    VehicleManagerMod.m_cachedVehicleData[vehicleID].IsUnbunchingInProgress = !canLeaveStop;
                    return(canLeaveStop);
                }
                //end mod
            }
            //begin mod(+): track if unbunching happens
            VehicleManagerMod.m_cachedVehicleData[vehicleID].IsUnbunchingInProgress = false;
            //end mod
            return(true);
        }