Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CommandingManagerComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Commanding", description: "Commanding manager, attach to game mode entity!.")]
5
6//------------------------------------------------------------------------------------------------
8{
9 [Attribute("{04D3B38E23F51754}Prefabs/AI/Groups/Slave_Group.et")]
10 protected ResourceName m_sAIGroupPrefab;
11
12 [Attribute("{54764D4E706F348C}Configs/Commanding/Commands.conf")]
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;
24
25 protected static const int NORMAL_PRIORITY = 50;
26
27 //------------------------------------------------------------------------------------------------
29 static SCR_CommandingManagerComponent GetInstance()
30 {
31 return s_Instance;
32 }
33
34 //------------------------------------------------------------------------------------------------
37 {
38 return m_sAIGroupPrefab;
39 }
40
41 //------------------------------------------------------------------------------------------------
42 // constructor
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
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)
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 AIGroupMovementComponent slaveGroupMovementComp = AIGroupMovementComponent.Cast(slaveGroup.FindComponent(AIGroupMovementComponent));
119 if (slaveGroupMovementComp)
120 slaveGroupMovementComp.SetFormationDisplacement(0);
121 }
122
123 //------------------------------------------------------------------------------------------------
130 void RequestCommandExecution(int commandIndex, RplId cursorTargetID, RplId groupRplID, vector targetPosition, int playerID, float seed)
131 {
132 //find entity of AI that will be responding to commands
134 RplId responderRplId;
135 if (command && command.ShouldPlayAIResponse())
136 {
137 //find speaking AI, find its rplid and pass it, then in playing response, get the entity from rpl it
138 SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
139 if (!groupsManager)
140 return;
141
142 SCR_AIGroup playerGroup = groupsManager.GetPlayerGroup(playerID);
143 if (!playerGroup)
144 return;
145
146 SCR_AIGroup slaveGroup = playerGroup.GetSlave();
147 if (!slaveGroup)
148 return;
149
150 AIAgent agent = slaveGroup.GetLeaderAgent();
151 if (agent)
152 {
153 IEntity owner = agent.GetControlledEntity();
154 if (owner)
155 responderRplId = Replication.FindItemId(owner);
156 }
157 }
158
159 //check if the passed arguments are valid, if yes, send a callback RPC to commanders playercontroller so he can make a gesture.
160 RPC_DoExecuteCommand(commandIndex, cursorTargetID, groupRplID, responderRplId, targetPosition, playerID, seed);
161 Rpc(RPC_DoExecuteCommand, commandIndex, cursorTargetID, groupRplID, responderRplId, targetPosition, playerID, seed);
162 }
163
164 //------------------------------------------------------------------------------------------------
171 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
172 void RPC_DoExecuteCommand(int commandIndex, RplId cursorTargetID, RplId groupRplID, RplId responderRplID, vector targetPosition, int playerID, float seed)
173 {
174 RplComponent rplComp;
175 IEntity cursorTarget, group;
176 rplComp = RplComponent.Cast(Replication.FindItem(cursorTargetID));
177 if (rplComp)
178 cursorTarget = rplComp.GetEntity();
179
180 rplComp = RplComponent.Cast(Replication.FindItem(groupRplID));
181 if (rplComp)
182 group = rplComp.GetEntity();
183
184 rplComp = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
185 if (rplComp)
186 {
188 if (command.Execute(cursorTarget, group, targetPosition, playerID, rplComp.IsProxy()))
189 {
190 PlayCommanderSound(playerID, commandIndex, seed);
191
192 //call this later when the commander is done speaking
193 //todo: replace with callback from audio
194 SCR_BaseGroupCommand groupCommand = SCR_BaseGroupCommand.Cast(command);
195 if (groupCommand && groupCommand.ShouldPlayAIResponse())
196 GetGame().GetCallqueue().CallLater(PlayAICommandResponse, 2000, false, playerID, true, seed, responderRplID);
197
198 if (!rplComp.IsMaster())
199 return;
200
201 PlayerController controller = GetGame().GetPlayerManager().GetPlayerController(playerID);
202 if (!controller)
203 return;
204
205 SCR_PlayerControllerCommandingComponent commandingComp = SCR_PlayerControllerCommandingComponent.Cast(controller.FindComponent(SCR_PlayerControllerCommandingComponent));
206 if (!commandingComp)
207 return;
208
209 commandingComp.CommandExecutedCallback(commandIndex);
210 }
211 }
212 }
213
214 //------------------------------------------------------------------------------------------------
218 void PlayCommanderSound(int playerID, int commandIndex, float seed)
219 {
220 SCR_ChimeraCharacter playerCharacter = SCR_ChimeraCharacter.Cast(GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID));
221 if (!playerCharacter)
222 return;
223
224 SignalsManagerComponent signalManager = SignalsManagerComponent.Cast(playerCharacter.FindComponent(SignalsManagerComponent));
225 if (!signalManager)
226 return;
227
228 SCR_CommunicationSoundComponent soundComponent = SCR_CommunicationSoundComponent.Cast(playerCharacter.FindComponent(SCR_CommunicationSoundComponent));
229 if (!soundComponent)
230 return;
231
232 string soundEventName = GetCommandSoundEventName(commandIndex);
233 if (soundEventName.IsEmpty())
234 return;
235
236 float soundEventSeed = GetCommandSoundEventSeed(commandIndex);
237 if (soundEventSeed == -1)
238 soundEventSeed = seed;
239
240 int signalSoldierCalled = signalManager.FindSignal("SoldierCalled");
241 int signalSeed = signalManager.FindSignal("Seed");
242 int signalSoldierCaller = signalManager.FindSignal("SoldierCaller");
243
244 //for now some values are hard set since we dont need different cases.
245 signalManager.SetSignalValue(signalSoldierCalled, 1000);
246 signalManager.SetSignalValue(signalSoldierCaller, 0);
247 signalManager.SetSignalValue(signalSeed, seed);
248 soundComponent.SoundEventPriority(soundEventName, NORMAL_PRIORITY);
249 }
250
251 //------------------------------------------------------------------------------------------------
252 void PlayAICommandResponse(int playerID, bool positive, float seed, RplId responderRplId)
253 {
254 IEntity character = IEntity.Cast(Replication.FindItem(responderRplId));
255 if (!character)
256 return;
257
259 if (!soundComponent)
260 return;
261
263 if (!signalManager)
264 return;
265
266 int signalSeed = signalManager.FindSignal("Seed");
267 signalManager.SetSignalValue(signalSeed, seed);
268 soundComponent.SoundEventPriority(SCR_SoundEvent.SOUND_CP_POSITIVEFEEDBACK, 50);
269 }
270
271 //------------------------------------------------------------------------------------------------
276 {
277 return m_mNameCommand.Get(commandName);
278 }
279
280 //------------------------------------------------------------------------------------------------
284 int FindCommandIndex(string commandName)
285 {
286 SCR_BaseRadialCommand command = FindCommand(commandName);
287 if (!command)
288 return -1;
289
290 return m_aCommands.Find(command);
291 }
292
293 //------------------------------------------------------------------------------------------------
296 string GetCommandSoundEventName(int commandIndex)
297 {
298 SCR_BaseRadialCommand command = m_aCommands.Get(commandIndex);
299 SCR_BaseGroupCommand groupCommand = SCR_BaseGroupCommand.Cast(command);
300 if (!groupCommand)
301 return string.Empty;
302
303
304 return groupCommand.GetSoundEventName();
305 }
306
307 //------------------------------------------------------------------------------------------------
310 float GetCommandSoundEventSeed(int commandIndex)
311 {
312 SCR_BaseRadialCommand command = m_aCommands.Get(commandIndex);
313 SCR_BaseGroupCommand groupCommand = SCR_BaseGroupCommand.Cast(command);
314 if (!groupCommand)
315 return -2;
316
317
318 return groupCommand.GetSoundEventSeed();
319 }
320
321 //------------------------------------------------------------------------------------------------
325 string FindCommandNameFromIndex(int commandIndex)
326 {
327 SCR_BaseRadialCommand command = m_aCommands.Get(commandIndex);
328 if (!command)
329 return string.Empty;
330
331 return command.GetCommandName();
332 }
333
334 //------------------------------------------------------------------------------------------------
338 bool CanShowCommand(string commandName)
339 {
340 SCR_BaseRadialCommand command = FindCommand(commandName);
341 if (!command)
342 return false;
343
344 return command.CanBeShown();
345 }
346
347 //------------------------------------------------------------------------------------------------
351 bool CanShowOnMap(string commandName)
352 {
353 SCR_BaseRadialCommand command = FindCommand(commandName);
354 if (!command)
355 return false;
356
357 return command.CanShowOnMap();
358 }
359
360 //------------------------------------------------------------------------------------------------
363 {
365 return m_CommandsConfig;
366
367 Resource holder = BaseContainerTools.LoadContainer(m_sCommandsConfigPath);
368 if (!holder)
369 return null;
370
371 BaseContainer container = holder.GetResource().ToBaseContainer();
372 if (!container)
373 return null;
374
375 SCR_PlayerCommandsConfig commandsConfig = SCR_PlayerCommandsConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
376 if (!commandsConfig)
377 return null;
378
379 m_CommandsConfig = commandsConfig;
380 return m_CommandsConfig;
381 }
382
383 //------------------------------------------------------------------------------------------------
386 {
387 return m_iMaxAIPerGroup;
388 }
389
390 //------------------------------------------------------------------------------------------------
392 void SetMaxAIPerGroup(int max)
393 {
394 m_iMaxAIPerGroup = max;
395 }
396
397 //------------------------------------------------------------------------------------------------
399 {
400 SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
401 if (!groupsManager)
402 return null;
403
404 SCR_AIGroup playerGroup = groupsManager.GetPlayerGroup(playerID);
405 if (!playerGroup)
406 return null;
407
408 SCR_AIGroup slaveGroup = playerGroup.GetSlave();
409 if (!slaveGroup)
410 return null;
411
412 AIAgent agent = slaveGroup.GetLeaderAgent();
413 if (!agent)
414 return null;
415
416 return agent.GetControlledEntity();
417 }
418
419 //------------------------------------------------------------------------------------------------
421 string GetCommandDisplayTextByName(string commandName)
422 {
423 SCR_BaseRadialCommand command = FindCommand(commandName);
424 if (!command)
425 return string.Empty;
426
427 return command.GetCommandDisplayName();
428 }
429}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum ECommunicationType NORMAL_PRIORITY
SCR_BaseGameMode GetGameMode()
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_CommandingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
ref array< ref SCR_BaseRadialCommand > m_aCommands
IEntity GetRespondingAI(int playerID)
void RequestCommandExecution(int commandIndex, RplId cursorTargetID, RplId groupRplID, vector targetPosition, int playerID, float seed)
string FindCommandNameFromIndex(int commandIndex)
void ResetSlaveGroupWaypoints(int playerId, IEntity player)
string GetCommandDisplayTextByName(string commandName)
string GetCommandSoundEventName(int commandIndex)
void SetMaxAIPerGroup(int max)
SCR_BaseRadialCommand FindCommand(string commandName)
void RPC_DoExecuteCommand(int commandIndex, RplId cursorTargetID, RplId groupRplID, RplId responderRplID, vector targetPosition, int playerID, float seed)
float GetCommandSoundEventSeed(int commandIndex)
SCR_PlayerCommandsConfig m_CommandsConfig
int FindCommandIndex(string commandName)
bool CanShowCommand(string commandName)
ResourceName GetGroupPrefab()
void PlayAICommandResponse(int playerID, bool positive, float seed, RplId responderRplId)
ref map< string, ref SCR_BaseRadialCommand > m_mNameCommand
void InitiateCommandMaps()
SCR_PlayerCommandsConfig GetCommandsConfig()
void PlayCommanderSound(int playerID, int commandIndex, float seed)
bool CanShowOnMap(string commandName)
ResourceName m_sCommandsConfigPath
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Replication item identifier.
Definition RplId.c:14
SCR_AIGroup GetSlave()
ScriptInvokerBase< SCR_BaseGameMode_PlayerIdAndEntity > GetOnPlayerSpawned()
bool Execute(IEntity cursorTarget, IEntity target, vector targetPosition, int playerID, bool isClient)
array< ref SCR_BaseRadialCommand > GetCommands()
Definition Types.c:486
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14