public override void clearState() { lastRainReport = DateTime.MinValue; lastAirTempReport = DateTime.MaxValue; lastTrackTempReport = DateTime.MaxValue; airTempAtLastReport = float.MinValue; trackTempAtLastReport = float.MinValue; rainAtLastReport = float.MinValue; currentConditions = null; }
public override void clearState() { lastRainReport = DateTime.MinValue; lastAirTempReport = DateTime.MaxValue; lastTrackTempReport = DateTime.MaxValue; airTempAtLastReport = float.MinValue; trackTempAtLastReport = float.MinValue; rainAtLastReport = float.MinValue; currentConditions = null; conditionsAtStartOfThisLap = null; timeWhenCloudIncreased = DateTime.MinValue; timeWhenRainExpected = DateTime.MinValue; waitingForRainEstimate = false; rainDensityAtLastCheck = -1; maxRainChangeRate = -1; }
override protected void triggerInternal(GameStateData previousGameState, GameStateData currentGameState) { currentConditions = currentGameState.Conditions.getMostRecentConditions(); if (currentConditions != null) { if (airTempAtLastReport == float.MinValue) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = currentConditions.TrackTemperature; rainAtLastReport = currentConditions.RainDensity; lastRainReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; lastAirTempReport = currentGameState.Now; } else { Boolean canReportAirChange = enableTrackAndAirTempReports && currentGameState.Now > lastAirTempReport.Add(AirTemperatureReportMaxFrequency); Boolean canReportTrackChange = enableTrackAndAirTempReports && currentGameState.Now > lastTrackTempReport.Add(TrackTemperatureReportMaxFrequency); Boolean reportedCombinedTemps = false; if (canReportAirChange || canReportTrackChange) { if (currentConditions.TrackTemperature > trackTempAtLastReport + minTrackTempDeltaToReport && currentConditions.AmbientTemperature > airTempAtLastReport + minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = currentConditions.TrackTemperature; lastAirTempReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airAndTrackTemp", MessageContents (folderAirAndTrackTempIncreasing, folderAirTempIsNow, convertTemp(currentConditions.AmbientTemperature), folderTrackTempIsNow, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, this)); reportedCombinedTemps = true; } else if (currentConditions.TrackTemperature < trackTempAtLastReport - minTrackTempDeltaToReport && currentConditions.AmbientTemperature < airTempAtLastReport - minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = currentConditions.TrackTemperature; lastAirTempReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airAndTrackTemp", MessageContents (folderAirAndTrackTempDecreasing, folderAirTempIsNow, convertTemp(currentConditions.AmbientTemperature), folderTrackTempIsNow, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, this)); reportedCombinedTemps = true; } } if (!reportedCombinedTemps && canReportAirChange) { if (currentConditions.AmbientTemperature > airTempAtLastReport + minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; lastAirTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airTemp", MessageContents (folderAirTempIncreasing, convertTemp(currentConditions.AmbientTemperature), getTempUnit()), 0, this)); } else if (currentConditions.AmbientTemperature < airTempAtLastReport - minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; lastAirTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airTemp", MessageContents (folderAirTempDecreasing, convertTemp(currentConditions.AmbientTemperature), getTempUnit()), 0, this)); } } if (!reportedCombinedTemps && canReportTrackChange) { if (currentConditions.TrackTemperature > trackTempAtLastReport + minTrackTempDeltaToReport) { trackTempAtLastReport = currentConditions.TrackTemperature; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("trackTemp", MessageContents (folderTrackTempIncreasing, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, this)); } else if (currentConditions.TrackTemperature < trackTempAtLastReport - minTrackTempDeltaToReport) { trackTempAtLastReport = currentConditions.TrackTemperature; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("trackTemp", MessageContents (folderTrackTempDecreasing, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, this)); } } if (currentGameState.Now > lastRainReport.Add(RainReportMaxFrequency)) { // TODO: the implementation is coupled to the PCars mRainDensity value, which is 0 or 1 if (currentConditions.RainDensity == 0 && rainAtLastReport == 1) { rainAtLastReport = currentConditions.RainDensity; lastRainReport = currentGameState.Now; audioPlayer.playMessage(new QueuedMessage(folderStoppedRaining, 0, this)); } else if (currentConditions.RainDensity == 1 && rainAtLastReport == 0) { rainAtLastReport = currentConditions.RainDensity; lastRainReport = currentGameState.Now; audioPlayer.playMessage(new QueuedMessage(folderSeeingSomeRain, 0, this)); } } } } }
override protected void triggerInternal(GameStateData previousGameState, GameStateData currentGameState) { currentConditions = currentGameState.Conditions.getMostRecentConditions(); if (currentGameState.SessionData.IsNewLap) { conditionsAtStartOfThisLap = currentConditions; } if (currentConditions != null) { // for pcars track temp, we're only interested in changes at the start line (a single point on the track) because the track // temp is localised. The air temp is (probably) localised too, but will be less variable float trackTempToUse = CrewChief.isPCars() && conditionsAtStartOfThisLap != null ? conditionsAtStartOfThisLap.TrackTemperature : currentConditions.TrackTemperature; if (airTempAtLastReport == float.MinValue) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = trackTempToUse; rainAtLastReport = currentConditions.RainDensity; lastRainReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; lastAirTempReport = currentGameState.Now; } else { Boolean canReportAirChange = enableTrackAndAirTempReports && currentGameState.Now > lastAirTempReport.Add(AirTemperatureReportMaxFrequency); Boolean canReportTrackChange = enableTrackAndAirTempReports && currentGameState.Now > lastTrackTempReport.Add(TrackTemperatureReportMaxFrequency); Boolean reportedCombinedTemps = false; TimeSpan rainReportFrequency = CrewChief.gameDefinition.gameEnum == GameEnum.RF2_64BIT ? RainReportMaxFrequencyRF2 : RainReportMaxFrequencyPCars; if (canReportAirChange || canReportTrackChange) { if (trackTempToUse > trackTempAtLastReport + minTrackTempDeltaToReport && currentConditions.AmbientTemperature > airTempAtLastReport + minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = trackTempToUse; lastAirTempReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airAndTrackTemp", 10, messageFragments: MessageContents (folderAirAndTrackTempIncreasing, folderAirTempIsNow, convertTemp(currentConditions.AmbientTemperature), folderTrackTempIsNow, convertTemp(trackTempToUse), getTempUnit()), abstractEvent: this, priority: 0)); reportedCombinedTemps = true; } else if (trackTempToUse < trackTempAtLastReport - minTrackTempDeltaToReport && currentConditions.AmbientTemperature < airTempAtLastReport - minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = trackTempToUse; lastAirTempReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airAndTrackTemp", 10, messageFragments: MessageContents (folderAirAndTrackTempDecreasing, folderAirTempIsNow, convertTemp(currentConditions.AmbientTemperature), folderTrackTempIsNow, convertTemp(trackTempToUse), getTempUnit()), abstractEvent: this, priority: 0)); reportedCombinedTemps = true; } } if (!reportedCombinedTemps && canReportAirChange) { if (currentConditions.AmbientTemperature > airTempAtLastReport + minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; lastAirTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airTemp", 10, messageFragments: MessageContents (folderAirTempIncreasing, convertTemp(currentConditions.AmbientTemperature), getTempUnit()), abstractEvent: this, priority: 0)); } else if (currentConditions.AmbientTemperature < airTempAtLastReport - minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; lastAirTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airTemp", 10, messageFragments: MessageContents (folderAirTempDecreasing, convertTemp(currentConditions.AmbientTemperature), getTempUnit()), abstractEvent: this, priority: 0)); } } if (!reportedCombinedTemps && canReportTrackChange) { if (trackTempToUse > trackTempAtLastReport + minTrackTempDeltaToReport) { trackTempAtLastReport = trackTempToUse; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("trackTemp", 10, messageFragments: MessageContents (folderTrackTempIncreasing, convertTemp(trackTempToUse), getTempUnit()), abstractEvent: this, priority: 0)); } else if (trackTempToUse < trackTempAtLastReport - minTrackTempDeltaToReport) { trackTempAtLastReport = trackTempToUse; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("trackTemp", 10, messageFragments: MessageContents (folderTrackTempDecreasing, convertTemp(trackTempToUse), getTempUnit()), abstractEvent: this, priority: 0)); } } //pcars2 test warning if (enablePCarsRainPrediction && CrewChief.isPCars()) { if (previousGameState != null && currentGameState.SessionData.SessionRunningTime > 10) { if (currentGameState.RainDensity == 0) { // not raining so see if we can guess when it might start if (!waitingForRainEstimate) { if (previousGameState.CloudBrightness == 2 && currentGameState.CloudBrightness < 2) { timeWhenCloudIncreased = previousGameState.Now; waitingForRainEstimate = true; } } else if (currentGameState.CloudBrightness < 1.98) { // big enough change to calculate expected rain time TimeSpan timeDelta = currentGameState.Now - timeWhenCloudIncreased; // assume rain just after it hits 1.9 float millisTillRain = (float)timeDelta.TotalMilliseconds * 6f; // this is usually really inaccurate and can go either way timeWhenRainExpected = timeWhenCloudIncreased.AddMilliseconds(millisTillRain); waitingForRainEstimate = false; timeWhenCloudIncreased = DateTime.MinValue; DateTime when = currentGameState.Now.AddMilliseconds(millisTillRain); Console.WriteLine("It is now " + currentGameState.Now + ", we expect rain at game time " + when); int minutes = (int)Math.Round(millisTillRain / 60000); if (minutes > 2) { audioPlayer.playMessage(new QueuedMessage("expecting_rain", 10, messageFragments: MessageContents(folderExpectRain, new TimeSpanWrapper(TimeSpan.FromMinutes(minutes), Precision.MINUTES)), abstractEvent: this)); } } } else { // cancel waiting for rain waitingForRainEstimate = false; timeWhenCloudIncreased = DateTime.MinValue; } } } if (currentGameState.Now > lastRainReport.Add(rainReportFrequency)) { // for PCars mRainDensity value is 0 or 1 if (CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_32BIT || CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_64BIT || CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_NETWORK) { if (currentGameState.RainDensity == 0 && rainAtLastReport == 1) { rainAtLastReport = currentGameState.RainDensity; lastRainReport = currentGameState.Now; audioPlayer.playMessage(new QueuedMessage(folderStoppedRaining, 10, abstractEvent: this, priority: 2)); } else if (currentConditions.RainDensity == 1 && rainAtLastReport == 0) { rainAtLastReport = currentGameState.RainDensity; lastRainReport = currentGameState.Now; audioPlayer.playMessage(new QueuedMessage(folderSeeingSomeRain, 10, abstractEvent: this, priority: 5)); } } else if (CrewChief.gameDefinition.gameEnum == GameEnum.RF2_64BIT || CrewChief.gameDefinition.gameEnum == GameEnum.PCARS2) { if (rainDensityAtLastCheck != -1 && rainDensityAtLastCheck != currentConditions.RainDensity) { float rainChangeRate = (float)(Math.Abs(rainDensityAtLastCheck - currentConditions.RainDensity) / rainReportFrequency.TotalSeconds); if (rainChangeRate > ConditionsMonitor.maxRainChangeRate) { ConditionsMonitor.maxRainChangeRate = rainChangeRate; } } rainDensityAtLastCheck = currentConditions.RainDensity; RainLevel currentRainLevel = getRainLevel(currentConditions.RainDensity); RainLevel lastReportedRainLevel = getRainLevel(rainAtLastReport); if (currentRainLevel != lastReportedRainLevel) { Boolean increasing = currentConditions.RainDensity > rainAtLastReport; switch (currentRainLevel) { case RainLevel.DRIZZLE: audioPlayer.playMessageImmediately(new QueuedMessage(increasing ? folderDrizzleIncreasing : folderDrizzleDecreasing, 0, type: SoundType.IMPORTANT_MESSAGE, priority: 0)); break; case RainLevel.LIGHT: audioPlayer.playMessageImmediately(new QueuedMessage(increasing ? folderRainLightIncreasing : folderRainLightDecreasing, 0, type: SoundType.IMPORTANT_MESSAGE, priority: 0)); break; case RainLevel.MID: audioPlayer.playMessageImmediately(new QueuedMessage(increasing ? folderRainMidIncreasing : folderRainMidDecreasing, 0, type: SoundType.IMPORTANT_MESSAGE, priority: 0)); break; case RainLevel.HEAVY: audioPlayer.playMessageImmediately(new QueuedMessage(increasing ? folderRainHeavyIncreasing : folderRainHeavyDecreasing, 0, type: SoundType.IMPORTANT_MESSAGE, priority: 0)); break; case RainLevel.STORM: audioPlayer.playMessageImmediately(new QueuedMessage(folderRainMax, 0, type: SoundType.IMPORTANT_MESSAGE, priority: 0)); break; case RainLevel.NONE: audioPlayer.playMessage(new QueuedMessage(folderStoppedRaining, 10, abstractEvent: this, priority: 3)); break; } lastRainReport = currentGameState.Now; rainAtLastReport = currentConditions.RainDensity; } } } } } }
override protected void triggerInternal(GameStateData previousGameState, GameStateData currentGameState) { currentConditions = currentGameState.Conditions.getMostRecentConditions(); if (currentConditions != null) { if (airTempAtLastReport == float.MinValue) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = currentConditions.TrackTemperature; rainAtLastReport = currentConditions.RainDensity; lastRainReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; lastAirTempReport = currentGameState.Now; } else { Boolean canReportAirChange = enableTrackAndAirTempReports && currentGameState.Now > lastAirTempReport.Add(AirTemperatureReportMaxFrequency); Boolean canReportTrackChange = enableTrackAndAirTempReports && currentGameState.Now > lastTrackTempReport.Add(TrackTemperatureReportMaxFrequency); Boolean reportedCombinedTemps = false; if (canReportAirChange || canReportTrackChange) { if (currentConditions.TrackTemperature > trackTempAtLastReport + minTrackTempDeltaToReport && currentConditions.AmbientTemperature > airTempAtLastReport + minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = currentConditions.TrackTemperature; lastAirTempReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airAndTrackTemp", MessageContents (folderAirAndTrackTempIncreasing, folderAirTempIsNow, convertTemp(currentConditions.AmbientTemperature), folderTrackTempIsNow, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, this)); reportedCombinedTemps = true; } else if (currentConditions.TrackTemperature < trackTempAtLastReport - minTrackTempDeltaToReport && currentConditions.AmbientTemperature < airTempAtLastReport - minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; trackTempAtLastReport = currentConditions.TrackTemperature; lastAirTempReport = currentGameState.Now; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airAndTrackTemp", MessageContents (folderAirAndTrackTempDecreasing, folderAirTempIsNow, convertTemp(currentConditions.AmbientTemperature), folderTrackTempIsNow, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, this)); reportedCombinedTemps = true; } } if (!reportedCombinedTemps && canReportAirChange) { if (currentConditions.AmbientTemperature > airTempAtLastReport + minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; lastAirTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airTemp", MessageContents (folderAirTempIncreasing, convertTemp(currentConditions.AmbientTemperature), getTempUnit()), 0, this)); } else if (currentConditions.AmbientTemperature < airTempAtLastReport - minAirTempDeltaToReport) { airTempAtLastReport = currentConditions.AmbientTemperature; lastAirTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("airTemp", MessageContents (folderAirTempDecreasing, convertTemp(currentConditions.AmbientTemperature), getTempUnit()), 0, this)); } } if (!reportedCombinedTemps && canReportTrackChange) { if (currentConditions.TrackTemperature > trackTempAtLastReport + minTrackTempDeltaToReport) { trackTempAtLastReport = currentConditions.TrackTemperature; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("trackTemp", MessageContents (folderTrackTempIncreasing, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, this)); } else if (currentConditions.TrackTemperature < trackTempAtLastReport - minTrackTempDeltaToReport) { trackTempAtLastReport = currentConditions.TrackTemperature; lastTrackTempReport = currentGameState.Now; // do the reporting audioPlayer.playMessage(new QueuedMessage("trackTemp", MessageContents (folderTrackTempDecreasing, convertTemp(currentConditions.TrackTemperature), getTempUnit()), 0, this)); } } if (currentGameState.Now > lastRainReport.Add(CrewChief.gameDefinition.gameEnum == GameEnum.RF2_64BIT ? RainReportMaxFrequencyRF2 : RainReportMaxFrequencyPCars)) { // for PCars mRainDensity value is 0 or 1 if (CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_32BIT || CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_64BIT || CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_NETWORK) { if (currentConditions.RainDensity == 0 && rainAtLastReport == 1) { rainAtLastReport = currentConditions.RainDensity; lastRainReport = currentGameState.Now; audioPlayer.playMessage(new QueuedMessage(folderStoppedRaining, 0, this)); } else if (currentConditions.RainDensity == 1 && rainAtLastReport == 0) { rainAtLastReport = currentConditions.RainDensity; lastRainReport = currentGameState.Now; audioPlayer.playMessage(new QueuedMessage(folderSeeingSomeRain, 0, this)); } } else if (CrewChief.gameDefinition.gameEnum == GameEnum.RF2_64BIT) { RainLevel currentRainLevel = getRainLevel(currentConditions.RainDensity); RainLevel lastReportedRainLevel = getRainLevel(rainAtLastReport); if (currentRainLevel != lastReportedRainLevel) { Boolean increasing = currentConditions.RainDensity > rainAtLastReport; switch (currentRainLevel) { case RainLevel.DRIZZLE: audioPlayer.playMessage(new QueuedMessage(folderDrizzleIncreasing, 0, this)); break; case RainLevel.LIGHT: audioPlayer.playMessage(new QueuedMessage(increasing ? folderRainLightIncreasing : folderRainLightDecreasing, 0, this)); break; case RainLevel.MID: audioPlayer.playMessage(new QueuedMessage(increasing ? folderRainMidIncreasing : folderRainMidDecreasing, 0, this)); break; case RainLevel.HEAVY: audioPlayer.playMessage(new QueuedMessage(increasing ? folderRainHeavyIncreasing : folderRainHeavyDecreasing, 0, this)); break; case RainLevel.STORM: audioPlayer.playMessage(new QueuedMessage(folderRainMax, 0, this)); break; case RainLevel.NONE: audioPlayer.playMessage(new QueuedMessage(folderStoppedRaining, 0, this)); break; } lastRainReport = currentGameState.Now; rainAtLastReport = currentConditions.RainDensity; } } } } } }