//this is also called when train is stopped in the station and then started internal void OnDestinationReached(VehicleStationLocation station, RootTask task) { if (Vehicle.Schedule.TraverseOrder == VehicleScheduleTraverseOrder.BackAndForth) { _measurement = null; return; } if (_measurement is TravelMeasurement measurement) { if (task.Behavior == RootTaskBehavior.NonStop) { return; } measurement.Finish(task); } if (!_measurementInvalidated) { _measurement = new StationLoadingMeasurement(this, task); } else { _measurementInvalidated = false; } }
public void GetStationTaskTransfersSum(ImmutableList <Vehicle> vehicles, VehicleStationLocation station, out bool isIncomplete, out bool isEstimated, TaskTransfers transfersSum) { int count = vehicles.Count; isIncomplete = false; isEstimated = false; for (int i = 0; i < vehicles.Count; i++) { if (!vehicles[i].IsEnabled) { continue; } VehicleScheduleData scheduleData = this[vehicles[i]]; IReadOnlyDictionary <Item, TransferData> transfers = scheduleData?.Capacity.GetTransfersPerStation()?[station]; float?mult; if (transfers != null && (mult = scheduleData.ScheduleMonthlyMultiplier) != null) { isEstimated |= scheduleData.ScheduleAvereageDuration.Estimated; transfersSum.Add(transfers, mult, scheduleData.ScheduleAvereageDuration.Estimated); } else { isIncomplete = true; } } }
public TaskSnapshot(RootTask task, int index) { this.task = task; location = task.Destination.VehicleStationLocation; version = VehicleScheduleHelper.Current.GetRootTaskVersion(task); nonstop = task.Behavior == RootTaskBehavior.NonStop; this.index = index; }
public TimeSpan?GetStationTime(VehicleStationLocation station) { if (_stationTimes.TryGetValue(station, out DurationDataSet timeData)) { return(timeData.TotalAverage); } return(null); }
private void OnConnectedStationChange(VehicleStationLocation station) { if (station == _station.Location) { InvalidateConnectedStations(); InvalidateDemandBuildings(); Invalidate(); } }
private DurationDataSet GetOrAddStationTimeSet(VehicleStationLocation station) { if (!_stationTimes.TryGetValue(station, out DurationDataSet result)) { result = new DurationDataSet(1); _stationTimes.Add(station, result); } return(result); }
public virtual void OnStationRemoved(VehicleStationLocation station) { foreach (RootTask task in _data.Keys) { if (task.Destination.VehicleStationLocation == station) { _data.Remove(task); } } }
public TimeSpan?GetTravelTime(VehicleStationLocation startStation, VehicleStationLocation endStation, List <VehicleStationLocation> nonstopStations = null) { int?hashCode = GetLocationsHashCode(nonstopStations); if (_travelTimes.TryGetValue((startStation, endStation, hashCode), out DurationDataSet travelTime)) { return(travelTime.TotalAverage); } return(null); }
public IReadOnlyDictionary <Item, TransferData> this[VehicleStationLocation idx] { get { if (_transfPerSt.TryGetValue(idx, out TaskTransfers taskTransfers)) { return(taskTransfers.Transfers); } return(null); } }
public override void OnStationRemoved(VehicleStationLocation station) { base.OnStationRemoved(station); foreach (RootTask task in _distanceData.Keys) { if (task.Destination.VehicleStationLocation == station) { _distanceData.Remove(task); } } }
private DurationDataSet GetOrAddTravelTimeSet(VehicleStationLocation start, VehicleStationLocation end, List <VehicleStationLocation> nonstopList) { int?hashCode = GetLocationsHashCode(nonstopList); if (!_travelTimes.TryGetValue((start, end, hashCode), out DurationDataSet travelTime)) { travelTime = new DurationDataSet(1); _travelTimes.Add((start, end, hashCode), travelTime); } return(travelTime); }
public TimeSpan?GetGlobalStationDuration(VehicleStationLocation station) { InvalidateDurationPerStation(); TimeSpan?result = _durationPerStation.GetStationTime(station); if (result == null) { InvalidateDurationPerStation(true); result = _durationPerStation.GetStationTime(station); } return(result); }
public TimeSpan?GetGlobalTravelDuration(VehicleStationLocation startStation, VehicleStationLocation endStation, List <VehicleStationLocation> nonstopStations = null) { InvalidateDurationPerStation(); TimeSpan?result = _durationPerStation.GetTravelTime(startStation, endStation, nonstopStations); if (result == null) { InvalidateDurationPerStation(true); result = _durationPerStation.GetTravelTime(startStation, endStation, nonstopStations); } return(result); }
public void Add(VehicleStationLocation station, TaskTransfers transfers, float?multiplier = null, bool estimated = false) { if (isReadonly) { throw new InvalidOperationException("TransfersPerStation is readonly"); } if (_transfPerSt.TryGetValue(station, out TaskTransfers taskTransf)) { taskTransf.Add(transfers, multiplier, estimated); } else { _transfPerSt.Add(station, new TaskTransfers(transfers, multiplier, estimated)); } }
static private void RootTask_SetCurrentTask_pof(RootTask __instance, int ____subTaskIndex) { Vehicle vehicle = __instance.Vehicle; if (vehicle && ____subTaskIndex == 0) { VehicleStationLocation vehicleStation = __instance.Destination?.VehicleStationLocation; if (vehicleStation != null) { Current.OnDestinationReached(vehicle, vehicleStation, __instance); } else { Current.OnMeasurementInvalidated(vehicle); } } }
public bool RemoveDemand(VehicleStationLocation location, IStorageNetworkNode demand) { if (location.IsDead) { return(false); } if (_additionalDemands.TryGetValue(location.VehicleStation, out UniqueList <IStorageNetworkNode> list)) { bool result = list.QuickRemove(demand); if (result) { OnDemandChange(location.VehicleStation); } return(result); } return(false); }
static private void RootTask_OnStop_pof(RootTask __instance) { Vehicle vehicle = __instance.Vehicle; VehicleStationLocation vehicleStation = __instance.Destination?.VehicleStationLocation; if (vehicle) { if (vehicleStation != null && __instance.IsCompleted) { Current.OnStationLeaved(vehicle, vehicleStation, __instance); } else { Current.OnMeasurementInvalidated(vehicle); } } }
public IEnumerable <(RootTask endStationTask, VehicleStationLocation startStation, VehicleStationLocation endStation, List <VehicleStationLocation> nonstopStations)> GetNonNonstopScheduleParts() { List <VehicleStationLocation> firstNonstopList = new List <VehicleStationLocation>(); List <VehicleStationLocation> currentNonstopList = new List <VehicleStationLocation>(); VehicleStationLocation firstNonNonstop = null, lastNonNonstop = null; RootTask firstNonNonstopTask = null; foreach (TaskSnapshot snapshot in _lastSnapshot.TaskSnapshots) { if (snapshot.nonstop) { if (firstNonNonstop == null) { firstNonstopList.Add(snapshot.location); } else { currentNonstopList.Add(snapshot.location); } } else { if (firstNonNonstop == null) { firstNonNonstop = snapshot.location; firstNonNonstopTask = snapshot.task; } if (lastNonNonstop != null) { yield return(snapshot.task, lastNonNonstop, snapshot.location, currentNonstopList.Count > 0 ? new List <VehicleStationLocation>(currentNonstopList) : null); } currentNonstopList.Clear(); lastNonNonstop = snapshot.location; } } if (firstNonNonstop != null && lastNonNonstop != null) { List <VehicleStationLocation> tmpNonstopList = new (firstNonstopList); tmpNonstopList.AddRange(currentNonstopList); yield return(firstNonNonstopTask, lastNonNonstop, firstNonNonstop, tmpNonstopList.Count > 0 ? tmpNonstopList : null); } yield break; }
public bool AddDemand(VehicleStationLocation location, IStorageNetworkNode demand) { if (demand is Store || demand is Lab) { if (DemandHelper.IsInBasicDemand(location.VehicleStation, demand)) { return(false); } _connectedBuildings.Add(demand.Building); bool result = GetOrCreateDemandsList(location.VehicleStation).Add(demand); if (result) { OnDemandChange(location.VehicleStation); } return(result); } throw new ArgumentException("Only Store and Lab can be added as a station demand", nameof(demand)); }
private void OnDestinationReached(Vehicle vehicle, VehicleStationLocation vehicleStation, RootTask task) { // NotificationUtils.ShowVehicleHint(vehicle, "OnDestinationReached " + vehicleStation.Location.Name); DestinationReached?.Invoke(vehicle, vehicleStation, task); }
private void OnStationLeaved(Vehicle vehicle, VehicleStationLocation vehicleStation, RootTask rootTask) { // NotificationUtils.ShowVehicleHint(vehicle, "OnStationLeaved " + vehicleStation.Location.Name); StationLeaved?.Invoke(vehicle, vehicleStation, rootTask); }
internal void OnStationRemoved(VehicleStationLocation station) { _travelData.OnStationRemoved(station); _stationLoadingData.OnStationRemoved(station); }
private void OnStationLeaved(Vehicle vehicle, VehicleStationLocation station, RootTask task) { GetOrCreateVehicleScheduleData(vehicle).OnStationLeaved(station, task); }
public IReadOnlyDictionary <Item, TransferData> GetStationTaskTransfersSum(ImmutableList <Vehicle> vehicles, VehicleStationLocation station, out bool isIncomplete, out bool isEstimated) { TaskTransfers transfersSum = new TaskTransfers(); GetStationTaskTransfersSum(vehicles, station, out isIncomplete, out isEstimated, transfersSum); return(transfersSum.Transfers); }