Пример #1
0
 public override void respond(String voiceMessage)
 {
     if (isLast)
     {
         audioPlayer.playMessageImmediately(new QueuedMessage(folderLast, 0));
     }
     else if (currentPosition == 1)
     {
         audioPlayer.playMessageImmediately(new QueuedMessage(folderLeading, 0));
     }
     else if (currentPosition > 0)
     {
         if (SoundCache.availableSounds.Contains(folderDriverPositionIntro))
         {
             audioPlayer.playMessageImmediately(new QueuedMessage("position", 0,
                                                                  messageFragments: MessageContents(folderDriverPositionIntro, folderStub + currentPosition)));
         }
         else
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(folderStub + currentPosition, 0));
         }
     }
     else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_MY_POSITION))
     {
         // only play 'no data' if we asked for position directly
         audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0));
     }
 }
Пример #2
0
 public override void respond(String voiceMessage)
 {
     if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_MY_POSITION))
     {
         if (isLast)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(folderLast, 0, this));
         }
         else if (currentPosition == 1)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(folderLeading, 0, this));
         }
         else if (currentPosition > 0)
         {
             if (currentPosition < 25)
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage(folderStub + currentPosition, 0, this));
             }
             else
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("position", MessageContents(currentPosition), 0, this));
             }
         }
         else
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0, null));
         }
     }
 }
Пример #3
0
 public override void respond(String voiceMessage)
 {
     if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.CAR_STATUS) ||
         SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.DAMAGE_REPORT) ||
         SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.STATUS))
     {
         readStatus();
     }
     else
     {
         QueuedMessage damageMessage = null;
         if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_AERO))
         {
             damageMessage = getDamageMessage(Component.AERO, true);
         }
         if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_TRANSMISSION))
         {
             damageMessage = getDamageMessage(Component.TRANNY, true);
         }
         if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_ENGINE))
         {
             damageMessage = getDamageMessage(Component.ENGINE, true);
         }
         if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_SUSPENSION))
         {
             damageMessage = getDamageMessage(Component.SUSPENSION, true);
         }
         if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_BRAKES))
         {
             damageMessage = getDamageMessage(Component.BRAKES, true);
         }
         if (CrewChief.gameDefinition.gameEnum != GameEnum.IRACING && damageMessage != null)
         {
             // play this immediately or play "stand by", and queue it to be played in a few seconds
             if (delayResponses && Utilities.random.Next(10) >= 2 && SoundCache.availableSounds.Contains(AudioPlayer.folderStandBy))
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderStandBy, 0));
                 int secondsDelay = Math.Max(5, Utilities.random.Next(11));
                 audioPlayer.pauseQueue(secondsDelay);
                 damageMessage.dueTime = (DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond) + (1000 * secondsDelay);
                 audioPlayer.playDelayedImmediateMessage(damageMessage);
             }
             else
             {
                 audioPlayer.playMessageImmediately(damageMessage);
             }
         }
         else
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0));
         }
     }
 }
Пример #4
0
        public override void respond(string voiceMessage)
        {
            Boolean fromStatusRequest = SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.CAR_STATUS) ||
                                        SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.STATUS);
            Boolean gotData = false;

            if (engineData != null)
            {
                gotData = true;
                EngineStatus currentEngineStatus = engineData.getEngineStatusFromCurrent(maxSafeWaterTemp, maxSafeOilTemp);
                if (currentEngineStatus.HasFlag(EngineStatus.ALL_CLEAR))
                {
                    lastStatusMessage = currentEngineStatus;
                    if (!fromStatusRequest)
                    {
                        audioPlayer.playMessageImmediately(new QueuedMessage(folderAllClear, 0));
                    }
                }
                else if (currentEngineStatus.HasFlag(EngineStatus.HOT_OIL) && currentEngineStatus.HasFlag(EngineStatus.HOT_WATER))
                {
                    lastStatusMessage = currentEngineStatus;
                    audioPlayer.playMessageImmediately(new QueuedMessage(folderHotOilAndWater, 0));
                }
                else if (currentEngineStatus.HasFlag(EngineStatus.HOT_OIL))
                {
                    // don't play this if the last message was about hot oil *and* water - wait for 'all clear'
                    if (!lastStatusMessage.HasFlag(EngineStatus.HOT_OIL) && !lastStatusMessage.HasFlag(EngineStatus.HOT_WATER))
                    {
                        lastStatusMessage = currentEngineStatus;
                        audioPlayer.playMessageImmediately(new QueuedMessage(folderHotOil, 0));
                    }
                }
                else if (currentEngineStatus.HasFlag(EngineStatus.HOT_WATER))
                {
                    // don't play this if the last message was about hot oil *and* water - wait for 'all clear'
                    if (!lastStatusMessage.HasFlag(EngineStatus.HOT_OIL) && !lastStatusMessage.HasFlag(EngineStatus.HOT_WATER))
                    {
                        lastStatusMessage = currentEngineStatus;
                        audioPlayer.playMessageImmediately(new QueuedMessage(folderHotWater, 0));
                    }
                }
            }
            if (!gotData && !fromStatusRequest)
            {
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0));
            }
        }
Пример #5
0
        public override void respond(String voiceMessage)
        {
            Boolean haveData = false;

            if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_MY_GAP_IN_FRONT) && currentGapInFront != -1)
            {
                if (isLeading && isRace)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(Position.folderLeading, 0, this));

                    haveData = true;
                }
                else
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage("Timings/gap_in_front",
                                                                         MessageContents(TimeSpan.FromMilliseconds(currentGapInFront * 1000)), 0, this));

                    haveData = true;
                }
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_MY_GAP_BEHIND) &&
                     currentGapBehind != -1)
            {
                if (isLast && isRace)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(Position.folderLast, 0, this));

                    haveData = true;
                }
                else
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage("Timings/gap_behind",
                                                                         MessageContents(TimeSpan.FromMilliseconds(currentGapBehind * 1000)), 0, this));

                    haveData = true;
                }
            }
            if (!haveData)
            {
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0, this));
            }
        }
Пример #6
0
 public override void respond(string voiceMessage)
 {
     if (currentConditions == null)
     {
         audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0, null));
     }
     else
     {
         if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_THE_AIR_TEMP))
         {
             audioPlayer.playMessageImmediately(new QueuedMessage("airTemp",
                                                                  MessageContents(folderAirTempIsNow, convertTemp(currentConditions.AmbientTemperature), getTempUnit()), 0, null));
         }
         if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_THE_TRACK_TEMP))
         {
             audioPlayer.playMessageImmediately(new QueuedMessage("trackTemp",
                                                                  MessageContents(folderTrackTempIsNow, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, null));
         }
     }
 }
Пример #7
0
 public virtual void setSpeechRecogniser(SpeechRecogniser speechRecogniser)
 {
     this.speechRecogniser = speechRecogniser;
 }
 public void setSpeechRecogniser(SpeechRecogniser speechRecogniser)
 {
     this.speechRecogniser = speechRecogniser;
 }
Пример #9
0
        public override void respond(String voiceMessage)
        {
            Boolean gotData = false;

            if (currentGameState != null)
            {
                if (voiceMessage.StartsWith(SpeechRecogniser.WHAT_TYRE_IS) || voiceMessage.StartsWith(SpeechRecogniser.WHAT_TYRES_IS))
                {
                    string opponentKey = getOpponentKey(voiceMessage, " " + SpeechRecogniser.ON).Item1;
                    if (opponentKey != null)
                    {
                        OpponentData opponentData = currentGameState.OpponentData[opponentKey];
                        if (opponentData.CurrentTyres == TyreType.R3E_NEW_Option)
                        {
                            gotData = true;
                            audioPlayer.playMessageImmediately(new QueuedMessage(MandatoryPitStops.folderMandatoryPitStopsOptionTyres, 0, null));
                        }
                        else if (opponentData.CurrentTyres == TyreType.R3E_NEW_Prime)
                        {
                            gotData = true;
                            audioPlayer.playMessageImmediately(new QueuedMessage(MandatoryPitStops.folderMandatoryPitStopsPrimeTyres, 0, null));
                        }
                    }
                }

                if (voiceMessage.StartsWith(SpeechRecogniser.WHATS) &&
                    (voiceMessage.EndsWith(SpeechRecogniser.LAST_LAP) || voiceMessage.EndsWith(SpeechRecogniser.BEST_LAP)))
                {
                    if (voiceMessage.EndsWith(SpeechRecogniser.LAST_LAP))
                    {
                        float lastLap = getOpponentLastLap(getOpponentKey(voiceMessage, SpeechRecogniser.POSSESSIVE + " ").Item1);
                        if (lastLap != -1)
                        {
                            gotData = true;
                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentLastLap", MessageContents(
                                                                                     TimeSpan.FromSeconds(lastLap)), 0, null));
                        }
                    }
                    else
                    {
                        float bestLap = getOpponentBestLap(getOpponentKey(voiceMessage, SpeechRecogniser.POSSESSIVE + " ").Item1);
                        if (bestLap != -1)
                        {
                            gotData = true;
                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentBestLap", MessageContents(
                                                                                     TimeSpan.FromSeconds(bestLap)), 0, null));
                        }
                    }
                }
                else if (voiceMessage.StartsWith(SpeechRecogniser.WHERE_IS))
                {
                    Tuple <string, Boolean> response = getOpponentKey(voiceMessage, "");
                    string  opponentKey         = response.Item1;
                    Boolean gotByPositionNumber = response.Item2;
                    if (opponentKey != null && currentGameState.OpponentData.ContainsKey(opponentKey))
                    {
                        OpponentData opponent = currentGameState.OpponentData[opponentKey];
                        if (opponent.IsActive)
                        {
                            int position = opponent.Position;
                            OpponentData.OpponentDelta opponentDelta = opponent.getTimeDifferenceToPlayer(currentGameState.SessionData);
                            if (opponentDelta == null || (opponentDelta.lapDifference == 0 && Math.Abs(opponentDelta.time) < 0.05))
                            {
                                // the delta is not usable - say the position if we didn't directly ask by position

                                // TODO: we need a "right infront" or "right behind" type response here for when the delta is < 0.05 (< 1 tenth rounded)
                                if (!gotByPositionNumber)
                                {
                                    if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentPosition", MessageContents(folderOpponentPositionIntro, Position.folderStub + position), 0, null));
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentPosition", MessageContents(Position.folderStub + position), 0, null));
                                    }
                                    gotData = true;
                                }
                            }
                            else
                            {
                                gotData = true;
                                if (opponentDelta.lapDifference == 1)
                                {
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), Position.folderOneLapBehind), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), Position.folderOneLapBehind), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta", MessageContents(Position.folderOneLapBehind), 0, null));
                                    }
                                }
                                else if (opponentDelta.lapDifference > 1)
                                {
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), opponentDelta.lapDifference, Position.folderLapsBehind), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), opponentDelta.lapDifference, Position.folderLapsBehind), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                             MessageContents(opponentDelta.lapDifference, Position.folderLapsBehind), 0, null));
                                    }
                                }
                                else if (opponentDelta.lapDifference == -1)
                                {
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), Position.folderOneLapAhead), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), Position.folderOneLapAhead), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta", MessageContents(Position.folderOneLapAhead), 0, null));
                                    }
                                }
                                else if (opponentDelta.lapDifference < -1)
                                {
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), Math.Abs(opponentDelta.lapDifference), Position.folderLapsAhead), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), Math.Abs(opponentDelta.lapDifference), Position.folderLapsAhead), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                             MessageContents(Math.Abs(opponentDelta.lapDifference), Position.folderLapsAhead), 0, null));
                                    }
                                }
                                else
                                {
                                    TimeSpan delta         = TimeSpan.FromSeconds(Math.Abs(opponentDelta.time));
                                    String   aheadOrBehind = Position.folderAhead;
                                    if (opponentDelta.time < 0)
                                    {
                                        aheadOrBehind = Position.folderBehind;
                                    }
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), delta, aheadOrBehind), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), delta, aheadOrBehind), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                             MessageContents(delta, aheadOrBehind), 0, null));
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Driver " + opponent.DriverRawName + " is no longer active in this session");
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_BEHIND_ON_TRACK))
                {
                    string opponentKey = currentGameState.getOpponentKeyBehindOnTrack();
                    if (opponentKey != null)
                    {
                        OpponentData  opponent = currentGameState.OpponentData[opponentKey];
                        QueuedMessage queuedMessage;
                        if (SoundCache.useTTS)
                        {
                            queuedMessage = new QueuedMessage("opponentNameAndPosition", MessageContents(opponent,
                                                                                                         Position.folderStub + opponent.Position), 0, null);
                        }
                        else
                        {
                            queuedMessage = new QueuedMessage("opponentNameAndPosition", MessageContents(opponent,
                                                                                                         Position.folderStub + opponent.Position),
                                                              MessageContents(Position.folderStub + opponent.Position, folderCantPronounceName), 0, null);
                        }
                        if (queuedMessage.canBePlayed)
                        {
                            audioPlayer.playMessageImmediately(queuedMessage);
                            gotData = true;
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_IN_FRONT_ON_TRACK))
                {
                    string opponentKey = currentGameState.getOpponentKeyInFrontOnTrack();
                    if (opponentKey != null)
                    {
                        OpponentData  opponent = currentGameState.OpponentData[opponentKey];
                        QueuedMessage queuedMessage;
                        if (SoundCache.useTTS)
                        {
                            queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent,
                                                                                              Position.folderStub + opponent.Position), 0, null);
                        }
                        else
                        {
                            queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent,
                                                                                              Position.folderStub + opponent.Position),
                                                              MessageContents(Position.folderStub + opponent.Position, folderCantPronounceName), 0, null);
                        }

                        if (queuedMessage.canBePlayed)
                        {
                            audioPlayer.playMessageImmediately(queuedMessage);

                            gotData = true;
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_BEHIND_IN_THE_RACE))
                {
                    if (currentGameState.isLast())
                    {
                        audioPlayer.playMessageImmediately(new QueuedMessage(Position.folderLast, 0, null));

                        gotData = true;
                    }
                    else
                    {
                        OpponentData opponent = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position + 1, false);
                        if (opponent != null)
                        {
                            QueuedMessage queuedMessage;
                            if (SoundCache.useTTS)
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), 0, null);
                            }
                            else
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), MessageContents(folderCantPronounceName), 0, null);
                            }

                            if (queuedMessage.canBePlayed)
                            {
                                audioPlayer.playMessageImmediately(queuedMessage);

                                gotData = true;
                            }
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_IN_FRONT_IN_THE_RACE))
                {
                    if (currentGameState.SessionData.Position == 1)
                    {
                        audioPlayer.playMessageImmediately(new QueuedMessage(Position.folderLeading, 0, null));

                        gotData = true;
                    }
                    else
                    {
                        OpponentData opponent = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false);
                        if (opponent != null)
                        {
                            QueuedMessage queuedMessage;
                            if (SoundCache.useTTS)
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), 0, null);
                            }
                            else
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), MessageContents(folderCantPronounceName), 0, null);
                            }

                            if (queuedMessage.canBePlayed)
                            {
                                audioPlayer.playMessageImmediately(queuedMessage);

                                gotData = true;
                            }
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_LEADING) && currentGameState.SessionData.Position > 1)
                {
                    OpponentData opponent = currentGameState.getOpponentAtPosition(1, false);
                    if (opponent != null)
                    {
                        QueuedMessage queuedMessage;
                        if (SoundCache.useTTS)
                        {
                            queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), 0, null);
                        }
                        else
                        {
                            queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), MessageContents(folderCantPronounceName), 0, null);
                        }
                        if (queuedMessage.canBePlayed)
                        {
                            audioPlayer.playMessageImmediately(queuedMessage);

                            gotData = true;
                        }
                    }
                }
                else if (voiceMessage.StartsWith(SpeechRecogniser.WHOS_IN))
                {
                    string opponentKey = getOpponentKey(voiceMessage, "").Item1;
                    if (opponentKey != null)
                    {
                        if (opponentKey == positionIsPlayerKey)
                        {
                            audioPlayer.playMessageImmediately(new QueuedMessage(folderWeAre, 0, null));

                            gotData = true;
                        }
                        else if (currentGameState.OpponentData.ContainsKey(opponentKey))
                        {
                            OpponentData  opponent = currentGameState.OpponentData[opponentKey];
                            QueuedMessage queuedMessage;
                            if (SoundCache.useTTS)
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), 0, null);
                            }
                            else
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), MessageContents(folderCantPronounceName), 0, null);
                            }
                            if (queuedMessage.canBePlayed)
                            {
                                audioPlayer.playMessageImmediately(queuedMessage);

                                gotData = true;
                            }
                        }
                    }
                }
            }
            if (!gotData)
            {
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0, null));
            }
        }
Пример #10
0
        // This is called immediately after initialising the speech recogniser in MainWindow
        public static void initialise(AudioPlayer audioPlayer, SpeechRecogniser speechRecogniser)
        {
            stopped = false;
            macros.Clear();
            if (UserSettings.GetUserSettings().getBoolean("enable_command_macros"))
            {
                // load the json:
                MacroContainer macroContainer = loadCommands(getUserMacrosFileLocation());
                // if it's valid, load the command sets:
                if (macroContainer.assignments != null && macroContainer.assignments.Length > 0 && macroContainer.macros != null)
                {
                    // get the assignments by game:
                    Dictionary <String, KeyBinding[]> assignmentsByGame = new Dictionary <String, KeyBinding[]>();
                    foreach (Assignment assignment in macroContainer.assignments)
                    {
                        if (!assignmentsByGame.ContainsKey(assignment.gameDefinition))
                        {
                            assignmentsByGame.Add(assignment.gameDefinition, assignment.keyBindings);
                        }
                    }

                    Dictionary <string, ExecutableCommandMacro> voiceTriggeredMacros = new Dictionary <string, ExecutableCommandMacro>();
                    foreach (Macro macro in macroContainer.macros)
                    {
                        Boolean hasCommandForCurrentGame = false;
                        Boolean allowAutomaticTriggering = false;
                        // eagerly load the key bindings for each macro:
                        foreach (CommandSet commandSet in macro.commandSets)
                        {
                            if (commandSet.gameDefinition.Equals(CrewChief.gameDefinition.gameEnum.ToString(), StringComparison.InvariantCultureIgnoreCase))
                            {
                                // this does the conversion from key characters to key enums and stores the result to save us doing it every time
                                if (!commandSet.loadActionItems(assignmentsByGame[commandSet.gameDefinition]))
                                {
                                    Console.WriteLine("Macro \"" + macro.name + "\" failed to load - some actionItems didn't parse succesfully");
                                }
                                else
                                {
                                    allowAutomaticTriggering = commandSet.allowAutomaticTriggering;
                                    hasCommandForCurrentGame = true;
                                }
                                break;
                            }
                        }
                        if (hasCommandForCurrentGame)
                        {
                            // make this macro globally visible:
                            ExecutableCommandMacro commandMacro = new ExecutableCommandMacro(audioPlayer, macro, assignmentsByGame, allowAutomaticTriggering);
                            macros.Add(macro.name, commandMacro);
                            // if there's a voice command, load it into the recogniser:
                            if (macro.voiceTriggers != null && macro.voiceTriggers.Length > 0)
                            {
                                foreach (String voiceTrigger in macro.voiceTriggers)
                                {
                                    if (voiceTriggeredMacros.ContainsKey(voiceTrigger))
                                    {
                                        Console.WriteLine("Voice trigger " + voiceTrigger + " has already been allocated to a different command");
                                    }
                                    else
                                    {
                                        voiceTriggeredMacros.Add(voiceTrigger, commandMacro);
                                    }
                                }
                            }
                            else if (macro.integerVariableVoiceTrigger != null && macro.integerVariableVoiceTrigger.Length > 0)
                            {
                                if (voiceTriggeredMacros.ContainsKey(macro.integerVariableVoiceTrigger))
                                {
                                    Console.WriteLine("Voice trigger " + macro.integerVariableVoiceTrigger + " has already been allocated to a different command");
                                }
                                else
                                {
                                    voiceTriggeredMacros.Add(macro.integerVariableVoiceTrigger, commandMacro);
                                }
                            }
                        }
                    }
                    try
                    {
                        speechRecogniser.loadMacroVoiceTriggers(voiceTriggeredMacros);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to load command macros into speech recogniser: " + e.Message);
                    }
                }
            }
            else
            {
                Console.WriteLine("Command macros are disabled");
            }
        }
Пример #11
0
 public override void respond(String voiceMessage)
 {
     if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.SET_ALARM_CLOCK))
     {
         int     index           = voiceMessage.Length;
         Boolean isPastMidDay    = false;
         Boolean isAfterMidnight = false;
         foreach (String ams in SpeechRecogniser.AM)
         {
             if (voiceMessage.Contains(" " + ams))
             {
                 index           = voiceMessage.IndexOf(" " + ams);
                 isAfterMidnight = true;
             }
         }
         foreach (String pms in SpeechRecogniser.PM)
         {
             if (voiceMessage.Contains(" " + pms))
             {
                 index        = voiceMessage.IndexOf(" " + pms);
                 isPastMidDay = true;
             }
         }
         voiceMessage = voiceMessage.Substring(0, index);
         Tuple <int, int> hourWithIndex = getHourDigits(voiceMessage);
         int hour = isPastMidDay ? hourWithIndex.Item1 + 12 : hourWithIndex.Item1;
         if (hour >= 12 && !isAfterMidnight)
         {
             isPastMidDay = true;
         }
         String minutesString = voiceMessage.Substring(hourWithIndex.Item2);
         int    minutes       = getMinuteDigits(minutesString);
         if (hourWithIndex.Item1 != -1 && minutes != -1)
         {
             SetAlarm(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hour, minutes, 00));
             Console.WriteLine("Alarm has been set to " + new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hour, minutes, 00).ToString());
             if (hour == 0)
             {
                 // not 100% sure its needed but there just in case.
                 isPastMidDay = false;
                 hour         = 24;
             }
             if (hour > 12)
             {
                 hour = hour - 12;
             }
             if (minutes < 10)
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("alarm", 0,
                                                                      messageFragments: MessageContents(notifyYouAt, hour, NumberReader.folderOh, minutes, isPastMidDay ? folderPM : folderAM),
                                                                      type: SoundType.CRITICAL_MESSAGE, priority: 0));
             }
             else
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("alarm", 0,
                                                                      messageFragments: MessageContents(notifyYouAt, hour, minutes, isPastMidDay ? folderPM : folderAM),
                                                                      type: SoundType.CRITICAL_MESSAGE, priority: 0));
             }
         }
     }
     else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.CLEAR_ALARM_CLOCK))
     {
         alarmTimes.Clear();
         audioPlayer.playMessageImmediately(new QueuedMessage("alarm", 0,
                                                              messageFragments: MessageContents(AudioPlayer.folderAcknowlegeOK)));
     }
 }
        public override void respond(String voiceMessage)
        {
            if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_ADD))
            {
                int amount = 0;
                foreach (KeyValuePair <String[], int> entry in SpeechRecogniser.numberToNumber)
                {
                    foreach (String numberStr in entry.Key)
                    {
                        if (voiceMessage.Contains(" " + numberStr + " "))
                        {
                            amount = entry.Value;
                            break;
                        }
                    }
                }
                if (amount == 0)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderDidntUnderstand, 0));
                    return;
                }
                if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.LITERS))
                {
                    AddFuel(amount);
                    audioPlayer.playMessageImmediately(new QueuedMessage("iracing_add_fuel", 0,
                                                                         messageFragments: MessageContents(AudioPlayer.folderAcknowlegeOK, amount, amount == 1 ? Fuel.folderLitre : Fuel.folderLitres)));
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.GALLONS))
                {
                    AddFuel(convertGallonsToLitres(amount));
                    audioPlayer.playMessageImmediately(new QueuedMessage("iracing_add_fuel", 0,
                                                                         messageFragments: MessageContents(AudioPlayer.folderAcknowlegeOK, amount, amount == 1 ? Fuel.folderGallon : Fuel.folderGallons)));
                }
                else
                {
                    Console.WriteLine("Got fuel request with no unit, assuming " + (Fuel.fuelReportsInGallon ? " gallons" : "litres"));
                    if (!Fuel.fuelReportsInGallon)
                    {
                        AddFuel(amount);
                        audioPlayer.playMessageImmediately(new QueuedMessage("iracing_add_fuel", 0,
                                                                             messageFragments: MessageContents(AudioPlayer.folderAcknowlegeOK, amount, amount == 1 ? Fuel.folderLitre : Fuel.folderLitres)));
                    }
                    else
                    {
                        AddFuel(convertGallonsToLitres(amount));
                        audioPlayer.playMessageImmediately(new QueuedMessage("iracing_add_fuel", 0,
                                                                             messageFragments: MessageContents(AudioPlayer.folderAcknowlegeOK, amount, amount == 1 ? Fuel.folderGallon : Fuel.folderGallons)));
                    }
                }
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_FUEL_TO_THE_END))
            {
                Fuel  fuelEvent    = (Fuel)CrewChief.getEvent("Fuel");
                float litresNeeded = fuelEvent.getLitresToEndOfRace(true);

                if (litresNeeded == float.MaxValue)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0));
                }
                else if (litresNeeded <= 0)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(Fuel.folderPlentyOfFuel, 0));
                }
                else if (litresNeeded > 0)
                {
                    int roundedLitresNeeded = (int)Math.Ceiling(litresNeeded);
                    AddFuel(roundedLitresNeeded);
                    if (roundedLitresNeeded > fuelCapacity - currentFuel)
                    {
                        // if we have a known fuel capacity and this is less than the calculated amount of fuel we need, warn about it.
                        audioPlayer.playMessage(new QueuedMessage(Fuel.folderWillNeedToStopAgain, 0, secondsDelay: 4, abstractEvent: this));
                    }
                    else
                    {
                        audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderFuelToEnd, 0));
                    }
                    return;
                }
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_TEAROFF))
            {
                Tearoff();
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_FAST_REPAIR))
            {
                FastRepair();
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CLEAR_ALL))
            {
                ClearAll();
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CLEAR_TYRES))
            {
                ClearTires();
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CLEAR_WIND_SCREEN))
            {
                ClearTearoff();
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CLEAR_FAST_REPAIR))
            {
                ClearFastRepair();
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CLEAR_FUEL))
            {
                ClearFuel();
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_TYRE_PRESSURE) ||
                     SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_FRONT_LEFT_TYRE_PRESSURE) ||
                     SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_FRONT_RIGHT_TYRE_PRESSURE) ||
                     SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_REAR_LEFT_TYRE_PRESSURE) ||
                     SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_REAR_RIGHT_TYRE_PRESSURE))
            {
                int amount = 0;
                foreach (KeyValuePair <String[], int> entry in SpeechRecogniser.numberToNumber)
                {
                    foreach (String numberStr in entry.Key)
                    {
                        if (voiceMessage.Contains(" " + numberStr))
                        {
                            amount = entry.Value;
                            break;
                        }
                    }
                }
                if (amount == 0)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderDidntUnderstand, 0));
                    return;
                }
                else
                {
                    if (pressureUnit == PressureUnit.PSI)
                    {
                        amount = convertPSItoKPA(amount);
                    }
                    if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_TYRE_PRESSURE))
                    {
                        ChangeTire(PitCommandModeTypes.LF, amount);
                        ChangeTire(PitCommandModeTypes.RF, amount);
                        ChangeTire(PitCommandModeTypes.LR, amount);
                        ChangeTire(PitCommandModeTypes.RR, amount);
                        audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                        return;
                    }
                    else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_FRONT_LEFT_TYRE_PRESSURE))
                    {
                        ChangeTire(PitCommandModeTypes.LF, amount);
                        audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                        return;
                    }
                    else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_FRONT_RIGHT_TYRE_PRESSURE))
                    {
                        ChangeTire(PitCommandModeTypes.RF, amount);
                        audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                        return;
                    }
                    else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_REAR_LEFT_TYRE_PRESSURE))
                    {
                        ChangeTire(PitCommandModeTypes.LR, amount);
                        audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                        return;
                    }
                    else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_REAR_RIGHT_TYRE_PRESSURE))
                    {
                        ChangeTire(PitCommandModeTypes.RR, amount);
                        audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                        return;
                    }
                }
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_ALL_TYRES))
            {
                ChangeTire(PitCommandModeTypes.LF, lastColdFLPressure);
                ChangeTire(PitCommandModeTypes.RF, lastColdFRPressure);
                ChangeTire(PitCommandModeTypes.LR, lastColdRLPressure);
                ChangeTire(PitCommandModeTypes.RR, lastColdRRPressure);
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_FRONT_LEFT_TYRE))
            {
                ChangeTire(PitCommandModeTypes.LF, lastColdFLPressure);
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_FRONT_RIGHT_TYRE))
            {
                ChangeTire(PitCommandModeTypes.RF, lastColdFRPressure);
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_REAR_LEFT_TYRE))
            {
                ChangeTire(PitCommandModeTypes.LR, lastColdRLPressure);
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_REAR_RIGHT_TYRE))
            {
                ChangeTire(PitCommandModeTypes.RR, lastColdRRPressure);
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_LEFT_SIDE_TYRES))
            {
                ClearTires();
                ChangeTire(PitCommandModeTypes.LF, lastColdFLPressure);
                ChangeTire(PitCommandModeTypes.LR, lastColdRLPressure);
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.PIT_STOP_CHANGE_RIGHT_SIDE_TYRES))
            {
                ClearTires();
                ChangeTire(PitCommandModeTypes.RF, lastColdFRPressure);
                ChangeTire(PitCommandModeTypes.RR, lastColdRRPressure);
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderAcknowlegeOK, 0));
                return;
            }

            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOW_MANY_INCIDENT_POINTS))
            {
                audioPlayer.playMessageImmediately(new QueuedMessage("Incidents/incidents", 0, messageFragments: MessageContents(folderYouHave, incidentsCount, folderincidents)));
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_THE_INCIDENT_LIMIT))
            {
                if (hasLimitedIncidents)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage("Incidents/limit", 0, messageFragments: MessageContents(folderincidentlimit, maxIncidentCount)));
                }
                else
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage("Incidents/limit", 0, messageFragments: MessageContents(folderUnlimited)));
                }
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_MY_IRATING))
            {
                if (iRating != -1)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage("license/irating", 0, messageFragments: MessageContents(iRating)));
                    return;
                }
                else
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0));
                    return;
                }
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_MY_LICENSE_CLASS))
            {
                if (licenseLevel.Item2 == -1)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0));
                    return;
                }
                if (licenseLevel.Item2 != -1)
                {
                    Tuple <int, int>       wholeandfractional = Utilities.WholeAndFractionalPart(licenseLevel.Item2, 2);
                    List <MessageFragment> messageFragments   = new List <MessageFragment>();

                    if (licenseLevel.Item1.ToLower() == "a")
                    {
                        messageFragments.Add(MessageFragment.Text(folderLicenseA));
                    }
                    else if (licenseLevel.Item1.ToLower() == "b")
                    {
                        messageFragments.Add(MessageFragment.Text(folderLicenseB));
                    }
                    else if (licenseLevel.Item1.ToLower() == "c")
                    {
                        messageFragments.Add(MessageFragment.Text(folderLicenseC));
                    }
                    else if (licenseLevel.Item1.ToLower() == "d")
                    {
                        messageFragments.Add(MessageFragment.Text(folderLicenseD));
                    }
                    else if (licenseLevel.Item1.ToLower() == "r")
                    {
                        messageFragments.Add(MessageFragment.Text(folderLicenseR));
                    }
                    else if (licenseLevel.Item1.ToLower() == "wc")
                    {
                        messageFragments.Add(MessageFragment.Text(folderLicensePro));
                    }
                    else
                    {
                        audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0));
                        return;
                    }
                    messageFragments.AddRange(MessageContents(wholeandfractional.Item1, NumberReader.folderPoint, wholeandfractional.Item2));
                    QueuedMessage licenceLevelMessage = new QueuedMessage("License/license", 0, messageFragments: messageFragments);
                    audioPlayer.playDelayedImmediateMessage(licenceLevelMessage);
                }
                return;
            }
            else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_THE_SOF))
            {
                if (strenghtOfField != -1)
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage("license/irating", 0, messageFragments: MessageContents(strenghtOfField)));
                    return;
                }
                else
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0));
                    return;
                }
            }
        }
Пример #13
0
 public override void respond(string voiceMessage)
 {
     if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.SESSION_STATUS) ||
         SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.STATUS))
     {
         if (hasOutstandingPenalty)
         {
             if (lapsCompleted - penaltyLap == 2)
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("youHaveAPenaltyBoxThisLap", 0,
                                                                      messageFragments: MessageContents(folderYouHavePenalty, PitStops.folderMandatoryPitStopsPitThisLap)));
             }
             else
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage(folderYouHavePenalty, 0));
             }
         }
     }
     else
     {
         if (!hasHadAPenalty)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(folderYouDontHaveAPenalty, 0));
             return;
         }
         if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.DO_I_HAVE_A_PENALTY))
         {
             if (hasOutstandingPenalty)
             {
                 if (lapsCompleted - penaltyLap == 2)
                 {
                     audioPlayer.playMessageImmediately(new QueuedMessage("youHaveAPenaltyBoxThisLap", 0,
                                                                          messageFragments: MessageContents(folderYouHavePenalty, PitStops.folderMandatoryPitStopsPitThisLap)));
                 }
                 else
                 {
                     audioPlayer.playMessageImmediately(new QueuedMessage(folderYouHavePenalty, 0));
                 }
             }
             else
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage(folderYouDontHaveAPenalty, 0));
             }
         }
         else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HAVE_I_SERVED_MY_PENALTY))
         {
             if (hasOutstandingPenalty)
             {
                 List <MessageFragment> messages = new List <MessageFragment>();
                 messages.Add(MessageFragment.Text(AudioPlayer.folderNo));
                 messages.Add(MessageFragment.Text(folderYouStillHavePenalty));
                 if (lapsCompleted - penaltyLap == 2)
                 {
                     messages.Add(MessageFragment.Text(PitStops.folderMandatoryPitStopsPitThisLap));
                 }
                 audioPlayer.playMessageImmediately(new QueuedMessage("noYouStillHaveAPenalty", 0, messageFragments: messages));
             }
             else
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("yesYouServedYourPenalty", 0,
                                                                      messageFragments: MessageContents(AudioPlayer.folderYes, folderPenaltyServed)));
             }
         }
         else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.DO_I_STILL_HAVE_A_PENALTY))
         {
             if (hasOutstandingPenalty)
             {
                 List <MessageFragment> messages = new List <MessageFragment>();
                 messages.Add(MessageFragment.Text(AudioPlayer.folderYes));
                 messages.Add(MessageFragment.Text(folderYouStillHavePenalty));
                 if (lapsCompleted - penaltyLap == 2)
                 {
                     messages.Add(MessageFragment.Text(PitStops.folderMandatoryPitStopsPitThisLap));
                 }
                 audioPlayer.playMessageImmediately(new QueuedMessage("yesYouStillHaveAPenalty", 0, messageFragments: messages));
             }
             else
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("noYouServedYourPenalty", 0,
                                                                      messageFragments: MessageContents(AudioPlayer.folderNo, folderPenaltyServed)));
             }
         }
     }
 }
Пример #14
0
 public override void respond(String voiceMessage)
 {
     if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHATS_MY_FUEL_LEVEL))
     {
         if (!fuelUseActive)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0, null));
         }
         else if (currentFuel >= 2)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage("Fuel/level",
                                                                  MessageContents((int)currentFuel, folderLitresRemaining), 0, null));
         }
         else
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(folderAboutToRunOut, 0, null));
         }
     }
     else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_FUEL))
     {
         Boolean haveData = false;
         if (initialised && currentFuel > -1)
         {
             if (averageUsagePerLap > 0)
             {
                 int lapsOfFuelLeft = (int)Math.Floor(currentFuel / averageUsagePerLap);
                 if (lapsOfFuelLeft <= 1)
                 {
                     audioPlayer.playMessageImmediately(new QueuedMessage("Fuel/estimate",
                                                                          MessageContents(folderAboutToRunOut), 0, null));
                 }
                 else
                 {
                     audioPlayer.playMessageImmediately(new QueuedMessage("Fuel/estimate",
                                                                          MessageContents(folderWeEstimate, lapsOfFuelLeft, folderLapsRemaining), 0, null));
                 }
                 haveData = true;
             }
             else if (averageUsagePerMinute > 0)
             {
                 int minutesOfFuelLeft = (int)Math.Floor(currentFuel / averageUsagePerMinute);
                 if (minutesOfFuelLeft <= 1)
                 {
                     audioPlayer.playMessageImmediately(new QueuedMessage("Fuel/estimate",
                                                                          MessageContents(folderAboutToRunOut), 0, null));
                 }
                 else
                 {
                     audioPlayer.playMessageImmediately(new QueuedMessage("Fuel/estimate",
                                                                          MessageContents(folderWeEstimate, minutesOfFuelLeft, folderMinutesRemaining), 0, null));
                 }
                 haveData = true;
             }
         }
         if (!haveData)
         {
             if (!fuelUseActive)
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage(folderPlentyOfFuel, 0, null));
             }
             else if (currentFuel >= 2)
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("Fuel/level",
                                                                      MessageContents((int)currentFuel, folderLitresRemaining), 0, null));
             }
             else if (currentFuel >= 1)
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("Fuel/level",
                                                                      MessageContents(folderOneLitreRemaining), 0, null));
             }
             else if (currentFuel > 0)
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage("Fuel/level",
                                                                      MessageContents(folderAboutToRunOut), 0, null));
             }
             else
             {
                 audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0, null));
             }
         }
     }
 }
Пример #15
0
        public override void respond(String voiceMessage)
        {
            QueuedMessage damageMessage = null;

            if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_AERO))
            {
                if (aeroDamage == DamageLevel.NONE)
                {
                    damageMessage = new QueuedMessage(folderNoAeroDamage, 0, null);
                }
                else if (aeroDamage == DamageLevel.MAJOR || aeroDamage == DamageLevel.DESTROYED)
                {
                    damageMessage = new QueuedMessage(folderSevereAeroDamage, 0, null);
                }
                else if (aeroDamage == DamageLevel.MINOR)
                {
                    damageMessage = new QueuedMessage(folderMinorAeroDamage, 0, null);
                }
                else if (aeroDamage == DamageLevel.TRIVIAL)
                {
                    damageMessage = new QueuedMessage(folderJustAScratch, 0, null);
                }
            }
            if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_TRANSMISSION))
            {
                if (trannyDamage == DamageLevel.NONE || trannyDamage == DamageLevel.TRIVIAL)
                {
                    damageMessage = new QueuedMessage(folderNoTransmissionDamage, 0, null);
                }
                else if (trannyDamage == DamageLevel.DESTROYED)
                {
                    damageMessage = new QueuedMessage(folderBustedTransmission, 0, null);
                }
                else if (trannyDamage == DamageLevel.MAJOR)
                {
                    damageMessage = new QueuedMessage(folderSevereTransmissionDamage, 0, null);
                }
                else if (trannyDamage == DamageLevel.MINOR)
                {
                    damageMessage = new QueuedMessage(folderMinorTransmissionDamage, 0, null);
                }
            }
            if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_ENGINE))
            {
                if (engineDamage == DamageLevel.NONE || engineDamage == DamageLevel.TRIVIAL)
                {
                    damageMessage = new QueuedMessage(folderNoEngineDamage, 0, null);
                }
                else if (engineDamage == DamageLevel.DESTROYED)
                {
                    damageMessage = new QueuedMessage(folderBustedEngine, 0, null);
                }
                else if (engineDamage == DamageLevel.MAJOR)
                {
                    damageMessage = new QueuedMessage(folderSevereEngineDamage, 0, null);
                }
                else if (engineDamage == DamageLevel.MINOR)
                {
                    damageMessage = new QueuedMessage(folderMinorEngineDamage, 0, null);
                }
            }
            if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_SUSPENSION))
            {
                if (isMissingWheel)
                {
                    damageMessage = new QueuedMessage(folderMissingWheel, 0, null);
                }
                if ((maxSuspensionDamage == DamageLevel.NONE || maxSuspensionDamage == DamageLevel.TRIVIAL) && !isMissingWheel)
                {
                    damageMessage = new QueuedMessage(folderNoSuspensionDamage, 0, null);
                }
                else if (maxSuspensionDamage == DamageLevel.DESTROYED)
                {
                    damageMessage = new QueuedMessage(folderBustedSuspension, 0, null);
                }
                else if (maxSuspensionDamage == DamageLevel.MAJOR)
                {
                    damageMessage = new QueuedMessage(folderSevereSuspensionDamage, 0, null);
                }
                else if (maxSuspensionDamage == DamageLevel.MINOR && !isMissingWheel)
                {
                    damageMessage = new QueuedMessage(folderMinorSuspensionDamage, 0, null);
                }
            }
            if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.HOWS_MY_BRAKES))
            {
                if (maxBrakeDamage == DamageLevel.NONE || maxBrakeDamage == DamageLevel.TRIVIAL)
                {
                    damageMessage = new QueuedMessage(folderNoBrakeDamage, 0, null);
                }
                else if (maxBrakeDamage == DamageLevel.DESTROYED)
                {
                    damageMessage = new QueuedMessage(folderBustedBrakes, 0, null);
                }
                else if (maxBrakeDamage == DamageLevel.MAJOR)
                {
                    damageMessage = new QueuedMessage(folderSevereBrakeDamage, 0, null);
                }
                else if (maxBrakeDamage == DamageLevel.MINOR)
                {
                    damageMessage = new QueuedMessage(folderMinorBrakeDamage, 0, null);
                }
            }
            if (damageMessage != null)
            {
                // play this immediately or play "stand by", and queue it to be played in a few seconds
                if (delayResponses && random.Next(10) >= 2 && SoundCache.availableSounds.Contains(AudioPlayer.folderStandBy))
                {
                    audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderStandBy, 0, null));
                    int secondsDelay = Math.Max(5, random.Next(11));
                    audioPlayer.pauseQueue(secondsDelay);
                    damageMessage.dueTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + (1000 * secondsDelay);
                    audioPlayer.playMessage(damageMessage);
                }
                else
                {
                    audioPlayer.playMessageImmediately(damageMessage);
                }
            }
            else
            {
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0, null));
            }
        }