Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_TimeAndWeatherHandlerComponent.c
Go to the documentation of this file.
4
5class SCR_TimeAndWeatherHandlerComponent : SCR_BaseGameModeComponent
6{
7 [Attribute("8", UIWidgets.Slider, "Starting time of day (hours)", "0 23 1", category:"Time")]
8 protected int m_iStartingHours;
9
10 [Attribute("0", UIWidgets.Slider, "Starting time of day (minutes)", "0 59 1", category:"Time")]
11 protected int m_iStartingMinutes;
12
13 [Attribute("0", category:"Time")]
15
16 [Attribute("0", desc: "Random time range is superior to random time. When both are set to true, random range will be used.", category:"Time")]
18
19 [Attribute("8", UIWidgets.Slider, "Starting range of starting time of day \n (hours)", "0 23 1", category:"Time")]
20 protected int m_iRangeHoursStart;
21
22 [Attribute("0", UIWidgets.Slider, "Starting range of starting time of day \n (minutes)", "0 59 1", category:"Time")]
23 protected int m_iRangeMinutesStart;
24
25 [Attribute("8", UIWidgets.Slider, "Ending range of starting time of day \n (hours)", "0 23 1", category:"Time")]
26 protected int m_iRangeHoursEnd;
27
28 [Attribute("0", UIWidgets.Slider, "Ending range of starting time of day \n (minutes)", "0 59 1", category:"Time")]
29 protected int m_iRangeMinutesEnd;
30
31 [Attribute("1", UIWidgets.Slider, "Time acceleration during the day (1 = 100%, 2 = 200% etc)", "0.1 12 0.1", category:"Time")]
32 protected float m_fDayTimeAcceleration;
33
34 [Attribute("1", UIWidgets.Slider, "Time acceleration during the night (1 = 100%, 2 = 200% etc)", "0.1 12 0.1", category:"Time")]
35 protected float m_fNightTimeAcceleration;
36
37 [Attribute("0", category:"Weather")]
39
40 [Attribute("0", desc: "Use predefine sets of weather and time.", category:"Weather")]
42
43 [Attribute(desc: "List of predefine time and weather settings.", category:"Weather")]
44 protected ref array<ref SCR_TimeAndWeatherState> m_aStartingWeatherAndTime;
45
46 [Attribute("0", desc: "Weather can change during gameplay", category:"Weather")]
48
49 [Attribute("0", desc: "Scenario header setting will overwrite these values.", category:"Weather")]
50 protected bool m_bAllowHeaderSettings;
51
52 [Attribute(defvalue: "0", desc: "Wind Override", category:"Wind")]
53 protected bool m_bWindOverride;
54
55 [Attribute(defvalue: "0", UIWidgets.Slider, desc: "Wind Speed", params: "0 20", category:"Wind")]
56 protected float m_fWindSpeed;
57
58 [Attribute(defvalue: "0", UIWidgets.Slider, desc: "Wind Direction", params: "0 1", category:"Wind")]
59 protected float m_fWindDirection;
60
61 [Attribute(defvalue: "0", desc: "Fog Override", category:"Fog")]
62 protected bool m_bFogOverride;
63
64 [Attribute(defvalue: "0", UIWidgets.Slider, desc: "Fog Amount", params: "0 1", category:"Fog")]
65 protected float m_fFogAmount;
66
67 [Attribute(defvalue: "0", UIWidgets.Slider, desc: "Fog Height Density", params: "0 1", category:"Fog")]
68 protected float m_fFogHeightDensity;
69
70 [Attribute(defvalue: "0", desc: "Override Date", category:"Date")]
71 protected bool m_bDateOverride;
72
73 [Attribute(defvalue: "1", UIWidgets.Slider, desc: "Day", params: "1 31", category:"Date")]
74 protected int m_iDay;
75
76 [Attribute(defvalue: "1", UIWidgets.Slider, desc: "Month", params: "1 12", category:"Date")]
77 protected int m_iMonth;
78
79 [Attribute(defvalue: "1989", UIWidgets.Slider, desc: "Year", params: "1899 2050", category:"Date")]
80 protected int m_iYear;
81
82 const int DAYTIME_CHECK_PERIOD = 60000; //ms
83 const float DEFAULT_DAYTIME_START = 5.0;
84 const float DEFAULT_DAYTIME_END = 19.0;
85 const int DAY_DURATION = 24 * 60 * 60;
86
87 protected bool m_bDaytimeAcceleration = true;
88 protected bool m_bSavedSettingApplied = false;
89
90 protected static SCR_TimeAndWeatherHandlerComponent s_Instance;
91
92 //------------------------------------------------------------------------------------------------
94 static SCR_TimeAndWeatherHandlerComponent GetInstance()
95 {
96 return s_Instance;
97 }
98
99 //------------------------------------------------------------------------------------------------
100 void SetupWind(float windSpeed, float windDirection)
101 {
102 ChimeraWorld world = ChimeraWorld.CastFrom(GetOwner().GetWorld());
103 if (!world)
104 return;
105
106 TimeAndWeatherManagerEntity manager = world.GetTimeAndWeatherManager();
107 if (!manager)
108 return;
109
110 manager.SetWindSpeedOverride(true, windSpeed);
111 manager.SetWindDirectionOverride(true, windDirection);
112 }
113
114 //------------------------------------------------------------------------------------------------
115 void SetupFog(float fogAmount, float fogHeightDensity)
116 {
117 ChimeraWorld world = ChimeraWorld.CastFrom(GetOwner().GetWorld());
118 if (!world)
119 return;
120
121 TimeAndWeatherManagerEntity manager = world.GetTimeAndWeatherManager();
122 if (!manager)
123 return;
124
125 manager.SetFogAmountOverride(true, fogAmount);
126 manager.SetFogHeightDensityOverride(true, fogHeightDensity);
127 }
128
129 //------------------------------------------------------------------------------------------------
130 void SetupDate(int day, int month, int year)
131 {
132 ChimeraWorld world = ChimeraWorld.CastFrom(GetOwner().GetWorld());
133 if (!world)
134 return;
135
136 TimeAndWeatherManagerEntity manager = world.GetTimeAndWeatherManager();
137 if (!manager)
138 return;
139
140 if (!manager.SetDate(year, month, day))
141 Print("SCR_TimeAndWeatherHandlerComponent: Invalid date parameter", LogLevel.ERROR);
142 }
143
144 //------------------------------------------------------------------------------------------------
150 void SetupDaytimeAndWeather(int hours, int minutes, int seconds = 0, string loadedWeatherState = "", bool loadDone = false)
151 {
153 return;
154
155 m_bSavedSettingApplied = loadDone;
156
157 ChimeraWorld world = ChimeraWorld.CastFrom(GetOwner().GetWorld());
158 if (!world)
159 return;
160
161 TimeAndWeatherManagerEntity manager = world.GetTimeAndWeatherManager();
162 if (!manager)
163 return;
164
165 float sunrise, morning, evening, sunset;
166
167 // Use world-calculated sunrise and sunset values if possible, otherwise use defaults
168 if (manager.GetSunriseHour(sunrise))
169 {
170 manager.GetSunsetHour(sunset);
171 }
172 else
173 {
174 sunrise = DEFAULT_DAYTIME_START;
175 sunset = DEFAULT_DAYTIME_END;
176 }
177
179 {
180 // Compile a list of presets based on the sunrise and sunset times of current world if we're randomizing
181 morning = sunrise + 0.25; // Just so it's not still completely dark at the start
182 float noon = (sunrise + sunset) * 0.5;
183 float afternoon = (noon + sunset) * 0.5;
184 evening = sunset - 0.5;
185 float night = noon + 12;
186
187 if (night >= 24)
188 night -= 24;
189
190 array<float> startingTimes = {morning, noon, afternoon, evening, night};
191
192 // Add weights so evening / night is a bit more rare
193 int index = SCR_ArrayHelper.GetWeightedIndex({25, 25, 25, 15, 10}, Math.RandomFloat01());
194 float startingTime;
195
196 if (startingTimes.IsIndexValid(index))
197 startingTime = startingTimes[index];
198 else
199 startingTime = startingTimes.GetRandomElement();
200
201 manager.TimeToHoursMinutesSeconds(startingTime, hours, minutes, seconds);
202 }
203
204 if (m_bRandomStartingDaytimeRange && !loadDone)
205 {
207 {
208 hours = Math.RandomInt(m_iRangeHoursStart, m_iRangeHoursEnd);
209 }
210 else
211 {
212 hours = Math.RandomInt(m_iRangeHoursStart, m_iRangeHoursEnd + 24) - 24;
213 }
214
216 {
217 minutes = Math.RandomInt(m_iRangeMinutesStart, m_iRangeMinutesEnd);
218 }
219 else
220 {
221 minutes = Math.RandomInt(m_iRangeHoursStart, m_iRangeHoursEnd + 60) - 60;
222 }
223 }
224
225 if (m_bRandomStartingWeather && !loadDone)
226 {
227 array<ref WeatherState> weatherStates = {};
228 manager.GetWeatherStatesList(weatherStates);
229
230 if (!weatherStates.IsEmpty())
231 manager.ForceWeatherTo(!m_bRandomWeatherChanges, weatherStates.GetRandomElement().GetStateName());
232 }
233
235 {
236 SCR_TimeAndWeatherState timeAndWEatherState = m_aStartingWeatherAndTime.GetRandomElement();
237 manager.ForceWeatherTo(!m_bRandomWeatherChanges, timeAndWEatherState.GetWeatherPresetName());
238 hours = timeAndWEatherState.GetStartingHour();
239 minutes = timeAndWEatherState.GetStartingMinutes();
240 }
241
242 if (!loadedWeatherState.IsEmpty())
243 manager.ForceWeatherTo(!m_bRandomWeatherChanges, loadedWeatherState);
244
245 manager.SetHoursMinutesSeconds(hours, minutes, seconds);
246
247 // Periodically check if the acceleration is correct, based on time of day
248 // SetTimeEvent is not usable since it requires changing Periodicity attribute directly in the manager entity in the world layer
250 {
252 GetGame().GetCallqueue().Remove(HandleDaytimeAcceleration);
253 GetGame().GetCallqueue().CallLater(HandleDaytimeAcceleration, DAYTIME_CHECK_PERIOD, true, false);
254 }
255 }
256
257 //------------------------------------------------------------------------------------------------
258 protected void HandleDaytimeAcceleration(bool setup = false)
259 {
260 ChimeraWorld world = ChimeraWorld.CastFrom(GetOwner().GetWorld());
261 if (!world)
262 return;
263
264 TimeAndWeatherManagerEntity manager = world.GetTimeAndWeatherManager();
265 if (!manager)
266 return;
267
268 if (manager.IsNightHour(manager.GetTimeOfTheDay()))
269 {
270 if (m_bDaytimeAcceleration || setup)
271 {
273 manager.SetDayDuration(DAY_DURATION / m_fNightTimeAcceleration);
274 }
275 }
276 else
277 {
278 if (!m_bDaytimeAcceleration || setup)
279 {
281 manager.SetDayDuration(DAY_DURATION / m_fDayTimeAcceleration);
282 }
283 }
284 }
285
286 //------------------------------------------------------------------------------------------------
287 override void OnWorldPostProcess(World world)
288 {
289 super.OnWorldPostProcess(world);
290
291 if (!Replication.IsServer() || !GetGame().InPlayMode())
292 return;
293
294 if (s_Instance != this)
295 {
296 Print("Multiple instances of SCR_TimeAndWeatherHandlerComponent detected.", LogLevel.WARNING);
297 return;
298 }
299
301
302 if (m_bDateOverride)
304
305 if (m_bFogOverride)
307
308 if (m_bWindOverride)
310 }
311
312 //------------------------------------------------------------------------------------------------
313 override void OnPostInit(IEntity owner)
314 {
315 // Allow only one instance
316 if (s_Instance || !GetGame().InPlayMode())
317 return;
318
319 // Allow permanent startign daytime & weather for debugging purposes
320#ifdef TDM_CLI_SELECTION
321 return;
322#endif
323
324 s_Instance = this;
325
326 if (!Replication.IsServer())
327 return;
328
329 SCR_MissionHeader header = SCR_MissionHeader.Cast(GetGame().GetMissionHeader());
330
331 if (m_bAllowHeaderSettings && header && header.m_bOverrideScenarioTimeAndWeather)
332 {
333 m_iStartingHours = header.m_iStartingHours;
334 m_iStartingMinutes = header.m_iStartingMinutes;
335 m_bRandomStartingDaytime = header.m_bRandomStartingDaytime;
336 m_fDayTimeAcceleration = header.m_fDayTimeAcceleration;
337 m_fNightTimeAcceleration = header.m_fNightTimeAcceleration;
338 m_bRandomStartingWeather = header.m_bRandomStartingWeather;
339 m_bRandomWeatherChanges = header.m_bRandomWeatherChanges;
340 }
341 }
342}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
const float DEFAULT_DAYTIME_START
const float DEFAULT_DAYTIME_END
void SetupDate(int day, int month, int year)
void HandleDaytimeAcceleration(bool setup=false)
void SetupWind(float windSpeed, float windDirection)
const int DAYTIME_CHECK_PERIOD
void SetupFog(float fogAmount, float fogHeightDensity)
bool m_bUsePredefineStartingTimeAndWeather
override void OnWorldPostProcess(World world)
ref array< ref SCR_TimeAndWeatherState > m_aStartingWeatherAndTime
void SetupDaytimeAndWeather(int hours, int minutes, int seconds=0, string loadedWeatherState="", bool loadDone=false)
Definition Math.c:13
Main replication API.
Definition Replication.c:14
void ForceWeatherTo(bool setLooping, string weatherID=string.Empty, float transitionDuration=0, float stateDuration=0.001, int playerThatChangedWeather=0)
Definition World.c:16
IEntity GetOwner()
Owner entity of the fuel tank.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute