Map provider weather inputs

This commit is contained in:
2026-05-15 23:47:35 -07:00
parent 8ae5ecb3b0
commit ff6fc61af3
8 changed files with 204 additions and 7 deletions
@@ -111,15 +111,30 @@ bool UAgrarianWeatherProviderSubsystem::ApplySnapshotToGameState(const FAgrarian
return false;
}
GameState->SetRegionalTemperatureProfile(Snapshot.DailyLowTemperatureC, Snapshot.DailyHighTemperatureC);
GameState->SetRegionalObservedTemperature(
Snapshot.CurrentTemperatureC,
1.0f,
FString::Printf(TEXT("%s:%s"), *Snapshot.Provider, *Snapshot.ProviderTimestamp));
GameState->SetWeather(Snapshot.MappedWeather);
GameState->ApplyMappedWeatherInputs(MapSnapshotToAgrarianWeatherInputs(Snapshot));
return true;
}
FAgrarianMappedWeatherInputs UAgrarianWeatherProviderSubsystem::MapSnapshotToAgrarianWeatherInputs(const FAgrarianWeatherProviderSnapshot& Snapshot) const
{
FAgrarianMappedWeatherInputs MappedInputs;
MappedInputs.TemperatureC = Snapshot.CurrentTemperatureC;
MappedInputs.DailyLowTemperatureC = Snapshot.DailyLowTemperatureC;
MappedInputs.DailyHighTemperatureC = Snapshot.DailyHighTemperatureC;
MappedInputs.PrecipitationMm = Snapshot.PrecipitationMm;
MappedInputs.WindSpeedKmh = Snapshot.WindSpeedKmh;
MappedInputs.CloudCoverPercent = Snapshot.CloudCoverPercent;
MappedInputs.RelativeHumidityPercent = Snapshot.RelativeHumidityPercent;
MappedInputs.PressureMslHpa = Snapshot.PressureMslHpa > 0.0f ? Snapshot.PressureMslHpa : 1013.25f;
MappedInputs.VisibilityMeters = Snapshot.VisibilityMeters;
MappedInputs.ProviderWeatherCode = Snapshot.WeatherCode;
MappedInputs.MappedWeather = Snapshot.MappedWeather;
MappedInputs.Provider = Snapshot.Provider;
MappedInputs.ProviderTimestamp = Snapshot.ProviderTimestamp;
MappedInputs.bHasProviderData = Snapshot.bIsValid;
return MappedInputs;
}
bool UAgrarianWeatherProviderSubsystem::TryApplyCachedSnapshot(FName TileId, const FString& Provider, AAgrarianGameState* GameState)
{
if (!GameState || !GameState->HasAuthority())
@@ -331,6 +346,7 @@ bool UAgrarianWeatherProviderSubsystem::ParseOpenMeteoForecast(const FString& Re
OutSnapshot.CloudCoverPercent = static_cast<float>(CloudCover);
OutSnapshot.RelativeHumidityPercent = static_cast<float>(RelativeHumidity);
OutSnapshot.PressureMslHpa = static_cast<float>(Pressure);
OutSnapshot.VisibilityMeters = FMath::Clamp(10000.0f - (OutSnapshot.CloudCoverPercent * 35.0f) - (OutSnapshot.PrecipitationMm * 250.0f), 250.0f, 10000.0f);
OutSnapshot.WeatherCode = FMath::RoundToInt(WeatherCode);
OutSnapshot.MappedWeather = MapOpenMeteoWeatherCode(OutSnapshot.WeatherCode, OutSnapshot.PrecipitationMm, OutSnapshot.WindSpeedKmh);
OutSnapshot.bIsValid = true;
@@ -378,8 +394,16 @@ bool UAgrarianWeatherProviderSubsystem::ParseNoaaNwsGridData(const FString& Resp
double PrecipitationPercent = 0.0;
double WindSpeedKmh = 0.0;
double RelativeHumidity = 0.0;
double SkyCover = 0.0;
double Pressure = 0.0;
double Visibility = 0.0;
ReadFirstGridValue(*PropertiesObject, TEXT("probabilityOfPrecipitation"), PrecipitationPercent);
ReadFirstGridValue(*PropertiesObject, TEXT("windSpeed"), WindSpeedKmh);
ReadFirstGridValue(*PropertiesObject, TEXT("relativeHumidity"), RelativeHumidity);
ReadFirstGridValue(*PropertiesObject, TEXT("skyCover"), SkyCover);
ReadFirstGridValue(*PropertiesObject, TEXT("pressure"), Pressure);
ReadFirstGridValue(*PropertiesObject, TEXT("visibility"), Visibility);
OutSnapshot.TileId = TileId;
OutSnapshot.Latitude = FMath::Clamp(Latitude, -90.0f, 90.0f);
@@ -391,6 +415,10 @@ bool UAgrarianWeatherProviderSubsystem::ParseNoaaNwsGridData(const FString& Resp
OutSnapshot.DailyHighTemperatureC = static_cast<float>(TemperatureC + 4.0);
OutSnapshot.PrecipitationMm = PrecipitationPercent > 30.0 ? 0.1f : 0.0f;
OutSnapshot.WindSpeedKmh = static_cast<float>(WindSpeedKmh);
OutSnapshot.CloudCoverPercent = static_cast<float>(SkyCover);
OutSnapshot.RelativeHumidityPercent = static_cast<float>(RelativeHumidity);
OutSnapshot.PressureMslHpa = Pressure > 0.0 ? static_cast<float>(Pressure / 100.0) : 1013.25f;
OutSnapshot.VisibilityMeters = Visibility > 0.0 ? static_cast<float>(Visibility) : FMath::Clamp(10000.0f - (OutSnapshot.CloudCoverPercent * 35.0f), 250.0f, 10000.0f);
OutSnapshot.WeatherCode = PrecipitationPercent > 30.0 ? 61 : 0;
OutSnapshot.MappedWeather = MapOpenMeteoWeatherCode(OutSnapshot.WeatherCode, OutSnapshot.PrecipitationMm, OutSnapshot.WindSpeedKmh);
OutSnapshot.bIsValid = true;