コード例 #1
0
        public IReadOnlyDictionary <Item, TransferData> GetRouteTotalTransfers(bool skipForOnlyOneVehicle = true)
        {
            if (!HasValidData || VehicleSchedule.Vehicle.Route != null)
            {
                TaskTransfers totalTransfers = new TaskTransfers();
                VehicleRoute  route          = VehicleSchedule.Vehicle.Route;
                if (skipForOnlyOneVehicle && route.Vehicles.Count == 1)
                {
                    return(null);
                }
                foreach (Vehicle vehicle in route.Vehicles.ToArray())
                {
                    if (vehicle.IsEnabled)
                    {
                        VehicleScheduleData vehicleData = VehicleScheduleDataManager.Current[vehicle];
                        float?mult;
                        if (vehicleData == null || !vehicleData.Capacity.HasValidData || (mult = vehicleData.ScheduleMonthlyMultiplier) == null)
                        {
                            return(null);
                        }
                        totalTransfers.Add(vehicleData.Capacity.TotalTransfers, mult, vehicleData.ScheduleAvereageDuration.Estimated);
                    }
                }

                return(totalTransfers.Transfers);
            }
            return(null);
        }
コード例 #2
0
        public TransfersPerStationCont GetRouteTransfersPerStation(bool skipForOnlyOneVehicle = true)
        {
            if (!HasValidData || VehicleSchedule.Vehicle.Route != null)
            {
                TransfersPerStationCont totalTransfers = new TransfersPerStationCont();
                VehicleRoute            route          = VehicleSchedule.Vehicle.Route;
                if (skipForOnlyOneVehicle && route.Vehicles.Count == 1)
                {
                    return(null);
                }
                foreach (Vehicle vehicle in route.Vehicles.ToArray())
                {
                    if (vehicle.IsEnabled)
                    {
                        VehicleScheduleData vehicleData = VehicleScheduleDataManager.Current[vehicle];
                        float?mult;
                        if (vehicleData == null || !vehicleData.Capacity.HasValidData || (mult = vehicleData.ScheduleMonthlyMultiplier) == null)
                        {
                            return(null);
                        }
                        totalTransfers.Add(vehicleData.Capacity.GetTransfersPerStation(), mult, vehicleData.ScheduleAvereageDuration.Estimated);
                    }
                }

                return(totalTransfers.AsReadonly());
            }
            return(null);
        }
コード例 #3
0
        private static void VehicleWindowScheduleTab_Initialize_prf(VehicleWindowScheduleTab __instance, VehicleWindow window)
        {
            VehicleScheduleData        scheduleData = VehicleScheduleDataManager.Current.GetOrCreateVehicleScheduleData(window.Vehicle);
            VehicleScheduleTabExtender tabExt       = __instance.gameObject.AddComponent <VehicleScheduleTabExtender>();

            tabExt.Initialize(scheduleData);
        }
 private void OnVehicleRouteChanged(Vehicle vehicle, VehicleRoute oldRoute, VehicleRoute newRoute)
 {
     if (newRoute != null && oldRoute != newRoute && newRoute.Vehicles.Count > 1)
     {
         VehicleScheduleData vehicleData = ReplaceVehicleScheduleDataFromRouteCopy(vehicle);
         vehicleData.CallDataChangedEventsForRoute(null);
     }
 }
コード例 #5
0
            public void OnRouteAddedToVehicle(Vehicle vehicle)
            {
                MarkDirty();
                VehicleScheduleData data = Manager <VehicleScheduleDataManager> .Current.GetOrCreateVehicleScheduleData(vehicle);

                data.SubscribeOwnDataChanged(OnVehicleDataChanged);
                data.CallDataChangedEventsForRoute(null);
            }
 public VehicleScheduleData GetOrCreateVehicleScheduleData(Vehicle vehicle)
 {
     if (!_vehiclesData.ContainsKey(vehicle) || _vehiclesData[vehicle] == null)
     {
         _vehiclesData[vehicle] = new VehicleScheduleData(vehicle);
     }
     return(_vehiclesData[vehicle]);
 }
        public void UnsubscribeDataChanged(Vehicle vehicle, Action <VehicleScheduleData, RootTask> handler)
        {
            VehicleScheduleData scheduleData = this[vehicle];

            if (scheduleData != null)
            {
                scheduleData.UnsubscribeDataChanged(handler);
            }
        }
コード例 #8
0
        private void OnVehicleIsEnabledChanged(Vehicle vehicle)
        {
            CacheData cacheData = null;

            if (vehicle.Route != null && (cacheData = this[vehicle.Route]) != null)
            {
                cacheData.MarkDirty();
                VehicleScheduleData data = Manager <VehicleScheduleDataManager> .Current.GetOrCreateVehicleScheduleData(vehicle);

                data.CallDataChangedEventsForRoute(null);
            }
        }
        internal void Read(StateBinaryReader reader)
        {
            _vehiclesData.Clear();
            int count = reader.ReadInt();

            for (int i = 0; i < count; i++)
            {
                int     vehicleId = reader.ReadInt();
                Vehicle vehicle   = LazyManager <VehicleManager> .Current.FindById(vehicleId);

                _vehiclesData.Add(vehicle, VehicleScheduleData.Read(reader, vehicle));
            }
        }
コード例 #10
0
 /* Add own average values to the provided vehicle data (skip when own data aren't complete) */
 internal void AddAverageValuesToVehicleData(VehicleScheduleData data)
 {
     if (data.Vehicle.Route != Vehicle.Route)
     {
         throw new InvalidOperationException("Vehicles must have the same route for copy average values");
     }
     if (GetAverageTravelDuration() == null)
     {
         return;
     }
     _travelData.AddAverageValuesToDataSet(data._travelData, data.Vehicle);
     _stationLoadingData.AddAverageValuesToDataSet(data._stationLoadingData, data.Vehicle);
     data.OnDataChanged(null);
 }
コード例 #11
0
            public void OnRouteRemovedFromVehicle(Vehicle vehicle, VehicleRoute oldRoute)
            {
                MarkDirty();
                VehicleScheduleData data = Manager <VehicleScheduleDataManager> .Current[vehicle];

                if (data != null)
                {
                    data.UnsubscribeOwnDataChanged(OnVehicleDataChanged);
                    if (oldRoute.Vehicles.Count > 0)
                    {
                        data = Manager <VehicleScheduleDataManager> .Current[oldRoute.Vehicles[0]];
                        data.CallDataChangedEventsForRoute(null);
                    }
                }
            }
コード例 #12
0
            internal static Measurement Read(StateBinaryReader reader, VehicleScheduleData data, RootTask task)
            {
                byte id = reader.ReadByte();

                switch (id)
                {
                case 0:
                    return(new StationLoadingMeasurement(data, task));

                case 1:
                    return(new TravelMeasurement(data, task));
                }

                throw new ArgumentException("Unknown id " + id.ToString());
            }
コード例 #13
0
        internal static VehicleScheduleData Read(StateBinaryReader reader, Vehicle vehicle)
        {
            VehicleScheduleData result = new VehicleScheduleData(vehicle)
            {
                _travelData         = TaskTravelDurationDataSet.Read(reader, vehicle.Schedule),
                _stationLoadingData = TaskDurationDataSet.Read(reader, vehicle.Schedule)
            };

            if (reader.ReadBool())
            {
                result._measurement = Measurement.Read(reader, vehicle.Schedule, result);
            }

            return(result);
        }
        /** add times from scheduleData to the existing data for averaging */
        public void AddTimes(VehicleScheduleData scheduleData)
        {
            foreach ((RootTask endStationTask, VehicleStationLocation startStation, VehicleStationLocation endStation, List <VehicleStationLocation> nonstopStations) in scheduleData.GetNonNonstopScheduleParts())
            {
                TimeSpan?duration = scheduleData.GetAverageTravelDuration(endStationTask);
                if (duration != null)
                {
                    DurationDataSet travelTime = GetOrAddTravelTimeSet(startStation, endStation, nonstopStations);
                    travelTime.Add(duration.Value);
                }

                TimeSpan?stationDuration = scheduleData.GetAverageStationLoadingDuration(endStationTask);
                if (stationDuration != null)
                {
                    DurationDataSet stationTimeSet = GetOrAddStationTimeSet(endStation);
                    stationTimeSet.Add(stationDuration.Value);
                }
            }
        }
コード例 #15
0
        public IReadOnlyDictionary <Item, TransferData> GetRouteTaskTransfers(RootTask task, bool skipForOnlyOneVehicle = true)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (!HasValidData || VehicleSchedule.Vehicle.Route != null)
            {
                TaskTransfers routeTransfers = new TaskTransfers();
                VehicleRoute  route          = VehicleSchedule.Vehicle.Route;
                if (skipForOnlyOneVehicle && route.Vehicles.Count == 1)
                {
                    return(null);
                }
                int taskIndex = task.GetIndex();
                foreach (Vehicle vehicle in route.Vehicles.ToArray())
                {
                    if (vehicle.IsEnabled)
                    {
                        VehicleScheduleData vehicleData = VehicleScheduleDataManager.Current[vehicle];
                        float?mult;
                        if (vehicleData == null || !vehicleData.Capacity.HasValidData || (mult = vehicleData.ScheduleMonthlyMultiplier) == null)
                        {
                            return(null);
                        }

                        IReadOnlyDictionary <Item, TransferData> transfers = vehicleData.Capacity.GetTransfers(vehicle.Schedule.GetTasks()[taskIndex]);
                        if (transfers != null)
                        {
                            routeTransfers.Add(transfers, mult, vehicleData.ScheduleAvereageDuration.Estimated);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }

                return(routeTransfers.Transfers);
            }
            return(null);
        }
        /** copies average values of all vehicles in the route and add it as one-time data (will be overwriten when own data are available) */
        public VehicleScheduleData ReplaceVehicleScheduleDataFromRouteCopy(Vehicle vehicle)
        {
            if (vehicle.Route == null || vehicle.Route.Vehicles.Count <= 1)
            {
                throw new InvalidOperationException("Vehicle route is null or have only one vehicle");
            }

            VehicleScheduleData result = GetOrCreateVehicleScheduleData(vehicle);

            result.NotificationsTurnedOff = true;
            try
            {
                result.ClearAllData();
                result.ChangeDataBufferSize(vehicle.Route.Vehicles.Count);

                foreach (Vehicle currVehicle in vehicle.Route.Vehicles.ToList())
                {
                    if (currVehicle == vehicle)
                    {
                        continue;
                    }

                    if (!_vehiclesData.TryGetValue(currVehicle, out VehicleScheduleData currData))
                    {
                        continue;
                    }

                    currData.AddAverageValuesToVehicleData(result);
                }
                result.AdjustDataAfterCopy();
            }
            finally
            {
                result.NotificationsTurnedOff = false;
            }

            return(result);
        }
コード例 #17
0
 protected override void DoRead(StateBinaryReader reader, VehicleSchedule schedule, VehicleScheduleData data)
 {
     base.DoRead(reader, schedule, data);
     _startDistance = null;
     if (ScheduleStopwatch.GetSchemaVersion(typeof(VehicleScheduleData)) >= 2)
     {
         if (reader.ReadBool())
         {
             _startDistance = reader.ReadFloat();
         }
     }
 }
コード例 #18
0
 public TravelMeasurement(VehicleScheduleData data, RootTask task) : base(data, task)
 {
     _startDistance = _vehicleScheduleData.Vehicle.WorldTraveledDistanceCounter.Lifetime;
 }
 protected virtual void DoRead(StateBinaryReader reader, VehicleSchedule schedule, VehicleScheduleData data)
 {
     startTime = new DateTime(reader.ReadLong());
 }
            internal static Measurement Read(StateBinaryReader reader, VehicleSchedule schedule, VehicleScheduleData data)
            {
                RootTask    task   = schedule.GetTasks()[reader.ReadInt()];
                Measurement result = MeasurementSurrogate.Read(reader, data, task);

                result.DoRead(reader, schedule, data);
                return(result);
            }
 public Measurement(VehicleScheduleData data, RootTask task)
 {
     startTime            = TimeManager.Current.DateTime;
     this.Task            = task;
     _vehicleScheduleData = data;
 }
 public DurationsPerStationsContainer(VehicleScheduleData scheduleData)
 {
     AddTimes(scheduleData);
 }
        public void SubscribeDataChanged(Vehicle vehicle, Action <VehicleScheduleData, RootTask> handler, bool priority = false)
        {
            VehicleScheduleData data = GetOrCreateVehicleScheduleData(vehicle);

            data.SubscribeDataChanged(handler, priority);
        }
 /** add times from scheduleData as new (not to the average), keeps old data when new data isn't available */
 public void NewTimes(VehicleScheduleData scheduleData)
 {
     MarkForOverwrite();
     AddTimes(scheduleData);
 }
コード例 #26
0
 private void OnVehicleDataChanged(VehicleScheduleData _)
 {
     MarkDirty();
 }