4 protected float m_DayTemperature;
5 protected float m_NightTemperature;
7 protected float m_EnvironmentTemperature;
8 protected float m_Timer;
9 protected float m_MaxTemps[12];
10 protected float m_MinTemps[12];
11 protected float m_Sunrise_Jan;
12 protected float m_Sunset_Jan;
13 protected float m_Sunrise_Jul;
14 protected float m_Sunset_Jul;
24 m_DayTemperature = 10;
25 m_NightTemperature = 6;
26 m_Weather =
g_Game.GetWeather();
27 m_EnvironmentTemperature = 12.0;
33 m_MaxTemps = {3,5,7,14,19,24,26,25,21,16,10,5};
34 m_MinTemps = {-3,-2,0,4,9,14,18,17,12,7,4,0};
37 float GetApproxSunriseTime(
float monthday )
39 if ( monthday <= 8.0 )
40 return ( ( m_Sunrise_Jan - m_Sunrise_Jul ) / ( 8 - 1 ) ) * ( 1 - monthday ) + m_Sunrise_Jan;
42 return ( ( ( monthday - 8 ) * ( m_Sunrise_Jan - m_Sunrise_Jul ) ) / ( 13 - 8 ) ) + m_Sunrise_Jul;
44 float GetApproxSunsetTime(
float monthday )
46 if ( monthday <= 8.0 )
47 return ( ( m_Sunset_Jan - m_Sunset_Jul ) / (8 - 1) ) * ( 1 - monthday ) + m_Sunset_Jan;
49 return ( ( ( monthday - 8 ) * ( m_Sunset_Jan - m_Sunset_Jul ) ) / ( 13 - 8 ) ) + m_Sunset_Jul;
51 protected float CalcBaseEnvironmentTemperature(
float monthday,
float daytime )
53 float approxSunrise = GetApproxSunriseTime( monthday );
54 float approxSunset = GetApproxSunsetTime( monthday );
55 float dayLight = approxSunset - approxSunrise;
56 float nightTime = 24.0 - dayLight;
57 int tempArrayIndex =
Math.Floor(monthday) - 1;
58 int tempArrayIndexToLerp = tempArrayIndex + 1;
59 if ( tempArrayIndexToLerp >= 12 )
60 tempArrayIndexToLerp = 0;
61 float tempArrayLerp = monthday -
Math.Floor(monthday);
62 float minTempA = m_MinTemps[tempArrayIndex];
63 float minTempB = m_MinTemps[tempArrayIndexToLerp];
64 float maxTempA = m_MaxTemps[tempArrayIndex];
65 float maxTempB = m_MaxTemps[tempArrayIndexToLerp];
66 float eveningMinA = minTempA + ( 0.5 *
Math.AbsFloat( minTempA - maxTempA ) );
67 float eveningMinB = minTempB + ( 0.5 *
Math.AbsFloat( minTempB - maxTempB ) );
69 if ( ( daytime >= approxSunrise ) && ( daytime <= approxSunset ) ) {
70 if ( daytime <= ( approxSunrise + ( dayLight * 0.75 ) ) )
72 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
73 Math.Lerp( maxTempA, maxTempB, tempArrayLerp ),
74 ( ( daytime - approxSunrise ) / ( dayLight * 0.75 ) ) );
77 Math.Lerp( maxTempA, maxTempB, tempArrayLerp ),
78 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
79 ( ( ( daytime - approxSunrise ) - ( dayLight * 0.75 ) ) / ( dayLight - ( dayLight * 0.75 ) ) ) );
81 if ( ( daytime > approxSunset ) && ( daytime < 24 ) )
83 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
84 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
85 ( ( daytime - approxSunset ) / ( 24 - approxSunset ) ) / 2.0 );
88 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
89 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
90 ( ( ( daytime + ( 24 - approxSunset ) ) / nightTime ) / 2.0 ) + 0.5 );
93 void UpdateBaseEnvTemperature(
float timeslice)
98 int year, month, day, hour, minute;
99 GetGame().GetWorld().GetDate( year, month, day, hour, minute );
100 m_EnvironmentTemperature = CalcBaseEnvironmentTemperature( month + ( day / 32.0 ), hour + ( minute / 60.0 ) );
106 float GetBaseEnvTemperature()
108 return m_EnvironmentTemperature;
110 float GetBaseEnvTemperatureExact(
int month,
int day,
int hour,
int minute)
112 return CalcBaseEnvironmentTemperature( month + ( day / 32.0 ), hour + ( minute / 60.0 ) );
116 float GetDayTemperature()
118 return m_DayTemperature;
121 float GetNightTemperature()
123 return m_NightTemperature;
126 bool WeatherOnBeforeChange(
EWeatherPhenomenon type,
float actual,
float change,
float time )
139 void BaseTempDebug(
int month,
int day)
141 Print(
"--------------------");
142 for (
int i = 0; i < 24; i++ )
144 for (
int j = 0; j < 6; j++ )
146 int minute = ( j * 10 );
147 Print(
string.Format(
"%1:%2 %3", i, minute, GetBaseEnvTemperatureExact( month, day, i, minute ) ) );