Exemplo n.º 1
0
        public void UpdateLivePositions()
        {
            int i = 1;
            IEnumerable <LiveStandingsItem> query;

            SessionTimerModule stm = API.Instance.FindModule("SessionTimer") as SessionTimerModule;

            if ((stm.SessionType == SessionType.LapRace || stm.SessionType == SessionType.TimeRace) && stm.SessionState == SessionState.Racing)
            {
                query = Items.OrderByDescending(s => s.CurrentTrackPct);
                foreach (LiveStandingsItem si in query)
                {
                    si.PositionLive = i++;
                }
            }
            else
            {
                query = Items.OrderBy(s => s.Position);
                foreach (LiveStandingsItem si in query)
                {
                    si.PositionLive = si.Position;
                }
            }
        }
Exemplo n.º 2
0
        public void Update(Dictionary <string, object> dict, API api, Module caller)
        {
            double currTime = (double)api.GetData("SessionTime");

            OldPosition = Position;

            int carIdx = int.Parse(dict.GetDictValue("CarIdx"));

            if (Driver == null || Driver.CarIndex != carIdx)
            {
                return;
            }

            Position         = int.Parse(dict.GetDictValue("Position"));
            ClassPosition    = int.Parse(dict.GetDictValue("ClassPosition")) + 1;
            GapLaps          = int.Parse(dict.GetDictValue("Lap"));
            GapTime          = float.Parse(dict.GetDictValue("Time").Replace('.', ','));
            FastestLapNumber = int.Parse(dict.GetDictValue("FastestLap"));
            float newTime = float.Parse(dict.GetDictValue("FastestTime").Replace('.', ','));

            LapTimeImproved = newTime < FastestLapTime || (newTime != 0 && FastestLapTime == 0) && !first;
            FastestLapTime  = newTime;
            LastLapTime     = float.Parse(dict.GetDictValue("LastTime").Replace('.', ','));
            LapsLed         = int.Parse(dict.GetDictValue("LapsLed"));
            LapsComplete    = int.Parse(dict.GetDictValue("LapsComplete"));
            Incidents       = int.Parse(dict.GetDictValue("Incidents"));

            SurfaceType surfaceType = ((SurfaceType[])api.GetData("CarIdxTrackSurface"))[carIdx];

            SessionTimerModule m           = (SessionTimerModule)API.Instance.FindModule("SessionTimer");
            SessionType        sessionType = m.SessionType;

            bool inpits = ((bool[])api.GetData("CarIdxOnPitRoad"))[carIdx];

            if (sessionType == SessionType.LapRace || sessionType == SessionType.TimeRace)
            {
                InPits = inpits || surfaceType == SurfaceType.InPitStall;
            }
            else
            {
                InPits = inpits || surfaceType == SurfaceType.InPitStall || surfaceType == SurfaceType.NotInWorld;
            }
            Surface = surfaceType;

            Track track = ((SessionsModule)API.Instance.FindModule("Sessions")).Track;


            SessionState sessionState = m.SessionState;
            int          finishLine   = m.LapsTotal + 1;

            if (finishLine < 0)
            {
                finishLine = int.MaxValue;
            }

            SurfaceType surface   = (SurfaceType)((int[])api.GetData("CarIdxTrackSurface"))[Driver.CarIndex];
            int         lapNumber = ((int[])api.GetData("CarIdxLap"))[Driver.CarIndex];
            float       trackPct  = ((float[])api.GetData("CarIdxLapDistPct"))[Driver.CarIndex];

            if (currentime >= prevtime)
            {
                currentime = (double)api.GetData("SessionTime");
            }

            double timeoffset = 0;

            if (((double)api.GetData("SessionTime") - (double)api.GetData("ReplaySessionTime")) < 2)
            {
                timeoffset = (int)api.GetData("ReplayFrameNum") - ((double)api.GetData("SessionTime") * 60);
            }

            double prevpos    = PrevTrackPct;
            double prevupdate = PrevTrackPctUpdate;
            float  curpos     = ((float[])api.GetData("CarIdxLapDistPct"))[Driver.CarIndex];

            CurrentLap.ReplayPos = (int)(((double)api.GetData("SessionTime") * 60) + timeoffset);

            if (currentime > prevupdate && curpos != prevpos)
            {
                float speed = 0;

                if (curpos < 0.1 && prevpos > 0.9)
                {
                    speed = (float)((((curpos - prevpos) + 1) * (double)track.Length) / (currentime - prevupdate));
                }
                else
                {
                    speed = (float)(((curpos - prevpos) * (double)track.Length) / (currentime - prevupdate));
                }

                if (Math.Abs(Prevspeed - speed) < 1 && (curpos - prevpos) >= 0)
                {
                    Speed = speed;
                }

                Prevspeed          = speed;
                PrevTrackPct       = curpos;
                PrevTrackPctUpdate = currentime;

                if (!Finished)
                {
                    CurrentTrackPct = lapNumber + trackPct - 1;
                }

                if (curpos < 0.1 && prevpos > 0.9 && !Finished)
                {
                    if (surface != SurfaceType.NotInWorld && speed > 0)
                    {
                        Double now = currentime - ((curpos / (1 + curpos - prevpos)) * (currentime - prevtime));

                        Sector sector = new Sector();
                        sector.Number = Sector;
                        sector.Speed  = Speed;
                        sector.Time   = (float)(now - SectorBegin);
                        sector.Begin  = SectorBegin;

                        CurrentLap.Sectors.Add(sector);
                        CurrentLap.Time = (float)(now - Begin);
                        // TODO CurrentLap.ClassPosition = SharedData.Sessions.CurrentSession.getClassPosition(driver.Driver);
                        if (sessionType == SessionType.LapRace || sessionType == SessionType.TimeRace)
                        {
                            CurrentLap.Gap = (float)GapLive;
                        }
                        else
                        {
                            LiveStandingsItem leader = ((LiveStandingsModule)caller).Leader;
                            if (leader != null)
                            {
                                CurrentLap.Gap = CurrentLap.Time - leader.FastestLapTime;
                            }
                        }

                        CurrentLap.GapLaps = 0;


                        if (CurrentLap.LapNumber > 0 && Laps.FindIndex(l => l.LapNumber.Equals(CurrentLap.LapNumber)) == -1 &&
                            (sessionState != SessionState.Gridding || sessionState != SessionState.Cooldown))
                        {
                            Laps.Add(CurrentLap);
                        }

                        CurrentLap             = new Lap();
                        CurrentLap.LapNumber   = lapNumber;
                        CurrentLap.Gap         = PreviousLap.Gap;
                        CurrentLap.GapLaps     = PreviousLap.GapLaps;
                        CurrentLap.ReplayPos   = (int)(((double)api.GetData("SessionTime") * 60) + timeoffset);
                        CurrentLap.SessionTime = (double)api.GetData("SessionTime");
                        SectorBegin            = now;
                        Sector = 0;
                        Begin  = now;

                        // caution lap calc
                        //if (m.SessionFlags.FlagSet(SessionFlag.Yellow) && Position == 1)
                        //    SharedData.Sessions.CurrentSession.CautionLaps++;

                        // class laps led
                        //if (SharedData.Sessions.CurrentSession.getClassLeader(driver.Driver.CarClassName).Driver.CarIdx == driver.Driver.CarIdx && driver.CurrentLap.LapNum > 1)
                        //    driver.ClassLapsLed = driver.ClassLapsLed + 1;
                    }
                }

                if (track.Sectors.Count > 0 && Driver.CarIndex >= 0)
                {
                    for (int j = 0; j < track.Sectors.Count; j++)
                    {
                        if (curpos > track.Sectors[j] && j > Sector)
                        {
                            double now    = currentime - ((curpos - track.Sectors[j]) * (curpos - prevpos));
                            Sector sector = new Sector();
                            sector.Number = Sector;
                            sector.Time   = (float)(now - SectorBegin);
                            sector.Speed  = Speed;
                            sector.Begin  = SectorBegin;
                            CurrentLap.Sectors.Add(sector);
                            SectorBegin = now;
                            Sector      = j;
                        }
                    }
                }

                if (CurrentLap.LapNumber + CurrentLap.GapLaps >= finishLine && surface != SurfaceType.NotInWorld &&
                    (sessionType == SessionType.LapRace || sessionType == SessionType.TimeRace) && !Finished)
                {
                    ((LiveStandingsModule)caller).UpdateLivePositions();
                    CurrentTrackPct = (Math.Floor(CurrentTrackPct) + 0.0064) - (0.0001 * Position);
                    Finished        = true;
                }

                if (Driver.CarIndex >= 0)
                {
                    Surface = surface;
                }
            }

            if (((LiveStandingsModule)caller).Leader != null)
            {
                Out = dict.GetDictValue("ReasonOutStr").StartsWith("Disconnected") || CurrentTrackPct <= ((LiveStandingsModule)caller).Leader.CurrentTrackPct * 0.75;
            }

            GridItem gridItem = GridModule.FindDriverStatic(this);

            if (gridItem != null)
            {
                Dnq = gridItem.QualiTime <= 0.0;
            }

            Dsq = dict.GetDictValue("ReasonOutStr").StartsWith("Disqualified");
            Dns = (sessionType == SessionType.LapRace || sessionType == SessionType.TimeRace) ? CurrentTrackPct == 0.0 : false;

            prevtime           = currentime;
            CurrentSessionTime = currentime;
        }