Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CommandingManagerComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Commanding", description: "Commanding manager, attach to game mode entity!.")]
3 {
4 }
5 
6 //------------------------------------------------------------------------------------------------
8 {
9  [Attribute("{000CD338713F2B5A}Prefabs/AI/Groups/Group_Base.et")]
10  protected ResourceName m_sAIGroupPrefab;
11 
12  [Attribute("{54764D4E706F348B}Configs/Commanding/Commands.conf")]
13  protected ResourceName m_sCommandsConfigPath;
14 
15  [Attribute(defvalue: "8", UIWidgets.EditBox, desc: "How many AI soldiers can be recruited into single player group")]
16  protected int m_iMaxAIPerGroup;
17 
19 
20  protected static SCR_CommandingManagerComponent s_Instance;
21 
22  protected ref array<ref SCR_BaseRadialCommand> m_aCommands;
23  protected ref map<string, ref SCR_BaseRadialCommand> m_mNameCommand = new map<string, ref SCR_BaseRadialCommand>();
24 
25  protected static const int NORMAL_PRIORITY = 50;
26 
27  //------------------------------------------------------------------------------------------------
30  {
31  return s_Instance;
32  }
33 
34  //------------------------------------------------------------------------------------------------
36  ResourceName GetGroupPrefab()
37  {
38  return m_sAIGroupPrefab;
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  // constructor
46  void SCR_CommandingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
47  {
48  if (!s_Instance)
49  s_Instance = this;
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  override void OnPostInit(IEntity owner)
54  {
55  super.OnPostInit(owner);
56 
58 
60  if (!gameMode)
61  return;
62 
63  gameMode.GetOnPlayerSpawned().Insert(ResetSlaveGroupWaypoints);
64  }
65 
66  //------------------------------------------------------------------------------------------------
69  {
71  if (!commandsConfig)
72  return;
73 
74  m_aCommands = commandsConfig.GetCommands();
75 
76  foreach (SCR_BaseRadialCommand command : m_aCommands)
77  {
78  m_mNameCommand.Insert(command.GetCommandName(), command);
79  }
80  }
81 
82  //------------------------------------------------------------------------------------------------
86  void ResetSlaveGroupWaypoints(int playerId, IEntity player)
87  {
88  PlayerController pc = GetGame().GetPlayerManager().GetPlayerController(playerId);
89  if (!pc)
90  return;
91 
92  //do nothing if player is not a leader of group
93  SCR_PlayerControllerGroupComponent groupComponent = SCR_PlayerControllerGroupComponent.Cast(pc.FindComponent(SCR_PlayerControllerGroupComponent));
94  if (!groupComponent || !groupComponent.IsPlayerLeaderOwnGroup())
95  return;
96 
97  SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
98  if (!groupsManager)
99  return;
100 
101  SCR_AIGroup masterGroup = groupsManager.GetPlayerGroup(playerId);
102  if (!masterGroup)
103  return;
104 
105  //no need to do this for empty group because there are no AIs to mess things up
106  SCR_AIGroup slaveGroup = masterGroup.GetSlave();
107  if (!slaveGroup || slaveGroup.GetAgentsCount() <= 0)
108  return;
109 
110  //reset the waypoints for slave group, so they go to their default behavior
111  array<AIWaypoint> currentWaypoints = {};
112  slaveGroup.GetWaypoints(currentWaypoints);
113  foreach (AIWaypoint currentwp : currentWaypoints)
114  {
115  slaveGroup.RemoveWaypoint(currentwp);
116  }
117 
118  AIFormationComponent slaveGroupFormationComp = slaveGroup.GetFormationComponent();
119  if (slaveGroupFormationComp)
120  slaveGroupFormationComp.SetFormationDisplacement(0);
121 
122  //remove master-slave connection from slave
123  slaveGroup.SetMaster(null);
124 
125  SCR_CommandingManagerComponent commandingManager = SCR_CommandingManagerComponent.GetInstance();
126  if (!commandingManager)
127  return;
128 
129  //prepare new slave group for player
130  Resource groupPrefabRes = Resource.Load(commandingManager.GetGroupPrefab());
131  if (!groupPrefabRes.IsValid())
132  return;
133 
134  IEntity groupEntity = GetGame().SpawnEntityPrefab(groupPrefabRes);
135 
136  if (!groupEntity)
137  return;
138 
139  SCR_AIGroup newSlaveGroup = SCR_AIGroup.Cast(groupEntity);
140  if (!newSlaveGroup)
141  return;
142 
143  RplComponent RplComp = RplComponent.Cast(newSlaveGroup.FindComponent(RplComponent));
144  if (!RplComp)
145  return;
146 
147  RplId slaveGroupRplID = RplComp.Id();
148 
149  RplComp = RplComponent.Cast(masterGroup.FindComponent(RplComponent));
150  if (!RplComp)
151  return;
152 
153  groupsManager.RequestSetGroupSlave(RplComp.Id(), slaveGroupRplID);
154  }
155 
156  //------------------------------------------------------------------------------------------------
163  void RequestCommandExecution(int commandIndex, RplId cursorTargetID, RplId groupRplID, vector targetPosition, int playerID)
164  {
165  //check if the passed arguments are valid, if yes, send a callback RPC to commanders playercontroller so he can make a gesture.
166  RPC_DoExecuteCommand(commandIndex, cursorTargetID, groupRplID, targetPosition, playerID);
167  Rpc(RPC_DoExecuteCommand, commandIndex, cursorTargetID, groupRplID, targetPosition, playerID);
168  }
169 
170  //------------------------------------------------------------------------------------------------
177  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
178  void RPC_DoExecuteCommand(int commandIndex, RplId cursorTargetID, RplId groupRplID, vector targetPosition, int playerID)
179  {
180  RplComponent rplComp;
181  IEntity cursorTarget, group;
182  rplComp = RplComponent.Cast(Replication.FindItem(cursorTargetID));
183  if (rplComp)
184  cursorTarget = rplComp.GetEntity();
185 
186  rplComp = RplComponent.Cast(Replication.FindItem(groupRplID));
187  if (rplComp)
188  group = rplComp.GetEntity();
189 
190  rplComp = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
191  if (rplComp)
192  {
194  if (command.Execute(cursorTarget, group, targetPosition, playerID, rplComp.IsProxy()))
195  {
196  PlayCommanderSound(playerID, commandIndex);
197  if (!rplComp.IsMaster())
198  return;
199 
200  PlayerController controller = GetGame().GetPlayerManager().GetPlayerController(playerID);
201  if (!controller)
202  return;
203 
204  SCR_PlayerControllerCommandingComponent commandingComp = SCR_PlayerControllerCommandingComponent.Cast(controller.FindComponent(SCR_PlayerControllerCommandingComponent));
205  if (!commandingComp)
206  return;
207 
208  commandingComp.CommandExecutedCallback(commandIndex);
209  }
210  }
211  }
212 
213  //------------------------------------------------------------------------------------------------
217  void PlayCommanderSound(int playerID, int commandIndex)
218  {
219  SCR_ChimeraCharacter playerCharacter = SCR_ChimeraCharacter.Cast(GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID));
220  if (!playerCharacter)
221  return;
222 
223  SignalsManagerComponent signalManager = SignalsManagerComponent.Cast(playerCharacter.FindComponent(SignalsManagerComponent));
224  if (!signalManager)
225  return;
226 
227  SCR_CommunicationSoundComponent soundComponent = SCR_CommunicationSoundComponent.Cast(playerCharacter.FindComponent(SCR_CommunicationSoundComponent));
228  if (!soundComponent)
229  return;
230 
231  string soundEventName = GetCommandSoundEventName(commandIndex);
232  if (soundEventName.IsEmpty())
233  return;
234 
235  int signalSoldierCalled = signalManager.FindSignal("SoldierCalled");
236 
237  signalManager.SetSignalValue(signalSoldierCalled, 1000);
238  soundComponent.SoundEventPriority(soundEventName, NORMAL_PRIORITY);
239  }
240 
241  //------------------------------------------------------------------------------------------------
245  SCR_BaseRadialCommand FindCommand(string commandName)
246  {
247  return m_mNameCommand.Get(commandName);
248  }
249 
250  //------------------------------------------------------------------------------------------------
254  int FindCommandIndex(string commandName)
255  {
256  SCR_BaseRadialCommand command = FindCommand(commandName);
257  if (!command)
258  return -1;
259 
260  return m_aCommands.Find(command);
261  }
262 
263  //------------------------------------------------------------------------------------------------
266  string GetCommandSoundEventName(int commandIndex)
267  {
268  SCR_BaseRadialCommand command = m_aCommands.Get(commandIndex);
269  SCR_BaseGroupCommand groupCommand = SCR_BaseGroupCommand.Cast(command);
270  if (!groupCommand)
271  return string.Empty;
272 
273 
274  return groupCommand.GetSoundEventName();
275  }
276 
277  //------------------------------------------------------------------------------------------------
281  string FindCommandNameFromIndex(int commandIndex)
282  {
283  SCR_BaseRadialCommand command = m_aCommands.Get(commandIndex);
284  if (!command)
285  return string.Empty;
286 
287  return command.GetCommandName();
288  }
289 
290  //------------------------------------------------------------------------------------------------
294  bool CanShowCommand(string commandName)
295  {
296  SCR_BaseRadialCommand command = FindCommand(commandName);
297  if (!command)
298  return false;
299 
300  return command.CanBeShown();
301  }
302 
303  //------------------------------------------------------------------------------------------------
307  bool CanShowOnMap(string commandName)
308  {
309  SCR_BaseRadialCommand command = FindCommand(commandName);
310  if (!command)
311  return false;
312 
313  return command.CanShowOnMap();
314  }
315 
316  //------------------------------------------------------------------------------------------------
319  {
320  if (m_CommandsConfig)
321  return m_CommandsConfig;
322 
323  Resource holder = BaseContainerTools.LoadContainer(m_sCommandsConfigPath);
324  if (!holder)
325  return null;
326 
327  BaseContainer container = holder.GetResource().ToBaseContainer();
328  if (!container)
329  return null;
330 
331  SCR_PlayerCommandsConfig commandsConfig = SCR_PlayerCommandsConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
332  if (!commandsConfig)
333  return null;
334 
335  m_CommandsConfig = commandsConfig;
336  return m_CommandsConfig;
337  }
338 
339  //------------------------------------------------------------------------------------------------
342  {
343  return m_iMaxAIPerGroup;
344  }
345 
346  //------------------------------------------------------------------------------------------------
348  void SetMaxAIPerGroup(int max)
349  {
350  m_iMaxAIPerGroup = max;
351  }
352 }
m_aCommands
protected ref array< ref SCR_BaseRadialCommand > m_aCommands
Definition: SCR_CommandingManagerComponent.c:22
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
m_sCommandsConfigPath
Configs Commanding Commands conf protected ResourceName m_sCommandsConfigPath
Definition: SCR_CommandingManagerComponent.c:13
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ResetSlaveGroupWaypoints
void ResetSlaveGroupWaypoints(int playerId, IEntity player)
Definition: SCR_CommandingManagerComponent.c:86
FindCommand
SCR_BaseRadialCommand FindCommand(string commandName)
Definition: SCR_CommandingManagerComponent.c:245
GetGroupPrefab
ResourceName GetGroupPrefab()
Definition: SCR_CommandingManagerComponent.c:36
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
FindCommandIndex
int FindCommandIndex(string commandName)
Definition: SCR_CommandingManagerComponent.c:254
CanShowOnMap
bool CanShowOnMap(string commandName)
Definition: SCR_CommandingManagerComponent.c:307
m_iMaxAIPerGroup
protected int m_iMaxAIPerGroup
Definition: SCR_CommandingManagerComponent.c:16
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
PlayCommanderSound
void PlayCommanderSound(int playerID, int commandIndex)
Definition: SCR_CommandingManagerComponent.c:217
GetCommandsConfig
SCR_PlayerCommandsConfig GetCommandsConfig()
Definition: SCR_CommandingManagerComponent.c:318
FindCommandNameFromIndex
string FindCommandNameFromIndex(int commandIndex)
Definition: SCR_CommandingManagerComponent.c:281
SCR_BaseRadialCommand
Definition: SCR_BaseRadialCommand.c:2
SetMaxAIPerGroup
void SetMaxAIPerGroup(int max)
Definition: SCR_CommandingManagerComponent.c:348
InitiateCommandMaps
void InitiateCommandMaps()
Definition: SCR_CommandingManagerComponent.c:68
RequestCommandExecution
void RequestCommandExecution(int commandIndex, RplId cursorTargetID, RplId groupRplID, vector targetPosition, int playerID)
Definition: SCR_CommandingManagerComponent.c:163
RPC_DoExecuteCommand
void RPC_DoExecuteCommand(int commandIndex, RplId cursorTargetID, RplId groupRplID, vector targetPosition, int playerID)
Definition: SCR_CommandingManagerComponent.c:178
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_CommandingManagerComponent.c:53
GetMaxAIPerGroup
int GetMaxAIPerGroup()
Definition: SCR_CommandingManagerComponent.c:341
GetCommandSoundEventName
string GetCommandSoundEventName(int commandIndex)
Definition: SCR_CommandingManagerComponent.c:266
CanShowCommand
bool CanShowCommand(string commandName)
Definition: SCR_CommandingManagerComponent.c:294
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_mNameCommand
protected ref map< string, ref SCR_BaseRadialCommand > m_mNameCommand
Definition: SCR_CommandingManagerComponent.c:23
NORMAL_PRIORITY
enum ECommunicationType NORMAL_PRIORITY
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
SCR_PlayerCommandsConfig
Commands config root.
Definition: SCR_PlayerCommandsConfig.c:4
m_CommandsConfig
protected SCR_PlayerCommandsConfig m_CommandsConfig
Definition: SCR_CommandingManagerComponent.c:18
SCR_BaseGroupCommand
Definition: SCR_BaseGroupCommand.c:3
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_CommandingManagerComponent
void SCR_CommandingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CommandingManagerComponent.c:46
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
SCR_CommandingManagerComponentClass
Definition: SCR_CommandingManagerComponent.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
Attribute
SCR_CommandingManagerComponentClass SCR_BaseGameModeComponentClass Attribute("{000CD338713F2B5A}Prefabs/AI/Groups/Group_Base.et")
Definition: SCR_CommandingManagerComponent.c:9
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199