Persist applied weather debug state
This commit is contained in:
@@ -49,6 +49,13 @@ AAgrarianGameState::AAgrarianGameState()
|
||||
ActiveGrowingSeason.MinAverageGrowingTempC = 7.0f;
|
||||
ActiveGrowingSeason.CropSafetyBufferDays = 14;
|
||||
ActiveGrowingSeason.ClimateProfile = TEXT("coastal_mediterranean_mild");
|
||||
ActiveWeatherInputs.TileId = ActiveSolarTileId;
|
||||
ActiveWeatherInputs.Latitude = ActiveTileLatitude;
|
||||
ActiveWeatherInputs.Longitude = ActiveTileLongitude;
|
||||
ActiveWeatherDebug.TileId = ActiveSolarTileId;
|
||||
ActiveWeatherDebug.Latitude = ActiveTileLatitude;
|
||||
ActiveWeatherDebug.Longitude = ActiveTileLongitude;
|
||||
ActiveWeatherDebug.AppliedWeather = Weather;
|
||||
}
|
||||
|
||||
void AAgrarianGameState::BeginPlay()
|
||||
@@ -99,6 +106,7 @@ void AAgrarianGameState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& O
|
||||
DOREPLIFETIME(AAgrarianGameState, bHasRegionalObservedTemperature);
|
||||
DOREPLIFETIME(AAgrarianGameState, RegionalWeatherSource);
|
||||
DOREPLIFETIME(AAgrarianGameState, ActiveWeatherInputs);
|
||||
DOREPLIFETIME(AAgrarianGameState, ActiveWeatherDebug);
|
||||
DOREPLIFETIME(AAgrarianGameState, DaysPerAgrarianYear);
|
||||
DOREPLIFETIME(AAgrarianGameState, ActiveSolarTileId);
|
||||
DOREPLIFETIME(AAgrarianGameState, ActiveTileLatitude);
|
||||
@@ -130,6 +138,7 @@ void AAgrarianGameState::SetWeather(EAgrarianWeatherType NewWeather)
|
||||
if (HasAuthority())
|
||||
{
|
||||
Weather = NewWeather;
|
||||
ActiveWeatherDebug.AppliedWeather = NewWeather;
|
||||
UpdateAmbientTemperature();
|
||||
OnRep_Weather();
|
||||
}
|
||||
@@ -180,6 +189,22 @@ void AAgrarianGameState::ApplyMappedWeatherInputs(const FAgrarianMappedWeatherIn
|
||||
ActiveWeatherInputs.VisibilityMeters = FMath::Max(0.0f, ActiveWeatherInputs.VisibilityMeters);
|
||||
ActiveWeatherInputs.bHasProviderData = true;
|
||||
|
||||
ActiveWeatherDebug.TileId = ActiveWeatherInputs.TileId != NAME_None ? ActiveWeatherInputs.TileId : ActiveSolarTileId;
|
||||
ActiveWeatherDebug.Latitude = ActiveWeatherInputs.TileId != NAME_None ? ActiveWeatherInputs.Latitude : ActiveTileLatitude;
|
||||
ActiveWeatherDebug.Longitude = ActiveWeatherInputs.TileId != NAME_None ? ActiveWeatherInputs.Longitude : ActiveTileLongitude;
|
||||
ActiveWeatherDebug.Provider = ActiveWeatherInputs.Provider;
|
||||
ActiveWeatherDebug.ProviderTimestamp = ActiveWeatherInputs.ProviderTimestamp;
|
||||
ActiveWeatherDebug.AppliedWeather = ActiveWeatherInputs.MappedWeather;
|
||||
ActiveWeatherDebug.ProviderWeatherCode = ActiveWeatherInputs.ProviderWeatherCode;
|
||||
ActiveWeatherDebug.TemperatureC = ActiveWeatherInputs.TemperatureC;
|
||||
ActiveWeatherDebug.PrecipitationMm = ActiveWeatherInputs.PrecipitationMm;
|
||||
ActiveWeatherDebug.WindSpeedKmh = ActiveWeatherInputs.WindSpeedKmh;
|
||||
ActiveWeatherDebug.CloudCoverPercent = ActiveWeatherInputs.CloudCoverPercent;
|
||||
ActiveWeatherDebug.RelativeHumidityPercent = ActiveWeatherInputs.RelativeHumidityPercent;
|
||||
ActiveWeatherDebug.PressureMslHpa = ActiveWeatherInputs.PressureMslHpa;
|
||||
ActiveWeatherDebug.VisibilityMeters = ActiveWeatherInputs.VisibilityMeters;
|
||||
ActiveWeatherDebug.bHasProviderData = ActiveWeatherInputs.bHasProviderData;
|
||||
|
||||
SetRegionalTemperatureProfile(ActiveWeatherInputs.DailyLowTemperatureC, ActiveWeatherInputs.DailyHighTemperatureC);
|
||||
SetRegionalObservedTemperature(
|
||||
ActiveWeatherInputs.TemperatureC,
|
||||
@@ -188,6 +213,11 @@ void AAgrarianGameState::ApplyMappedWeatherInputs(const FAgrarianMappedWeatherIn
|
||||
SetWeather(ActiveWeatherInputs.MappedWeather);
|
||||
}
|
||||
|
||||
FAgrarianWeatherDebugSnapshot AAgrarianGameState::GetWeatherDebugSnapshot() const
|
||||
{
|
||||
return ActiveWeatherDebug;
|
||||
}
|
||||
|
||||
float AAgrarianGameState::GetClearSkyTemperatureForHour(float HourOfDay) const
|
||||
{
|
||||
const float LowTemperature = FMath::Min(RegionalDailyLowTemperatureC, RegionalDailyHighTemperatureC);
|
||||
|
||||
@@ -55,6 +55,9 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Replicated, Category = "Agrarian|World|Weather")
|
||||
FAgrarianMappedWeatherInputs ActiveWeatherInputs;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Replicated, Category = "Agrarian|World|Weather")
|
||||
FAgrarianWeatherDebugSnapshot ActiveWeatherDebug;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Replicated, Category = "Agrarian|World|Tile Solar")
|
||||
FName ActiveSolarTileId = TEXT("gz_us_ca_pacifica_utm10n_e544_n4160");
|
||||
|
||||
@@ -109,6 +112,9 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|World|Weather")
|
||||
void ApplyMappedWeatherInputs(const FAgrarianMappedWeatherInputs& MappedInputs);
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Agrarian|World|Weather")
|
||||
FAgrarianWeatherDebugSnapshot GetWeatherDebugSnapshot() const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Agrarian|World|Temperature")
|
||||
float GetClearSkyTemperatureForHour(float HourOfDay) const;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "AgrarianPersistenceSubsystem.h"
|
||||
#include "AgrarianGameCharacter.h"
|
||||
#include "AgrarianGameState.h"
|
||||
#include "AgrarianInventoryComponent.h"
|
||||
#include "AgrarianPersistentActorComponent.h"
|
||||
#include "AgrarianSaveGame.h"
|
||||
@@ -120,6 +121,44 @@ int32 UAgrarianPersistenceSubsystem::RestoreWorldActors(const UAgrarianSaveGame*
|
||||
return RestoredCount;
|
||||
}
|
||||
|
||||
bool UAgrarianPersistenceSubsystem::CaptureWorldState(UAgrarianSaveGame* SaveGame) const
|
||||
{
|
||||
UWorld* World = GetWorld();
|
||||
AAgrarianGameState* GameState = World ? World->GetGameState<AAgrarianGameState>() : nullptr;
|
||||
if (!SaveGame || !GameState)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SaveGame->WorldHours = GameState->WorldHours;
|
||||
SaveGame->Weather = GameState->Weather;
|
||||
SaveGame->WeatherInputs = GameState->ActiveWeatherInputs;
|
||||
SaveGame->WeatherDebug = GameState->GetWeatherDebugSnapshot();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UAgrarianPersistenceSubsystem::RestoreWorldState(const UAgrarianSaveGame* SaveGame) const
|
||||
{
|
||||
UWorld* World = GetWorld();
|
||||
AAgrarianGameState* GameState = World ? World->GetGameState<AAgrarianGameState>() : nullptr;
|
||||
if (!SaveGame || !GameState || !GameState->HasAuthority())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GameState->WorldHours = SaveGame->WorldHours;
|
||||
if (SaveGame->WeatherInputs.bHasProviderData)
|
||||
{
|
||||
GameState->ApplyMappedWeatherInputs(SaveGame->WeatherInputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameState->SetWeather(SaveGame->Weather);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32 UAgrarianPersistenceSubsystem::CapturePlayers(UAgrarianSaveGame* SaveGame) const
|
||||
{
|
||||
if (!SaveGame)
|
||||
@@ -209,6 +248,7 @@ bool UAgrarianPersistenceSubsystem::SaveCurrentWorld() const
|
||||
return false;
|
||||
}
|
||||
|
||||
CaptureWorldState(SaveGame);
|
||||
CapturePlayers(SaveGame);
|
||||
CaptureWorldActors(SaveGame);
|
||||
return WriteSave(SaveGame);
|
||||
|
||||
@@ -46,6 +46,12 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Persistence")
|
||||
int32 RestoreWorldActors(const UAgrarianSaveGame* SaveGame, bool bClearExistingActors = true) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Persistence")
|
||||
bool CaptureWorldState(UAgrarianSaveGame* SaveGame) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Persistence")
|
||||
bool RestoreWorldState(const UAgrarianSaveGame* SaveGame) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Persistence")
|
||||
int32 CapturePlayers(UAgrarianSaveGame* SaveGame) const;
|
||||
|
||||
|
||||
@@ -61,6 +61,12 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
|
||||
EAgrarianWeatherType Weather = EAgrarianWeatherType::Clear;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
|
||||
FAgrarianMappedWeatherInputs WeatherInputs;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
|
||||
FAgrarianWeatherDebugSnapshot WeatherDebug;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
|
||||
TArray<FAgrarianSavedPlayer> Players;
|
||||
|
||||
|
||||
@@ -19,6 +19,15 @@ struct FAgrarianMappedWeatherInputs
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
FName TileId = NAME_None;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float Latitude = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float Longitude = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float TemperatureC = 12.0f;
|
||||
|
||||
@@ -62,6 +71,57 @@ struct FAgrarianMappedWeatherInputs
|
||||
bool bHasProviderData = false;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FAgrarianWeatherDebugSnapshot
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
FName TileId = NAME_None;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float Latitude = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float Longitude = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
FString Provider = TEXT("deterministic");
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
FString ProviderTimestamp;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
EAgrarianWeatherType AppliedWeather = EAgrarianWeatherType::Clear;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
int32 ProviderWeatherCode = 0;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float TemperatureC = 12.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float PrecipitationMm = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float WindSpeedKmh = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float CloudCoverPercent = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float RelativeHumidityPercent = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float PressureMslHpa = 1013.25f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
float VisibilityMeters = 10000.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Weather")
|
||||
bool bHasProviderData = false;
|
||||
};
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class EAgrarianSeason : uint8
|
||||
{
|
||||
|
||||
@@ -122,6 +122,9 @@ bool UAgrarianWeatherProviderSubsystem::ApplySnapshotToGameState(const FAgrarian
|
||||
FAgrarianMappedWeatherInputs UAgrarianWeatherProviderSubsystem::MapSnapshotToAgrarianWeatherInputs(const FAgrarianWeatherProviderSnapshot& Snapshot) const
|
||||
{
|
||||
FAgrarianMappedWeatherInputs MappedInputs;
|
||||
MappedInputs.TileId = Snapshot.TileId;
|
||||
MappedInputs.Latitude = Snapshot.Latitude;
|
||||
MappedInputs.Longitude = Snapshot.Longitude;
|
||||
MappedInputs.TemperatureC = Snapshot.CurrentTemperatureC;
|
||||
MappedInputs.DailyLowTemperatureC = Snapshot.DailyLowTemperatureC;
|
||||
MappedInputs.DailyHighTemperatureC = Snapshot.DailyHighTemperatureC;
|
||||
|
||||
Reference in New Issue
Block a user