11 protected ResourceName m_sDefaultGroupPrefab;
22 [
Attribute(
"Flags", UIWidgets.ResourcePickerThumbnail,
"Flag icon of this particular group.",
params:
"edds")]
34 static Widget s_wDebugLayout;
42 protected ref map<Faction, ref array<SCR_AIGroup>>
m_mPlayableGroups =
new map<Faction, ref array<SCR_AIGroup>>();
71 RplComponent rplComponent = RplComponent.Cast(
GetOwner().FindComponent(RplComponent));
75 return rplComponent.IsProxy();
89 previousGroup.RemovePlayer(playerID);
94 if (newGroup.IsFull())
100 newGroup.AddPlayer(playerID);
117 SCR_PlayerControllerGroupComponent playerGroupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
118 if (!playerGroupController)
125 RplId groupRplID = Replication.FindId(group);
127 array<int> requesterIDs = {};
128 group.GetRequesterIDs(requesterIDs);
130 for (
int i = 0, count = requesterIDs.Count(); i < count; i++)
132 if(!group.IsPlayerInGroup(playerID))
133 SCR_NotificationsComponent.SendToPlayer(requesterIDs[i],
ENotification.GROUPS_REQUEST_CANCELLED);
136 playerGroupController.ClearAllRequesters(groupRplID);
153 group.AddPlayer(playerID);
164 FactionManager factionManager =
GetGame().GetFactionManager();
172 array<Faction> factions = {};
174 factionManager.GetFactionsList(factions);
176 foreach (
Faction faction : factions)
182 array<ref SCR_GroupPreset> groups = {};
184 scrFaction.GetPredefinedGroups(groups);
192 newGroup.SetCanDeleteIfNoPlayer(
false);
194 gr.SetupGroup(newGroup);
196 if (newGroup.GetGroupFlag().IsEmpty())
197 newGroup.SetGroupFlag(0, !scrFaction.GetGroupFlagImageSet().IsEmpty());
211 group.SetGroupLeader(playerID);
228 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
252 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
271 group.SetPrivate(isPrivate);
281 array<SCR_AIGroup> groups;
284 for (
int i = groups.Count() - 1; i >= 0; i--)
328 Faction faction = factionManager.GetPlayerFaction(playerID);
336 for (
int i = playableGroups.Count() - 1; i >= 0; i--)
338 if (playableGroups[i] && playableGroups[i].IsPlayerInGroup(playerID))
339 return playableGroups[i];
352 array<SCR_AIGroup> playableGroups;
354 for (
int i = playableGroups.Count() - 1; i >= 0; i--)
356 if (playableGroups[i].IsPlayerInGroup(playerID))
371 s_wDebugLayout =
GetGame().GetWorkspace().CreateWidgets(
"{661C199F3D59BB24}UI/layouts/Debug/Groups.layout");
373 VerticalLayoutWidget groupsLayout = VerticalLayoutWidget.Cast(s_wDebugLayout.FindAnyWidget(
"GroupsLayout"));
378 while (groupsLayout.GetChildren())
380 groupsLayout.GetChildren().RemoveFromHierarchy();
384 for (
int i = playableGroups.Count() - 1; i >= 0; i--)
386 Widget groupEntry =
GetGame().GetWorkspace().CreateWidgets(
"{898A1945FD29FC71}UI/layouts/Debug/GroupsGroupEntry.layout", groupsLayout);
387 RichTextWidget groupName = RichTextWidget.Cast(groupEntry.FindAnyWidget(
"GroupName"));
389 groupName.SetText(playableGroups[i].
GetGroupID().ToString() +
": " + playableGroups[i].GetCallsignSingleString());
391 array<int> playerIDs = playableGroups[i].GetPlayerIDs();
392 int playersCount = playerIDs.Count();
394 for (
int j = 0; j < playersCount; j++)
396 HorizontalLayoutWidget characterEntry = HorizontalLayoutWidget.Cast(groupEntry.GetWorkspace().CreateWidgets(
"{952C36C11AF74465}UI/layouts/Debug/GroupsCharacterEntry.layout", groupEntry));
397 TextWidget playerNameWidget = TextWidget.Cast(characterEntry.FindAnyWidget(
"CharacterName"));
398 if (!playerNameWidget)
401 playerNameWidget.SetText(
GetGame().GetPlayerManager().GetPlayerName(playerIDs[j]));
419 array<SCR_AIGroup> allGroups = {};
420 array<SCR_AIGroup> currentGroups = {};
425 for (
int j = currentGroups.Count() - 1; j >= 0; j--)
427 if (currentGroups[j])
428 allGroups.Insert(currentGroups[j]);
432 outAllGroups = allGroups;
439 Faction groupFaction = group.GetFaction();
446 group.SetRadioFrequency(frequency);
455 SetEventMask(
GetOwner(), EntityEvent.FRAME);
468 if (group.GetPlayerCount() > 0)
472 if (!group.GetDeleteIfNoPlayer())
474 if (group.IsPrivate())
475 group.SetPrivate(
false);
497 if (group.GetPlayerCount() < group.GetMaxMembers())
501 Faction faction = group.GetFaction();
514 int groupsCount = groups.Count();
515 if (groupsCount == 0 && !scrFaction.GetCanCreateOnlyPredefinedGroups())
522 for (
int i = groupsCount - 1; i >= 0; i--)
530 if (!scrFaction.GetCanCreateOnlyPredefinedGroups())
542 IEntity radio = gagdetManager.GetGadgetByType(EGadgetType.RADIO);
546 return BaseRadioComponent.Cast(radio.FindComponent(BaseRadioComponent));
568 tsv.SetFrequency(group.GetRadioFrequency());
589 if (group.GetAgentsCount() > 0)
593 Faction faction = group.GetFaction();
602 int groupsCount = groups.Count();
603 if (groupsCount == 0)
607 for (
int i = groupsCount - 1; i >= 0; i--)
609 if (groups[i] == group)
612 if (groups[i].GetAgentsCount() == 0)
635 Faction faction = group.GetFaction();
643 int frequency = group.GetRadioFrequency();
644 int foundGroupsWithFrequency = 0;
645 array<SCR_AIGroup> existingGroups = {};
652 if (checkedGroup && checkedGroup.GetRadioFrequency() == frequency)
653 foundGroupsWithFrequency++;
658 if (foundGroupsWithFrequency <= 1)
665 if (slaveGroup && slaveGroup.GetAgentsCount() <= 0)
668 if (groups.Find(group) >= 0)
669 groups.RemoveItem(group);
677 array<SCR_AIGroup> groups;
685 if (groups.Find(group) < 0)
686 groups.Insert(group);
696 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
699 FactionManager factionManager =
GetGame().GetFactionManager();
703 Faction faction = factionManager.GetFactionByIndex(factionIndex);
709 group.SetFaction(faction);
729 if (scrFaction.GetCanCreateOnlyPredefinedGroups())
737 if (!newPlayerGroup || !owner)
740 PlayerController controller = PlayerController.Cast(owner.GetOwner());
744 SCR_PlayerControllerGroupComponent groupComp = SCR_PlayerControllerGroupComponent.Cast(controller.FindComponent(SCR_PlayerControllerGroupComponent));
752 oldGroup.RemovePlayer(controller.GetPlayerId());
772 for (
int i = factionGroups.Count() - 1; i >= 0; i--)
774 if (!factionGroups[i])
778 return factionGroups[i];
790 RplComponent rplComp = RplComponent.Cast(
GetOwner().FindComponent(RplComponent));
799 Resource groupResource = Resource.Load(m_sDefaultGroupPrefab);
800 if (!groupResource.IsValid())
807 group.DeactivateAI();
809 group.SetFaction(faction);
816 if (commandingManager)
818 IEntity groupEntity =
GetGame().SpawnEntityPrefab(Resource.Load(commandingManager.GetGroupPrefab()));
826 slaveGroup.DeactivateAI();
828 RplComponent RplComp = RplComponent.Cast(slaveGroup.FindComponent(RplComponent));
832 RplId slaveGroupRplID = RplComp.Id();
834 RplComp = RplComponent.Cast(group.FindComponent(RplComponent));
844 GetGame().GetCallqueue().CallLater(UpdateDebugUI, 1,
false);
862 for (
int i = 0, count = factionGroups.Count(); i < count; i++)
864 if (!factionGroups[i].IsFull() && factionGroups[i] != ownGroup && (!respectPrivate || !factionGroups[i].IsPrivate()))
866 group = factionGroups[i];
885 if (playerGroup && playerGroup.GetPlayerCount() == 1)
898 if (scrFaction.GetCanCreateOnlyPredefinedGroups())
918 int factionHQFrequency;
921 factionHQFrequency = militaryFaction.GetFactionRadioFrequency();
927 if (minFrequencyAvailable == factionHQFrequency)
936 if (usedForFactions.Find(frequencyFaction) == -1)
943 return minFrequencyAvailable;
945 Print(
"Ran out of frequencies for groups", LogLevel.WARNING);
961 factions.Insert(faction);
965 if (usedForFactions.Find(faction) == -1)
967 usedForFactions.Insert(faction);
982 if (usedForFactions.Find(faction))
994 if (!faction || !frequency)
1000 if (factions.Count() <= 1 && factions.Find(faction) != -1)
1004 int factionIdx = factions.Find(faction);
1005 if (factionIdx >= 0 && factionIdx < factions.Count())
1006 factions.Remove(factionIdx);
1035 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
1039 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(masterGroupID));
1043 masterGroup =
SCR_AIGroup.Cast(rplComp.GetEntity());
1047 rplComp = RplComponent.Cast(Replication.FindItem(slaveGroupID));
1055 masterGroup.SetSlave(group);
1063 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
1066 SCR_ChimeraCharacter AIMember;
1067 array<SCR_ChimeraCharacter> AIMembers;
1068 GetAIMembers(groupRplCompID, aiCharacterComponentID, AIMembers, AIMember);
1069 if (!AIMembers || !AIMember)
1072 AIMembers.RemoveItem(AIMember);
1080 void GetAIMembers(RplId groupRplCompID, RplId aiCharacterComponentID, out array<SCR_ChimeraCharacter> members, out SCR_ChimeraCharacter AIMember)
1082 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(aiCharacterComponentID));
1086 AIMember = SCR_ChimeraCharacter.Cast(rplComp.GetEntity());
1090 rplComp = RplComponent.Cast(Replication.FindItem(groupRplCompID));
1098 members = group.GetAIMembers();
1125 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
1128 SCR_ChimeraCharacter AIMember;
1129 array<SCR_ChimeraCharacter> AIMembers;
1130 GetAIMembers(groupRplCompID, aiCharacterComponentID, AIMembers, AIMember);
1131 if (!AIMembers || !AIMember)
1134 AIMembers.Insert(AIMember);
1142 if (!group || !agent)
1145 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(agent.GetControlledEntity());
1149 RplId groupCompRplID, characterCompRplID;
1150 RplComponent rplComp = RplComponent.Cast(group.FindComponent(RplComponent));
1154 groupCompRplID = rplComp.Id();
1156 rplComp = RplComponent.Cast(character.FindComponent(RplComponent));
1160 characterCompRplID = rplComp.Id();
1201 ClearEventMask(
GetOwner(), EntityEvent.FRAME);
1210 PlayerController controller =
GetGame().GetPlayerManager().GetPlayerController(playerId);
1218 IEntity radio = gadgetManager.GetGadgetByType(EGadgetType.RADIO);
1222 BaseRadioComponent radioComponent = BaseRadioComponent.Cast(radio.FindComponent(BaseRadioComponent));
1223 if (!radioComponent)
1226 SCR_PlayerControllerGroupComponent groupComponent = SCR_PlayerControllerGroupComponent.Cast(controller.FindComponent(SCR_PlayerControllerGroupComponent));
1227 if (!groupComponent || groupComponent.GetActualGroupFrequency() == 0)
1234 transceiver.SetFrequency(groupComponent.GetActualGroupFrequency());
1243 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
1245 if (playerFactionAffiliation)
1253 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
1254 if (playerController)
1257 if (playerFactionAffiliation)
1266 int playerID = reconnectData.m_iPlayerId;
1272 Faction faction = factionManager.GetPlayerFaction(playerID);
1293 SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
1332 s_wDebugLayout.RemoveFromHierarchy();