Initial Agrarian Unreal project
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
// Copyright Pacificao. All Rights Reserved.
|
||||
|
||||
#include "AgrarianGameState.h"
|
||||
#include "Net/UnrealNetwork.h"
|
||||
|
||||
AAgrarianGameState::AAgrarianGameState()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
bReplicates = true;
|
||||
}
|
||||
|
||||
void AAgrarianGameState::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
|
||||
if (!HasAuthority())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WorldHours += (DeltaSeconds / 60.0f) * GameHoursPerRealMinute;
|
||||
while (WorldHours >= 24.0f)
|
||||
{
|
||||
WorldHours -= 24.0f;
|
||||
}
|
||||
|
||||
UpdateAmbientTemperature();
|
||||
}
|
||||
|
||||
void AAgrarianGameState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||
{
|
||||
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||
DOREPLIFETIME(AAgrarianGameState, WorldHours);
|
||||
DOREPLIFETIME(AAgrarianGameState, Weather);
|
||||
DOREPLIFETIME(AAgrarianGameState, AmbientTemperatureC);
|
||||
}
|
||||
|
||||
bool AAgrarianGameState::IsNight() const
|
||||
{
|
||||
return WorldHours < 6.0f || WorldHours > 20.0f;
|
||||
}
|
||||
|
||||
void AAgrarianGameState::SetWeather(EAgrarianWeatherType NewWeather)
|
||||
{
|
||||
if (HasAuthority())
|
||||
{
|
||||
Weather = NewWeather;
|
||||
UpdateAmbientTemperature();
|
||||
OnRep_Weather();
|
||||
}
|
||||
}
|
||||
|
||||
void AAgrarianGameState::OnRep_Weather()
|
||||
{
|
||||
UpdateAmbientTemperature();
|
||||
}
|
||||
|
||||
void AAgrarianGameState::UpdateAmbientTemperature()
|
||||
{
|
||||
const float DayWarmth = FMath::Sin((WorldHours / 24.0f) * 2.0f * PI - (PI * 0.5f)) * 8.0f;
|
||||
float WeatherModifier = 0.0f;
|
||||
|
||||
switch (Weather)
|
||||
{
|
||||
case EAgrarianWeatherType::Rain:
|
||||
WeatherModifier = -3.0f;
|
||||
break;
|
||||
case EAgrarianWeatherType::ColdWind:
|
||||
WeatherModifier = -8.0f;
|
||||
break;
|
||||
case EAgrarianWeatherType::Storm:
|
||||
WeatherModifier = -5.0f;
|
||||
break;
|
||||
default:
|
||||
WeatherModifier = 0.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
AmbientTemperatureC = 10.0f + DayWarmth + WeatherModifier;
|
||||
}
|
||||
Reference in New Issue
Block a user