Exemplo n.º 1
0
        private static TrackDefinition getDefinitionForLength(List <TrackDefinition> possibleDefinitions, float trackLength, int maxError)
        {
            TrackDefinition closestLengthDef        = null;
            float           closestLengthDifference = float.MaxValue;

            foreach (TrackDefinition def in possibleDefinitions)
            {
                if (def.trackLength == trackLength)
                {
                    return(def);
                }
                else
                {
                    float thisDiff = Math.Abs(trackLength - def.trackLength);
                    if (thisDiff < maxError)
                    {
                        if (closestLengthDef == null || thisDiff < closestLengthDifference)
                        {
                            closestLengthDef        = def;
                            closestLengthDifference = thisDiff;
                        }
                    }
                }
            }
            return(closestLengthDef);
        }
Exemplo n.º 2
0
        public static TrackDefinition getTrackDefinition(String trackName, float trackLength, int sectorsOnTrack)
        {
            List <TrackDefinition> defsWhichMatchName = new List <TrackDefinition>();

            foreach (TrackDefinition def in assettoTracks)
            {
                if (def.name.Equals(trackName))
                {
                    return(def);
                }
            }
            TrackDefinition unknownTrackDef = new TrackDefinition(trackName, trackLength, sectorsOnTrack, new float[] { 0f, 0f });

            unknownTrackDef.unknownTrack = true;
            return(unknownTrackDef);
        }
Exemplo n.º 3
0
 public static TrackDefinition getTrackDefinition(String trackName, float trackLength)
 {
     if (CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_32BIT || CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_64BIT || CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_NETWORK)
     {
         List <TrackDefinition> defsWhichMatchName = new List <TrackDefinition>();
         foreach (TrackDefinition def in pCarsTracks)
         {
             if (def.name == trackName)
             {
                 defsWhichMatchName.Add(def);
             }
         }
         if (defsWhichMatchName.Count == 1)
         {
             return(defsWhichMatchName[0]);
         }
         TrackDefinition defGuessedFromLength = null;
         if (defsWhichMatchName.Count > 1)
         {
             defGuessedFromLength = getDefinitionForLength(defsWhichMatchName, trackLength, 2);
         }
         else
         {
             defGuessedFromLength = getDefinitionForLength(pCarsTracks, trackLength, 2);
         }
         if (defGuessedFromLength != null)
         {
             return(defGuessedFromLength);
         }
         String nameToLog = trackName != null ? trackName : "null";
         return(new TrackDefinition("unknown track - name " + nameToLog + ", length = " + trackLength, trackLength));
     }
     else if (CrewChief.gameDefinition.gameEnum == GameEnum.RACE_ROOM)
     {
         return(new TrackDefinition("R3E track, length = " + trackLength, trackLength));
     }
     else if (CrewChief.gameDefinition.gameEnum == GameEnum.RF1)
     {
         return(new TrackDefinition(trackName, trackLength));
     }
     else
     {
         String nameToLog = trackName != null ? trackName : "null";
         return(new TrackDefinition("unknown track - name " + nameToLog + ", length = " + trackLength, trackLength));
     }
 }
Exemplo n.º 4
0
 public static String getLandmarkForLapDistance(TrackDefinition currentTrack, float lapDistance)
 {
     if (currentTrack != null && lapDistance > 0 && currentTrack.trackLandmarks != null)
     {
         foreach (TrackLandmark trackLandmark in currentTrack.trackLandmarks)
         {
             if (lapDistance > trackLandmark.distanceRoundLapStart && lapDistance < trackLandmark.distanceRoundLapEnd)
             {
                 return(trackLandmark.landmarkName);
             }
         }
         // check again with more generous limits
         foreach (TrackLandmark trackLandmark in currentTrack.trackLandmarks)
         {
             if (lapDistance > (Math.Max(0, trackLandmark.distanceRoundLapStart - 70)) &&
                 lapDistance < Math.Min(currentTrack.trackLength, trackLandmark.distanceRoundLapEnd + 70))
             {
                 return(trackLandmark.landmarkName);
             }
         }
     }
     return(null);
 }