Ejemplo n.º 1
0
        public override void trigger(Object lastStateObj, Object currentStateObj, GameStateData currentGameState)
        {
            F12018StructWrapper currentWrapper = (F12018StructWrapper)currentStateObj;

            if (currentWrapper.packetLapData.m_lapData == null || currentWrapper.packetMotionData.m_carMotionData == null || currentWrapper.packetCarTelemetryData.m_carTelemetryData == null)
            {
                return;
            }
            Boolean inPits       = currentWrapper.packetLapData.m_lapData[currentWrapper.packetLapData.m_header.m_playerCarIndex].m_pitStatus != 0;
            Boolean isSpectating = currentWrapper.packetSessionData.m_isSpectating != 0;

            if (inPits || isSpectating)
            {
                return;
            }

            DateTime now = new DateTime(currentWrapper.ticksWhenRead);

            if (enabled && currentWrapper.packetMotionData.m_carMotionData.Length > 1)
            {
                int playerIndex = currentWrapper.packetMotionData.m_header.m_playerCarIndex;

                CarMotionData playerData = currentWrapper.packetMotionData.m_carMotionData[playerIndex];

                float[] currentPlayerPosition = new float[] { playerData.m_worldPositionX, playerData.m_worldPositionZ };

                List <float[]> currentOpponentPositions    = new List <float[]>();
                List <float[]> currentOpponentVelocityData = new List <float[]>();
                float[]        playerVelocityData          = new float[3];
                playerVelocityData[0] = (float)currentWrapper.packetCarTelemetryData.m_carTelemetryData[currentWrapper.packetCarTelemetryData.m_header.m_playerCarIndex].m_speed * 0.277778f;
                playerVelocityData[1] = playerData.m_worldVelocityX;
                playerVelocityData[2] = playerData.m_worldVelocityZ;

                for (int i = 0; i < currentWrapper.packetMotionData.m_carMotionData.Length; i++)
                {
                    if (i == playerIndex)
                    {
                        continue;
                    }
                    CarMotionData opponentData     = currentWrapper.packetMotionData.m_carMotionData[i];
                    float[]       currentPositions = new float[] { opponentData.m_worldPositionX, opponentData.m_worldPositionZ };
                    currentOpponentPositions.Add(currentPositions);
                    currentOpponentVelocityData.Add(new float[] { opponentData.m_worldVelocityX, opponentData.m_worldVelocityZ });
                }
                if (currentOpponentPositions.Count() > 0)
                {
                    float playerRotation = playerData.m_yaw;
                    if (playerRotation < 0)
                    {
                        playerRotation = playerRotation * -1;
                    }
                    else
                    {
                        playerRotation = twoPi - playerRotation;
                    }
                    internalSpotter.triggerInternal(playerRotation, currentPlayerPosition, playerVelocityData, currentOpponentPositions, currentOpponentVelocityData);
                }
            }
        }
Ejemplo n.º 2
0
        public override GameStateData mapToGameStateData(Object structWrapper, GameStateData previousGameState)
        {
            F12018StructWrapper wrapper = (F12018StructWrapper)structWrapper;
            long ticks = wrapper.ticksWhenRead;

            // TODO: one or two minor things here ;)
            return(new GameStateData(ticks));
        }
Ejemplo n.º 3
0
        public F12018StructWrapper CreateCopy(long ticksWhenCopied, Boolean forSpotter)
        {
            F12018StructWrapper copy = new F12018StructWrapper();

            copy.ticksWhenRead          = ticksWhenCopied;
            copy.packetLapData          = this.packetLapData;
            copy.packetSessionData      = this.packetSessionData;
            copy.packetMotionData       = this.packetMotionData;
            copy.packetCarTelemetryData = this.packetCarTelemetryData;

            if (!forSpotter)
            {
                copy.packetCarSetupData     = this.packetCarSetupData;
                copy.packetCarStatusData    = this.packetCarStatusData;
                copy.packetEventData        = this.packetEventData;
                copy.packetParticipantsData = this.packetParticipantsData;
            }
            return(copy);
        }
Ejemplo n.º 4
0
 public override Object ReadGameDataFromFile(String filename, int pauseBeforeStart)
 {
     if (dataReadFromFile == null || filename != lastReadFileName)
     {
         dataReadFromFileIndex = 0;
         var filePathResolved = Utilities.ResolveDataFile(this.dataFilesPath, filename);
         dataReadFromFile = DeSerializeObject <F12018StructWrapper[]>(filePathResolved);
         lastReadFileName = filename;
         Thread.Sleep(pauseBeforeStart);
     }
     if (dataReadFromFile != null && dataReadFromFile.Length > dataReadFromFileIndex)
     {
         F12018StructWrapper structWrapperData = dataReadFromFile[dataReadFromFileIndex];
         workingData    = structWrapperData;
         newSpotterData = true;
         dataReadFromFileIndex++;
         return(structWrapperData);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 5
0
        public override Object ReadGameData(Boolean forSpotter)
        {
            F12018StructWrapper latestData = workingData.CreateCopy(DateTime.UtcNow.Ticks, forSpotter);

            lock (this)
            {
                if (!initialised)
                {
                    if (!InitialiseInternal())
                    {
                        throw new GameDataReadException("Failed to initialise UDP client");
                    }
                }
                if (forSpotter)
                {
                    newSpotterData = false;
                }
            }
            if (!forSpotter && dumpToFile && dataToDump != null && workingData != null /* && latestData has some sane data?*/)
            {
                dataToDump.Add(latestData);
            }
            return(latestData);
        }