Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CallsignManagerComponent.c
Go to the documentation of this file.
2[ComponentEditorProps(category: "GameScripted/Callsign", description: "")]
6
7//~ ScriptInvokers
8//~ Called when callsign changed or is assigned
9void SCR_GroupsManagerComponent_OnPlayerCallsignChanged(int playerId, int companyCallsignIndex, int platoonCallsignIndex, int squadCallsignIndex, int characterCallsignNumber, ERoleCallsign characterRole);
11
13{
16
18 protected ref array<ref array<int>> m_aDuplicateCallsigns = {};
19
22
23 //~ Script invoker (Server only)
24 protected ref ScriptInvokerBase<SCR_GroupsManagerComponent_OnPlayerCallsignChanged> m_OnPlayerCallsignChanged = new ScriptInvokerBase<SCR_GroupsManagerComponent_OnPlayerCallsignChanged>();
25
26 //~ Ref (Server only)
28
29
30 //======================================== GET CALLSIGN ========================================\\
31 //------------------------------------------------------------------------------------------------
40 bool GetEntityCallsignIndexes(IEntity entity, out int companyCallsignIndex, out int platoonCallsignIndex, out int squadCallsignIndex, out int characterCallsignIndex)
41 {
43
44 return callsignComponent && callsignComponent.GetCallsignIndexes(companyCallsignIndex, platoonCallsignIndex, squadCallsignIndex, characterCallsignIndex);
45 }
46
47 //------------------------------------------------------------------------------------------------
56 bool GetEntityCallsignIndexes(SCR_EditableEntityComponent editableEntity, out int companyCallsignIndex, out int platoonCallsignIndex, out int squadCallsignIndex, out int characterCallsignIndex)
57 {
58 return GetEntityCallsignIndexes(editableEntity.GetOwner(), companyCallsignIndex, platoonCallsignIndex, squadCallsignIndex, characterCallsignIndex);
59 }
60
61 //------------------------------------------------------------------------------------------------
71 bool GetEntityCallsignNames(IEntity entity, out string companyCallsignName, out string platoonCallsignName, out string squadCallsignName, out string characterCallsignName, out string format)
72 {
74
75 if (!callsignComponent)
76 return false;
77
78 return callsignComponent.GetCallsignNames(companyCallsignName, platoonCallsignName, squadCallsignName, characterCallsignName, format);
79 }
80
81 //------------------------------------------------------------------------------------------------
91 bool GetEntityCallsignNames(SCR_EditableEntityComponent editableEntity, out string companyCallsignName, out string platoonCallsignName, out string squadCallsignName, out string characterCallsignName, out string format)
92 {
93 return GetEntityCallsignNames(editableEntity.GetOwner(), companyCallsignName, platoonCallsignName, squadCallsignName, characterCallsignName, format);
94 }
95
96 //------------------------------------------------------------------------------------------------
103 void AssignCallGroupCallsign(notnull SCR_AIGroup group, Faction faction, SCR_CallsignGroupComponent masterCallsignComponent, out int companyIndex, out int platoonIndex, out int squadIndex)
104 {
105 companyIndex = -1;
106 platoonIndex = -1;
107 squadIndex = -1;
108
109 //~ Use master callsign
110 if (masterCallsignComponent)
111 {
112 masterCallsignComponent.GetCallsignIndexes(companyIndex, platoonIndex, squadIndex);
113 return;
114 }
115
116 //Faction has no callsigns
117 if (!m_mAvailableCallsigns.Contains(faction))
118 return;
119
120 SCR_Faction ScrFaction = SCR_Faction.Cast(faction);
121
122 if (!ScrFaction)
123 return;
124
125 SCR_FactionCallsignInfo callsignInfo = ScrFaction.GetCallsignInfo();
126 if (!callsignInfo)
127 return;
128
129 //~Todo: Add logic for assigning same company callsigns by getting closest (same faction) company
130
131
132 if (callsignInfo.GetIsAssignedRandomly())
133 AssignRandomGroupCallsigns(faction, companyIndex, platoonIndex, squadIndex);
134 else if (callsignInfo.GetAssignCallsignBasedOnGroupRole())
135 AssignGroupRoleSpecificGroupCallsign(faction, group, companyIndex, platoonIndex, squadIndex);
136 else
137 AssignFirstAvailableGroupCallsign(faction, companyIndex, platoonIndex, squadIndex);
138
139 }
140
141 //------------------------------------------------------------------------------------------------
142 protected void AssignFirstAvailableGroupCallsign(Faction faction, out int companyIndex, out int platoonIndex, out int squadIndex)
143 {
144 SCR_FactionCallsignData factionCallsign;
145 if (m_mAvailableCallsigns.Find(faction, factionCallsign))
146 {
147 if (factionCallsign.GetFirstAvailibleCallsign(companyIndex, platoonIndex, squadIndex))
148 {
149 RemoveAvailableGroupCallsign(faction, companyIndex, platoonIndex, squadIndex);
150 return;
151 }
152 }
153
154 //Callsign was not assigned as all callsigns are taken
155 AssignRandomDuplicateCallsign(faction, companyIndex, platoonIndex, squadIndex);
156 Print(string.Format("All available callsigns are taken for faction '%1', so a random duplicate is assigned instead. If this happenes a lot then more callsigns should be added for this faction!", faction.GetFactionName()), LogLevel.WARNING);
157 }
158
159 //------------------------------------------------------------------------------------------------
160 //~Todo: Not yet used. Should check neighbouring groups and assign the same company if close to same faction group
161 protected void AssignCompanySpecificGroupCallsign(Faction faction, out int specificCompanyIndex, out int platoonIndex, out int squadIndex)
162 {
163 SCR_FactionCallsignData factionCallsign;
164 if (m_mAvailableCallsigns.Find(faction, factionCallsign))
165 {
166 if (factionCallsign.GetSpecificCompanyCallsign(specificCompanyIndex, platoonIndex, squadIndex))
167 {
168 RemoveAvailableGroupCallsign(faction, specificCompanyIndex, platoonIndex, squadIndex);
169 return;
170 }
171 }
172
173 //Callsign was not assigned as all callsigns are taken
174 AssignRandomDuplicateCallsign(faction, specificCompanyIndex, platoonIndex, squadIndex);
175 Print(string.Format("All available callsigns are taken for faction '%1', so a random duplicate is assigned instead. If this happenes a lot then more callsigns should be added for this faction!", faction.GetFactionName()), LogLevel.WARNING);
176 }
177
178 //------------------------------------------------------------------------------------------------
179 protected void AssignGroupRoleSpecificGroupCallsign(Faction faction, notnull SCR_AIGroup group, out int companyIndex, out int platoonIndex, out int squadIndex)
180 {
181 SCR_FactionCallsignData factionCallsign;
182 if (m_mAvailableCallsigns.Find(faction, factionCallsign))
183 {
184 if (factionCallsign.GetGroupRoleSpecificCompanyCallsign(group, companyIndex, platoonIndex, squadIndex))
185 {
186 RemoveAvailableGroupCallsign(faction, companyIndex, platoonIndex, squadIndex);
187 return;
188 }
189
190 if (factionCallsign.GetRandomCallsign(companyIndex, platoonIndex, squadIndex))
191 {
192 RemoveAvailableGroupCallsign(faction, companyIndex, platoonIndex, squadIndex);
193 return;
194 }
195 }
196
197 //Callsign was not assigned as all callsigns are taken
198 AssignRandomDuplicateCallsign(faction, companyIndex, platoonIndex, squadIndex);
199 PrintFormat("All available callsigns are taken for faction '%1', so a random duplicate is assigned instead. If this happenes a lot then more callsigns should be added for this faction!", faction.GetFactionName(), level: LogLevel.WARNING);
200 }
201
202 //------------------------------------------------------------------------------------------------
208 void AssignRandomGroupCallsigns(Faction faction, out int companyIndex, out int platoonIndex, out int squadIndex)
209 {
210 SCR_FactionCallsignData factionCallsign;
211 if (m_mAvailableCallsigns.Find(faction, factionCallsign))
212 {
213 if (factionCallsign.GetRandomCallsign(companyIndex, platoonIndex, squadIndex))
214 {
215 RemoveAvailableGroupCallsign(faction, companyIndex, platoonIndex, squadIndex);
216 return;
217 }
218 }
219
220 //Callsign was not assigned as all callsigns are taken
221 AssignRandomDuplicateCallsign(faction, companyIndex, platoonIndex, squadIndex);
222 Print(string.Format("All available callsigns are taken for faction '%1', so a random duplicate is assigned instead. If this happenes a lot then more callsigns should be added for this faction!", faction.GetFactionName()), LogLevel.WARNING);
223 }
224
225 //------------------------------------------------------------------------------------------------
232 // TODO: available -> available
233 void MakeGroupCallsignAvailible(Faction faction, int companyIndex, int platoonIndex, int squadIndex)
234 {
235 //Check if callsign was assigned duplicate
236 if (!m_aDuplicateCallsigns.IsEmpty())
237 {
238 int count = m_aDuplicateCallsigns.Count();
239
240 for(int i = 0; i < count; i++)
241 {
242 //The assigned callsign was a duplicate safty. So it is removed from the duplicate list instead of making it available again
243 if (m_aDuplicateCallsigns[i][0] == companyIndex && m_aDuplicateCallsigns[i][1] == platoonIndex && m_aDuplicateCallsigns[i][2] == squadIndex)
244 {
245 m_aDuplicateCallsigns.Remove(i);
246 return;
247 }
248 }
249 }
250
251 SCR_FactionCallsignData factionCallsignData;
252
253 if (m_mAvailableCallsigns.Find(faction, factionCallsignData))
254 factionCallsignData.AddCallsign(companyIndex, platoonIndex, squadIndex);
255 }
256
257 //------------------------------------------------------------------------------------------------
258 //A callsign is assigned
260 protected void RemoveAvailableGroupCallsign(Faction faction, int companyIndex, int platoonIndex, int squadIndex)
261 {
262 SCR_FactionCallsignData factionCallsignData;
263 if (m_mAvailableCallsigns.Find(faction, factionCallsignData))
264 factionCallsignData.RemoveCallsign(companyIndex, platoonIndex, squadIndex);
265 }
266
267 //------------------------------------------------------------------------------------------------
269 protected void AssignRandomDuplicateCallsign(Faction faction, out int company, out int platoon, out int squad)
270 {
271 SCR_Faction ScrFaction = SCR_Faction.Cast(faction);
272 if (!ScrFaction)
273 return;
274
275 SCR_FactionCallsignInfo factionCallsignInfo = ScrFaction.GetCallsignInfo();
276 if (!factionCallsignInfo)
277 return;
278
279 if (factionCallsignInfo.GetRandomCallsign(company, platoon, squad))
280 {
281 array<int> duplicateCallsign = {};
282 duplicateCallsign.Insert(company);
283 duplicateCallsign.Insert(platoon);
284 duplicateCallsign.Insert(squad);
285
286 m_aDuplicateCallsigns.Insert(duplicateCallsign);
287 }
288 }
289
290 //------------------------------------------------------------------------------------------------
292 protected void OnPlayerSpawn(int playerId, IEntity playerEntity)
293 {
294 if (!m_GroupManager || !playerEntity)
295 return;
296
297 SCR_CallsignCharacterComponent characterCallsign = SCR_CallsignCharacterComponent.Cast(playerEntity.FindComponent(SCR_CallsignCharacterComponent));
298 if (!characterCallsign)
299 return;
300
301 //~ Init player Callsign component to make sure it knows it is a player and it listens to on Callsign Changed
302 characterCallsign.InitPlayerOnServer(playerId);
303
304 //~ Get player Group
305 SCR_AIGroup playerGroup = m_GroupManager.GetPlayerGroup(playerId);
306 if (!playerGroup)
307 return;
308
309 //~ Get master if group is slave
310 if (playerGroup.IsSlave())
311 {
312 SCR_AIGroup master = playerGroup.GetMaster();
313
314 if (master)
315 playerGroup = master;
316 }
317
318 int companyIndex, platoonIndex, squadIndex, characterNumber;
319 ERoleCallsign characterRole;
320
321 //~ Get player callsign from manager (If any)
322 if (!GetPlayerCallsign(playerId, companyIndex, platoonIndex, squadIndex, characterNumber, characterRole))
323 return;
324
325 //~ Assign player callsign if found
326 characterCallsign.AssignCharacterCallsign(playerGroup.GetFaction(), companyIndex, platoonIndex, squadIndex, characterNumber, characterRole, playerGroup.GetPlayerAndAgentCount(true) <= 1);
327 }
328
329 //------------------------------------------------------------------------------------------------
336 void SetPlayerCallsign(int playerId, int companyIndex, int platoonIndex, int squadIndex, int characterNumber, ERoleCallsign characterRole = ERoleCallsign.NONE)
337 {
338 if (playerId <= 0)
339 {
340 Print("'SetPlayerCallsign': Invalid player ID: " + playerId, LogLevel.ERROR);
341 return;
342 }
343
344 SCR_PlayerCallsignData playerCallsignData;
345
346 //~ Create new Data if non existing
347 if (!m_mPlayerCallsignData.Find(playerId, playerCallsignData))
348 playerCallsignData = new SCR_PlayerCallsignData();
349
350 //~ Set new player callsign data
351 playerCallsignData.SetPlayerCallsignIndexes(companyIndex, platoonIndex, squadIndex, characterNumber, characterRole);
352 m_mPlayerCallsignData.Set(playerId, playerCallsignData);
353
354 //~ Call On player callsign changed
355 m_OnPlayerCallsignChanged.Invoke(playerId, companyIndex, platoonIndex, squadIndex, characterNumber, characterRole);
356 }
357
358 //------------------------------------------------------------------------------------------------
359 protected void OnPlayerLeftGame(int playerId)
360 {
361 if (m_mPlayerCallsignData.Contains(playerId))
362 m_mPlayerCallsignData.Remove(playerId);
363 }
364
365 //------------------------------------------------------------------------------------------------
373 bool GetPlayerCallsign(int playerId, out int companyIndex, out int platoonIndex, out int squadIndex, out int characterNumber = -1, out ERoleCallsign characterRole = ERoleCallsign.NONE)
374 {
375 SCR_PlayerCallsignData playerCallsignData;
376 if (m_mPlayerCallsignData.Find(playerId, playerCallsignData))
377 return playerCallsignData.GetPlayerCallsignIndexes(companyIndex, platoonIndex, squadIndex, characterNumber, characterRole);
378 else
379 return false;
380 }
381
382 //------------------------------------------------------------------------------------------------
384 ScriptInvokerBase<SCR_GroupsManagerComponent_OnPlayerCallsignChanged> GetOnPlayerCallsignChanged()
385 {
387 }
388
389 //------------------------------------------------------------------------------------------------
390 protected void FillAvailableCallsigns()
391 {
392 array<Faction> factions = {};
393 FactionManager factionManager = GetGame().GetFactionManager();
394
395 if (!factionManager)
396 return;
397
398 factionManager.GetFactionsList(factions);
399
400 foreach (Faction faction: factions)
401 {
402 SCR_Faction ScrFaction = SCR_Faction.Cast(faction);
403
404 if (!ScrFaction)
405 continue;
406
407 SCR_FactionCallsignInfo factionCallsignInfo = ScrFaction.GetCallsignInfo();
408
409 if (!factionCallsignInfo)
410 continue;
411
412 array<ref SCR_CallsignInfo> companyArray = {};
413 array<ref SCR_CallsignInfo> platoonArray = {};
414 array<ref SCR_CallsignInfo> squadArray = {};
415
416 factionCallsignInfo.GetCompanyArray(companyArray);
417 if (companyArray.IsEmpty())
418 continue;
419
420 factionCallsignInfo.GetPlatoonArray(platoonArray);
421 if (platoonArray.IsEmpty())
422 continue;
423
424 factionCallsignInfo.GetSquadArray(squadArray);
425 if (squadArray.IsEmpty())
426 continue;
427
428 SCR_FactionCallsignData factionCallsignData = new SCR_FactionCallsignData(factionCallsignInfo);
429
430 m_mAvailableCallsigns.Insert(faction, factionCallsignData);
431 }
432 }
433
434 //------------------------------------------------------------------------------------------------
435 override void EOnInit(IEntity owner)
436 {
437 super.EOnInit(owner);
438
440
441 if (GetGameMode().IsMaster())
442 {
444 if (!m_GroupManager)
445 Debug.Error2("SCR_CallsignManagerComponent: EOnInit", "Could not find SCR_GroupsManagerComponent!");
446
449 }
450 }
451
452 //------------------------------------------------------------------------------------------------
453 override void OnPostInit(IEntity owner)
454 {
455 super.OnPostInit(owner);
456
457 if (SCR_Global.IsEditMode(owner))
458 return;
459
460 SetEventMask(owner, EntityEvent.INIT);
461 }
462
463 //------------------------------------------------------------------------------------------------
464 // destructor
466 {
467 if (!GetGameMode())
468 return;
469
470 if (GetGameMode().IsMaster())
471 {
474 }
475 }
476}
ERoleCallsign
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
func SCR_GroupsManagerComponent_OnPlayerCallsignChanged
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition Debug.c:13
proto external Managed FindComponent(typename typeName)
int GetPlayerAndAgentCount(bool checkMasterAndSlaves=false)
SCR_AIGroup GetMaster()
bool IsSlave()
Faction GetFaction()
ScriptInvokerBase< SCR_BaseGameMode_OnPlayerDisconnected > GetOnPlayerDisconnected()
ScriptInvokerBase< SCR_BaseGameMode_PlayerIdAndEntity > GetOnPlayerSpawned()
Component of assigning and storing squad names.
bool GetCallsignNames(out string company, out string platoon, out string squad, out string character, out string format)
bool GetCallsignIndexes(out int companyIndex, out int platoonIndex, out int squadIndex, out int characterNumber=-1, out ERoleCallsign characterRole=ERoleCallsign.NONE)
Manages available callsigns for each faction.
ref map< Faction, ref SCR_FactionCallsignData > m_mAvailableCallsigns
All available callsigns are stored here.
void AssignRandomGroupCallsigns(Faction faction, out int companyIndex, out int platoonIndex, out int squadIndex)
ref ScriptInvokerBase< SCR_GroupsManagerComponent_OnPlayerCallsignChanged > m_OnPlayerCallsignChanged
SCR_GroupsManagerComponent m_GroupManager
void AssignRandomDuplicateCallsign(Faction faction, out int company, out int platoon, out int squad)
If all callsigns are taken then assign a random callsign. This is an edge case safety as otherwise en...
void SetPlayerCallsign(int playerId, int companyIndex, int platoonIndex, int squadIndex, int characterNumber, ERoleCallsign characterRole=ERoleCallsign.NONE)
void AssignCompanySpecificGroupCallsign(Faction faction, out int specificCompanyIndex, out int platoonIndex, out int squadIndex)
ref array< ref array< int > > m_aDuplicateCallsigns
Assigned Duplicate callsigns. If all callsigns are assigned then this stores any assigned dupplicates...
bool GetEntityCallsignIndexes(IEntity entity, out int companyCallsignIndex, out int platoonCallsignIndex, out int squadCallsignIndex, out int characterCallsignIndex)
bool GetEntityCallsignNames(IEntity entity, out string companyCallsignName, out string platoonCallsignName, out string squadCallsignName, out string characterCallsignName, out string format)
bool GetPlayerCallsign(int playerId, out int companyIndex, out int platoonIndex, out int squadIndex, out int characterNumber=-1, out ERoleCallsign characterRole=ERoleCallsign.NONE)
void OnPlayerSpawn(int playerId, IEntity playerEntity)
Assign callsign for players when they are spawned (Server Only).
override void OnPostInit(IEntity owner)
bool GetEntityCallsignNames(SCR_EditableEntityComponent editableEntity, out string companyCallsignName, out string platoonCallsignName, out string squadCallsignName, out string characterCallsignName, out string format)
void AssignGroupRoleSpecificGroupCallsign(Faction faction, notnull SCR_AIGroup group, out int companyIndex, out int platoonIndex, out int squadIndex)
bool GetEntityCallsignIndexes(SCR_EditableEntityComponent editableEntity, out int companyCallsignIndex, out int platoonCallsignIndex, out int squadCallsignIndex, out int characterCallsignIndex)
ScriptInvokerBase< SCR_GroupsManagerComponent_OnPlayerCallsignChanged > GetOnPlayerCallsignChanged()
Returns ScriptInvoker on player callsign changed.
void AssignCallGroupCallsign(notnull SCR_AIGroup group, Faction faction, SCR_CallsignGroupComponent masterCallsignComponent, out int companyIndex, out int platoonIndex, out int squadIndex)
void AssignFirstAvailableGroupCallsign(Faction faction, out int companyIndex, out int platoonIndex, out int squadIndex)
void RemoveAvailableGroupCallsign(Faction faction, int companyIndex, int platoonIndex, int squadIndex)
void MakeGroupCallsignAvailible(Faction faction, int companyIndex, int platoonIndex, int squadIndex)
ref map< int, ref SCR_PlayerCallsignData > m_mPlayerCallsignData
Holds all the callsigns that are assigned to players.
For each faction, holds available companies, which in turn hold available platoons,...
void AddCallsign(int companyIndex, int platoonIndex, int squadIndex)
bool GetRandomCallsign(out int company, out int platoon, out int squad)
bool GetSpecificCompanyCallsign(out int company, out int platoon, out int squad)
void RemoveCallsign(int companyIndex, int platoonIndex, int squadIndex)
bool GetGroupRoleSpecificCompanyCallsign(notnull SCR_AIGroup group, out int company, out int platoon, out int squad)
bool GetFirstAvailibleCallsign(out int firstAvailableCompany, out int firstAvailablePlatoon, out int firstAvailableSquad)
void GetSquadArray(notnull array< ref SCR_CallsignInfo > squadArray)
void GetPlatoonArray(notnull array< ref SCR_CallsignInfo > platoonArray)
void GetCompanyArray(notnull array< ref SCR_CallsignInfo > companyArray)
bool GetRandomCallsign(out int company, out int platoon, out int squad)
SCR_FactionCallsignInfo GetCallsignInfo()
static bool IsEditMode()
Definition Functions.c:1566
void SetPlayerCallsignIndexes(int company, int platoon, int squad, int character, ERoleCallsign role)
bool GetPlayerCallsignIndexes(out int company, out int platoon, out int squad, out int character, out ERoleCallsign role)
Definition Types.c:486
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
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
EntityEvent
Various entity events.
Definition EntityEvent.c:14