Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CoverageRadioComponent.c
Go to the documentation of this file.
2{
3}
4
6class SCR_CoverageRadioComponent : ScriptedRadioComponent
7{
8 [Attribute("0", desc: "Source radio generates the radio signal. Should be limited to one per faction.", category: "Coverage")]
9 protected bool m_bIsSource;
10
11 protected bool m_bWasPowered = true;
12 protected bool m_bLastSignalSignature;
13 protected bool m_bCouldSend;
14 protected bool m_bCouldReceive;
15
16 protected float m_fSavedRange;
17
18 protected string m_sSavedEncryptionKey;
19
20 protected ref ScriptInvokerVoid m_OnCoverageChanged;
21
22 protected ref array<SCR_CoverageRadioComponent> m_aRadiosInRange = {};
23 protected ref array<SCR_CoverageRadioComponent> m_aInRangeOfRadios = {};
24
26
27 [RplProp(onRplName: "OnCoverageChanged")]
28 protected ref array<string> m_aEncryptionKeyCoverSend = {};
29
30 [RplProp(onRplName: "OnCoverageChanged")]
31 protected ref array<string> m_aEncryptionKeyCoverReceive = {};
32
33 //------------------------------------------------------------------------------------------------
34 void SetIsSource(bool isSource)
35 {
36 m_bIsSource = isSource;
37 }
38
39 //------------------------------------------------------------------------------------------------
40 bool IsSource()
41 {
42 return m_bIsSource;
43 }
44
45 //------------------------------------------------------------------------------------------------
47 {
48 return m_bWasPowered;
49 }
50
51 //------------------------------------------------------------------------------------------------
52 void PrepareCoverageUpdate(string encryptionKey, bool signature)
53 {
54 m_bCouldSend = m_aEncryptionKeyCoverSend.Contains(encryptionKey);
55 m_bCouldReceive = m_aEncryptionKeyCoverReceive.Contains(encryptionKey);
56
57 m_aEncryptionKeyCoverSend.RemoveItem(encryptionKey);
58 m_aEncryptionKeyCoverReceive.RemoveItem(encryptionKey);
59
60 m_bLastSignalSignature = signature;
61 }
62
63 //------------------------------------------------------------------------------------------------
64 void FinishCoverageUpdate(string encryptionKey)
65 {
66 bool canSend = m_aEncryptionKeyCoverSend.Contains(encryptionKey);
67 bool canReceive = m_aEncryptionKeyCoverReceive.Contains(encryptionKey);
68
69 if (canSend == m_bCouldSend && canReceive == m_bCouldReceive)
70 return;
71
72 Replication.BumpMe();
74 }
75
76 //------------------------------------------------------------------------------------------------
77 void GetRadiosInRange(notnull array<SCR_CoverageRadioComponent> radios)
78 {
79 radios.Copy(m_aRadiosInRange);
80 }
81
82 //------------------------------------------------------------------------------------------------
83 void GetRadiosInRangeOf(notnull array<SCR_CoverageRadioComponent> radios)
84 {
85 radios.Copy(m_aInRangeOfRadios);
86 }
87
88 //------------------------------------------------------------------------------------------------
90 // \param encryptionFilter When an encryption key is used, returns only radios with this encryption
91 int GetRadiosInRangeCount(string encryptionFilter = "")
92 {
93 if (encryptionFilter.IsEmpty())
94 {
95 return m_aRadiosInRange.Count();
96 }
97 else
98 {
99 int count;
100
101 foreach (SCR_CoverageRadioComponent radio : m_aRadiosInRange)
102 {
103 if (radio.GetEncryptionKey() == encryptionFilter)
104 count++;
105 }
106
107 return count;
108 }
109 }
110
111 //------------------------------------------------------------------------------------------------
113 // \param encryptionFilter When an encryption key is used, returns only radios with this encryption
114 int GetRadiosInRangeOfCount(string encryptionFilter = "")
115 {
116 if (encryptionFilter.IsEmpty())
117 {
118 return m_aInRangeOfRadios.Count();
119 }
120 else
121 {
122 int count;
123
124 foreach (SCR_CoverageRadioComponent radio : m_aInRangeOfRadios)
125 {
126 if (radio.GetEncryptionKey() == encryptionFilter)
127 count++;
128 }
129
130 return count;
131 }
132 }
133
134 //------------------------------------------------------------------------------------------------
136 // \param radio Radio we want to check for coverage
137 // \param inMyRange True = check if the given radio is covered by this radio, False = check if the given radio covers this radio
138 bool ConnectedRadiosContain(notnull SCR_CoverageRadioComponent radio, bool inMyRange)
139 {
140 if (inMyRange)
141 return m_aRadiosInRange.Contains(radio);
142 else
143 return m_aInRangeOfRadios.Contains(radio);
144 }
145
146 //------------------------------------------------------------------------------------------------
148 {
149 return m_fSavedRange;
150 }
151
152 //------------------------------------------------------------------------------------------------
154 {
155 return m_sSavedEncryptionKey;
156 }
157
158 //------------------------------------------------------------------------------------------------
159 SCR_ERadioCoverageStatus GetCoverageByEncryption(string encryptionKey)
160 {
161 return m_mCoverage.Get(encryptionKey);
162 }
163
164 //------------------------------------------------------------------------------------------------
165 void AddRadioInRange(notnull SCR_CoverageRadioComponent component)
166 {
167 if (m_aRadiosInRange.Contains(component))
168 return;
169
170 m_aRadiosInRange.Insert(component);
171 }
172
173 //------------------------------------------------------------------------------------------------
174 void RemoveRadioInRange(notnull SCR_CoverageRadioComponent component)
175 {
176 int index = m_aRadiosInRange.Find(component);
177
178 if (index < 0)
179 return;
180
181 m_aRadiosInRange.Remove(index);
182 }
183
184 //------------------------------------------------------------------------------------------------
185 void AddRadioInRangeOf(notnull SCR_CoverageRadioComponent component)
186 {
187 if (m_aInRangeOfRadios.Contains(component))
188 return;
189
190 m_aInRangeOfRadios.Insert(component);
191 }
192
193 //------------------------------------------------------------------------------------------------
194 void RemoveRadioInRangeOf(notnull SCR_CoverageRadioComponent component)
195 {
196 int index = m_aInRangeOfRadios.Find(component);
197
198 if (index < 0)
199 return;
200
202 }
203
204 //------------------------------------------------------------------------------------------------
205 void OnPowerToggle(bool powered)
206 {
207 m_bWasPowered = powered;
208
209 if (!powered)
210 {
211 m_aRadiosInRange.Clear();
212
213 foreach (SCR_CoverageRadioComponent radio : m_aInRangeOfRadios)
214 {
215 if (!radio)
216 continue;
217
218 radio.RemoveRadioInRange(this);
219 radio.RemoveRadioInRangeOf(this);
220 }
221
222 m_aInRangeOfRadios.Clear();
223 }
224 }
225
226 //------------------------------------------------------------------------------------------------
227 void OnRangeChanged(float newRange)
228 {
229 m_fSavedRange = newRange;
230 }
231
232 //------------------------------------------------------------------------------------------------
233 void OnEncryptionChanged(string newEncryptionKey)
234 {
235 m_sSavedEncryptionKey = newEncryptionKey;
236 }
237
238 //------------------------------------------------------------------------------------------------
240 {
241 if (!m_OnCoverageChanged)
242 m_OnCoverageChanged = new ScriptInvokerVoid();
243
244 return m_OnCoverageChanged;
245 }
246
247 //------------------------------------------------------------------------------------------------
248 protected void OnCoverageChanged()
249 {
250 m_mCoverage.Clear();
251
252 foreach (string sending : m_aEncryptionKeyCoverSend)
253 {
254 m_mCoverage.Set(sending, SCR_ERadioCoverageStatus.SEND);
255 }
256
257 foreach (string receiving : m_aEncryptionKeyCoverReceive)
258 {
259 if (m_aEncryptionKeyCoverSend.Contains(receiving))
260 m_mCoverage.Set(receiving, SCR_ERadioCoverageStatus.BOTH_WAYS);
261 else
262 m_mCoverage.Set(receiving, SCR_ERadioCoverageStatus.RECEIVE);
263 }
264
265 if (m_OnCoverageChanged)
266 m_OnCoverageChanged.Invoke();
267
269
270 if (coverageSystem)
271 coverageSystem.OnCoverageChanged(this);
272 }
273
274 //------------------------------------------------------------------------------------------------
275 void Ping(string encryptionKey, bool signalSignature, bool reverse = false)
276 {
277 // Signature changes each update so we know which radios have already been pinged to prevent infinite loops
278 if (m_bLastSignalSignature == signalSignature)
279 return;
280
281 m_bLastSignalSignature = signalSignature;
282
283 if (reverse)
284 {
285 m_aEncryptionKeyCoverSend.Insert(encryptionKey);
286
287 if (m_sSavedEncryptionKey != encryptionKey || !IsPowered())
288 return;
289
290 foreach (SCR_CoverageRadioComponent inRangeOfRadio : m_aInRangeOfRadios)
291 {
292 inRangeOfRadio.Ping(encryptionKey, signalSignature, reverse);
293 }
294 }
295 else
296 {
297 m_aEncryptionKeyCoverReceive.Insert(encryptionKey);
298
299 if (m_sSavedEncryptionKey != encryptionKey || !IsPowered())
300 return;
301
302 foreach (SCR_CoverageRadioComponent radioInRange : m_aRadiosInRange)
303 {
304 radioInRange.Ping(encryptionKey, signalSignature, reverse);
305 }
306 }
307 }
308
309 //------------------------------------------------------------------------------------------------
310 override void OnInit(IEntity owner)
311 {
312 super.OnInit(owner);
313
314 // Check for play mode again in case init event was set from outside of this class
315 if (!GetGame().InPlayMode())
316 return;
317
318 // Map descriptor is only used for visual stuff. No need for it on headless.
319 if (RplSession.Mode() != RplMode.Dedicated)
320 {
321 SCR_RadioCoverageMapDescriptorComponent mapDescriptor = SCR_RadioCoverageMapDescriptorComponent.Cast(owner.FindComponent(SCR_RadioCoverageMapDescriptorComponent));
322
323 if (mapDescriptor)
324 mapDescriptor.SetParentRadio(this);
325 }
326
328
329 if (!manager)
330 return;
331
332 BaseTransceiver transceiver = GetTransceiver(0);
333
334 if (!transceiver)
335 return;
336
337 m_fSavedRange = transceiver.GetRange();
338 m_sSavedEncryptionKey = GetEncryptionKey();
339 m_bWasPowered = IsPowered();
340
341 manager.RegisterRadioComponent(this, m_fSavedRange);
342 }
343
344 //------------------------------------------------------------------------------------------------
345 override void OnPostInit(IEntity owner)
346 {
347 super.OnPostInit(owner);
348
349 if (!GetGame().InPlayMode())
350 return;
351
352 SetEventMask(owner, EntityEvent.INIT);
353 }
354
355 //------------------------------------------------------------------------------------------------
356 override void OnDelete(IEntity owner)
357 {
358 // Map descriptor is only used for visual stuff. No need for it on headless.
359 if (RplSession.Mode() != RplMode.Dedicated)
360 {
361 SCR_RadioCoverageMapDescriptorComponent mapDescriptor = SCR_RadioCoverageMapDescriptorComponent.Cast(GetOwner().FindComponent(SCR_RadioCoverageMapDescriptorComponent));
362
363 if (mapDescriptor)
364 mapDescriptor.SetParentRadio(null);
365 }
366
368
369 foreach (SCR_CoverageRadioComponent radio : m_aInRangeOfRadios)
370 {
371 if (!radio)
372 continue;
373
374 radio.RemoveRadioInRange(this);
375 }
376
377 foreach (SCR_CoverageRadioComponent radio : m_aRadiosInRange)
378 {
379 if (!radio)
380 continue;
381
382 radio.RemoveRadioInRangeOf(this);
383 }
384
385 if (manager)
386 manager.UnregisterRadioComponent(this);
387
388 OnPowerToggle(false);
389 super.OnDelete(owner);
390 }
391}
ArmaReforgerScripted GetGame()
Definition game.c:1398
RplMode
Mode of replication.
Definition RplMode.c:9
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
ScriptInvokerVoid GetOnCoverageChanged()
SCR_ERadioCoverageStatus GetCoverageByEncryption(string encryptionKey)
void OnCoverageChanged()
void GetRadiosInRangeOf(notnull array< SCR_CoverageRadioComponent > radios)
void OnRangeChanged(float newRange)
int GetRadiosInRangeCount(string encryptionFilter="")
Returns the amount of radios which are covered by this radio's signal.
bool IsSource()
ref array< string > m_aEncryptionKeyCoverSend
void RemoveRadioInRangeOf(notnull SCR_CoverageRadioComponent component)
string GetSavedEncryption()
float GetSavedRange()
void GetRadiosInRange(notnull array< SCR_CoverageRadioComponent > radios)
void OnEncryptionChanged(string newEncryptionKey)
ref array< string > m_aEncryptionKeyCoverReceive
void RemoveRadioInRange(notnull SCR_CoverageRadioComponent component)
void AddRadioInRange(notnull SCR_CoverageRadioComponent component)
void PrepareCoverageUpdate(string encryptionKey, bool signature)
bool WasPowered()
bool ConnectedRadiosContain(notnull SCR_CoverageRadioComponent radio, bool inMyRange)
Returns true if the provided radio is covered by this radio or vice versa, depending on the direction...
void AddRadioInRangeOf(notnull SCR_CoverageRadioComponent component)
void SetIsSource(bool isSource)
void FinishCoverageUpdate(string encryptionKey)
int GetRadiosInRangeOfCount(string encryptionFilter="")
Returns the amount of radios which are covering this radio with their signal.
void OnPowerToggle(bool powered)
ref map< string, SCR_ERadioCoverageStatus > m_mCoverage
void Ping(string encryptionKey, bool signalSignature, bool reverse=false)
ref array< SCR_CoverageRadioComponent > m_aInRangeOfRadios
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
proto external Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
void UnregisterRadioComponent(notnull SCR_CoverageRadioComponent component)
void RegisterRadioComponent(notnull SCR_CoverageRadioComponent component, float range=-1)
static SCR_RadioCoverageSystem GetInstance()
void OnCoverageChanged(notnull SCR_CoverageRadioComponent radio)
Definition Types.c:486
IEntity GetOwner()
Owner entity of the fuel tank.
proto external string GetEncryptionKey()
proto external BaseTransceiver GetTransceiver(int idx)
proto external bool IsPowered()
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14