private CommandWeatherSetV1 GetCspCommand()
        {
            if (_weatherTransitionTimePassed.Elapsed >= _weatherTransitionDuration)
            {
                _weatherTransitionDuration = MathUtils.Random(TimeBetweenWeatherChangesMin, TimeBetweenWeatherChangesMax);
                _weatherTransitionTimePassed.Restart();
                _currentWeather = _nextWeather;
                _nextWeather    = AllowedWeatherTypes.RandomElement();
            }

            return(new CommandWeatherSetV1 {
                Timestamp = (ulong)(_startingDate + _timePassedTotal.Elapsed).ToUnixTimestamp(),
                TimeToApply = (float)UpdatePeriod.TotalSeconds,
                WeatherCurrent = _currentWeather,
                WeatherNext = _nextWeather,
                Transition = (float)(_weatherTransitionTimePassed.Elapsed.TotalSeconds / _weatherTransitionDuration.TotalSeconds).SmoothStep()
            });
        }
Example #2
0
        private CommandWeatherSetV2 GetCspCommand()
        {
            if (_weatherTransitionTimePassed.Elapsed >= _weatherTransitionDuration)
            {
                _weatherTransitionDuration = MathUtils.Random(TimeBetweenWeatherChangesMin, TimeBetweenWeatherChangesMax);
                _weatherTransitionTimePassed.Restart();
                _currentWeather       = _nextWeather;
                _nextWeather          = WeatherInfos.Keys.RandomElement();
                _currentWindSpeed     = _nextWindSpeed;
                _nextWindSpeed        = MathUtils.Random(20d);
                _currentWindDirection = _nextWindDirection;
                _nextWindDirection    = MathUtils.Random(360d);
                _currentHumidity      = _nextHumidity;
                _nextHumidity         = MathUtils.Random(100d);
                _currentPressure      = _nextPressure;
                _nextPressure         = MathUtils.Random(950d, 1050d);
            }

            var transition = (_weatherTransitionTimePassed.Elapsed.TotalSeconds / _weatherTransitionDuration.TotalSeconds).Saturate().SmoothStep();

            return(new CommandWeatherSetV2 {
                Timestamp = (ulong)(_startingDate + _timePassedTotal.Elapsed).ToUnixTimestamp(),
                TimeToApply = (Half)UpdatePeriod.TotalSeconds,
                WeatherCurrent = _currentWeather,
                WeatherNext = _nextWeather,
                Transition = (ushort)(65535 * transition),
                WindSpeedKmh = (Half)transition.Lerp(_currentWindSpeed, _nextWindSpeed),
                WindDirectionDeg = (Half)transition.Lerp(_currentWindDirection, _nextWindDirection),
                Humidity = (byte)(transition.Lerp(_currentHumidity, _nextHumidity) * 255d),
                Pressure = (Half)transition.Lerp(_currentPressure, _nextPressure),
                TemperatureAmbient = 25,
                TemperatureRoad = 25,
                TrackGrip = 95d,
                RainIntensity = (Half)_rainIntensity,
                RainWetness = (Half)_rainWetness,
                RainWater = (Half)_rainWater
            });
        }