public void Process(DataSample data, TimeSpan relativeTime)
        {
            ShowAnyPendingFastestLap(data, relativeTime);

            if (lastFastestLap != data.Telemetry.FastestLap)
                NoteNewFastestLap(data, relativeTime);
        }
        public bool IsActive(DataSample data)
        {
            var state = GetBattlePosition(data);

            switch(state.State)
            {
                case BattlePosition.Started:
                    directionAction = () =>
                    {
                        SwitchToBattle(data, state.Driver);
                        editMarker.Start();
                    };
                    return true;

                case BattlePosition.Inside:
                    directionAction = () =>
                    {
                        UpdateBattleCamera(data);
                        UpdateCameraIfOvertake(data);
                    };
                    return true;

                case BattlePosition.Finished:
                    directionAction = () => editMarker.Stop();
                    return true;

                case BattlePosition.Outside:
                    directionAction = () => { };
                    return false;
            }

            throw new Exception("Invalid Battle state {0}".F(state));
        }
		static DataSample[] CreatesSamples(params float[] values)
		{
			var s = new SessionData { DriverInfo = new SessionData._DriverInfo { Drivers = new [] { new SessionData._DriverInfo._Drivers { UserName = "******", CarNumberRaw = 1 } } } };

			var sample1 = new DataSample 
			{
                IsConnected = true,
				SessionData = s,
				Telemetry = new Telemetry {	
					{ "CarIdxLap",	new[] { 1 }	}, 
					{ "CarIdxLapDistPct", new[] { values[0] } }
				}
			};


			var sample2 = new DataSample 
			{
                IsConnected = true,
				SessionData = s,
				Telemetry = new Telemetry {	
					{ "CarIdxLap",	new[] { 1 }	}, 
					{ "CarIdxLapDistPct", new[] { values[1] } }
				}
			};

			return new[] { sample1,	sample2	};
		}
        OverlayData.Driver[] LatestRunningOrder(DataSample data, TimeSpan relativeTime)
        {
            var drivers = data.Telemetry.Cars.Where(c => !c.Details.IsPaceCar).Select(c => new OverlayData.Driver
            {
                UserName = c.Details.UserName,
                CarNumber = c.Details.CarNumberDisplay,
                Position = c.Position,
                CarIdx = c.CarIdx,
                PitStopCount = c.PitStopCount
            })
            .OrderBy(c => c.Position)
            .ToArray();

            if (lastDrivers != null)
                foreach (var d in drivers.OrderBy(d => d.Position))
                {
                    var lastPosition = lastDrivers.FirstOrDefault(lp => lp.CarIdx == d.CarIdx);
                    if (lastPosition != null && lastPosition.Position != d.Position)
                    {
                        var position = d.Position != null ? d.Position.Value.ToString() : "";
                        var indicator = d.Position != null ? d.Position.Value.Ordinal() : "";
                        var msg = "{0} in {1}{2}".F(d.UserName, position, indicator);
                        TraceInfo.WriteLine("{0} {1}", data.Telemetry.SessionTimeSpan, msg);
                        commentaryMessages.Add(msg, relativeTime.TotalSeconds);
                    }
                }

            lastDrivers = drivers;

            return drivers;
        }
        public bool IsActive(DataSample data)
        {
            var state = GetBattlePosition(data);

            switch(state.State)
            {
                case BattlePosition.Started:
                    directionAction = () =>
                    {
                        adjustedCamera = null;
                        SwitchToBattle(data, state.Driver, establishingShot: true);
                        editMarker.Start(data.Telemetry.Positions[battleLeader.CarIdx]);
                    };
                    return true;

                case BattlePosition.Inside:
                    directionAction = () =>
                    {
                        UpdateBattleCamera(data);
                        UpdateCameraIfOvertake(data);
                    };
                    return true;

                case BattlePosition.Finished:
                    directionAction = () => editMarker.Stop();
                    return true;

                case BattlePosition.Outside:
                    directionAction = () => { };
                    return false;
            }

            throw new Exception("Invalid Battle state {0}".F(state));
        }
        void AnnounceIfDriverHasFinished(DataSample data, TimeSpan relativeTime, SessionData._SessionInfo._Sessions session, int i, ref OverlayData.LeaderBoard leaderBoard)
        {
            if (!data.LastSample.Telemetry.Cars[i].HasSeenCheckeredFlag || haveNotedCheckerdFlag[i])
                return;

            haveNotedCheckerdFlag[i] = true;

            var driver = data.SessionData.DriverInfo.CompetingDrivers[i];
            var position = (int)session.ResultsPositions.First(r => r.CarIdx == i).Position;
            var pitStopCount = data.Telemetry.Cars[i].PitStopCount;

            var drivers = leaderBoard.Drivers.Where(d => d.CarIdx != i)
                .Select(d => d.Clone())
                .ToList();

            drivers.Insert((int)position - 1, new OverlayData.Driver
            {
                CarNumber = driver.CarNumber,
                UserName = driver.UserName,
                Position = position,
                CarIdx = i,
                PitStopCount = pitStopCount

            });

            var p = 1;
            foreach (var d in drivers)
                d.Position = p++;

            leaderBoard = captureLeaderBoard.CreateLeaderBoard(data, relativeTime, drivers.ToArray());

            var msg = string.Format("{0} finished in {1}{2}", driver.UserName, position, position.Ordinal());
            TraceInfo.WriteLine("{0} {1}", data.Telemetry.SessionTimeSpan, msg);
            commentaryMessages.Add(msg, relativeTime.TotalSeconds);
        }
 static void IncrementPitStopCounts(TrackLocation[] lastTrackLocation, int[] carIdxPitStopCount, DataSample data)
 {
     var current = data.Telemetry.CarIdxTrackSurface;
     for (var i = 0; i < current.Length; i++)
         if (lastTrackLocation[i] != TrackLocation.InPitStall && current[i] == TrackLocation.InPitStall)
             carIdxPitStopCount[i] += 1;
 }
        public void Process(DataSample data, TimeSpan relativeTime)
        {
            try
            {
                var cameraGroupName = "";
                var cameraName = "";

                var cameraGroup = data.SessionData.CameraInfo.Groups.FirstOrDefault(g => g.GroupNum == data.Telemetry.CamGroupNumber);
                if (cameraGroup != null)
                {
                    cameraGroupName = cameraGroup.GroupName;
                    var camera = cameraGroup.Cameras.FirstOrDefault(c => c.CameraNum == data.Telemetry.CamCameraNumber);
                    if (camera != null)
                        cameraName = camera.CameraName;
                }

                TraceDebug.WriteLine("{0} Camera: Driver: {1}, GroupNumber: {2}, Number: {3}, State: {4}, GroupName: {5}, Name: {6}",
                    data.Telemetry.SessionTimeSpan,
                    data.Telemetry.CamCar.Details.Driver.UserName,
                    data.Telemetry.CamGroupNumber,
                    data.Telemetry.CamCameraNumber,
                    data.Telemetry.CamCameraState,
                    cameraGroupName,
                    cameraName);
            }
            catch(Exception e)
            {
                TraceError.WriteLine(e.Message);
                TraceError.WriteLine(e.StackTrace);
            }
        }
 static void CaptureLastTrackLocations(TrackLocation[] lastTrackLocation, DataSample data)
 {
     var last = data.LastSample.Telemetry.CarIdxTrackSurface;
     for (var i = 0; i < last.Length; i++)
         if (last[i] != TrackLocation.NotInWorld)
             lastTrackLocation[i] = last[i];
 }
        public bool IsActive(DataSample data)
        {
            var position = GetIncidentPosition(data);

            switch (position)
            {
                case IncidentPosition.Started:
                    directionAction = () =>
                    {
                        editMarker.Start();
                        SwitchToIncident(data);
                    };
                    return true;

                case IncidentPosition.Inside:
                    directionAction = () => {};
                    return true;

                case IncidentPosition.Finished:
                    directionAction = () =>
                    {
                        editMarker.Stop();
                        WatchForNextIncident(data);
                    };
                    return true;

                case IncidentPosition.Outside:
                    directionAction = () => { };
                    return false;
            }

            throw new Exception("Invalid Incident Position {0}".F(position));
        }
        static void CapturePitStopCounts(TrackLocation[] lastTrackLocation, int[] carIdxPitStopCount, DataSample data)
        {
            if (data.LastSample == null)
                return;

            CaptureLastTrackLocations(lastTrackLocation, data);
            IncrementPitStopCounts(lastTrackLocation, carIdxPitStopCount, data);
        }
        public static Car Find(DataSample data, TimeSpan battleGap, double factor, IEnumerable<string> preferredDrivers)
        {
            preferredCarIdxs = GetPreferredCarIdxs(data, preferredDrivers);

            var allBattles = All(data, battleGap, preferredCarIdxs, factor);

            return SelectABattle(data, allBattles, random.Next(10100) / 100.0);
        }
        public bool IsActive(DataSample data)
        {
            if (isWatchingRandomDriver && data.Telemetry.SessionTimeSpan < finishWatchingRandomDriverAt)
                return true;

            isWatchingRandomDriver = false;
            return false;
        }
        public void Process(DataSample data, TimeSpan relativeTime)
        {
            if (data.Telemetry.SessionTimeSpan.Subtract(lastTime).TotalSeconds < period)
                return;

            lastTime = data.Telemetry.SessionTimeSpan;

            processor(data, relativeTime);
        }
        void NoteNewFastestLap(DataSample data, TimeSpan relativeTime)
        {
            if (timeToNoteFastestLap == null)
                timeToNoteFastestLap = data.Telemetry.SessionTime + 20;

            lastFastestLap = data.Telemetry.FastestLap;

            TraceInfo.WriteLine("{0} Driver {1} recorded a new fast lap of {2:0.00}", data.Telemetry.SessionTimeSpan, lastFastestLap.Driver.UserName, lastFastestLap.Time.TotalSeconds);
        }
        static void ApplyHasSeenCheckeredFlag(DataSample data, bool[] hasSeenCheckeredFlag)
        {
            if (data.LastSample != null && data.Telemetry.LeaderHasFinished)
                for (int i = 1; i < data.SessionData.DriverInfo.CompetingDrivers.Length; i++)
                    if (data.LastSample.Telemetry.CarIdxLapDistPct[i] > 0.90 && data.Telemetry.CarIdxLapDistPct[i] < 0.10)
                        hasSeenCheckeredFlag[i] = true;

            data.Telemetry.HasSeenCheckeredFlag = hasSeenCheckeredFlag;
        }
        bool InFirstLapPeriod(DataSample data)
        {
            if( !raceHasStarted)
            {
                raceHasStarted = data.Telemetry.SessionState == SessionState.Racing;
                raceStartTime = data.Telemetry.SessionTimeSpan;
                return true;
            }

            return data.Telemetry.SessionTimeSpan < raceStartTime + Settings.Default.FollowLeaderAtRaceStartPeriod;
        }
        bool ActiveRule(IDirectionRule rule, DataSample data)
        {
            if (rule.IsActive(data))
            {
                currentRule = rule;
                rule.Direct(data);
                return true;
            }

            return false;
        }
        public bool IsActive(DataSample data)
        {
            if (isVetoed = vetoRule.IsActive(data))
            {
                Trace.WriteLineIf(!wasVetored, "{0}. Vetoing rule {1} with {2}".F(data.Telemetry.SessionTimeSpan, mainRule.Name, vetoRule.Name));
                wasVetored = true;
                return true;
            }

            return mainRule.IsActive(data);
        }
        public void Process(DataSample data)
        {
            if (ActiveRule(currentRule, data))
                return;

            foreach (var rule in directionRules)
                if (ActiveRule(rule, data))
                    return;

            currentRule = ruleRandom;
            currentRule.Direct(data);
        }
Example #21
0
        static void CaptureLastTrackLocations(TrackLocation[] lastTrackLocation, DataSample data)
        {
            var last = data.LastSample.Telemetry.CarIdxTrackSurface;

            for (var i = 0; i < last.Length; i++)
            {
                if (last[i] != TrackLocation.NotInWorld)
                {
                    lastTrackLocation[i] = last[i];
                }
            }
        }
        public void Process(DataSample data, TimeSpan relativeTime, ref OverlayData.LeaderBoard leaderBoard)
        {
            if (leaderBoardUpdateRate == 0 || leaderBoard == null)
                leaderBoard = captureLeaderBoard.CreateLeaderBoard(data, relativeTime, LatestRunningOrder(data, relativeTime));
            else
                leaderBoard = captureLeaderBoard.CreateLeaderBoard(data, relativeTime, leaderBoard.Drivers);

            leaderBoardUpdateRate++;
            leaderBoardUpdateRate = leaderBoardUpdateRate % 8;

            overlayData.LeaderBoards.Add(leaderBoard);
        }
        static void ieventRacing_NewData(DataSample data)
        {
            //You can access your game data here
            var x = data.Telemetry.SessionTimeSpan;
            var z = data.Telemetry["AirTemp"];

            var y = data.SessionData.WeekendInfo.TrackDisplayName;
            var r = data.Telemetry.SessionData.Raw;


            Trace.WriteLine("Time: {0}".F(x));
        }
        void MarkResultFlashCardStart(DataSample data, TimeSpan relativeTime, SessionData._SessionInfo._Sessions session, int i)
        {
            if (!data.LastSample.Telemetry.Cars[i].HasSeenCheckeredFlag || overlayData.TimeForOutroOverlay != null)
                return;
            
            var position = (int)session.ResultsPositions.First(r => r.CarIdx == i).Position;

            if (position == Settings.Default.ResultsFlashCardPosition)
            {
                overlayData.TimeForOutroOverlay = relativeTime.TotalSeconds;
                TraceInfo.WriteLine("{0} Mark show results flash card.", data.Telemetry.SessionTimeSpan);
            }
        }
        OverlayData.CamDriver CreateCamDriver(DataSample data, TimeSpan relativeTime)
        {
            var driver = GetCurrentDriverDetails(data);

            if (driver == null)
                return null;

            return new OverlayData.CamDriver
            {
                StartTime = relativeTime.TotalSeconds,
                CurrentDriver = driver,
            };
        }
        public void Process(DataSample data, TimeSpan relativeTime, ref OverlayData.LeaderBoard leaderBoard)
        {
            var session = data.SessionData.SessionInfo.Sessions[data.Telemetry.SessionNum];

            leaderBoard = captureLeaderBoard.CreateLeaderBoard(data, relativeTime, leaderBoard.Drivers);

            for (int i = 1; i < data.SessionData.DriverInfo.CompetingDrivers.Length; i++)
            {
                AnnounceIfDriverHasFinished(data, relativeTime, session, i, ref leaderBoard);
                MarkResultFlashCardStart(data, relativeTime, session, i);
            }

            overlayData.LeaderBoards.Add(leaderBoard);
        }
        void AddEvent(InterestState interest, DataSample d, TimeSpan t)
        {
            raceEvents.Add(new OverlayData.RaceEvent 
            {
                Interest = interest, 
                StartTime = lastStartTime.TotalSeconds, 
                EndTime = t.TotalSeconds,
                WithOvertake = withOvertake
            });
            lastStartTime = t;

            TraceInfo.WriteLine("{0} Stopping {1}{2}", d.Telemetry.SessionTimeSpan, interest.ToString(), withOvertake ? " - with Overtake" : "");
            withOvertake = false;
        }
        static void ApplyHasSeenCheckeredFlag(DataSample data, bool[] hasSeenCheckeredFlag)
        {
            if (data.LastSample != null && data.Telemetry.LeaderHasFinished)
            {
                for (int i = 1; i < data.SessionData.DriverInfo.Drivers.Length; i++)
                {
                    if (data.LastSample.Telemetry.CarIdxLapDistPct[i] > 0.90 && data.Telemetry.CarIdxLapDistPct[i] < 0.10)
                    {
                        hasSeenCheckeredFlag[i] = true;
                    }
                }
            }

            data.Telemetry.HasSeenCheckeredFlag = hasSeenCheckeredFlag;
        }
        public void Direct(DataSample data)
        {
            if (isWatchingRandomDriver)
                return;

            isWatchingRandomDriver = true;

            finishWatchingRandomDriverAt = data.Telemetry.SessionTimeSpan + stickyTime;

            camera = cameraControl.FindACamera(new[] { CameraAngle.LookingInfrontOfCar, CameraAngle.LookingAtCar, CameraAngle.LookingAtTrack });
            car = FindADriver(data);

            TraceInfo.WriteLine("{0} Changing camera to random driver: {1}; camera: {2}", data.Telemetry.SessionTimeSpan, car.UserName, camera.CameraName);
            cameraControl.CameraOnDriver((short)car.CarNumberRaw, camera.CameraNumber);
        }
        public void Direct(DataSample data)
        {
            if (isVetoed)
            {
                vetoRule.Direct(data);
                return;
            }

            if (wasVetored)
                mainRule.Redirect(data);

            wasVetored = false;

            mainRule.Direct(data);
        }
        void SwitchToFinishingDrivers(DataSample data)
        {
            var session = data.SessionData.SessionInfo.Sessions[data.Telemetry.SessionNum];

            if (lastFinisherCarIdx != -1 && !data.Telemetry.Cars[lastFinisherCarIdx].HasSeenCheckeredFlag)
            {
                timeOfFinisher = DateTime.Now.AddSeconds(2.0 * Settings.AppliedTimingFactor);
                return;
            }

            if (timeOfFinisher > DateTime.Now)
                return;

            Car nextFinisher;

            if (!data.Telemetry.LeaderHasFinished)
                nextFinisher = data.Telemetry.Cars
                    .OrderBy(c => c.Position)
                    .Where( c=> c.Details.Driver != null)
                    .Where( c=> c.HasData)
                    .First();
            else
                nextFinisher = data.Telemetry.Cars
                        .Where(c => c.TotalDistance > 0)
                        .Where(c => !c.HasSeenCheckeredFlag)
                        .Where(c => !c.Details.IsPaceCar)
                        .Where(c => c.HasData)
                        .Where(c => c.Details.Driver != null)
                        .Where(c => c.TrackSurface == TrackLocation.OnTrack)
                        .OrderByDescending(c => c.DistancePercentage)
                        .ThenBy(c => c.OfficialPostion == 0 ? int.MaxValue : c.OfficialPostion)
                        .FirstOrDefault();

            if (nextFinisher == null)
            {
                Trace.WriteLine("{0} Found no more finishers.".F(data.Telemetry.SessionTimeSpan), "DEBUG");
                return;
            }

            Trace.WriteLine("{0} Found {1} in position {2}".F(data.Telemetry.SessionTimeSpan, nextFinisher.Details.UserName, nextFinisher.Position), "DEBUG");

            timeOfFinisher = DateTime.Now;
            lastFinisherCarIdx = nextFinisher.CarIdx;

            TraceInfo.WriteLine("{0} Switching camera to {1} as they cross finishing line in position {2}", data.Telemetry.SessionTimeSpan, nextFinisher.Details.UserName, nextFinisher.Position);

            cameraControl.CameraOnDriver(nextFinisher.Details.CarNumberRaw, cameraControl.LastLapCameraNumber);
        }
        public void Process(DataSample data, TimeSpan relativeTime)
        {
            foreach (var car in data.Telemetry.Cars.Where(c => !c.Details.IsPaceCar))
            {
                if (pitStopState[car.CarIdx] == PitStopState.None && car.TrackSurface == TrackLocation.InPitStall)
                {
                    pitStopState[car.CarIdx] = PitStopState.Entering;
                    var msg = "{0} has pitted".F(car.Details.UserName);
                    TraceInfo.WriteLine("{0} {1}", data.Telemetry.SessionTimeSpan, msg);
                    commentaryMessages.Add(msg, relativeTime);
                }

                if (pitStopState[car.CarIdx] == PitStopState.Entering && car.TrackSurface != TrackLocation.InPitStall)
                    pitStopState[car.CarIdx] = PitStopState.None;
            }
        }
Example #33
0
        /// <summary>
        /// Mixes in the LastSample field
        /// Also disconnect the link list - so only the immediate sample has ref to last sample.
        /// </summary>
        public static IEnumerable <DataSample> WithLastSample(this IEnumerable <DataSample> samples)
        {
            DataSample lastDataSample = null;

            foreach (var data in samples)
            {
                data.LastSample = lastDataSample;
                if (lastDataSample != null)
                {
                    lastDataSample.LastSample = null;
                }
                lastDataSample = data;

                yield return(data);
            }
        }
Example #34
0
        static void CapturePitStopCounts(TrackLocation[] lastTrackLocation, int[] carIdxPitStopCount, DataSample data)
        {
            if (data.LastSample == null)
            {
                return;
            }

            CaptureLastTrackLocations(lastTrackLocation, data);
            IncrementPitStopCounts(lastTrackLocation, carIdxPitStopCount, data);
        }
Example #35
0
        static void IncrementPitStopCounts(TrackLocation[] lastTrackLocation, int[] carIdxPitStopCount, DataSample data)
        {
            var current = data.Telemetry.CarIdxTrackSurface;

            for (var i = 0; i < current.Length; i++)
            {
                if (lastTrackLocation[i] != TrackLocation.InPitStall && current[i] == TrackLocation.InPitStall)
                {
                    carIdxPitStopCount[i] += 1;
                }
            }
        }
 public Car Car(DataSample data)
 {
     return(data.Telemetry.Cars[this.carIdx]);
 }
 static void ApplyIsFinalLap(DataSample data)
 {
     data.Telemetry.IsFinalLap = data.Telemetry.RaceLaps >= data.SessionData.SessionInfo.Sessions[data.Telemetry.SessionNum].ResultsLapsComplete;
 }