public string GetLeaderboard()
    {
        StringBuilder sb = new StringBuilder();

        sb.Append("Lap ");
        sb.Append(CurrentLap.ToString());
        sb.Append("/");
        sb.AppendLine(LapsNumber.ToString());

        int position = 1;

        foreach (Driver driver in Drivers.OrderBy(x => x.TotalTime))
        {
            sb.AppendFormat($"{position} {driver.Name} ");
            sb.AppendFormat($"{driver.TotalTime:f3}" + Environment.NewLine);

            position++;
        }

        foreach (Driver driver in FailedDrivers)
        {
            sb.AppendFormat($"{position} {driver.Name} ");
            sb.AppendLine(driver.FailureReason + Environment.NewLine);
            position++;
        }

        return(sb.ToString());
    }
Пример #2
0
        private bool ShouldFinishLap(SimulatorDataSet dataSet, ILapInfo currentLap)
        {
            SessionInfo sessionInfo = dataSet.SessionInfo;

            if (currentLap.Completed)
            {
                return(true);
            }

            // Use completed laps indication to end lap, when we use the sim provided lap times. This gives us the biggest assurance that lap time is already properly set. But wait for lap to be at least 5 seconds in
            if (dataSet.SimulatorSourceInfo.HasLapTimeInformation && (currentLap.LapNumber < DriverInfo.CompletedLaps + 1))
            {
                currentLap.LapCompletionMethod = LapCompletionMethod.ByLapNumber;
                return(true);
            }


            // Crossed line at out lap
            if (dataSet.SessionInfo.SessionType != SessionType.Race && currentLap.PitLap && (DriverInfo.LapDistance - _previousTickLapDistance < sessionInfo.TrackInfo.LayoutLength.InMeters * -0.90))
            {
                currentLap.LapCompletionMethod = LapCompletionMethod.ByCrossingTheLine;
                return(true);
            }

            if ((!dataSet.SimulatorSourceInfo.HasLapTimeInformation || dataSet.SimulatorSourceInfo.SimNotReportingEndOfOutLapCorrectly) && (DriverInfo.LapDistance - _previousTickLapDistance < sessionInfo.TrackInfo.LayoutLength.InMeters * -0.90))
            {
                currentLap.LapCompletionMethod = LapCompletionMethod.ByCrossingTheLine;
                return(true);
            }

            if (!dataSet.SimulatorSourceInfo.OutLapIsValid && !currentLap.Valid && DriverInfo.CurrentLapValid && DriverInfo.IsPlayer && (currentLap.FirstLap && !InvalidateFirstLap))
            {
                currentLap.LapCompletionMethod = LapCompletionMethod.ByChangingValidity;
                return(true);
            }

            if (!dataSet.SimulatorSourceInfo.OutLapIsValid && !currentLap.Valid && DriverInfo.CurrentLapValid && DriverInfo.IsPlayer && currentLap.PitLap && _previousTickLapDistance < DriverInfo.LapDistance && SessionType.Race != sessionInfo.SessionType && !DriverInfo.InPits)
            {
                currentLap.LapCompletionMethod = LapCompletionMethod.ByChangingValidity2;
                return(true);
            }

            if (!currentLap.Valid && DriverInfo.CurrentLapValid && SessionType.Race == sessionInfo.SessionType && !DriverInfo.IsPlayer && (currentLap.FirstLap && !InvalidateFirstLap))
            {
                currentLap.LapCompletionMethod = LapCompletionMethod.ByChangingValidity3;
                return(true);
            }

            // Driver is DNF/DQ -> finish timed lap, and set it to invalid
            if (DriverInfo.FinishStatus != DriverFinishStatus.Na && DriverInfo.FinishStatus != DriverFinishStatus.None)
            {
                CurrentLap.InvalidateLap(LapInvalidationReasonKind.DriverDnf);
                return(true);
            }

            return(false);
        }
Пример #3
0
 private void UpdateCurrentLap(SimulatorDataSet dataSet)
 {
     CurrentLap.Tick(dataSet, DriverInfo);
     CurrentLap.InvalidBySim = !DriverInfo.CurrentLapValid;
     LapPercentage           = (DriverInfo.LapDistance / dataSet.SessionInfo.TrackInfo.LayoutLength) * 100;
     if (CurrentLap.Valid && SessionType.Race != dataSet.SessionInfo.SessionType && (InPits || !DriverInfo.CurrentLapValid) && _lapsInfo.Count >= 1)
     {
         CurrentLap.Valid = false;
     }
 }
Пример #4
0
 private void UpdateCurrentLap(SimulatorDataSet dataSet)
 {
     CurrentLap.Tick(dataSet, DriverInfo);
     CurrentLap.InvalidBySim = !DriverInfo.CurrentLapValid;
     LapPercentage           = (DriverInfo.LapDistance / dataSet.SessionInfo.TrackInfo.LayoutLength.InMeters) * 100;
     if (CurrentLap.Valid && SessionType.Race != dataSet.SessionInfo.SessionType && (InPits || !DriverInfo.CurrentLapValid) && _lapsInfo.Count >= 1)
     {
         CurrentLap.InvalidateLap(InPits ? LapInvalidationReasonKind.DriverInPits : LapInvalidationReasonKind.InvalidatedBySim);
     }
 }
Пример #5
0
    void MakeGhost()
    {
        if (ghostCar == null)
        {
            return;
        }
        GameObject gc = Instantiate(ghostCar, new Vector3(90, -20f, 0.69f), Quaternion.identity);

        gc.GetComponent <GhostCarManager>().target = gameObject;
        gc.name  = CurrentLap.ToString();
        gc.layer = LayerMask.NameToLayer("Enemy");
    }
Пример #6
0
        public void ProcessIncomingPacket(TelemetryPacket packet)
        {
            lock (syncLock)
            {
                HasDataBeenReceived = true;
                if (F1SpeedSettings.LogPacketData)
                {
                    OnPacketProcessed(packet);
                }

                CheckCircuit(packet);

                if (HasLapChanged(packet))
                {
                    if (!packet.IsInPitLane)
                    {
                        _lastLapTime = packet.PreviousLapTime;
                        _lastLapFuel = packet.FuelRemaining;
                        CurrentLap.MarkLapCompleted();
                    }
                    else
                    {
                        OnReturnedToGarage(CurrentLap);
                    }

                    if (CurrentLap.IsCompleteLap && (int)packet.Lap != 0 && (int)packet.Lap > CurrentLap.LapNumber)
                    {
                        if (string.IsNullOrEmpty(CurrentLap.CircuitName) && string.IsNullOrEmpty(CurrentLap.LapType))
                        {
                            CurrentLap.LapType = _lapType;
                        }

                        foreach (var exporter in _currentLapExporters)
                        {
                            exporter.Save(CurrentLap);
                        }

                        if (IsCurrentLapFastestLap)
                        {
                            OnSetFastestLap(new LapEventArgs {
                                Lap = CurrentLap
                            }, FastestLap);

                            FastestLap = CurrentLap;
                            SaveFastestLap();
                        }

                        OnCompletedFullLap(new CompletedFullLapEventArgs {
                            CompletedLap      = CurrentLap,
                            CurrentLapNumber  = (int)packet.Lap,
                            PreviousLapNumber = CurrentLap.LapNumber
                        });
                    }
                    else
                    {
                        if (CurrentLap.IsOutLap)
                        {
                            OnFinishedOutLap(CurrentLap);
                        }

                        // Lap is invalid
                        //_laps.Remove(CurrentLap);

                        //OnRemovedLap(CurrentLap);
                    }

                    // Start new current lap
                    _laps.Add(new TelemetryLap(_currectCircuit, _lapType));
                    CurrentLap.AddPacket(packet);
                    OnStartedLap(CurrentLap);
                }
                else
                {
                    CurrentLap.AddPacket(packet);
                }
            }  // end lock
        }