DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
BunkerBroadcastScheduler.c
См. документацию.
2{
3 protected bool m_IsActivePeriod;
4 protected int m_BatchSelectionTimer;
5 protected bool m_BatchSelected;
6 protected int m_BatchLifetimeTimer;
7
10
12 protected BunkerBroadcastConfigInstance m_Config;
14
17
20
21 private bool m_ForceBroadcast;
22
24
26
28 {
29 if (!m_Instance)
31
32 return m_Instance;
33 }
34
36 {
37 m_Handler = handler;
38
43
45
47
49
50 if (m_PersitenceStorage.IsLoaded())
51 {
54 PrintToRPT("Difference in minutes: " + m_LastReportDifferenceMinutes);
55 // TODO@RR force broadcast on server restart if time condition passes
56 //if (m_LastReportDifferenceMinutes > THRESHOLD(time calculated from the overall period and number of broadcasts))
58 m_ForceBroadcast = true;
59 }
60 else
61 PrintToRPT(string.Format("storage does not exist - hour:%1 minute:%2", m_LastReportHour, m_LastReportMinute));
62
63 if (m_Handler)
64 m_Handler.GetOnActiveBunkersSelected().Insert(BatchSelected);
65 }
66
68 {
69 if (m_Handler)
70 m_Handler.GetOnActiveBunkersSelected().Remove(BatchSelected);
71 }
72
73 // --------------------------------------------------------------------------------
74
79
80 // --------------------------------------------------------------------------------
81
83 {
84 int year, month, day, hour, minute;
85 GetGame().GetWorld().GetDate(year, month, day, hour, minute);
86
87 // Convert to minutes from midnight for simpler comparisons
88 int now = hour * 60 + minute;
89
90 foreach (BunkerBroadcastPeriod period : m_Config.schedulerSettings.periods)
91 {
92 int start = period.GetStartHour() * 60 + period.GetStartMinute();
93 int end = period.GetEndHour() * 60 + period.GetEndMinute();
94
95 bool active = false;
96
97 if (start < end)
98 {
99 // Same-day range: [start, end]
100 active = (now >= start) && (now <= end);
101 }
102 else if (start > end)
103 {
104 // Wrap-around range: [start, 24h) U [0, end]
105 active = (now >= start) || (now <= end);
106 }
107 else
108 {
109 // start == end
110 // If minutes equal, interpret as full-day active; otherwise zero-length window (inactive)
111 active = true;
112 }
113
114 if (active)
115 {
116 m_IsActivePeriod = true;
117 return;
118 }
119 }
120
121 m_IsActivePeriod = false;
122 }
123
124 // --------------------------------------------------------------------------------
125
127 {
128 return m_IsActivePeriod;
129 }
130
131 // --------------------------------------------------------------------------------
132
133 void OnUpdate(float timeslice)
134 {
135 if (!m_IsActivePeriod)
136 {
137 m_BatchSelected = false;
138 return;
139 }
140
141 int timeTrackerDeltaMinutes;
142 m_WorldTimeTracker.TryPollDelta(timeslice, timeTrackerDeltaMinutes);
143 m_BatchLifetimeTimer += timeTrackerDeltaMinutes;
145 if (m_BatchLifetimeTimer >= m_Config.schedulerSettings.batchLifetimeLength)
146 {
147 m_BatchSelected = false;
150 }
151
153 if (!m_BatchSelected)
154 {
155 m_BatchSelectionTimer += timeTrackerDeltaMinutes;
157 if(m_BatchSelectionTimer >= 5)
158 {
159 #ifdef ENABLE_LOGGING
160 Log("Enforcing batch selection - inactivity");
161 #endif
164 }
165 }
166
167 if (m_ForceBroadcast || m_LastReportDifferenceMinutes >= m_Config.schedulerSettings.reportInterval)
168 {
171
172 m_ForceBroadcast = false;
173 }
174
176 }
177
178 // --------------------------------------------------------------------------------
179
180 private void SelectNewBunkers()
181 {
182 m_OnAskForNewBunkers.Invoke();
183 }
184
185 // --------------------------------------------------------------------------------
186
187 private void BatchSelected()
188 {
189 m_BatchSelected = true;
190 m_ActiveBunkers = m_Handler.GetActiveBunkers();
192
196 }
197
198 // --------------------------------------------------------------------------------
199
201 {
202 TStringArray results = new TStringArray();
204 {
205 TIntArray mapCoords = MapNavigationBehaviour.OrderedPositionNumbersFromGridCoords(active.GetPosition());
206 TIntArray xCoords = mapCoords.Slice(0, 2);
207 TIntArray yCoords = mapCoords.Slice(3, 5);
208 TStringArray xCoordsString = new TStringArray();
209 TStringArray yCoordsString = new TStringArray();
210 foreach(int ix : xCoords)
211 xCoordsString.Insert(ix.ToString());
212
213 foreach(int iy : yCoords)
214 yCoordsString.Insert(iy.ToString());
215
216 string mapCoordsConverted;
217 mapCoordsConverted = string.Join("", xCoordsString);
218 mapCoordsConverted += string.Join("", yCoordsString);
219 results.Insert(mapCoordsConverted);
220 results.Insert(active.GetLockCode());
221 }
222
223 return results;
224 }
225
226 // --------------------------------------------------------------------------------
227
228 private bool SendReport(TStringArray data, TStringArray morseData)
229 {
230 if (data.Count() == 0)
231 {
232 //#ifdef ENABLE_LOGGING
233 //Log("Nothing to report.");
234 //#endif
235 return false;
236 }
237
238 BunkerBroadcastManager bbm = GetGame().GetBunkerBroadcastManager();
239 if (bbm)
240 {
241 bbm.SetMessageSpeed(
242 m_Config.playbackSettings.dotDuration,
243 m_Config.playbackSettings.dashDuration,
244 m_Config.playbackSettings.symbolGapDuration,
245 m_Config.playbackSettings.wordGapDuration,
246 );
247 bbm.SetPauseBetweenBunkers(m_Config.playbackSettings.pauseBetweenBunkers);
248 bbm.SetBroadcastBunkerRepeatCount(m_Config.playbackSettings.bunkerRepetitions);
249 bbm.SetBroadcastTotalRepeatCount(m_Config.playbackSettings.messageRepetitions);
250
252
253 #ifdef ENABLE_LOGGING
254 Log("Reporting active bunkers:");
255 int i;
256 for (i = 0; i < data.Count(); i += 2)
257 {
258 Log(string.Format("position:%1 code:%2", data[i], data[i+1]), true);
259 }
260 for (i = 0; i < m_MorseOutputData.Count(); i += 2)
261 {
262 Log(string.Format("Morse position:%1 code:%2", m_MorseOutputData[i], m_MorseOutputData[i+1]), true);
263 }
264
265 Log("Report sent");
266 #endif
267
268 return true;
269 }
270
271 return false;
272 }
273
274 // --------------------------------------------------------------------------------
275
276 private void UpdatePersistentData()
277 {
278 int year, month, day, hour, minute;
279 g_Game.GetWorld().GetDate(year, month, day, hour, minute);
280
281 m_PersitenceStorage.m_SchedulerData.m_LastReportHour = hour;
282 m_PersitenceStorage.m_SchedulerData.m_LastReportMinute = minute;
283
284 TIntStringMap activeBunkerTempMap = new TIntStringMap();
285 m_PersitenceStorage.m_HandlerData.m_LastActiveBunkers.Clear();
287 {
288 activeBunkerTempMap.Insert(bunker.GetId(), bunker.GetLockCode());
289 }
290
291 m_PersitenceStorage.m_HandlerData.m_LastActiveBunkers.Copy(activeBunkerTempMap);
292 m_PersitenceStorage.Save();
293
294 m_LastReportHour = hour;
295 m_LastReportMinute = minute;
296
298 }
299
300 // --------------------------------------------------------------------------------
301
303 {
304 m_LastReportHour = m_PersitenceStorage.m_SchedulerData.m_LastReportHour;
305 m_LastReportMinute = m_PersitenceStorage.m_SchedulerData.m_LastReportMinute;
306 PrintToRPT(string.Format("storage loaded - hour:%1 minute:%2", m_LastReportHour, m_LastReportMinute));
307 }
308
309 // --------------------------------------------------------------------------------
310
312 {
313 int year, month, day, hour, minute;
314 GetGame().GetWorld().GetDate(year, month, day, hour, minute);
315
316 int prevTotalMinutes = m_LastReportHour * 60 + m_LastReportMinute;
317 int currTotalMinutes = hour * 60 + minute;
318
319 int minuteDiff = currTotalMinutes - prevTotalMinutes;
320
321 // Handle wrap-around (e.g., prev=23:55, curr=00:10 → +15m)
322 if (minuteDiff < -720) // -12 hours or more, must be a forward rollover
323 minuteDiff += 1440; // add 1 day
324 else if (minuteDiff > 720) // +12 hours or more, must be a backward rollover
325 minuteDiff -= 1440; // subtract 1 day
326
327 return minuteDiff;
328 }
329
330 #ifdef ENABLE_LOGGING
331 private static void Log(string message, bool indented = false)
332 {
333 #ifdef DIAG_DEVELOPER
335 #else
337 #endif
338 {
339 string indentation = "";
340 if (indented)
341 indentation = " \\__";
342
343 Debug.RadioGameplayLog(string.Format("%1 %2", indentation, message), m_Instance.ClassName(), "n/a", "n/a", "n/a");
344 }
345 }
346 #endif
347}
array< ref BunkerBroadcastComponentBase > BunkerComponentsArray
Определения BunkerBroadcastHandler.c:91
DayZGame g_Game
Определения DayZGame.c:4074
class LogTemplates Log(string message, LogTemplateID template_id=0)
Creates debug log (optional) from LogTemplate which are registred.
Определения LogTemplates.c:75
void MapNavigationBehaviour(PlayerBase pPlayer, EMapNavigationType pNavigationType=EMapNavigationType.BASIC)
Определения MapNavigationBehaviour.c:27
static ref RadialMenu m_Instance
Определения RadialMenu.c:55
proto native void SetBroadcastBunkerRepeatCount(int count)
proto native void SetPauseBetweenBunkers(float pause)
proto native void SetMessageSpeed(float dotDuration, float dashDuration, float symbolGap, float wordGap)
proto native void SetBroadcastTotalRepeatCount(int count)
proto native void BroadcastTextAsMorse(notnull array< string > inputs, notnull array< string > outputs)
static BunkerBroadcastPersistenceStorage GetInstance()
Определения BunkerBroadcastHandler.c:39
BunkerBroadcastHandler m_Handler
Определения BunkerBroadcastScheduler.c:11
ref WorldTimeTracker m_WorldTimeTracker
Определения BunkerBroadcastScheduler.c:25
ref ScriptInvoker m_OnAskForNewBunkers
Определения BunkerBroadcastScheduler.c:16
void ~BunkerBroadcastScheduler()
Определения BunkerBroadcastScheduler.c:67
void LoadLastReportTimeFromStorage()
Определения BunkerBroadcastScheduler.c:302
void OnUpdate(float timeslice)
Определения BunkerBroadcastScheduler.c:133
BunkerBroadcastConfigInstance m_Config
Определения BunkerBroadcastScheduler.c:12
ref TStringArray m_MorseOutputData
Определения BunkerBroadcastScheduler.c:9
int GetDifferenceFromLastReport()
Определения BunkerBroadcastScheduler.c:311
bool SendReport(TStringArray data, TStringArray morseData)
Определения BunkerBroadcastScheduler.c:228
int m_LastReportDifferenceMinutes
Определения BunkerBroadcastScheduler.c:19
void BunkerBroadcastScheduler(notnull BunkerBroadcastHandler handler)
Определения BunkerBroadcastScheduler.c:35
ref BunkerComponentsArray m_ActiveBunkers
Определения BunkerBroadcastScheduler.c:15
BunkerBroadcastPersistenceStorage m_PersitenceStorage
Определения BunkerBroadcastScheduler.c:13
ScriptInvoker GetOnAskForNewBunkers()
Определения BunkerBroadcastScheduler.c:75
static ref BunkerBroadcastScheduler m_Instance
Определения BunkerBroadcastScheduler.c:23
TStringArray PrepareReport()
Определения BunkerBroadcastScheduler.c:200
static BunkerBroadcastScheduler GetInstance(notnull BunkerBroadcastHandler handler)
Определения BunkerBroadcastScheduler.c:27
ref TStringArray m_ReportData
Определения BunkerBroadcastScheduler.c:8
static BunkerBroadcastConfigInstance GetData()
Определения CfgBunkerBroadcastHandler.c:46
static void RadioGameplayLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Определения 3_Game/DayZ/tools/Debug.c:267
Определения 3_Game/DayZ/tools/Debug.c:2
static bool IsRadioGameplayLogEnabled()
Определения 3_Game/DayZ/tools/Debug.c:844
TODO doc.
Определения EnScript.c:118
ScriptInvoker Class provide list of callbacks usage:
Определения 2_GameLib/DayZ/tools.c:116
DayZGame GetGame()
Определения gameplay.c:636
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
map< int, string > TIntStringMap
Определения EnScript.c:995
array< int > TIntArray
Определения EnScript.c:733
class array< Class T > TStringArray
proto void Insert(int index, string input)
Inserts a string into the n-th index, increasing the string length by the size of the input.
static string Join(string separator, notnull TStringArray tokens)
Определения EnString.c:424