Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VONAutoTune.c
Go to the documentation of this file.
3{
4 [Attribute("1")]
5 private bool m_bEnabled;
6
7 [Attribute()]
8 protected ref SCR_VONAutoTuneConfig m_VONAutoTuneConfig;
9
10 protected const float UPDATE_DELAY = 0.5;
11
14 protected SCR_PlayerControllerGroupComponent m_PlayerGroupComponent;
16 protected SCR_VONController m_VONController;
18 protected RplComponent m_RplComponent;
20
21 protected bool m_bMustUpdate;
22 protected float m_fUpdateDelay;
23
24 //------------------------------------------------------------------------------------------------
27 bool IsEnabled()
28 {
29 return m_bEnabled;
30 }
31
32 //------------------------------------------------------------------------------------------------
33 void SetRadios(IEntity entity, SCR_EVONAutoTuneFrequency tuneSpecificFrequency = SCR_EVONAutoTuneFrequency.NONE)
34 {
35 if (!entity || !m_VONAutoTuneConfig || !m_VONController)
36 return;
37
38 #ifdef VON_AUTO_TUNE_DEBUG
39 Print("VONAutoTune", LogLevel.DEBUG);
40 #endif
41
43
45 if (!faction)
46 return;
47
48 int groupId = m_PlayerGroupComponent.GetGroupID();
49 SCR_AIGroup group = m_GroupsManagerComponent.FindGroup(groupId);
50 if (!group)
51 return;
52
53 // set character role
54 SCR_EVONAutoTuneRole characterRadioRole = SCR_EVONAutoTuneRole.ANY;
55 if (faction.IsPlayerCommander(playerID))
56 characterRadioRole = SCR_EVONAutoTuneRole.COMMANDER;
57 else if (group.IsPlayerLeader(playerID))
58 characterRadioRole = SCR_EVONAutoTuneRole.SQUAD_LEADER;
59 else
60 characterRadioRole = SCR_EVONAutoTuneRole.SQUAD_MEMBER;
61
62 BaseRadioComponent foundRadio;
63 foreach (SCR_VONAutoTuneIdentityConfig identity : m_VONAutoTuneConfig.m_aAutoTuneList)
64 {
65 if (identity.m_sFactionKey != faction.GetFactionKey())
66 continue;
67
68 foundRadio = FindFirstRadio(m_VONController, identity.m_eRadioType, faction.GetFactionRadioEncryptionKey());
69 if (!foundRadio)
70 continue;
71
72 foreach (SCR_VONAutoTuneRoleConfig role : identity.m_aRoles)
73 {
74 if (role.m_eRole != SCR_EVONAutoTuneRole.ANY && role.m_eRole != characterRadioRole)
75 continue;
76
77 SetChannels(faction, foundRadio, role, groupId, tuneSpecificFrequency);
78 }
79 }
80 }
81
82 //--------------------------------- ---------------------------------------------------------------
83 protected void SetChannels(notnull SCR_Faction faction, notnull BaseRadioComponent radio, notnull SCR_VONAutoTuneRoleConfig roleConfig, int groupId, SCR_EVONAutoTuneFrequency tuneSpecificFrequency = SCR_EVONAutoTuneFrequency.NONE)
84 {
85 int transceiversCount = radio.TransceiversCount();
86
87 foreach (SCR_VONAutoTuneChannelConfig channel : roleConfig.m_aChannels)
88 {
89 if (channel.m_iChannel >= transceiversCount)
90 continue;
91
92 // if set tuneSpecificFrequency to NONE, tune according to all frequency types from the config
93 if (tuneSpecificFrequency != SCR_EVONAutoTuneFrequency.NONE && channel.m_eAutoTuneFrequency != tuneSpecificFrequency)
94 continue;
95
96 BaseTransceiver transceiver = radio.GetTransceiver(channel.m_iChannel);
97 int frequency = GetFrequency(faction, groupId, channel.m_eAutoTuneFrequency);
98 if (frequency > 0)
99 {
100 transceiver.SetFrequency(frequency);
101
102 #ifdef VON_AUTO_TUNE_DEBUG
103 Print("VONAutoTune Set channel:"+channel.m_iChannel+" frequency:"+frequency+" freqType:"+SCR_Enum.GetEnumName(SCR_EVONAutoTuneFrequency, channel.m_eAutoTuneFrequency), LogLevel.DEBUG);
104 #endif
105 }
106 }
107 }
108
109 //------------------------------------------------------------------------------------------------
110 protected int GetFrequency(notnull SCR_Faction faction, int groupId, SCR_EVONAutoTuneFrequency autoTuneFrequencyType)
111 {
112 if (autoTuneFrequencyType == SCR_EVONAutoTuneFrequency.SQUAD)
113 return m_PlayerGroupComponent.GetActualGroupFrequency();
114
115 if (autoTuneFrequencyType == SCR_EVONAutoTuneFrequency.PLATOON)
116 return GetPlatoonFrequency(faction);
117
118 if (autoTuneFrequencyType == SCR_EVONAutoTuneFrequency.OBJECTIVE_PLATOON)
119 return GetObjectiveOrPlatoonFrequency(faction, groupId);
120
121 if (autoTuneFrequencyType == SCR_EVONAutoTuneFrequency.COMMANDER)
122 return GetCommanderFrequency(faction);
123
124 return 0;
125 }
126
127 //------------------------------------------------------------------------------------------------
128 protected int GetPlatoonFrequency(notnull SCR_Faction faction)
129 {
130 return faction.GetFactionRadioFrequency();
131 }
132
133 //------------------------------------------------------------------------------------------------
134 protected int GetObjectiveOrPlatoonFrequency(notnull SCR_Faction faction, int groupId)
135 {
136 if (groupId < 0)
137 return 0;
138
139 int frequency = 0;
140
141 // finding out if the group has a task
142 SCR_Task task = m_TaskSystem.GetTaskAssignedTo(SCR_TaskExecutorGroup.FromGroup(groupId));
143 if (task && m_GroupTaskManagerComponent.CanAssignFrequencyToTask(task))
144 frequency = m_GroupTaskManagerComponent.GetTaskFrequency(task);
145
146 if (frequency <= 0)
147 frequency = GetPlatoonFrequency(faction);
148
149 return frequency;
150 }
151
152 //------------------------------------------------------------------------------------------------
153 protected int GetCommanderFrequency(notnull Faction faction)
154 {
156 return 0;
157
158 array<SCR_AIGroup> playableGroups = m_GroupsManagerComponent.GetPlayableGroupsByFaction(faction);
159 if (!playableGroups)
160 return 0;
161
162 foreach (SCR_AIGroup group : playableGroups)
163 {
164 if (group.GetGroupRole() == SCR_EGroupRole.COMMANDER)
165 return group.GetRadioFrequency();
166 }
167
168 return 0;
169 }
170
171 //------------------------------------------------------------------------------------------------
173 protected BaseRadioComponent FindFirstRadio(SCR_VONController vonController, ERadioType radioType, string encryptionKey)
174 {
175 array<ref SCR_VONEntry> entries = {};
176 vonController.GetVONEntries(entries);
177
178 SCR_VONEntryRadio radioEntry;
179 BaseRadioComponent baseRadio;
180 foreach (SCR_VONEntry entry : entries)
181 {
182 radioEntry = SCR_VONEntryRadio.Cast(entry);
183 if (!radioEntry)
184 continue;
185
186 baseRadio = radioEntry.GetTransceiver().GetRadio();
187 if (baseRadio.GetEncryptionKey() != encryptionKey)
188 continue;
189
190 SCR_RadioComponent radioComponent = SCR_RadioComponent.Cast(baseRadio.GetOwner().FindComponent(SCR_RadioComponent));
191 if (!radioComponent)
192 continue;
193
194 if (radioComponent.GetRadioType() == radioType)
195 return baseRadio;
196 }
197
198 return null;
199 }
200
201 //------------------------------------------------------------------------------------------------
203 {
205 }
206
207 //------------------------------------------------------------------------------------------------
208 protected void SetUpdateRadios()
209 {
210 m_bMustUpdate = true;
212 }
213
214 //------------------------------------------------------------------------------------------------
217 void Update(float timeSlice)
218 {
219 if (!m_bMustUpdate || !IsEnabled())
220 return;
221
222 if (m_fUpdateDelay > 0)
223 {
224 m_fUpdateDelay -= timeSlice;
225 return;
226 }
227
229 SetRadios(m_PlayerController.GetLocalMainEntity());
230
231 m_bMustUpdate = false;
232 }
233
234 //------------------------------------------------------------------------------------------------
238 void Init(notnull IEntity owner, notnull SCR_VONController vonController)
239 {
241 return;
242
243 m_VONController = vonController;
244
247 return;
248
251 return;
252
253 m_TaskSystem = SCR_TaskSystem.GetInstance();
254 if (!m_TaskSystem)
255 return;
256
259 return;
260
261 m_PlayerGroupComponent = SCR_PlayerControllerGroupComponent.Cast(m_PlayerController.FindComponent(SCR_PlayerControllerGroupComponent));
263 return;
264
265 vonController.GetOnEntriesChangedInvoker().Insert(OnEntriesChanged);
266 m_PlayerController.m_OnControlledEntityChanged.Insert(OnControlledEntityChanged);
267 }
268
269 //------------------------------------------------------------------------------------------------
271 void Deinit()
272 {
274 m_PlayerController.m_OnControlledEntityChanged.Remove(OnControlledEntityChanged);
275
276 if (m_VONController)
277 m_VONController.GetOnEntriesChangedInvoker().Remove(OnEntriesChanged);
278
279 }
280}
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_EGroupRole
Group roles.
void SCR_GroupTaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
SCR_EVONAutoTuneRole
Player role for auto tune setting.
func OnEntriesChanged
bool IsPlayerLeader(int playerID)
static Faction GetEntityFaction(notnull IEntity entity)
bool IsPlayerCommander(int playerId)
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
ref SCR_VONAutoTuneConfig m_VONAutoTuneConfig
int GetCommanderFrequency(notnull Faction faction)
void Init(notnull IEntity owner, notnull SCR_VONController vonController)
SCR_TaskSystem m_TaskSystem
RplComponent m_RplComponent
SCR_GroupTaskManagerComponent m_GroupTaskManagerComponent
seconds
const float UPDATE_DELAY
void SetChannels(notnull SCR_Faction faction, notnull BaseRadioComponent radio, notnull SCR_VONAutoTuneRoleConfig roleConfig, int groupId, SCR_EVONAutoTuneFrequency tuneSpecificFrequency=SCR_EVONAutoTuneFrequency.NONE)
SCR_PlayerController m_PlayerController
SCR_PlayerControllerGroupComponent m_PlayerGroupComponent
void Deinit()
Deinit VON Auto tune.
SCR_GroupsManagerComponent m_GroupsManagerComponent
SCR_VONController m_VONController
SCR_Task m_LastAddedTask
void SetRadios(IEntity entity, SCR_EVONAutoTuneFrequency tuneSpecificFrequency=SCR_EVONAutoTuneFrequency.NONE)
void OnControlledEntityChanged(IEntity from, IEntity to)
int GetObjectiveOrPlatoonFrequency(notnull SCR_Faction faction, int groupId)
void Update(float timeSlice)
BaseRadioComponent FindFirstRadio(SCR_VONController vonController, ERadioType radioType, string encryptionKey)
Find first equipped radio by type and encryptionKey.
int GetFrequency(notnull SCR_Faction faction, int groupId, SCR_EVONAutoTuneFrequency autoTuneFrequencyType)
int GetPlatoonFrequency(notnull SCR_Faction faction)
Voice over network entry data class, used for management of communication methods.
Definition SCR_VONEntry.c:4
VONEntry class for radio entries.
BaseTransceiver GetTransceiver()
Associated transceiver.
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