Exemple #1
0
        public SessionInfo(List <LapAnalyzer> lapData)
        {
            SessionID        = "0";
            playerCarIndex   = 0;
            participantsData = new PacketParticipantsData()
            {
                numActiveCars = (byte)lapData.Count,
                participants  = new ParticipantData[22]
            };
            Update(lapData[0].lapInfo.Details.circuitInfo);
            circuit.MotionInfo = new PacketMotionData()
            {
                carMotionData = new CarMotionData[22]
            };
            int i = 0;

            foreach (var lap in lapData)
            {
                participantsData.participants[i] = lap.lapInfo.Details.playerInfo;
                //circuit.motionInContextLog.AddRange(lap.lapInfo.Details.lap.lapMotion);
                i++;
            }
            participantsData.numActiveCars = (byte)i;
            Update(participantsData, true);
            i = 0;

            foreach (var lap in lapData)
            {
                var player = GetPlayerByIndex(i);
                player.AddLap(lap.lapInfo.Details.lap);
                i++;
            }
        }
Exemple #2
0
        public void Update(PacketParticipantsData data, bool addAlways = false)
        {
            participantsData = data;
            if (circuit != null)
            {
                // LogLine("Aantal auto's: " + participantsData.numActiveCars);
                circuit.NumberOfCars = data.numActiveCars;
            }
            int participantIndex = 0;

            foreach (var participant in data.participants)
            {
                var str = PacketHelper.GetString(participant.name, 48);
                // Data might be empty if not enough cars available
                if (str != "" || participant.driverId != 0)
                {
                    var isAI = (participant.aiControlled == (byte)1 ? "AI" : "=>");
                    // LogLine($"{isAI} {(int)participant.raceNumber} {str} {PacketHelper.Country(participant.nationality)}, {participant.driverId}, Team:{participant.teamId})");
                    lock (playerInfo)
                    {
                        var player = GetPlayerByDriverID(participant.driverId);

                        if (player == null || addAlways)
                        {
                            playerInfo[participantIndex] = new PlayerInfo(participant, participantIndex);
                        }
                        else
                        {
                            if (player.CarNumber != participant.raceNumber)
                            {
                                if (participant.raceNumber == 0)
                                {
                                    playerInfo[participantIndex] = new PlayerInfo(participant, participantIndex);
                                }
                                else
                                {
                                    throw new Exception($"Car switch detected {player.Name},{player.CarNumber} => {participant.name},{participant.raceNumber} ");
                                }
                            }
                            else
                            {
                                playerInfo[participantIndex]?.Update(participant);
                            }
                        }
                    }
                }
                participantIndex++;
            }
        }