Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_RadioCoverageSystem.c
Go to the documentation of this file.
1
void
OnCoverageChangedDelegate
(SCR_CoverageRadioComponent radio);
2
typedef
func
OnCoverageChangedDelegate
;
3
typedef
ScriptInvokerBase<OnCoverageChangedDelegate>
OnCoverageChangedInvoker
;
4
5
class
SCR_RadioCoverageSystem
:
GameSystem
6
{
7
override
static
void
InitInfo(
WorldSystemInfo
outInfo)
8
{
9
outInfo.SetAbstract(
false
);
10
}
11
12
protected
bool
m_bSignalSignature
;
13
protected
bool
m_bUpdateCoverage
;
14
protected
bool
m_bForcedPause
;
15
16
protected
ref
OnCoverageChangedInvoker
m_OnCoverageChanged
;
17
18
protected
ref array<SCR_CoverageRadioComponent>
m_aRadioComponents
= {};
19
20
protected
ref
map<string, SCR_CoverageRadioComponent>
m_mEncryptionSignalSources
=
new
map<string, SCR_CoverageRadioComponent>
();
21
22
protected
static
const
int
UPDATE_DELAY
= 2000;
23
24
//------------------------------------------------------------------------------------------------
25
static
SCR_RadioCoverageSystem
GetInstance
()
26
{
27
World
world =
GetGame
().GetWorld();
28
29
if
(!world)
30
return
null;
31
32
return
SCR_RadioCoverageSystem
.Cast(world.FindSystem(
SCR_RadioCoverageSystem
));
33
}
34
35
//------------------------------------------------------------------------------------------------
36
static
bool
UpdateAll
(
bool
forceRecalculation =
false
)
37
{
38
SCR_RadioCoverageSystem
system =
GetInstance
();
39
40
if
(system)
41
return
system.
UpdateRadios
(forceRecalculation);
42
43
return
false
;
44
}
45
46
//------------------------------------------------------------------------------------------------
47
override
event
bool
ShouldBePaused
()
48
{
49
return
true
;
50
}
51
52
//------------------------------------------------------------------------------------------------
53
override
void
OnStarted
()
54
{
55
if
(!
m_bForcedPause
)
56
{
57
UpdateRadios
(
true
);
58
GetGame
().GetCallqueue().CallLater(
UpdateRadios
,
UPDATE_DELAY
,
true
,
false
);
59
}
60
}
61
62
//------------------------------------------------------------------------------------------------
63
override
void
OnStopped
()
64
{
65
GetGame
().GetCallqueue().Remove(
UpdateRadios
);
66
}
67
68
//------------------------------------------------------------------------------------------------
69
protected
bool
UpdateRadios
(
bool
forceUpdateCoverage =
false
)
70
{
71
m_bUpdateCoverage
=
false
;
72
73
foreach
(SCR_CoverageRadioComponent radio :
m_aRadioComponents
)
74
{
75
UpdateRadioComponent
(radio);
76
}
77
78
if
(!
m_bUpdateCoverage
&& !forceUpdateCoverage)
79
return
m_bUpdateCoverage
;
80
81
if
(
Replication
.IsServer())
82
{
83
for
(
int
i = 0, count =
m_mEncryptionSignalSources
.Count(); i < count; i++)
84
{
85
UpdateCoverage
(
m_mEncryptionSignalSources
.GetKey(i));
86
}
87
}
88
89
return
m_bUpdateCoverage
;
90
}
91
92
//------------------------------------------------------------------------------------------------
93
protected
void
UpdateRadioComponent
(notnull SCR_CoverageRadioComponent component)
94
{
95
bool
rangesHandled;
96
string
encryption = component.GetEncryptionKey();
97
98
// Radio has been turned on or off
99
if
(!component.WasPowered() && component.IsPowered())
100
{
101
m_bUpdateCoverage
=
true
;
102
HandleRanges
(component);
103
component.OnPowerToggle(
true
);
104
rangesHandled =
true
;
105
106
if
(
Replication
.IsServer() && component.IsSource() && !
m_mEncryptionSignalSources
.Get(encryption))
107
m_mEncryptionSignalSources
.Set(encryption, component);
108
}
109
else
if
(component.WasPowered() && !component.IsPowered())
110
{
111
m_bUpdateCoverage
=
true
;
112
component.OnPowerToggle(
false
);
113
114
if
(
Replication
.IsServer() &&
m_mEncryptionSignalSources
.Get(encryption) == component)
115
FindNewSource
(encryption);
116
}
117
118
// Signal range has changed
119
float
currentRange = component.GetTransceiver(0).GetRange();
120
121
if
(currentRange != component.GetSavedRange())
122
{
123
m_bUpdateCoverage
=
true
;
124
component.OnRangeChanged(currentRange);
125
126
if
(!rangesHandled)
127
HandleRanges
(component, currentRange);
128
}
129
130
// Encryption key has changed
131
string
savedEncryption = component.GetSavedEncryption();
132
133
if
(encryption != savedEncryption)
134
{
135
m_bUpdateCoverage
=
true
;
136
137
if
(
Replication
.IsServer() &&
m_mEncryptionSignalSources
.Get(savedEncryption) == component)
138
FindNewSource
(savedEncryption);
139
140
if
(
Replication
.IsServer() && component.IsSource() && !
m_mEncryptionSignalSources
.Get(encryption))
141
m_mEncryptionSignalSources
.Set(encryption, component);
142
143
component.OnEncryptionChanged(encryption);
144
}
145
}
146
147
//------------------------------------------------------------------------------------------------
148
void
OnCoverageChanged
(notnull SCR_CoverageRadioComponent radio)
149
{
150
if
(
m_OnCoverageChanged
)
151
m_OnCoverageChanged
.Invoke(radio);
152
}
153
154
//------------------------------------------------------------------------------------------------
155
OnCoverageChangedInvoker
GetOnCoverageChanged
()
156
{
157
if
(!
m_OnCoverageChanged
)
158
m_OnCoverageChanged
=
new
OnCoverageChangedInvoker
();
159
160
return
m_OnCoverageChanged
;
161
}
162
163
//------------------------------------------------------------------------------------------------
164
void
TogglePeriodicUpdates
(
bool
toggle)
165
{
166
m_bForcedPause
= !toggle;
167
168
if
(toggle)
169
OnStarted
();
170
else
171
OnStopped
();
172
}
173
174
//------------------------------------------------------------------------------------------------
175
void
RegisterRadioComponent
(notnull SCR_CoverageRadioComponent component,
float
range = -1)
176
{
177
if
(
m_aRadioComponents
.Contains(component))
178
return
;
179
180
m_aRadioComponents
.Insert(component);
181
182
if
(!component.IsPowered())
183
return
;
184
185
if
(
Replication
.IsServer() && component.IsSource() && !
m_mEncryptionSignalSources
.Get(component.GetEncryptionKey()))
186
m_mEncryptionSignalSources
.Set(component.GetEncryptionKey(), component);
187
188
HandleRanges
(component, range);
189
}
190
191
//------------------------------------------------------------------------------------------------
192
void
UnregisterRadioComponent
(notnull SCR_CoverageRadioComponent component)
193
{
194
m_aRadioComponents
.RemoveItem(component);
195
196
if
(!
GetGame
().InPlayMode())
197
return
;
198
199
string
encryption = component.GetEncryptionKey();
200
201
if
(
Replication
.IsServer() &&
m_mEncryptionSignalSources
.Get(encryption) == component)
202
FindNewSource
(encryption);
203
204
UpdateRadios
(
true
);
205
}
206
207
//------------------------------------------------------------------------------------------------
208
protected
void
FindNewSource
(
string
encryptionKey)
209
{
210
m_mEncryptionSignalSources
.Set(encryptionKey, null);
211
212
foreach
(SCR_CoverageRadioComponent newSource :
m_aRadioComponents
)
213
{
214
if
(!newSource.IsPowered() || !newSource.IsSource() || newSource.GetEncryptionKey() != encryptionKey)
215
continue
;
216
217
m_mEncryptionSignalSources
.Set(encryptionKey, newSource);
218
break
;
219
}
220
}
221
222
//------------------------------------------------------------------------------------------------
223
protected
void
HandleRanges
(notnull SCR_CoverageRadioComponent component,
float
range = -1)
224
{
225
if
(range < 0)
226
range = component.GetTransceiver(0).GetRange();
227
228
float
rangeSq = range * range;
229
230
vector
position
= component.GetOwner().GetOrigin();
231
int
otherRange;
232
int
distanceSq;
233
234
foreach
(SCR_CoverageRadioComponent radio :
m_aRadioComponents
)
235
{
236
if
(radio == component || !radio.IsPowered())
237
continue
;
238
239
distanceSq =
vector
.DistanceSqXZ(radio.GetOwner().GetOrigin(),
position
);
240
241
if
(distanceSq <= rangeSq)
242
{
243
component.AddRadioInRange(radio);
244
radio.AddRadioInRangeOf(component);
245
}
246
else
247
{
248
component.RemoveRadioInRange(radio);
249
radio.RemoveRadioInRangeOf(component);
250
}
251
252
otherRange = radio.GetTransceiver(0).GetRange();
253
254
if
(distanceSq <= (otherRange * otherRange))
255
{
256
radio.AddRadioInRange(component);
257
component.AddRadioInRangeOf(radio);
258
}
259
}
260
}
261
262
//------------------------------------------------------------------------------------------------
263
protected
void
UpdateCoverage
(
string
encryptionKey)
264
{
265
SCR_CoverageRadioComponent source =
m_mEncryptionSignalSources
.Get(encryptionKey);
266
267
if
(!source)
268
return
;
269
270
// Signature changes each update so we know which radios have already been pinged to prevent infinite loops
271
foreach
(SCR_CoverageRadioComponent radio :
m_aRadioComponents
)
272
{
273
radio.PrepareCoverageUpdate(encryptionKey,
m_bSignalSignature
);
274
}
275
276
// Forward ping
277
m_bSignalSignature
= !
m_bSignalSignature
;
278
source.Ping(encryptionKey,
m_bSignalSignature
);
279
280
// Backward ping
281
m_bSignalSignature
= !
m_bSignalSignature
;
282
source.Ping(encryptionKey,
m_bSignalSignature
,
true
);
283
284
foreach
(SCR_CoverageRadioComponent radio :
m_aRadioComponents
)
285
{
286
radio.FinishCoverageUpdate(encryptionKey);
287
}
288
}
289
}
290
291
enum
SCR_ERadioCoverageStatus
292
{
293
NONE
,
294
RECEIVE
,
295
SEND
,
296
BOTH_WAYS
297
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
func
func
Definition
SCR_AIThreatSystem.c:6
position
vector position
Definition
SCR_DestructibleTreeV2.c:30
SEND
SCR_RadioCoverageSystem SEND
OnCoverageChangedDelegate
func OnCoverageChangedDelegate
Definition
SCR_RadioCoverageSystem.c:2
RECEIVE
SCR_RadioCoverageSystem RECEIVE
OnCoverageChangedInvoker
ScriptInvokerBase< OnCoverageChangedDelegate > OnCoverageChangedInvoker
Definition
SCR_RadioCoverageSystem.c:3
GameSystem
Definition
GameSystem.c:16
Replication
Main replication API.
Definition
Replication.c:14
SCR_RadioCoverageSystem
Definition
SCR_RadioCoverageSystem.c:6
SCR_RadioCoverageSystem::HandleRanges
void HandleRanges(notnull SCR_CoverageRadioComponent component, float range=-1)
Definition
SCR_RadioCoverageSystem.c:223
SCR_RadioCoverageSystem::UnregisterRadioComponent
void UnregisterRadioComponent(notnull SCR_CoverageRadioComponent component)
Definition
SCR_RadioCoverageSystem.c:192
SCR_RadioCoverageSystem::UpdateRadios
bool UpdateRadios(bool forceUpdateCoverage=false)
Definition
SCR_RadioCoverageSystem.c:69
SCR_RadioCoverageSystem::m_bForcedPause
bool m_bForcedPause
Definition
SCR_RadioCoverageSystem.c:14
SCR_RadioCoverageSystem::FindNewSource
void FindNewSource(string encryptionKey)
Definition
SCR_RadioCoverageSystem.c:208
SCR_RadioCoverageSystem::TogglePeriodicUpdates
void TogglePeriodicUpdates(bool toggle)
Definition
SCR_RadioCoverageSystem.c:164
SCR_RadioCoverageSystem::GetOnCoverageChanged
OnCoverageChangedInvoker GetOnCoverageChanged()
Definition
SCR_RadioCoverageSystem.c:155
SCR_RadioCoverageSystem::RegisterRadioComponent
void RegisterRadioComponent(notnull SCR_CoverageRadioComponent component, float range=-1)
Definition
SCR_RadioCoverageSystem.c:175
SCR_RadioCoverageSystem::OnStopped
override void OnStopped()
Definition
SCR_RadioCoverageSystem.c:63
SCR_RadioCoverageSystem::m_bSignalSignature
bool m_bSignalSignature
Definition
SCR_RadioCoverageSystem.c:12
SCR_RadioCoverageSystem::UpdateCoverage
void UpdateCoverage(string encryptionKey)
Definition
SCR_RadioCoverageSystem.c:263
SCR_RadioCoverageSystem::UPDATE_DELAY
static const int UPDATE_DELAY
Definition
SCR_RadioCoverageSystem.c:22
SCR_RadioCoverageSystem::m_OnCoverageChanged
ref OnCoverageChangedInvoker m_OnCoverageChanged
Definition
SCR_RadioCoverageSystem.c:16
SCR_RadioCoverageSystem::m_mEncryptionSignalSources
ref map< string, SCR_CoverageRadioComponent > m_mEncryptionSignalSources
Definition
SCR_RadioCoverageSystem.c:20
SCR_RadioCoverageSystem::OnStarted
override void OnStarted()
Definition
SCR_RadioCoverageSystem.c:53
SCR_RadioCoverageSystem::m_aRadioComponents
ref array< SCR_CoverageRadioComponent > m_aRadioComponents
Definition
SCR_RadioCoverageSystem.c:18
SCR_RadioCoverageSystem::ShouldBePaused
override event bool ShouldBePaused()
Definition
SCR_RadioCoverageSystem.c:47
SCR_RadioCoverageSystem::GetInstance
static SCR_RadioCoverageSystem GetInstance()
Definition
SCR_RadioCoverageSystem.c:25
SCR_RadioCoverageSystem::UpdateRadioComponent
void UpdateRadioComponent(notnull SCR_CoverageRadioComponent component)
Definition
SCR_RadioCoverageSystem.c:93
SCR_RadioCoverageSystem::m_bUpdateCoverage
bool m_bUpdateCoverage
Definition
SCR_RadioCoverageSystem.c:13
SCR_RadioCoverageSystem::OnCoverageChanged
void OnCoverageChanged(notnull SCR_CoverageRadioComponent radio)
Definition
SCR_RadioCoverageSystem.c:148
SCR_RadioCoverageSystem::UpdateAll
static bool UpdateAll(bool forceRecalculation=false)
Definition
SCR_RadioCoverageSystem.c:36
World
Definition
World.c:16
WorldSystemInfo
Structure holding world system meta-information required by the engine.
Definition
WorldSystemInfo.c:14
map
Definition
Types.c:486
vector
Definition
vector.c:13
NONE
@ NONE
When Shape is created and not initialized yet.
Definition
ShapeType.c:15
scripts
Game
Systems
SCR_RadioCoverageSystem.c
Generated by
1.17.0