15 protected ref map<Faction, ref SCR_FactionCallsignData> m_mAvailableCallsigns =
new map<Faction, ref SCR_FactionCallsignData>;
18 protected ref array<ref array<int>> m_aDuplicateCallsigns = {};
21 protected ref map<int, ref SCR_PlayerCallsignData> m_mPlayerCallsignData =
new map<int, ref SCR_PlayerCallsignData>;
24 protected ref ScriptInvokerBase<SCR_GroupsManagerComponent_OnPlayerCallsignChanged> m_OnPlayerCallsignChanged =
new ScriptInvokerBase<SCR_GroupsManagerComponent_OnPlayerCallsignChanged>();
40 bool GetEntityCallsignIndexes(IEntity entity, out
int companyCallsignIndex, out
int platoonCallsignIndex, out
int squadCallsignIndex, out
int characterCallsignIndex)
44 return callsignComponent && callsignComponent.GetCallsignIndexes(companyCallsignIndex, platoonCallsignIndex, squadCallsignIndex, characterCallsignIndex);
56 bool GetEntityCallsignIndexes(
SCR_EditableEntityComponent editableEntity, out
int companyCallsignIndex, out
int platoonCallsignIndex, out
int squadCallsignIndex, out
int characterCallsignIndex)
58 return GetEntityCallsignIndexes(editableEntity.GetOwner(), companyCallsignIndex, platoonCallsignIndex, squadCallsignIndex, characterCallsignIndex);
71 bool GetEntityCallsignNames(IEntity entity, out
string companyCallsignName, out
string platoonCallsignName, out
string squadCallsignName, out
string characterCallsignName, out
string format)
75 if (!callsignComponent)
78 return callsignComponent.GetCallsignNames(companyCallsignName, platoonCallsignName, squadCallsignName, characterCallsignName, format);
91 bool GetEntityCallsignNames(
SCR_EditableEntityComponent editableEntity, out
string companyCallsignName, out
string platoonCallsignName, out
string squadCallsignName, out
string characterCallsignName, out
string format)
93 return GetEntityCallsignNames(editableEntity.GetOwner(), companyCallsignName, platoonCallsignName, squadCallsignName, characterCallsignName, format);
102 void AssignCallGroupCallsign(
Faction faction, SCR_CallsignGroupComponent masterCallsignComponent, out
int companyIndex, out
int platoonIndex, out
int squadIndex)
109 if (masterCallsignComponent)
111 masterCallsignComponent.GetCallsignIndexes(companyIndex, platoonIndex, squadIndex);
116 if (!m_mAvailableCallsigns.Contains(faction))
131 if (!callsignInfo.GetIsAssignedRandomly())
132 AssignFirstAvailableGroupCallsign(faction, companyIndex, platoonIndex, squadIndex);
135 AssignRandomGroupCallsigns(faction, companyIndex, platoonIndex, squadIndex);
139 protected void AssignFirstAvailableGroupCallsign(
Faction faction, out
int companyIndex, out
int platoonIndex, out
int squadIndex)
142 if (m_mAvailableCallsigns.Find(faction, factionCallsign))
144 if (factionCallsign.GetFirstAvailibleCallsign(companyIndex, platoonIndex, squadIndex))
146 RemoveAvailableGroupCallsign(faction, companyIndex, platoonIndex, squadIndex);
152 AssignRandomDuplicateCallsign(faction, companyIndex, platoonIndex, squadIndex);
153 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);
158 protected void AssignCompanySpecificGroupCallsign(
Faction faction, out
int specificCompanyIndex, out
int platoonIndex, out
int squadIndex)
161 if (m_mAvailableCallsigns.Find(faction, factionCallsign))
163 if (factionCallsign.GetSpecificCompanyCallsign(specificCompanyIndex, platoonIndex, squadIndex))
165 RemoveAvailableGroupCallsign(faction, specificCompanyIndex, platoonIndex, squadIndex);
171 AssignRandomDuplicateCallsign(faction, specificCompanyIndex, platoonIndex, squadIndex);
172 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);
181 void AssignRandomGroupCallsigns(
Faction faction, out
int companyIndex, out
int platoonIndex, out
int squadIndex)
184 if (m_mAvailableCallsigns.Find(faction, factionCallsign))
186 if (factionCallsign.GetRandomCallsign(companyIndex, platoonIndex, squadIndex))
188 RemoveAvailableGroupCallsign(faction, companyIndex, platoonIndex, squadIndex);
194 AssignRandomDuplicateCallsign(faction, companyIndex, platoonIndex, squadIndex);
195 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);
206 void MakeGroupCallsignAvailible(
Faction faction,
int companyIndex,
int platoonIndex,
int squadIndex)
209 if (!m_aDuplicateCallsigns.IsEmpty())
211 int count = m_aDuplicateCallsigns.Count();
213 for(
int i = 0; i < count; i++)
216 if (m_aDuplicateCallsigns[i][0] == companyIndex && m_aDuplicateCallsigns[i][1] == platoonIndex && m_aDuplicateCallsigns[i][2] == squadIndex)
218 m_aDuplicateCallsigns.Remove(i);
226 if (m_mAvailableCallsigns.Find(faction, factionCallsignData))
227 factionCallsignData.AddCallsign(companyIndex, platoonIndex, squadIndex);
232 protected void RemoveAvailableGroupCallsign(
Faction faction,
int companyIndex,
int platoonIndex,
int squadIndex)
236 if (m_mAvailableCallsigns.Find(faction, factionCallsignData))
237 factionCallsignData.RemoveCallsign(companyIndex, platoonIndex, squadIndex);
242 protected void AssignRandomDuplicateCallsign(
Faction faction, out
int company, out
int platoon, out
int squad)
249 if (!factionCallsignInfo)
252 if (factionCallsignInfo.GetRandomCallsign(company, platoon, squad))
254 array<int> duplicateCallsign = {};
255 duplicateCallsign.Insert(company);
256 duplicateCallsign.Insert(platoon);
257 duplicateCallsign.Insert(squad);
259 m_aDuplicateCallsigns.Insert(duplicateCallsign);
265 protected void OnPlayerSpawn(
int playerId, IEntity playerEntity)
270 SCR_CallsignCharacterComponent characterCallsign = SCR_CallsignCharacterComponent.Cast(playerEntity.FindComponent(SCR_CallsignCharacterComponent));
271 if (!characterCallsign)
275 characterCallsign.InitPlayerOnServer(playerId);
278 SCR_AIGroup playerGroup = m_GroupManager.GetPlayerGroup(playerId);
283 if (playerGroup.IsSlave())
288 playerGroup = master;
291 int companyIndex, platoonIndex, squadIndex, characterNumber;
295 if (!GetPlayerCallsign(playerId, companyIndex, platoonIndex, squadIndex, characterNumber, characterRole))
299 characterCallsign.AssignCharacterCallsign(playerGroup.GetFaction(), companyIndex, platoonIndex, squadIndex, characterNumber, characterRole, playerGroup.GetPlayerAndAgentCount(
true) <= 1);
309 void SetPlayerCallsign(
int playerId,
int companyIndex,
int platoonIndex,
int squadIndex,
int characterNumber,
ERoleCallsign characterRole =
ERoleCallsign.NONE)
313 Print(
"'SetPlayerCallsign': Invalid player ID: " + playerId, LogLevel.ERROR);
320 if (!m_mPlayerCallsignData.Find(playerId, playerCallsignData))
324 playerCallsignData.SetPlayerCallsignIndexes(companyIndex, platoonIndex, squadIndex, characterNumber, characterRole);
325 m_mPlayerCallsignData.Set(playerId, playerCallsignData);
328 m_OnPlayerCallsignChanged.Invoke(playerId, companyIndex, platoonIndex, squadIndex, characterNumber, characterRole);
332 protected void OnPlayerLeftGame(
int playerId)
334 if (m_mPlayerCallsignData.Contains(playerId))
335 m_mPlayerCallsignData.Remove(playerId);
346 bool GetPlayerCallsign(
int playerId, out
int companyIndex, out
int platoonIndex, out
int squadIndex, out
int characterNumber = -1, out
ERoleCallsign characterRole =
ERoleCallsign.NONE)
349 if (m_mPlayerCallsignData.Find(playerId, playerCallsignData))
350 return playerCallsignData.GetPlayerCallsignIndexes(companyIndex, platoonIndex, squadIndex, characterNumber, characterRole);
357 ScriptInvokerBase<SCR_GroupsManagerComponent_OnPlayerCallsignChanged> GetOnPlayerCallsignChanged()
359 return m_OnPlayerCallsignChanged;
363 protected void FillAvailableCallsigns()
365 array<Faction> factions = {};
366 FactionManager factionManager =
GetGame().GetFactionManager();
371 factionManager.GetFactionsList(factions);
373 foreach (
Faction faction: factions)
382 if (!factionCallsignInfo)
385 array<ref SCR_CallsignInfo> companyArray = {};
386 array<ref SCR_CallsignInfo> platoonArray = {};
387 array<ref SCR_CallsignInfo> squadArray = {};
389 factionCallsignInfo.GetCompanyArray(companyArray);
390 if (companyArray.IsEmpty())
393 factionCallsignInfo.GetPlatoonArray(platoonArray);
394 if (platoonArray.IsEmpty())
397 factionCallsignInfo.GetSquadArray(squadArray);
398 if (squadArray.IsEmpty())
403 m_mAvailableCallsigns.Insert(faction, factionCallsignData);
408 override void EOnInit(IEntity owner)
410 super.EOnInit(owner);
412 FillAvailableCallsigns();
418 Debug.Error2(
"SCR_CallsignManagerComponent: EOnInit",
"Could not find SCR_GroupsManagerComponent!");
420 GetGameMode().GetOnPlayerDisconnected().Insert(OnPlayerLeftGame);
421 GetGameMode().GetOnPlayerSpawned().Insert(OnPlayerSpawn);
426 override void OnPostInit(IEntity owner)
428 super.OnPostInit(owner);
433 SetEventMask(owner, EntityEvent.INIT);
445 GetGameMode().GetOnPlayerDisconnected().Remove(OnPlayerLeftGame);
446 GetGameMode().GetOnPlayerSpawned().Remove(OnPlayerSpawn);