Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
TimeAndWeatherManagerEntity.c
Go to the documentation of this file.
2{
3}
5//~ Script invokers
6void SCR_TimeAndWeatherManager_OnWeatherStatePreview(bool previewEnabled, string weatherState);
9void SCR_TimeAndWeatherManager_OnWindPreview(bool previewEnabled, float windSpeed, float windDirectionDegrees);
12void SCR_TimeAndWeatherManager_OnDateTimePreview(bool previewEnabled, int year, int month, int day, float timeOfTheDay);
14
15void ScriptInvokerOnWindOverrideDataChangedMethod(notnull TimeAndWeatherManagerEntity manager, bool currentState, float currentSpeed, float currentDirection);
17typedef ScriptInvokerBase<ScriptInvokerOnWindOverrideDataChangedMethod> ScriptInvokerOnWindOverrideDataChanged;
18
19void ScriptInvokerOnWeatherChangedMethod(notnull TimeAndWeatherManagerEntity manager, int currentStateId, int nextStateId, bool transitioning);
21typedef ScriptInvokerBase<ScriptInvokerOnWeatherChangedMethod> ScriptInvokerOnWeatherChanged;
22
23
25class TimeAndWeatherManagerEntity : BaseTimeAndWeatherManagerEntity
26{
27 [Attribute(desc: "An ordered array of daytime info. Starting just after midnight and ending at midnight, the daytime must be ordered!")]
28 protected ref array<ref SCR_DayTimeInfoBase> m_aOrderedDaytimeInfo;
29
30 [Attribute(desc: "An ordered array of winddirection info, starting at north and having set steps between each wind direction. (default 45)")]
31 protected ref array<ref SCR_WindDirectionInfo> m_OrderedWindDirectionInfo;
32
33 [Attribute(desc: "An array of monephase naming in order from New moon to Full moon. Check GetMoonPhaseNameForDate before changing this array!")]
34 protected ref array<ref SCR_MoonPhaseInfo> m_aMoonPhasesInfo;
35
36 [Attribute(desc: "Ordered days of the weeks, Monday (Start), Tuesday, Wednesday, ect. to Sunday (Last)")]
37 protected ref array<LocalizedString> m_aOrderedDaysOfWeek;
38
39 protected int m_iDelayedPlayerChangingWind = -1;
40 protected float m_fDelayedWindSpeedOverride = -1;
41 protected float m_fDelayedWindDirectionOverride = -1;
42 protected bool m_bListiningToWindOverrideDelay = false;
44 //~ ScriptInvokers
45 protected ref ScriptInvokerBase<SCR_TimeAndWeatherManager_OnWeatherStatePreview> m_OnWeatherStatePreview;
46 protected ref ScriptInvokerBase<SCR_TimeAndWeatherManager_OnWindPreview> m_OnWindPreview;
47 protected ref ScriptInvokerBase<SCR_TimeAndWeatherManager_OnDateTimePreview> m_OnDateTimePreview;
50
51 //Replicated
52 protected bool m_bWeatherIsLooping = false;
53
54 [RplProp(onRplName: "OnWindOverrideStateChanged")]
55 protected bool m_bDelayedWindOverride;
56
57 //------------------------------------------------------------------------------------------------
65
66 //------------------------------------------------------------------------------------------------
77
78 //------------------------------------------------------------------------------------------------
84
85 //------------------------------------------------------------------------------------------------
86 override protected void EOnInit(IEntity owner)
87 {
88 RplComponent rplComp = SCR_EntityHelper.GetEntityRplComponent(owner);
89 if (!rplComp || rplComp.Role() != RplRole.Authority)
90 return;
91
93 GetTransitionManager().AddTransitionCallbacks(cb);
94 }
95
96 //------------------------------------------------------------------------------------------------
97 void OnWeatherChanged_S(bool transitioning = true)
98 {
99 int currentStateId = GetCurrentWeatherState().GetStateID();
100 int nextStateId = GetTransitionManager().GetNextState().GetStateID();
101 RpcDo_OnWeatherChanged(currentStateId, nextStateId, transitioning);
102 Rpc(RpcDo_OnWeatherChanged, currentStateId, nextStateId, transitioning);
103 }
104
105 //------------------------------------------------------------------------------------------------
106 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
107 protected void RpcDo_OnWeatherChanged(int currentStateId, int nextStateId, bool transitioning)
108 {
110 m_OnWeatherChanged.Invoke(this, currentStateId, nextStateId, transitioning);
111 }
112
113 //------------------------------------------------------------------------------------------------
116 {
118 }
119
120 //------------------------------------------------------------------------------------------------
125 bool SetWeatherStatePreview(bool preview, string stateName = "")
126 {
127 BaseWeatherStateTransitionManager weatherStateTransitionManager = GetTransitionManager();
128 if (!weatherStateTransitionManager)
129 return false;
130
131 if (!weatherStateTransitionManager.SetStatePreview(preview, stateName))
132 return false;
133
134 //Script invoker
136 m_OnWeatherStatePreview.Invoke(preview, stateName);
137
138 return true;
139 }
140
141 //------------------------------------------------------------------------------------------------
147 bool SetWindPreview(bool preview, float windSpeed = -1, float windAngleDegrees = -1)
148 {
149 BaseWeatherStateTransitionManager weatherStateTransitionManager = GetTransitionManager();
150 if (!weatherStateTransitionManager)
151 return false;
152
153 if (!weatherStateTransitionManager.SetWindPreview(preview, windSpeed, windAngleDegrees))
154 return false;
155
156 //Script invoker
157 if (m_OnWindPreview)
158 m_OnWindPreview.Invoke(preview, windSpeed, windAngleDegrees);
159
160 return true;
161 }
162
163 //------------------------------------------------------------------------------------------------
171 bool SetDateTimePreview(bool preview, int year = -1, int month = -1, int day = -1, float timeOfTheDay = -1)
172 {
173 BaseWeatherStateTransitionManager weatherStateTransitionManager = GetTransitionManager();
174 if (!weatherStateTransitionManager)
175 return false;
176
177 if (!weatherStateTransitionManager.SetDateTimePreview(preview, year, month, day, timeOfTheDay))
178 return false;
179
180 //Script ScriptInvoker
182 m_OnDateTimePreview.Invoke(preview, year, month, day, timeOfTheDay);
183
184 return true;
185 }
186
187 //------------------------------------------------------------------------------------------------
190 bool IsSunSet()
191 {
192 return IsSunSet(GetTimeOfTheDay());
193 }
194
195 //------------------------------------------------------------------------------------------------
200 bool IsSunSet(float timeToCheck)
201 {
202 float sunSetTime, sunRiseTime;
203
204 //~ The sun never sets
205 if (!GetSunsetHour(sunSetTime))
206 return false;
207
208 //~ The sun never rises
209 if (!GetSunriseHour(sunRiseTime))
210 return true;
211
212 //~ Returns if given time is >= than sunset or smaller than sunrise time
213 return (timeToCheck >= sunSetTime || timeToCheck < sunRiseTime);
214 }
215
216 //------------------------------------------------------------------------------------------------
220 {
221 int weekdayIndex = GetWeekDay();
222
223 if (weekdayIndex < 0 || weekdayIndex > m_aOrderedDaysOfWeek.Count())
224 return string.Empty;
225
226 return m_aOrderedDaysOfWeek[weekdayIndex];
227 }
228
229 //------------------------------------------------------------------------------------------------
232 string GetWeekDayStringForDate(int year, int month, int day)
233 {
234 int weekdayIndex = GetWeekDayForDate(year, month, day);
235
236 if (weekdayIndex < 0 || weekdayIndex > m_aOrderedDaysOfWeek.Count())
237 return string.Empty;
238
239 return m_aOrderedDaysOfWeek[weekdayIndex];
240 }
241
242
243 //------------------------------------------------------------------------------------------------
251 void SetCurrentWeatherLooping(bool setLooping, int playerChangedLooping = 0)
252 {
253 ForceWeatherTo(setLooping, playerThatChangedWeather: playerChangedLooping);
254 }
255
256 //------------------------------------------------------------------------------------------------
265 void ForceWeatherTo(bool setLooping, string weatherID = string.Empty, float transitionDuration = 0, float stateDuration = 0.001, int playerThatChangedWeather = 0)
266 {
267 if (!Replication.IsServer())
268 {
269 Print("'ForceWeatherTo' was called in 'TimeAndWeatherManagerEntity' but only server has authority to change weather!", LogLevel.WARNING);
270 return;
271 }
272
274 if (!transitionManager)
275 {
276 Print("'ForceWeatherTo' was called in 'TimeAndWeatherManagerEntity' but TransitionManager was not found!", LogLevel.WARNING);
277 return;
278 }
279
280 if (weatherID.IsEmpty())
281 {
282 WeatherState currentWeather = transitionManager.GetCurrentState();
283 weatherID = currentWeather.GetStateName();
284 }
285
286 WeatherStateTransitionNode transitionNode = transitionManager.CreateStateTransition(weatherID, transitionDuration, stateDuration);
287 if (!transitionNode)
288 {
289 Print("'ForceWeatherTo' in 'TimeAndWeatherManagerEntity' could not create a new WeatherStateTransitionNode", LogLevel.WARNING);
290 return;
291 }
292
293 transitionNode.SetLooping(setLooping);
294
295 //~ Remove Preview if any
296 if (transitionManager.IsPreviewingState())
298
299 transitionManager.EnqueueStateTransition(transitionNode, false);
300 transitionManager.RequestStateTransitionImmediately(transitionNode);
301
302 //~ Send to clients if weather is looping or not
303 if (setLooping != m_bWeatherIsLooping)
304 {
305 UpdateWeatherLooping(setLooping);
306 Rpc(UpdateWeatherLooping, setLooping);
307 }
308
309 //~ Send notification if player ID was given
310 if (playerThatChangedWeather > 0)
311 {
312 if (!setLooping)
313 {
314 SCR_NotificationsComponent.SendToUnlimitedEditorPlayers(ENotification.EDITOR_ATTRIBUTES_WEATHER_AUTO, playerThatChangedWeather);
315 }
316 else
317 {
318 BaseGameMode gameMode = GetGame().GetGameMode();
319 if (gameMode)
320 {
321 SCR_NotificationSenderComponent notificationSender = SCR_NotificationSenderComponent.Cast(gameMode.FindComponent(SCR_NotificationSenderComponent));
322
323 if (notificationSender)
324 notificationSender.OnWeatherChangedNotification(playerThatChangedWeather);
325 }
326 }
327 }
328 }
329
330 //------------------------------------------------------------------------------------------------
333 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
334 protected void UpdateWeatherLooping(bool isLooping)
335 {
336 m_bWeatherIsLooping = isLooping;
337 }
338
339 //------------------------------------------------------------------------------------------------
344 {
345 return m_bWeatherIsLooping;
346 }
347
348 //------------------------------------------------------------------------------------------------
352 {
353 int day, month, year;
354 GetDate(year, month, day);
356 }
357
358 //------------------------------------------------------------------------------------------------
367 SCR_MoonPhaseUIInfo GetMoonPhaseInfoForDate(int year, int month, int day, float timeOfTheDay24, float timezone, float dstOffset, float Latitude)
368 {
369 if (m_aMoonPhasesInfo.IsEmpty())
370 {
371 Print("Could not get moon phase name as m_aMoonPhasesInfo is empty!", LogLevel.ERROR);
372 return null;
373 }
374
375 float moonPhaseAmount = GetMoonPhaseForDate(year, month, day, timeOfTheDay24, timezone, dstOffset);
376
377 int nextPhaseYearCheck = year;
378 int nextPhaseMonthCheck = month;
379 int nextPhaseDayCheck = day + 1;
380
381 //Calculate if the next day is a valid date
382 if (!CheckValidDate(nextPhaseYearCheck, nextPhaseMonthCheck, nextPhaseDayCheck))
383 {
384 if (nextPhaseMonthCheck != 12)
385 {
386 nextPhaseMonthCheck += 1;
387 }
388 else
389 {
390 nextPhaseMonthCheck = 1;
391 nextPhaseYearCheck += 1;
392 }
393
394 nextPhaseDayCheck = 1;
395 }
396
397 //Check the next days moon phase
398 float nextPhaseAmount = GetMoonPhaseForDate(nextPhaseYearCheck, nextPhaseMonthCheck, nextPhaseDayCheck, timeOfTheDay24, timezone, dstOffset);
399 EMoonPhaseEnums beforeOrAfterFullMoon;
400
401 //Check if current moonphase is before or after full moon by checking if next days moonphase amount is higher or lower then current moon phase amount
402 if (nextPhaseAmount > moonPhaseAmount)
403 beforeOrAfterFullMoon = EMoonPhaseEnums.BEFORE_FULL_MOON;
404 else
405 beforeOrAfterFullMoon = EMoonPhaseEnums.AFTER_FULL_MOON;
406
407 int count = m_aMoonPhasesInfo.Count();
408
409 SCR_MoonPhaseUIInfo uiInfo;
410
411 for(int i = 0; i < count; i++)
412 {
413 if (i == count -1)
414 {
415 uiInfo = m_aMoonPhasesInfo[i].GetUIInfo();
416 break;
417 }
418
419 if (m_aMoonPhasesInfo[i].IsMoonPhase(moonPhaseAmount, beforeOrAfterFullMoon))
420 {
421 uiInfo = m_aMoonPhasesInfo[i].GetUIInfo();
422 break;
423 }
424
425 }
426
427 if (uiInfo)
428 uiInfo.SetMoonphaseImageRotation(Latitude >= 0);
429
430 return uiInfo;
431 }
432
433 //------------------------------------------------------------------------------------------------
434 // Sets the current weather.
435 // Only issuable by the authority.
436 // Automatically broadcast to all clients.
437 // \param hours Current weather as a normalized value <0.0, 1.0>
438 // \param immediateChange Whether change should be applied immediately, forcing recomputation. This should be true only in case of editor and similar items.
439 // \return Returns true when command is issued successfully, false otherwise.
440 //proto native bool SetCurrentWeather(float weather01, bool immediateChange = false);
441
442 //------------------------------------------------------------------------------------------------
443 // Retrieves the current weather.
444 // \return Current weather as a normalized value <0.0, 1.0>
445 //proto native float GetCurrentWeather();
446
447 //------------------------------------------------------------------------------------------------
448 // Sets the current preset.
449 // Only issuable by the authority.
450 // Automatically broadcast to all clients.
451 // \param hours Current preset as a normalized value <0.0, 1.0>
452 // \param immediateChange Whether change should be applied immediately, forcing recomputation. This should be true only in case of editor and similar items.
453 // \return Returns true when command is issued successfully, false otherwise.
454 //proto native bool SetCurrentPreset(float preset01, bool immediateChange = false);
455
456 //------------------------------------------------------------------------------------------------
457 // Retrieves the current preset.
458 // \return Current preset as a normalized value <0.0, 1.0>
459 // proto native float GetCurrentPreset();
460
461
462 //------------------------------------------------------------------------------------------------
466 {
467 ref TimeContainer cont = new TimeContainer();
468 GetHoursMinutesSeconds(cont.m_iHours, cont.m_iMinutes, cont.m_iSeconds);
469 return cont;
470 }
471
472 //------------------------------------------------------------------------------------------------
477 protected void CreateDayTimeInfoArray(int year = -1, int month = -1, int day = -1)
478 {
479 foreach (SCR_DayTimeInfoBase dayTimeInfo: m_aOrderedDaytimeInfo)
480 dayTimeInfo.Clear();
481
482 foreach (SCR_DayTimeInfoBase dayTimeInfo: m_aOrderedDaytimeInfo)
483 dayTimeInfo.SetDayTime(m_aOrderedDaytimeInfo, this, year, month, day);
484 }
485
486 //------------------------------------------------------------------------------------------------
491 {
493 return GetDayTimeUIInfo(GetTimeOfTheDay(), uiInfo);
494 }
495
496 //------------------------------------------------------------------------------------------------
501 {
503 EDayTimeEnums dayTimePhase;
504 return GetDayTimeUIInfo(GetTimeOfTheDay(), uiInfo, dayTimePhase);
505 }
506
507 //------------------------------------------------------------------------------------------------
516 int GetDayTimeUIInfo(float TimeOfDay, out SCR_UIInfo uiInfo, out EDayTimeEnums dayTimePhase = -1, int year = -1, int month = -1, int day = -1)
517 {
518 CreateDayTimeInfoArray(year, month, day);
519
520 int count = m_aOrderedDaytimeInfo.Count();
521
522 //If before early morning but after midnight
523 if (TimeOfDay < m_aOrderedDaytimeInfo[0].GetDayTime())
524 {
525 uiInfo = m_aOrderedDaytimeInfo[count -1].GetDayTimeUIInfo();
526 dayTimePhase = m_aOrderedDaytimeInfo[count -1].GetDaytimeEnum();
527 return count -1;
528 }
529
530 for (int i = 0; i < count -1; i++)
531 {
532 if (TimeOfDay > m_aOrderedDaytimeInfo[i].GetDayTime() && TimeOfDay < m_aOrderedDaytimeInfo[i +1].GetDayTime())
533 {
534 uiInfo = m_aOrderedDaytimeInfo[i].GetDayTimeUIInfo();
535 dayTimePhase = m_aOrderedDaytimeInfo[i].GetDaytimeEnum();
536 return i;
537 }
538 }
539
540 //Just before Midnight
541 uiInfo = m_aOrderedDaytimeInfo[count -2].GetDayTimeUIInfo();
542 dayTimePhase = m_aOrderedDaytimeInfo[count -2].GetDaytimeEnum();
543 return count -2;
544 }
545
546 //------------------------------------------------------------------------------------------------
553 int GetDayTimeInfoArray(out notnull array<SCR_DayTimeInfoBase> dayTimeInfoArray, int year = -1, int month = -1, int day = -1)
554 {
555 CreateDayTimeInfoArray(year, month, day);
556
557 dayTimeInfoArray.Clear();
558
560 dayTimeInfoArray.Insert(info);
561
562 return dayTimeInfoArray.Count();
563 }
564
570
571 //------------------------------------------------------------------------------------------------
574 int GetOrderedWindDirectionInfoArray(notnull array<SCR_WindDirectionInfo> orderedWindDirectionInfo)
575 {
577 orderedWindDirectionInfo.Insert(windInfo);
578
579 return m_OrderedWindDirectionInfo.Count();
580 }
581
588
589 //------------------------------------------------------------------------------------------------
594 {
596 return false;
597
598 windDirectionInfo = m_OrderedWindDirectionInfo[index];
599 return true;
600 }
601
609
610 //------------------------------------------------------------------------------------------------
615 bool GetWindDirectionInfoFromFloat(float windDirectionFloat, out int index, out SCR_WindDirectionInfo windDirectionInfo)
616 {
617 if (m_OrderedWindDirectionInfo.IsEmpty() || m_OrderedWindDirectionInfo.Count() < 2)
618 return false;
619
620 int count = m_OrderedWindDirectionInfo.Count();
621 float checkRange = (m_OrderedWindDirectionInfo[1].GetWindDirectionValue() - m_OrderedWindDirectionInfo[0].GetWindDirectionValue()) / 2;
622
623 for (int i = 0; i < count; i++)
624 {
625 float firstCheck = m_OrderedWindDirectionInfo[i].GetWindDirectionValue() - checkRange;
626 float secondCheck = m_OrderedWindDirectionInfo[i].GetWindDirectionValue() + checkRange;
627
628 if (firstCheck < 0)
629 {
630 firstCheck = firstCheck + 360;
631 if ((windDirectionFloat <= m_OrderedWindDirectionInfo[i].GetWindDirectionValue() || windDirectionFloat >= firstCheck) || (windDirectionFloat < secondCheck))
632 {
633 index = i;
634 windDirectionInfo = m_OrderedWindDirectionInfo[i];
635 return true;
636 }
637
638 }
639 else if (secondCheck > 360)
640 {
641 secondCheck = secondCheck - 360;
642 if ((windDirectionFloat >= firstCheck) && (windDirectionFloat > m_OrderedWindDirectionInfo[i].GetWindDirectionValue() || windDirectionFloat <= secondCheck))
643 {
644 index = i;
645 windDirectionInfo = m_OrderedWindDirectionInfo[i];
646 return true;
647 }
648 }
649 else
650 {
651 if (windDirectionFloat >= firstCheck && windDirectionFloat < secondCheck)
652 {
653 index = i;
654 windDirectionInfo = m_OrderedWindDirectionInfo[i];
655 return true;
656 }
657 }
658 }
659 return false;
660 }
661
667
668 //------------------------------------------------------------------------------------------------
672 void DelayedSetWindOverride(bool overrideWind, int playerChangingWind = -1)
673 {
674 m_bDelayedWindOverride = overrideWind;
675
676 if (playerChangingWind > -1)
677 m_iDelayedPlayerChangingWind = playerChangingWind;
678
680 }
681
687
688 //------------------------------------------------------------------------------------------------
692 void DelayedOverrideWindSpeed(float windSpeed, int playerChangingWind = -1)
693 {
694 m_fDelayedWindSpeedOverride = windSpeed;
695
696 if (playerChangingWind > -1)
697 m_iDelayedPlayerChangingWind = playerChangingWind;
698
700 }
701
707
708 //------------------------------------------------------------------------------------------------
712 void DelayedOverrideWindDirection(float windDirection, int playerChangingWind = -1)
713 {
714 m_fDelayedWindDirectionOverride = windDirection;
715
716 if (playerChangingWind > -1)
717 m_iDelayedPlayerChangingWind = playerChangingWind;
718
720 }
721
722 //Start listening to the frame delay to execute all wind changed in one go
724 {
726 return;
727
729 GetGame().GetCallqueue().CallLater(DelayedApplyWindOverride, 1);
730 }
731
732 //------------------------------------------------------------------------------------------------
736 {
737 //Set wind to auto
739 {
742 }
743 //Override wind
744 else
745 {
748
750
753
755 }
756
757 int changingPlayerId = m_iDelayedPlayerChangingWind;
760 Rpc(RpcDo_OnWindDataUpdated, m_bDelayedWindOverride, changingPlayerId);
761 }
762
763 //------------------------------------------------------------------------------------------------
764 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
765 protected void RpcDo_OnWindDataUpdated(bool currentState, int changingPlayerId)
766 {
767 float speed = GetWindSpeed();
768 float direction = GetWindDirection();
769 m_bDelayedWindOverride = currentState;
772
773 if (changingPlayerId < 0)
774 return;
775
777 {
778 int windDirectionIndex;
779 GetWindDirectionInfoFromFloat(direction, windDirectionIndex, null);
780 SCR_NotificationsComponent.SendLocalUnlimitedEditor(ENotification.EDITOR_ATTRIBUTES_WIND_CHANGED, changingPlayerId, speed * 1000, windDirectionIndex);
781 }
782 else
783 {
784 SCR_NotificationsComponent.SendLocalUnlimitedEditor(ENotification.EDITOR_ATTRIBUTES_WIND_DEFAULT, changingPlayerId);
785 }
786 }
787
788 //------------------------------------------------------------------------------------------------
798
805
806 //------------------------------------------------------------------------------------------------
810 {
811 return SetHoursMinutesSeconds(cont.m_iHours, cont.m_iMinutes, cont.m_iSeconds);
812 }
813
814 //------------------------------------------------------------------------------------------------
818
819 //------------------------------------------------------------------------------------------------
821 ScriptInvokerBase<SCR_TimeAndWeatherManager_OnWeatherStatePreview> GetOnWeatherStatePreview()
822 {
824 m_OnWeatherStatePreview = new ScriptInvokerBase<SCR_TimeAndWeatherManager_OnWeatherStatePreview>();
825
827 }
828
829 //------------------------------------------------------------------------------------------------
831 ScriptInvokerBase<SCR_TimeAndWeatherManager_OnWindPreview> GetOnWindPreview()
832 {
833 if (!m_OnWindPreview)
834 m_OnWindPreview = new ScriptInvokerBase<SCR_TimeAndWeatherManager_OnWindPreview>();
835
836 return m_OnWindPreview;
837 }
838
839 //------------------------------------------------------------------------------------------------
843
844 //------------------------------------------------------------------------------------------------
846 ScriptInvokerBase<SCR_TimeAndWeatherManager_OnDateTimePreview> GetOnDateTimePreview()
847 {
849 m_OnDateTimePreview = new ScriptInvokerBase<SCR_TimeAndWeatherManager_OnDateTimePreview>();
850
851 return m_OnDateTimePreview;
852 }
853
854 //======================================== RPL ========================================\\
855
856 //------------------------------------------------------------------------------------------------
857 override bool RplSave(ScriptBitWriter writer)
858 {
859 writer.WriteBool(m_bWeatherIsLooping);
860 return true;
861 }
862
863 //------------------------------------------------------------------------------------------------
864 override bool RplLoad(ScriptBitReader reader)
865 {
866 int isLooping;
867
868 reader.ReadBool(isLooping);
869
870
871 UpdateWeatherLooping(isLooping);
872
873 return true;
874 }
875
886 //proto native bool SetWeatherState(string stateName, bool setToStartVariant = true);
887
896 //proto native bool SetWeatherVariant(string variantName);
897
903 //proto native bool SetWeatherStateAndVariant(string stateName, string variantName);
904
912 //proto native WeatherTransitionRequestResponse RequestWeatherStateTransition(string stateName, float durationHrs = 0);
913
921 //proto native WeatherTransitionRequestResponse RequestWeatherVariantTransition(string variantName, float durationHrs = 0);
922}
923
925class TimeContainer
926{
928 int m_iHours;
933
941
942 //------------------------------------------------------------------------------------------------
943 // constructor
947 void TimeContainer(int hours = 0, int minutes = 0, int seconds = 0)
948 {
949 m_iHours = hours;
950 m_iMinutes = minutes;
951 m_iSeconds = seconds;
952 }
953
954 /*
955 Creates new time container from hours, minutes and seconds.
956 */
957
958 //------------------------------------------------------------------------------------------------
964 static TimeContainer FromHoursMinutesSeconds(int hours, int minutes, int seconds)
965 {
966 return new TimeContainer(hours, minutes, seconds);
967 }
968
969 /*
970 Creates new time container from time of the day <0.0, 0.24>
971 */
972
973 //------------------------------------------------------------------------------------------------
977 static TimeContainer FromTimeOfTheDay(float hours24)
978 {
979 int h, m, s;
980 TimeAndWeatherManagerEntity.TimeToHoursMinutesSeconds(hours24, h, m, s);
981 return new TimeContainer(h, m, s);
982 }
983
984 /*
985 Converts the content of this container into in-game time as a fraction of day <0.0, 0.24>.
986 */
987
988 //------------------------------------------------------------------------------------------------
992 {
993 return TimeAndWeatherManagerEntity.HoursMinutesSecondsToTime(m_iHours, m_iMinutes, m_iSeconds);
994 }
995}
996
997[BaseContainerProps(), SCR_BaseContainerCustomTitleEnum(EDayTimeEnums, "m_dayTimeEnum")]
999{
1000 [Attribute("0", UIWidgets.ComboBox, "Day Time Enum", "", ParamEnumArray.FromEnum(EDayTimeEnums))]
1001 protected EDayTimeEnums m_DayTimeEnum;
1002
1003 [Attribute()]
1004 protected ref SCR_UIInfo m_UIInfo;
1005
1006 protected float m_fTimeOfDay = -1;
1007
1008 //------------------------------------------------------------------------------------------------
1012 {
1013 return m_UIInfo;
1014 }
1015
1016 //------------------------------------------------------------------------------------------------
1019 EDayTimeEnums GetDaytimeEnum()
1020 {
1021 return m_DayTimeEnum;
1022 }
1023
1024 //------------------------------------------------------------------------------------------------
1028 {
1029 return m_fTimeOfDay;
1030 }
1031
1032 //------------------------------------------------------------------------------------------------
1034 void Clear()
1035 {
1036 m_fTimeOfDay = -1;
1037 }
1038
1039 //------------------------------------------------------------------------------------------------
1043 float GetDayTime(notnull array<ref SCR_DayTimeInfoBase> daytimeInfo, TimeAndWeatherManagerEntity timeAndWeatherEntity)
1044 {
1045 if (m_fTimeOfDay < 0)
1046 SetDayTime(daytimeInfo, timeAndWeatherEntity);
1047
1048 return m_fTimeOfDay;
1049 }
1050
1051 //------------------------------------------------------------------------------------------------
1058 void SetDayTime(notnull array<ref SCR_DayTimeInfoBase> daytimeInfo, TimeAndWeatherManagerEntity timeAndWeatherEntity, int year = -1, int month = -1, int day = -1)
1059 {
1060 Print(string.Format("%1 Uses the SCR_DayTimeInfoBase use one of the inherited classes instead!", typename.EnumToString(EDayTimeEnums, m_DayTimeEnum)), LogLevel.WARNING);
1061 }
1062}
1063
1064[BaseContainerProps(), SCR_BaseContainerCustomTitleEnum(EDayTimeEnums, "m_dayTimeEnum")]
1065class SCR_DayTimeInfoStatic: SCR_DayTimeInfoBase
1066{
1067 [Attribute(desc: "Hour which this daytime starts, is a value of 0 to 24.0")]
1068 protected int m_iHour;
1069
1070 //------------------------------------------------------------------------------------------------
1071 override void SetDayTime(notnull array<ref SCR_DayTimeInfoBase> daytimeInfo, TimeAndWeatherManagerEntity timeAndWeatherEntity, int year = -1, int month = -1, int day = -1)
1072 {
1073 if (m_fTimeOfDay > -1)
1074 return;
1075
1076 m_fTimeOfDay = m_iHour;
1077 }
1078}
1079
1080[BaseContainerProps(), SCR_BaseContainerCustomTitleEnum(EDayTimeEnums, "m_dayTimeEnum")]
1082{
1083 //------------------------------------------------------------------------------------------------
1084 override void SetDayTime(notnull array<ref SCR_DayTimeInfoBase> daytimeInfo, TimeAndWeatherManagerEntity timeAndWeatherEntity, int year = -1, int month = -1, int day = -1)
1085 {
1086 if (m_fTimeOfDay > -1)
1087 return;
1088
1089 if (year < 0)
1090 {
1091 timeAndWeatherEntity.GetDate(year, month, day);
1092 }
1093
1094 bool hasSunSetandRise;
1095
1096 switch (m_DayTimeEnum)
1097 {
1098 //~Todo: Needs to get sunset/sun rise of given date
1099 case EDayTimeEnums.DAYTIME_DAWN:
1100 {
1101 hasSunSetandRise = timeAndWeatherEntity.GetSunriseHourForDate(year, month, day, timeAndWeatherEntity.GetCurrentLatitude(), timeAndWeatherEntity.GetCurrentLongitude(), timeAndWeatherEntity.GetTimeZoneOffset(), timeAndWeatherEntity.GetDSTOffset(), m_fTimeOfDay);
1102
1103 //If has no sun rise
1104 if (!hasSunSetandRise)
1105 m_fTimeOfDay = 5;
1106
1107 return;
1108 }
1109 //~Todo: Get sunset time
1110 case EDayTimeEnums.DAYTIME_DUSK:
1111 {
1112 hasSunSetandRise = timeAndWeatherEntity.GetSunsetHourForDate(year, month, day, timeAndWeatherEntity.GetCurrentLatitude(), timeAndWeatherEntity.GetCurrentLongitude(), timeAndWeatherEntity.GetTimeZoneOffset(), timeAndWeatherEntity.GetDSTOffset(), m_fTimeOfDay);
1113
1114 //If has no sun set
1115 if (!hasSunSetandRise)
1116 m_fTimeOfDay = 19;
1117
1118 return;
1119 }
1120 }
1121
1122 Print(string.Format("%1 is not supported with autoTime!", typename.EnumToString(EDayTimeEnums, m_DayTimeEnum)), LogLevel.WARNING);
1123 }
1124}
1125
1126[BaseContainerProps(), SCR_BaseContainerCustomTitleEnum(EDayTimeEnums, "m_dayTimeEnum")]
1127class SCR_DayTimeInfoBetween: SCR_DayTimeInfoBase
1128{
1129 [Attribute("0", UIWidgets.ComboBox, "Day Time X", "", ParamEnumArray.FromEnum(EDayTimeEnums))]
1130 protected EDayTimeEnums m_DaytimeAfter;
1131
1132 [Attribute("0", UIWidgets.ComboBox, "Day Time Y", "", ParamEnumArray.FromEnum(EDayTimeEnums))]
1133 protected EDayTimeEnums m_DaytimeBefore;
1134
1135 //------------------------------------------------------------------------------------------------
1136 override void SetDayTime(notnull array<ref SCR_DayTimeInfoBase> daytimeInfo, TimeAndWeatherManagerEntity timeAndWeatherEntity, int year = -1, int month = -1, int day = -1)
1137 {
1138 if (m_DayTimeEnum == m_DaytimeAfter || m_DayTimeEnum == m_DaytimeBefore)
1139 {
1140 Print(string.Format("SCR_DayTimeInfoBetween %1 has a reference to itself!", typename.EnumToString(EDayTimeEnums, m_DayTimeEnum)), LogLevel.WARNING);
1141 return;
1142 }
1143
1144 if (m_fTimeOfDay > -1)
1145 return;
1146
1147 float dayTimeAfterSeconds, DayTimeBeforeSeconds;
1148 bool dayTimeAfterSet = false;
1149 bool dayTimeBeforeSet = false;
1150
1151 foreach (SCR_DayTimeInfoBase daytime: daytimeInfo)
1152 {
1153 if (daytime.GetDaytimeEnum() == m_DaytimeAfter)
1154 {
1155 dayTimeAfterSeconds = daytime.GetDayTime(daytimeInfo, timeAndWeatherEntity);
1156 dayTimeAfterSet = true;
1157
1158 if (dayTimeAfterSeconds == 24)
1159 dayTimeAfterSeconds = 0;
1160
1161 if (dayTimeAfterSet && dayTimeBeforeSet)
1162 break;
1163 }
1164 else if (daytime.GetDaytimeEnum() == m_DaytimeBefore)
1165 {
1166 DayTimeBeforeSeconds = daytime.GetDayTime(daytimeInfo, timeAndWeatherEntity);
1167 dayTimeBeforeSet = true;
1168
1169 if (DayTimeBeforeSeconds == 0)
1170 DayTimeBeforeSeconds = 24;
1171
1172 if (dayTimeAfterSet && dayTimeBeforeSet)
1173 break;
1174 }
1175 }
1176
1177 if (dayTimeAfterSeconds < 0 || !dayTimeAfterSet)
1178 {
1179 Print(string.Format("Could not set %1 as %2 daytime after was not correctly found! This might be because %2 is also depened on %1 or that it doesn't exist in the array!", typename.EnumToString(EDayTimeEnums, m_DayTimeEnum), typename.EnumToString(EDayTimeEnums, m_DaytimeAfter)), LogLevel.WARNING);
1180 m_fTimeOfDay = 0;
1181 return;
1182 }
1183
1184 if (DayTimeBeforeSeconds < 0 || !dayTimeBeforeSet)
1185 {
1186 Print(string.Format("Could not set %1 as %2 daytime before was not correctly found! This might be because %2 is also depened on %1 or that it doesn't exist in the array!", typename.EnumToString(EDayTimeEnums, m_DayTimeEnum), typename.EnumToString(EDayTimeEnums, m_DaytimeBefore)), LogLevel.WARNING);
1187 m_fTimeOfDay = 0;
1188 return;
1189 }
1190
1191 m_fTimeOfDay = (dayTimeAfterSeconds + DayTimeBeforeSeconds) / 2;
1192 }
1193}
1194
1197{
1198 [Attribute()]
1199 ref SCR_UIInfo m_UIInfo;
1200
1201 [Attribute()]
1202 protected int m_iWindDirection;
1203
1204 //------------------------------------------------------------------------------------------------
1207 {
1208 return m_UIInfo;
1209 }
1210
1211 //------------------------------------------------------------------------------------------------
1214 {
1215 return m_iWindDirection;
1216 }
1217}
1218
1220class SCR_MoonPhaseInfo
1221{
1222 [Attribute()]
1224
1225 [Attribute(desc: "IsMoonPhase will return true if moonPhaseAmount is equal or greater then m_fPhaseEqualOrGreater and less then m_fPhaseLessThen")]
1226 protected float m_fPhaseEqualOrGreater;
1227
1228 [Attribute(desc: "IsMoonPhase will return true if moonPhaseAmount is equal or greater then m_fPhaseEqualOrGreater and less then m_fPhaseLessThen")]
1229 protected float m_fPhaseLessThen;
1230
1234 [Attribute("0", UIWidgets.ComboBox, "Before Or AfterFull Moon", "", ParamEnumArray.FromEnum(EMoonPhaseEnums))]
1235 protected EMoonPhaseEnums m_iBeforeOrAfterFullMoon;
1236
1237 //------------------------------------------------------------------------------------------------
1240 {
1241 return m_UIInfo;
1242 }
1243
1244 //------------------------------------------------------------------------------------------------
1248 bool IsMoonPhase(float moonPhaseAmount, EMoonPhaseEnums beforeOrAfterFullMoon)
1249 {
1250 if (m_iBeforeOrAfterFullMoon != EMoonPhaseEnums.IGNORE && beforeOrAfterFullMoon != EMoonPhaseEnums.IGNORE)
1251 {
1252 if (m_iBeforeOrAfterFullMoon != beforeOrAfterFullMoon)
1253 return false;
1254 }
1255
1256 return moonPhaseAmount >= m_fPhaseEqualOrGreater && moonPhaseAmount < m_fPhaseLessThen;
1257 }
1258}
1259
1266
1267enum EDayTimeEnums
1268{
1274 DAYTIME_NIGHT
1275}
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
vector direction
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_WristwatchComponentClass m_iSeconds
func SCR_TimeAndWeatherManager_OnWeatherStatePreview
enum EMoonPhaseEnums DAYTIME_DAWN
enum EMoonPhaseEnums DAYTIME_AFTERNOON
float ToTimeOfTheDay()
ScriptInvokerBase< ScriptInvokerOnWeatherChangedMethod > ScriptInvokerOnWeatherChanged
SCR_UIInfo GetDayTimeUIInfo()
ScriptInvokerBase< ScriptInvokerOnWindOverrideDataChangedMethod > ScriptInvokerOnWindOverrideDataChanged
float m_fTimeOfDay
EDayTimeEnums m_DayTimeEnum
enum EMoonPhaseEnums DAYTIME_EVENING
func ScriptInvokerOnWindOverrideDataChangedMethod
func ScriptInvokerOnWeatherChangedMethod
int GetWindDirectionValue()
class SCR_WindDirectionInfo SCR_BaseContainerCustomTitleUIInfo("m_UIInfo")
class SCR_DayTimeInfoBase BaseContainerProps()
void TimeContainer(int hours=0, int minutes=0, int seconds=0)
class SCR_DayTimeInfoBase SCR_BaseContainerCustomTitleEnum(EDayTimeEnums, "m_dayTimeEnum")
enum EMoonPhaseEnums DAYTIME_DUSK
func SCR_TimeAndWeatherManager_OnWindPreview
enum EMoonPhaseEnums DAYTIME_MORNING
float GetDayTime()
func SCR_TimeAndWeatherManager_OnDateTimePreview
Main replication API.
Definition Replication.c:14
void SetDayTime(notnull array< ref SCR_DayTimeInfoBase > daytimeInfo, TimeAndWeatherManagerEntity timeAndWeatherEntity, int year=-1, int month=-1, int day=-1)
float GetDayTime(notnull array< ref SCR_DayTimeInfoBase > daytimeInfo, TimeAndWeatherManagerEntity timeAndWeatherEntity)
static RplComponent GetEntityRplComponent(notnull IEntity entity)
void SetMoonphaseImageRotation(bool northernHemisphere)
void ForceWeatherTo(bool setLooping, string weatherID=string.Empty, float transitionDuration=0, float stateDuration=0.001, int playerThatChangedWeather=0)
SCR_MoonPhaseUIInfo GetCurrentMoonPhaseInfoForDate()
bool SetWindPreview(bool preview, float windSpeed=-1, float windAngleDegrees=-1)
string GetWeekDayStringForDate(int year, int month, int day)
bool SetWeatherStatePreview(bool preview, string stateName="")
bool GetWindDirectionInfoFromIndex(int index, out SCR_WindDirectionInfo windDirectionInfo)
ScriptInvokerBase< SCR_TimeAndWeatherManager_OnWindPreview > GetOnWindPreview()
ScriptInvokerOnWeatherChanged GetOnWeatherChanged()
int GetCurrentDayTimeUIInfo(out SCR_UIInfo uiInfo)
void OnWeatherChanged_S(bool transitioning=true)
void CreateDayTimeInfoArray(int year=-1, int month=-1, int day=-1)
ref array< ref SCR_WindDirectionInfo > m_OrderedWindDirectionInfo
ref ScriptInvokerBase< SCR_TimeAndWeatherManager_OnWindPreview > m_OnWindPreview
bool IsAutomatedWindDisabled()
Proxies should use this instead of IsWindDirectionOverridden and IsWindSpeedOverridden as for them wi...
int GetOrderedWindDirectionInfoArray(notnull array< SCR_WindDirectionInfo > orderedWindDirectionInfo)
ref ScriptInvokerOnWeatherChanged m_OnWeatherChanged
void RpcDo_OnWindDataUpdated(bool currentState, int changingPlayerId)
void ClearDelayedWindOverrideVars()
Reset all changed wind variables.
ref array< ref SCR_MoonPhaseInfo > m_aMoonPhasesInfo
bool SetDateTimePreview(bool preview, int year=-1, int month=-1, int day=-1, float timeOfTheDay=-1)
int GetDayTimeUIInfo(float TimeOfDay, out SCR_UIInfo uiInfo, out EDayTimeEnums dayTimePhase=-1, int year=-1, int month=-1, int day=-1)
ref array< ref SCR_DayTimeInfoBase > m_aOrderedDaytimeInfo
ScriptInvokerBase< SCR_TimeAndWeatherManager_OnWeatherStatePreview > GetOnWeatherStatePreview()
ScriptInvokerOnWindOverrideDataChanged GetOnWindOverrideDataChanged()
ref ScriptInvokerBase< SCR_TimeAndWeatherManager_OnWeatherStatePreview > m_OnWeatherStatePreview
void RpcDo_OnWeatherChanged(int currentStateId, int nextStateId, bool transitioning)
ref ScriptInvokerBase< SCR_TimeAndWeatherManager_OnDateTimePreview > m_OnDateTimePreview
override bool RplSave(ScriptBitWriter writer)
ref ScriptInvokerOnWindOverrideDataChanged m_OnWindOverrideDataChanged
void DelayedSetWindOverride(bool overrideWind, int playerChangingWind=-1)
ScriptInvokerBase< SCR_TimeAndWeatherManager_OnDateTimePreview > GetOnDateTimePreview()
SCR_MoonPhaseUIInfo GetMoonPhaseInfoForDate(int year, int month, int day, float timeOfTheDay24, float timezone, float dstOffset, float Latitude)
bool GetWindDirectionInfoFromFloat(float windDirectionFloat, out int index, out SCR_WindDirectionInfo windDirectionInfo)
override bool RplLoad(ScriptBitReader reader)
int GetDayTimeInfoArray(out notnull array< SCR_DayTimeInfoBase > dayTimeInfoArray, int year=-1, int month=-1, int day=-1)
void DelayedOverrideWindSpeed(float windSpeed, int playerChangingWind=-1)
EDayTimeEnums GetCurrentDayTimeUIInfoAndPhase(out SCR_UIInfo uiInfo)
void DelayedOverrideWindDirection(float windDirection, int playerChangingWind=-1)
void SetCurrentWeatherLooping(bool setLooping, int playerChangedLooping=0)
ref array< LocalizedString > m_aOrderedDaysOfWeek
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
proto external bool CheckValidDate(int year, int month, int day)
proto external int GetWeekDayForDate(int year, int month, int day)
proto external bool SetWindDirectionOverride(bool doOverride, float windDirection=0)
proto float GetMoonPhaseForDate(int year, int month, int day, float timeOfTheDay24, float timezone, float dstOffset)
BaseWeatherManagerEntityClass GenericEntityClass GetCurrentWeatherState()
proto external float GetDSTOffset()
proto external bool SetHoursMinutesSeconds(int hours, int minutes, int seconds, bool immediateChange=false)
proto BaseWeatherStateTransitionManager GetTransitionManager()
proto external float GetTimeZoneOffset()
proto external float GetWindDirection()
proto external int GetWeekDay()
proto external float GetTimeOfTheDay()
proto void GetDate(out int year, out int month, out int day)
proto bool GetSunriseHour(out float hour24)
proto void GetHoursMinutesSeconds(out int hours, out int minutes, out int seconds)
proto external bool SetWindSpeedOverride(bool doOverride, float windSpeed=0)
proto external float GetCurrentLatitude()
proto external bool IsWindDirectionOverridden()
proto bool GetSunsetHour(out float hour24)
proto external float GetWindSpeed()
proto external bool IsWindSpeedOverridden()
@ IGNORE
Ignore any parent and always create root record.
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14