Beispiel #1
0
 public Event(eventType type, Int64 replay, DriverInfo driver, String desc, Sessions.SessionInfo.sessionType session, Int32 lap)
 {
     this.type = type;
     this.timestamp = DateTime.Now;
     this.replaypos = replay;
     this.driver = driver;
     this.description = desc;
     this.session = session;
     this.lapnum = lap;
     this.rewind = 0;
 }
Beispiel #2
0
 public String getSessionInfo(String script, String method, Sessions.SessionInfo session, Int32 rounding)
 {
     return scripts[script].SessionInfo(method, session, rounding);
 }
Beispiel #3
0
 public String getDriverInfo(String script, String method, Sessions.SessionInfo.StandingsItem standing, Sessions.SessionInfo session, Int32 rounding)
 {
     return scripts[script].DriverInfo(method, standing, session, rounding);
 }
Beispiel #4
0
        public static Boolean readCache(Int32 sessionId)
        {
            string cachefilename = Directory.GetCurrentDirectory() + "\\cache\\" + sessionId + "-sessions.xml";
            if (File.Exists(cachefilename))
            {
                FileStream fs = new FileStream(cachefilename, FileMode.Open);
                TextReader reader = new StreamReader(fs);
                System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(SharedData.Sessions.GetType());
                SharedData.Sessions = (Sessions)x.Deserialize(reader);
                fs.Close();
            }
            else
                return false;

            cachefilename = Directory.GetCurrentDirectory() + "\\cache\\" + sessionId + "-drivers.xml";
            if (File.Exists(cachefilename))
            {
                FileStream fs = new FileStream(cachefilename, FileMode.Open);
                TextReader reader = new StreamReader(fs);
                System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(SharedData.Drivers.GetType());
                SharedData.Drivers = (List<DriverInfo>)x.Deserialize(reader);
                fs.Close();
            }
            else
                return false;

            return true;
        }
Beispiel #5
0
        public static void writeCache(Int32 sessionId)
        {
            DirectoryInfo di = Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\cache\\");
            TextWriter tw = new StreamWriter(Directory.GetCurrentDirectory() + "\\cache\\" + sessionId + "-sessions.xml");
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(SharedData.Sessions.GetType());
            SharedData.Sessions = new iRTVO.Sessions();
            x.Serialize(tw, SharedData.Sessions);
            tw.Close();

            tw = new StreamWriter(Directory.GetCurrentDirectory() + "\\cache\\" + sessionId + "-drivers.xml");
            x = new System.Xml.Serialization.XmlSerializer(SharedData.Drivers.GetType());
            SharedData.Drivers = new List<DriverInfo>();
            x.Serialize(tw, SharedData.Drivers);
            tw.Close();
        }
Beispiel #6
0
            public webtimingDriver(Sessions.SessionInfo.StandingsItem driver, Sessions.SessionInfo session)
            {
                position = driver.Position.ToString();
                name = driver.Driver.Name;
                number = driver.Driver.NumberPlate;
                lap = driver.CurrentLap.LapNum.ToString();
                fastestlap = iRTVO.Overlay.floatTime2String(driver.FastestLap, 3, false);
                previouslap = iRTVO.Overlay.floatTime2String(driver.PreviousLap.LapTime, 3, false);
                pit = driver.PitStops.ToString();
                lapsled = driver.LapsLed.ToString();
                sectors = new string[0];

                classid = driver.Driver.CarClass.ToString();
                classname = driver.Driver.CarClassName;
                classposition = session.getClassPosition(driver.Driver).ToString();
                classgap = driver.ClassGapLive_HR;
                classinterval = driver.ClassIntervalLive_HR;

                Sessions.SessionInfo.StandingsItem leader = SharedData.Sessions.CurrentSession.FindPosition(1, dataorder.position);
                Sessions.SessionInfo.StandingsItem infront;

                if(driver.Position <= 1) {
                    infront = new Sessions.SessionInfo.StandingsItem();
                }
                else {
                    infront = SharedData.Sessions.CurrentSession.FindPosition(driver.Position - 1, dataorder.position);
                }

                if (SharedData.Sessions.CurrentSession.Type == Sessions.SessionInfo.sessionType.race
                    /* && (driver.Finished == true || driver.Sector == 0) */)
                {
                    if (infront.PreviousLap.GapLaps > driver.PreviousLap.GapLaps)
                    {
                        interval = (infront.FindLap(driver.PreviousLap.LapNum).LapNum - driver.PreviousLap.LapNum) + " L";
                    }
                    else
                    {
                        interval = iRTVO.Overlay.floatTime2String((driver.PreviousLap.Gap - infront.FindLap(driver.PreviousLap.LapNum).Gap), 3, false);
                    }

                    if (driver.PreviousLap.GapLaps > 0)
                    {
                        gap = driver.PreviousLap.GapLaps +" L";
                    }
                    else
                    {
                        gap = iRTVO.Overlay.floatTime2String(driver.PreviousLap.Gap, 3, false);
                    }
                }
                else
                {
                    interval = iRTVO.Overlay.floatTime2String((driver.FastestLap - infront.FastestLap), 3, false);
                    gap = iRTVO.Overlay.floatTime2String((driver.FastestLap - leader.FastestLap), 3, false);
                }

                if (SharedData.SelectedSectors.Count > 0)
                {
                    sectors = new string[SharedData.SelectedSectors.Count];

                    for (int i = 0; i < SharedData.SelectedSectors.Count; i++)
                    {
                        if (driver.Sector <= 0) // first sector, show previous lap times
                        {
                            if (i < driver.PreviousLap.SectorTimes.Count)
                            {
                                iRTVO.LapInfo.Sector sector = driver.PreviousLap.SectorTimes.Find(s => s.Num.Equals(i));
                                if(sector != null)
                                {
                                    sectors[i] = iRTVO.Overlay.floatTime2String(sector.Time, 1, false);
                                }
                                else
                                {
                                    sectors[i] = "-.--";
                                }
                            }
                            else
                            {
                                sectors[i] = "-.--";
                            }
                        }
                        else
                        {
                            if (i < driver.CurrentLap.SectorTimes.Count)
                            {
                                iRTVO.LapInfo.Sector sector = driver.CurrentLap.SectorTimes.Find(s => s.Num.Equals(i));
                                if(sector != null)
                                {
                                    sectors[i] = iRTVO.Overlay.floatTime2String(sector.Time, 1, false);
                                }
                                else
                                {
                                    sectors[i] = "-.--";
                                }
                            }
                            else
                            {
                                sectors[i] = "-.--";
                            }
                        }
                    }
                }

                if (SharedData.Sessions.CurrentSession.Type == Sessions.SessionInfo.sessionType.race &&
                    driver.TrackSurface == Sessions.SessionInfo.StandingsItem.SurfaceType.NotInWorld &&
                SharedData.allowRetire &&
                (SharedData.Sessions.CurrentSession.Time - driver.OffTrackSince) > 1)
                {
                    retired = true;
                    if (infront.CurrentLap.LapNum > driver.CurrentLap.LapNum)
                    {
                        interval = (infront.CurrentLap.LapNum - driver.CurrentLap.LapNum) + " L";
                    }
                    else
                    {
                        interval = iRTVO.Overlay.floatTime2String((driver.PreviousLap.Gap - infront.PreviousLap.Gap), 3, false);
                    }
                    if ((leader.CurrentLap.LapNum - driver.CurrentLap.LapNum) > 0)
                    {
                        gap = leader.CurrentLap.LapNum - driver.CurrentLap.LapNum + " L";
                    }
                    else
                    {
                        gap = iRTVO.Overlay.floatTime2String(driver.PreviousLap.Gap, 3, false);
                    }
                }
                else
                {
                    retired = false;
                }
            }
Beispiel #7
0
        public string formatFollowedText(LabelProperties label, Sessions.SessionInfo.StandingsItem standing, Sessions.SessionInfo session)
        {
            string output = "";

            Dictionary<string, int> formatMap = new Dictionary<string, int>()
            {
                {"fullname", 0},
                {"shortname", 1},
                {"initials", 2},
                {"license", 3},
                {"club", 4},
                {"car", 5},
                {"class", 6},
                {"carnum", 7},
                {"fastlap", 8},
                {"prevlap", 9},
                {"curlap", 10},
                {"lapnum", 11},
                {"speedfast_mph", 12},
                {"speedprev_mph", 13},
                {"speedfast_kph", 14},
                {"speedprev_kph", 15},
                {"position", 16},
                {"position_ord", 17},
                {"gap", 18},
                {"lapsled", 19},
                {"driverid", 20},
                {"interval", 21},
                {"interval_time", 22},
                {"livegap", 23},
                {"liveinterval", 24},
                {"livespeed_kph", 25},
                {"livespeed_mph", 26},
                {"sector1", 27},
                {"sector2", 28},
                {"sector3", 29},
                {"pitstops", 30},
                {"pitstoptime", 31},
                {"sector1_speed_kph", 32},
                {"sector2_speed_kph", 33},
                {"sector3_speed_kph", 34},
                {"sector1_speed_mph", 35},
                {"sector2_speed_mph", 36},
                {"sector3_speed_mph", 37},
                {"positiongain", 38},
                {"classposition", 39},
                {"classposition_ord", 40},
                {"classpositiongain", 41},
                {"classgap", 42},
                {"classlivegap", 43},
                {"classinterval", 44},
                {"classliveinterval", 45},
                {"classlapsled", 46},
                {"startposition", 47},
                {"classstartposition", 48},
                {"classstartposition_ord", 49},
                {"startposition_ord", 50},
                {"highestposition", 51},
                {"highestposition_ord", 52},
                {"lowestposition", 53},
                {"lowestposition_ord", 54},
                {"classhighestposition", 55},
                {"classhighestposition_ord", 56},
                {"classlowestposition", 57},
                {"classlowestposition_ord", 58},
                {"points", 59},
                {"points_pos", 60},
                {"points_pos_ord", 61},
                {"liveposition", 62},
                {"liveposition_ord", 63},
                {"classliveposition", 64},
                {"classliveposition_ord", 65},
                {"irating", 66},
                {"liveintervalfollowed", 67}
            };

            int start, end;
            StringBuilder t = new StringBuilder(label.text);

            // replace strings with numbers
            foreach (KeyValuePair<string, int> pair in formatMap)
            {
                t.Replace("{" + pair.Key + "}", "{" + pair.Value + "}");
            }

            // replace external strings with numbers
            int maxExternelData = 0;
            if (SharedData.externalData.ContainsKey(standing.Driver.UserId))
            {
                for (int i = 0; i < SharedData.externalData[standing.Driver.UserId].Length; i++)
                {
                    t.Replace("{external:" + i + "}", "{" + (formatMap.Keys.Count + i) + "}");
                }
                maxExternelData = Math.Max(maxExternelData, SharedData.externalData[standing.Driver.UserId].Length);
            }

            // remove leftovers
            string format = t.ToString();
            do
            {
                start = format.IndexOf("{external", 0);
                if (start >= 0)
                {
                    end = format.IndexOf('}', start) + 1;
                    format = format.Remove(start, end - start);
                }
            } while (start >= 0);

            t = new StringBuilder(format);

            // run scripts
            if (label.text.Contains("{script:"))
            {
                String[] scripts = SharedData.scripting.Scripts;
                foreach(String script in scripts) {
                    String text = t.ToString();
                    do
                    {
                        start = text.IndexOf("{script:" + script + ":", 0);
                        // if script name found
                        if (start >= 0)
                        {
                            end = text.IndexOf('}', start) + 1;
                            // if ending found
                            if (end > start)
                            {
                                String method = text.Substring(start + script.Length + 9, end - start - script.Length - 10);
                                t.Replace("{script:" + script + ":" + method + "}", SharedData.scripting.getDriverInfo(script, method, standing, session, label.rounding));
                            }
                        }
                        text = t.ToString();
                    } while (t.ToString().Contains("{script:" + script + ":"));
                }
            }

            // remove leftovers
            format = t.ToString();
            do
            {
                start = format.IndexOf("{script", 0);
                if (start >= 0)
                {
                    end = format.IndexOf('}', start) + 1;
                    format = format.Remove(start, end - start);
                }
            } while (start >= 0);

            if (standing.Driver.CarIdx < 0)
            {
                output = String.Format(format, getFollowedFormats(standing, session, label.rounding));
            }
            else if (SharedData.themeDriverCache[standing.Driver.CarIdx][label.rounding] == null)
            {
                string[] cache = getFollowedFormats(standing, session, label.rounding);
                SharedData.themeDriverCache[standing.Driver.CarIdx][label.rounding] = cache;
                try
                {
                    output = String.Format(format, cache);
                }
                catch (FormatException)
                {
                    output = "[invalid]";
                }
                SharedData.cacheMiss++;

            }
            else
            {
                try
                {
                    output = String.Format(format, SharedData.themeDriverCache[standing.Driver.CarIdx][label.rounding]);
                }
                catch (FormatException)
                {
                    output = "[invalid]";
                }

                SharedData.cacheHit++;
            }

            output = output.Replace("\\n", System.Environment.NewLine);

            if (label.uppercase)
                return output.ToUpper();
            else
                return output;
        }
Beispiel #8
0
        public string[] getSessionstateFormats(Sessions.SessionInfo session, Int32 rounding)
        {
            string[] output = new string[33] {
                session.LapsTotal.ToString(),
                session.LapsRemaining.ToString(),
                iRTVO.Overlay.floatTime2String((float)session.SessionLength, rounding, true),
                iRTVO.Overlay.floatTime2String((float)session.TimeRemaining, rounding, true),
                "",
                iRTVO.Overlay.floatTime2String((float)session.Time, rounding, true),
                "",
                SharedData.Track.name,
                round(SharedData.Track.length * 0.6214 / 1000, rounding),
                round(SharedData.Track.length / 1000, rounding),
                session.Cautions.ToString(),
                session.CautionLaps.ToString(),
                session.LeadChanges.ToString(),
                "",
                (session.LapsComplete + 1).ToString(),
                SharedData.Track.turns.ToString(),
                SharedData.Track.city,
                SharedData.Track.country,
                Math.Round(SharedData.Track.altitude).ToString(),
                translation[SharedData.Track.sky],
                Math.Round(SharedData.Track.tracktemp, rounding).ToString(),
                Math.Round(SharedData.Track.airtemp, rounding).ToString(),
                SharedData.Track.humidity.ToString(),
                SharedData.Track.fog.ToString(),
                Math.Round(SharedData.Track.airpressure, rounding).ToString(),
                Math.Round(SharedData.Track.windspeed, rounding).ToString(),
                Math.Round(360 * SharedData.Track.winddirection / (2*Math.PI), rounding).ToString(),
                Math.Round(SharedData.Track.altitude * 3.281, rounding).ToString(),
                Math.Round(SharedData.Track.tracktemp * 9/5 + 32, rounding).ToString(),
                Math.Round(SharedData.Track.airtemp * 9/5 + 32, rounding).ToString(),
                Math.Round(SharedData.Track.airpressure * 1.333224, rounding).ToString(),
                Math.Round(SharedData.Track.windspeed * 1.943844, rounding).ToString(),
                Math.Round(SharedData.Track.windspeed * 3.6, rounding).ToString(),
            };

            if (session.SessionLength == float.MaxValue)
                output[2] = "-.--";

            if(session.TimeRemaining > 600000)
                output[3] = "-.--";

            if ((session.LapsComplete) < 0)
                output[4] = "0";
            else
                output[4] = session.LapsComplete.ToString();

            // lap counter
            if (session.LapsTotal == Int32.MaxValue || session.LapsTotal < 1)
            {
                if (session.State == Sessions.SessionInfo.sessionState.checkered) // session ending
                    output[6] = translation["finishing"];
                else // normal
                    output[6] = iRTVO.Overlay.floatTime2String((float)SharedData.Sessions.CurrentSession.TimeRemaining, rounding, true);
            }
            else if (session.State == Sessions.SessionInfo.sessionState.gridding)
            {
                output[6] = translation["gridding"];
            }
            else if (session.State == Sessions.SessionInfo.sessionState.pacing)
            {
                output[6] = translation["pacelap"];
            }
            else
            {
                int currentlap = session.LapsComplete;

                if (session.LapsRemaining < 1 && session.LapsComplete > 0)
                {
                    output[6] = translation["finishing"];
                }
                else if (session.LapsRemaining == 1)
                {
                    output[6] = translation["finallap"];
                }
                else if (session.LapsRemaining <= SharedData.settings.LapCountdownFrom)
                { // x laps remaining
                    output[6] = String.Format("{0} {1} {2}",
                        session.LapsRemaining,
                        translation["laps"],
                        translation["remaining"]
                    );
                }
                else // normal behavior
                {
                    if (currentlap < 0)
                        currentlap = 0;

                    output[6] = String.Format("{0} {1} {2} {3}",
                        translation["lap"],
                        (currentlap + 1),
                        translation["of"],
                        session.LapsTotal
                    );

                }
            }

            switch (session.Type)
            {
                case Sessions.SessionInfo.sessionType.race:
                    output[13] = translation["race"];
                    break;
                case Sessions.SessionInfo.sessionType.qualify:
                    output[13] = translation["qualify"];
                    break;
                case Sessions.SessionInfo.sessionType.practice:
                    output[13] = translation["practice"];
                    break;
                default:
                    output[13] = "";
                    break;
            }

            return output;
        }
Beispiel #9
0
        // *-name *-info
        public string[] getFollowedFormats(Sessions.SessionInfo.StandingsItem standing, Sessions.SessionInfo session, Int32 rounding)
        {
            Double laptime = SharedData.currentSessionTime - standing.Begin;

            string[] output = new string[68] {
                standing.Driver.Name,
                standing.Driver.Shortname,
                standing.Driver.Initials,
                standing.Driver.SR,
                standing.Driver.Club,
                getCar(standing.Driver.CarId),
                getCarClass(standing.Driver.CarId), //driver.carclass.ToString(),
                (standing.Driver.NumberPlate).ToString(),
                iRTVO.Overlay.floatTime2String(standing.FastestLap, rounding, false),
                iRTVO.Overlay.floatTime2String(standing.PreviousLap.LapTime, rounding, false),
                "", // currentlap (live) // 10
                standing.CurrentLap.LapNum.ToString(),
                "", // fastlap speed mph
                "", // prev lap speed mph
                "", // fastlap speed kph
                "", // prev lap speed kph
                standing.Position.ToString(),
                ordinate(standing.Position), // ordinal
                "",
                standing.LapsLed.ToString(),
                standing.Driver.UserId.ToString(), //20
                "",
                "",
                "",
                "",
                (standing.Speed * 3.6).ToString("0"),
                (standing.Speed * 2.237).ToString("0"),
                "",
                "",
                "",
                standing.PitStops.ToString(), //30
                iRTVO.Overlay.floatTime2String(standing.PitStopTime, rounding, false),
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "", // 40
                "",
                "",
                "",
                "",
                "",
                standing.ClassLapsLed.ToString(),
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                standing.PositionLive.ToString(),
                ordinate(standing.PositionLive),
                "",
                "",
                standing.Driver.iRating.ToString(),
                ""
            };

            if (standing.FastestLap < 5)
                output[8] = translation["invalid"];

            if (standing.PreviousLap.LapTime < 5)
                output[9] = translation["invalid"];

            if (laptime/60 > 60)
                output[10] = translation["invalid"];
            else if (((SharedData.currentSessionTime - standing.Begin) < 5))
            {
                if (standing.PreviousLap.LapTime < 5)
                    output[10] = translation["invalid"];
                else
                    output[10] = iRTVO.Overlay.floatTime2String(standing.PreviousLap.LapTime, rounding, false);
            }
            //else if (standing.OnTrack == false)
            else if (standing.TrackSurface == Sessions.SessionInfo.StandingsItem.SurfaceType.NotInWorld)
            {
                output[10] = iRTVO.Overlay.floatTime2String(standing.FastestLap, rounding, false);
            }
            else {
                output[10] = iRTVO.Overlay.floatTime2String((float)(SharedData.currentSessionTime - standing.Begin), rounding, false);
            }

            if (standing.FastestLap > 0)
            {
                output[12] = ((3600 * SharedData.Track.length / (1609.344 * standing.FastestLap))).ToString("0.00");
                output[14] = (3.6 * SharedData.Track.length / standing.FastestLap).ToString("0.00");
            }
            else
            {
                output[12] = "-";
                output[14] = "-";
            }

            if (standing.PreviousLap.LapTime > 0)
            {
                output[13] = ((3600 * SharedData.Track.length / (1609.344 * standing.PreviousLap.LapTime))).ToString("0.00");
                output[15] = (3.6 * SharedData.Track.length / standing.PreviousLap.LapTime).ToString("0.00");
            }
            else
            {
                output[13] = "-";
                output[15] = "-";
            }

            /*if ((DateTime.Now - standing.OffTrackSince).TotalMilliseconds > 1000 && standing.OnTrack == false && SharedData.allowRetire)*/
            if (standing.TrackSurface == Sessions.SessionInfo.StandingsItem.SurfaceType.NotInWorld &&
                SharedData.allowRetire &&
                (SharedData.Sessions.CurrentSession.Time - standing.OffTrackSince) > 1)
            {
                output[18] = translation["out"];
            }
            else
            {
                if (standing.Position == 1)
                {
                    if (session.Type == Sessions.SessionInfo.sessionType.race)
                        output[18] = "";//iRTVO.Overlay.floatTime2String((float)standing.CurrentLap.SessionTime, rounding, true); //translation["leader"];
                    else
                        output[18] = iRTVO.Overlay.floatTime2String(standing.FastestLap, rounding, false);
                }
                else if (standing.PreviousLap.GapLaps > 0 && session.Type == Sessions.SessionInfo.sessionType.race)
                {
                    /*
                    if (session.State == Sessions.SessionInfo.sessionState.cooldown ||
                        (session.State == Sessions.SessionInfo.sessionState.checkered && standing.CurrentTrackPct > session.LapsComplete))
                    {
                        output[18] = translation["behind"] + standing.FindLap(session.LapsComplete).GapLaps + " ";
                        if (standing.FindLap(session.LapsComplete).GapLaps > 1)
                            output[18] += translation["laps"];
                        else
                            output[18] += translation["lap"];
                    }
                    else
                    {
                    */
                        output[18] = translation["behind"] + standing.PreviousLap.GapLaps + " ";
                        if (standing.PreviousLap.GapLaps > 1)
                            output[18] += translation["laps"];
                        else
                            output[18] += translation["lap"];
                    //}
                }
                else/* if (SharedData.standing[SharedData.overlaySession].Length > 0 && SharedData.standing[SharedData.overlaySession][0].fastLap > 0)*/
                {
                    if (session.Type == Sessions.SessionInfo.sessionType.race)
                    {
                        /*
                        if (session.State == Sessions.SessionInfo.sessionState.cooldown ||
                        (session.State == Sessions.SessionInfo.sessionState.checkered && standing.CurrentTrackPct > session.LapsComplete))
                        {
                            output[18] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.FindLap(session.LapsComplete).Gap), rounding, false);
                        }
                        else
                        {
                            output[18] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.PreviousLap.Gap), rounding, false);
                        }
                         * */
                        output[18] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.PreviousLap.Gap), rounding, false);
                    }
                    else if (standing.FastestLap <= 1)
                        output[18] = translation["invalid"];
                    else
                        output[18] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.FastestLap - session.FastestLap), rounding, false);
                }
            }

            // interval
            if (standing.Position > 1) // not leader
            {
                Sessions.SessionInfo.StandingsItem infront = new Sessions.SessionInfo.StandingsItem();
                infront = session.FindPosition(standing.Position - 1, dataorder.position);

                if (session.Type == Sessions.SessionInfo.sessionType.race)
                {
                    if ((infront.CurrentTrackPct - standing.CurrentTrackPct) > 1)
                    {
                        output[21] = translation["behind"] + standing.PreviousLap.GapLaps + " ";
                        if (standing.PreviousLap.GapLaps > 1)
                            output[21] += translation["laps"];
                        else
                            output[21] += translation["lap"];
                    }
                    else
                    {
                        output[21] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.PreviousLap.Gap - infront.PreviousLap.Gap), rounding, false);
                    }
                }
                else // qualify and practice
                {
                    if (standing.FastestLap <= 1)
                    {
                        output[21] = translation["invalid"];
                    }
                    else
                    {
                        output[21] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.FastestLap - infront.FastestLap), rounding, false);
                    }
                }

                output[22] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.PreviousLap.Gap - infront.PreviousLap.Gap), rounding, false);
            }
            else // leader
            {

                if (session.Type == Sessions.SessionInfo.sessionType.race)
                {
                    output[21] = ""; //iRTVO.Overlay.floatTime2String((float)standing.CurrentLap.SessionTime, rounding, true); //translation["leader"];
                    output[22] = output[21];
                }
                else // qualify and practice
                {
                    output[21] = iRTVO.Overlay.floatTime2String(standing.FastestLap, rounding, false);
                    output[22] = output[21];
                }
            }

            if (session.Type == Sessions.SessionInfo.sessionType.race)
            {
                output[23] = translation["behind"] + standing.GapLive_HR(rounding);
                output[24] = translation["behind"] + standing.IntervalLive_HR(rounding);
            }
            else {
                output[23] = output[18];
                output[24] = output[22];
            }

            // sectors
            if (SharedData.SelectedSectors.Count > 0)
            {
                for(int i = 0; i <= 2; i++) {
                    if (standing.Sector <= 0) // first sector, show previous lap times
                    {
                        if (i < standing.PreviousLap.SectorTimes.Count)
                        {
                            LapInfo.Sector sector = standing.PreviousLap.SectorTimes.Find(s => s.Num.Equals(i));
                            if(sector != null)
                            {

                                output[27 + i] = iRTVO.Overlay.floatTime2String(sector.Time, rounding, false);
                                output[32 + i] = (sector.Speed * 3.6).ToString("0.0");
                                output[35 + i] = (sector.Speed * 2.237).ToString("0.0");
                            }
                            else
                            {
                                output[27 + i] = "";
                                output[32 + i] = "";
                                output[35 + i] = "";
                            }
                        }
                        else
                        {
                            output[27 + i] = "";
                            output[32 + i] = "";
                            output[35 + i] = "";
                        }
                    }
                    else
                    {
                        if (i < standing.CurrentLap.SectorTimes.Count)
                        {
                            LapInfo.Sector sector = standing.CurrentLap.SectorTimes.Find(s => s.Num.Equals(i));
                            if(sector != null)
                            {
                                output[27 + i] = iRTVO.Overlay.floatTime2String(sector.Time, rounding, false);
                                output[32 + i] = (sector.Speed * 3.6).ToString("0.0");
                                output[35 + i] = (sector.Speed * 2.237).ToString("0.0");
                            }
                            else
                            {
                                output[27 + i] = "";
                                output[32 + i] = "";
                                output[35 + i] = "";
                            }
                        }
                        else
                        {
                            output[27 + i] = "";
                            output[32 + i] = "";
                            output[35 + i] = "";
                        }
                    }
                }
            }

            // position gain
            Sessions.SessionInfo qualifySession = SharedData.Sessions.findSessionType(Sessions.SessionInfo.sessionType.qualify);
            if (qualifySession.Type != Sessions.SessionInfo.sessionType.invalid)
            {
                int qualifyPos = qualifySession.FindDriver(standing.Driver.CarIdx).Position;
                if((qualifyPos - standing.Position) > 0)
                    output[38] = "+" + (qualifyPos - standing.Position).ToString();
                else
                    output[38] = (qualifyPos - standing.Position).ToString();

                output[47] = qualifyPos.ToString();
                output[50] = ordinate(qualifyPos);

                Int32 classqpos = qualifySession.getClassPosition(standing.Driver);
                output[48] = classqpos.ToString();
                output[49] = ordinate(classqpos);
            }

            // highest/lowest position
            output[51] = standing.HighestPosition.ToString();
            output[52] = ordinate(standing.HighestPosition);
            output[53] = standing.LowestPosition.ToString();
            output[54] = ordinate(standing.LowestPosition);

            output[55] = standing.HighestClassPosition.ToString();
            output[56] = ordinate(standing.HighestClassPosition);
            output[57] = standing.LowestClassPosition.ToString();
            output[58] = ordinate(standing.LowestClassPosition);

            /*
            // pititemr
            if ((DateTime.Now - standing.PitStopBegin).TotalSeconds > 1)
                output[31] = iRTVO.Overlay.floatTime2String(standing.PitStopTime, rounding, false);
            else
            {
                output[31] = iRTVO.Overlay.floatTime2String((float)(DateTime.Now - standing.PitStopBegin).TotalSeconds, rounding, false);
            }
            */

            // multiclass
            /*
                {"classposition", 39},
                {"classposition_ord", 40},
                {"classpositiongain", 41},
                {"classgap", 42},
                {"classlivegap", 43},
                {"classinterval", 44},
                {"classliveinterval", 45},
             */
            int classpos = session.getClassPosition(standing.Driver);
            Sessions.SessionInfo.StandingsItem classLeader = session.getClassLeader(standing.Driver.CarClassName);
            output[39] = classpos.ToString();
            output[40] = ordinate(classpos);
            output[43] = standing.ClassGapLive_HR;
            output[45] = standing.ClassIntervalLive_HR;

            if (qualifySession.Type != Sessions.SessionInfo.sessionType.invalid)
            {
                IEnumerable<Sessions.SessionInfo.StandingsItem> query = qualifySession.Standings.Where(s => s.Driver.CarClassName == standing.Driver.CarClassName).OrderBy(s => s.Position);
                Int32 position = 1;
                Int32 qualifyPos = 0;
                foreach (Sessions.SessionInfo.StandingsItem si in query)
                {
                    if (si.Driver.CarIdx == standing.Driver.CarIdx)
                    {
                        qualifyPos = position;
                        break;
                    }
                    else
                        position++;
                }

                if ((qualifyPos - classpos) > 0)
                    output[41] = "+" + (qualifyPos - classpos).ToString();
                else
                    output[41] = (qualifyPos - classpos).ToString();
            }

            if (standing.TrackSurface == Sessions.SessionInfo.StandingsItem.SurfaceType.NotInWorld &&
                SharedData.allowRetire &&
                (SharedData.Sessions.CurrentSession.Time - standing.OffTrackSince) > 1)
            {
                output[42] = translation["out"];
            }
            else
            {
                float gap = classLeader.PreviousLap.Gap - standing.PreviousLap.Gap;
                int gaplaps = classLeader.PreviousLap.LapNum - standing.PreviousLap.LapNum;
                if (classpos == 1)
                {
                    if (session.Type == Sessions.SessionInfo.sessionType.race)
                        output[42] = ""; //iRTVO.Overlay.floatTime2String((float)standing.CurrentLap.SessionTime, rounding, true); //translation["leader"];
                    else
                        output[42] = iRTVO.Overlay.floatTime2String(standing.FastestLap, rounding, false);
                }
                else if (gaplaps > 0 && session.Type == Sessions.SessionInfo.sessionType.race)
                {
                    output[42] = translation["behind"] + gaplaps + " ";
                    if (gaplaps > 1)
                        output[42] += translation["laps"];
                    else
                        output[42] += translation["lap"];
                    //}
                }
                else/* if (SharedData.standing[SharedData.overlaySession].Length > 0 && SharedData.standing[SharedData.overlaySession][0].fastLap > 0)*/
                {
                    if (session.Type == Sessions.SessionInfo.sessionType.race)
                    {
                        if (session.State == Sessions.SessionInfo.sessionState.cooldown ||
                        (session.State == Sessions.SessionInfo.sessionState.checkered && standing.CurrentTrackPct > session.LapsComplete))
                        {
                            output[42] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.FindLap(session.LapsComplete).Gap), rounding, false);
                        }
                        else
                        {
                            output[42] = translation["behind"] + iRTVO.Overlay.floatTime2String(gap, rounding, false);
                        }
                    }
                    else if (standing.FastestLap <= 1)
                        output[42] = translation["invalid"];
                    else
                        output[42] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.FastestLap - classLeader.FastestLap), rounding, false);

                }
            }

            // interval
            if (standing.PreviousLap.Position > 1)
            {
                Sessions.SessionInfo.StandingsItem infront = new Sessions.SessionInfo.StandingsItem();
                infront = session.FindPosition(standing.Position - 1, dataorder.position, standing.Driver.CarClassName);

                if (session.Type == Sessions.SessionInfo.sessionType.race)
                {
                    if ((infront.CurrentTrackPct - standing.CurrentTrackPct) > 1)
                    {
                        output[44] = translation["behind"] + standing.PreviousLap.GapLaps + " ";
                        if (standing.PreviousLap.GapLaps > 1)
                            output[44] += translation["laps"];
                        else
                            output[44] += translation["lap"];
                    }
                    else
                    {
                        output[44] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.PreviousLap.Gap - infront.PreviousLap.Gap), rounding, false);
                    }
                }
                else
                {
                    if (standing.FastestLap <= 1)
                    {
                        output[44] = translation["invalid"];
                    }
                    else
                    {
                        output[44] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.FastestLap - infront.FastestLap), rounding, false);
                    }
                }

                output[44] = translation["behind"] + iRTVO.Overlay.floatTime2String((standing.PreviousLap.Gap - infront.PreviousLap.Gap), rounding, false);
            }
            else
            {

                if (session.Type == Sessions.SessionInfo.sessionType.race)
                {
                    output[44] = ""; // iRTVO.Overlay.floatTime2String((float)standing.CurrentLap.SessionTime, rounding, true); //translation["leader"];
                }
                else
                {
                    output[44] = iRTVO.Overlay.floatTime2String(standing.FastestLap, rounding, false);
                }
            }

            if (session.Type == Sessions.SessionInfo.sessionType.race)
            {
                output[23] = translation["behind"] + standing.GapLive_HR(rounding);
                output[24] = translation["behind"] + standing.IntervalLive_HR(rounding);
            }
            else
            {
                output[23] = output[18];
                output[24] = output[22];
            }

            // points
            if (SharedData.externalCurrentPoints.ContainsKey(standing.Driver.UserId))
            {
                output[59] = SharedData.externalCurrentPoints[standing.Driver.UserId].ToString();
                int pos = 0;
                foreach (KeyValuePair<int, int> item in SharedData.externalCurrentPoints.OrderByDescending(key => key.Value))
                {
                    pos++;
                    if (item.Key == standing.Driver.UserId)
                    {
                        output[60] = pos.ToString();
                        output[61] = ordinate(pos);
                        break;
                    }
                }
            }
            else
            {
                output[59] = "0";
                output[60] = SharedData.externalCurrentPoints.Count().ToString();
                output[61] = ordinate(SharedData.externalCurrentPoints.Count());
            }

            int classlivepos = session.getClassLivePosition(standing.Driver);
            output[64] = classlivepos.ToString();
            output[65] = ordinate(classlivepos);

            // interval followed
            if(standing.DistanceToFollowed < 0)
                output[67] = translation["behind"] + Theme.round(standing.IntervalToFollowedLive, rounding);
            else
                output[67] = translation["ahead"] + Theme.round(standing.IntervalToFollowedLive, rounding);

            string[] extrenal;
            if (SharedData.externalData.ContainsKey(standing.Driver.UserId))
            {
                extrenal = SharedData.externalData[standing.Driver.UserId];
            }
            else
                extrenal = new string[0];

            string[] merged = new string[output.Length + extrenal.Length];
            Array.Copy(output, 0, merged, 0, output.Length);
            Array.Copy(extrenal, 0, merged, output.Length, extrenal.Length);

            return merged;
        }
Beispiel #10
0
        private void parseFlag(Sessions.SessionInfo session, Int64 flag)
        {
            /*
            Dictionary<Int32, sessionFlag> flagMap = new Dictionary<Int32, sessionFlag>()
            {
                // global flags
                0x00000001 = sessionFlag.checkered,
                0x00000002 = sessionFlag.white,
                green = sessionFlag.green,
                yellow = 0x00000008,
             *
                red = 0x00000010,
                blue = 0x00000020,
                debris = 0x00000040,
                crossed = 0x00000080,
             *
                yellowWaving = 0x00000100,
                oneLapToGreen = 0x00000200,
                greenHeld = 0x00000400,
                tenToGo = 0x00000800,
             *
                fiveToGo = 0x00001000,
                randomWaving = 0x00002000,
                caution = 0x00004000,
                cautionWaving = 0x00008000,

                // drivers black flags
                black = 0x00010000,
                disqualify = 0x00020000,
                servicible = 0x00040000, // car is allowed service (not a flag)
                furled = 0x00080000,
             *
                repair = 0x00100000,

                // start lights
                startHidden = 0x10000000,
                startReady = 0x20000000,
                startSet = 0x40000000,
                startGo = 0x80000000,

            };*/

            Int64 regularFlag = flag & 0x0000000f;
            Int64 specialFlag = (flag & 0x0000f000) >> (4 * 3);
            Int64 startlight = (flag & 0xf0000000) >> (4 * 7);

            if (regularFlag == 0x8 || specialFlag >= 0x4)
                session.Flag = Sessions.SessionInfo.sessionFlag.yellow;
            else if (regularFlag == 0x2)
                session.Flag = Sessions.SessionInfo.sessionFlag.white;
            else if (regularFlag == 0x1)
                session.Flag = Sessions.SessionInfo.sessionFlag.checkered;
            else
                session.Flag = Sessions.SessionInfo.sessionFlag.green;

            if (startlight == 0x1)
                session.StartLight = Sessions.SessionInfo.sessionStartLight.off;
            else if (startlight == 0x2)
                session.StartLight = Sessions.SessionInfo.sessionStartLight.ready;
            else if (startlight == 0x4)
                session.StartLight = Sessions.SessionInfo.sessionStartLight.set;
            else if (startlight == 0x8)
                session.StartLight = Sessions.SessionInfo.sessionStartLight.go;
        }