Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioFrameworkAIActions.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_ContainerAIActionTitle : BaseContainerCustomTitle
3 {
4  //------------------------------------------------------------------------------------------------
5  override bool _WB_GetCustomTitle(BaseContainer source, out string title)
6  {
7  title = source.GetClassName();
8  title.Replace("SCR_ScenarioFrameworkAIAction", "");
9  string sOriginal = title;
10  SplitStringByUpperCase(sOriginal, title);
11  return true;
12  }
13 
14  //------------------------------------------------------------------------------------------------
15  protected void SplitStringByUpperCase(string input, out string output)
16  {
17  output = "";
18  bool wasPreviousUpperCase;
19  int asciiChar;
20  for (int i, count = input.Length(); i < count; i++)
21  {
22  asciiChar = input.ToAscii(i);
23  bool isLowerCase = (asciiChar > 96 && asciiChar < 123);
24  if (i > 0 && !wasPreviousUpperCase && !isLowerCase)
25  {
26  output += " " + asciiChar.AsciiToString();
27  wasPreviousUpperCase = true;
28  }
29  else
30  {
31  if (isLowerCase)
32  wasPreviousUpperCase = false;
33  output += asciiChar.AsciiToString();
34  }
35  }
36  }
37 }
38 
39 //------------------------------------------------------------------------------------------------
42 class SCR_ScenarioFrameworkActionAI : SCR_ScenarioFrameworkActionBase
43 {
44  [Attribute(desc: "Target entity for AI Action - if left empty, it will attempt to retrieve it from the ")];
45  ref SCR_ScenarioFrameworkGet m_Getter;
46 
47  [Attribute(desc: "AI actions that will be executed on target AI")];
48  ref array<ref SCR_ScenarioFrameworkAIAction> m_aAIActions;
49 
50  //------------------------------------------------------------------------------------------------
51  override void OnActivate(IEntity object)
52  {
53  if (!CanActivate())
54  return;
55 
56  if (!m_Getter)
57  {
59  if (layer)
60  {
61  IEntity entity = layer.GetSpawnedEntity();
62  if (!entity)
63  {
64  Print(string.Format("ScenarioFramework Action: Entity not found for Action %1.", this), LogLevel.ERROR);
65  return;
66  }
67 
68  SCR_AIGroup targetAIGroup = SCR_AIGroup.Cast(entity);
69  if (!targetAIGroup)
70  {
71  Print(string.Format("ScenarioFramework Action: AI Group not found for Action %1.", this), LogLevel.ERROR);
72  return;
73  }
74 
75  foreach (SCR_ScenarioFrameworkAIAction AIAction : m_aAIActions)
76  {
77  AIAction.Init(targetAIGroup, object);
78  }
79  }
80 
81  return;
82  }
83 
84  SCR_ScenarioFrameworkParam<IEntity> entityWrapper = SCR_ScenarioFrameworkParam<IEntity>.Cast(m_Getter.Get());
85  if (!entityWrapper)
86  {
87  Print(string.Format("ScenarioFramework Action: Issue with Getter detected for Action %1.", this), LogLevel.ERROR);
88  return;
89  }
90 
91  IEntity entity = IEntity.Cast(entityWrapper.GetValue());
92  if (!entity)
93  {
94  Print(string.Format("ScenarioFramework Action: Entity not found for Action %1.", this), LogLevel.ERROR);
95  return;
96  }
97 
98  SCR_AIGroup targetAIGroup = SCR_AIGroup.Cast(entity);
99  if (!targetAIGroup)
100  {
101  Print(string.Format("ScenarioFramework Action: AI Group not found for Action %1.", this), LogLevel.ERROR);
102  return;
103  }
104 
105  foreach (SCR_ScenarioFrameworkAIAction AIAction : m_aAIActions)
106  {
107  AIAction.Init(targetAIGroup, object);
108  }
109  }
110 }
111 
112 //------------------------------------------------------------------------------------------------
115 class SCR_ScenarioFrameworkAIAction
116 {
118  IEntity m_IEntity;
119 
120  //------------------------------------------------------------------------------------------------
121  void Init(SCR_AIGroup targetAIGroup, IEntity entity)
122  {
123  if (!targetAIGroup)
124  return;
125 
126  m_AIGroup = targetAIGroup;
127  m_IEntity = entity;
128 
129  OnActivate();
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  void OnActivate();
134 }
135 
136 //------------------------------------------------------------------------------------------------
139 class SCR_ScenarioFrameworkAIAddWaypoint : SCR_ScenarioFrameworkAIAction
140 {
141  [Attribute(desc: "Target entity for waypoint")];
142  ref SCR_ScenarioFrameworkGet m_Getter;
143 
144  AIWaypoint m_Waypoint;
145 
146  //------------------------------------------------------------------------------------------------
147  override void OnActivate()
148  {
149  if (!m_Getter)
150  return;
151 
152  SCR_ScenarioFrameworkParam<IEntity> entityWrapper = SCR_ScenarioFrameworkParam<IEntity>.Cast(m_Getter.Get());
153  if (!entityWrapper)
154  {
155  Print(string.Format("ScenarioFramework Action: Issue with Getter detected for Action %1.", this), LogLevel.ERROR);
156  return;
157  }
158 
159  IEntity entity = IEntity.Cast(entityWrapper.GetValue());
160  if (!entity)
161  {
162  Print(string.Format("ScenarioFramework Action: Entity not found for Action %1.", this), LogLevel.ERROR);
163  return;
164  }
165 
167  if (!layer)
168  {
169  Print(string.Format("ScenarioFramework Action: Entity is not Layer Base for Action %1.", this), LogLevel.ERROR);
170  return;
171  }
172 
173  IEntity spawnedEntity = layer.GetSpawnedEntity();
174  if (!spawnedEntity)
175  {
176  layer.GetOnAllChildrenSpawned().Insert(OnWaypointSpawned);
177  return;
178  }
179 
180  m_Waypoint = AIWaypoint.Cast(spawnedEntity);
181  if (!m_Waypoint)
182  {
183  Print(string.Format("ScenarioFramework Action: Waypoint not found for Action %1.", this), LogLevel.ERROR);
184  return;
185  }
186 
187  m_AIGroup.AddWaypoint(m_Waypoint);
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  void OnWaypointSpawned(SCR_ScenarioFrameworkLayerBase layer)
192  {
193  layer.GetOnAllChildrenSpawned().Remove(OnWaypointSpawned);
194 
195  IEntity spawnedEntity = layer.GetSpawnedEntity();
196  if (!spawnedEntity)
197  return;
198 
199  m_Waypoint = AIWaypoint.Cast(spawnedEntity);
200  if (!m_Waypoint)
201  {
202  Print(string.Format("ScenarioFramework Action: Waypoint not found for Action %1.", this), LogLevel.ERROR);
203  return;
204  }
205 
206  m_AIGroup.AddWaypoint(m_Waypoint);
207  }
208 }
209 
210 //------------------------------------------------------------------------------------------------
213 class SCR_ScenarioFrameworkAIActionOnWaypointCompleted : SCR_ScenarioFrameworkAIAction
214 {
215  [Attribute(desc: "Target entity for waypoint")];
216  ref SCR_ScenarioFrameworkGet m_Getter;
217 
218  [Attribute(desc: "Actions that will be executed upon provided waypoint is completed for provided AI group")];
219  ref array<ref SCR_ScenarioFrameworkActionBase> m_aActionsOnWaypointCompleted;
220 
221  AIWaypoint m_Waypoint;
222 
223  //------------------------------------------------------------------------------------------------
224  override void OnActivate()
225  {
226  if (!m_Getter)
227  {
228  Print(string.Format("ScenarioFramework Action: Getter not found for Action %1.", this), LogLevel.ERROR);
229  return;
230  }
231 
232  SCR_ScenarioFrameworkParam<IEntity> entityWrapper = SCR_ScenarioFrameworkParam<IEntity>.Cast(m_Getter.Get());
233  if (!entityWrapper)
234  {
235  Print(string.Format("ScenarioFramework Action: Issue with Getter detected for Action %1.", this), LogLevel.ERROR);
236  return;
237  }
238 
239  IEntity entity = IEntity.Cast(entityWrapper.GetValue());
240  if (!entity)
241  {
242  Print(string.Format("ScenarioFramework Action: Entity not found for Action %1.", this), LogLevel.ERROR);
243  return;
244  }
245 
247  if (!layer)
248  {
249  Print(string.Format("ScenarioFramework Action: Entity is not Layer Base for Action %1.", this), LogLevel.ERROR);
250  return;
251  }
252 
253  IEntity spawnedEntity = layer.GetSpawnedEntity();
254  if (!spawnedEntity)
255  {
256  layer.GetOnAllChildrenSpawned().Insert(OnWaypointSpawned);
257  return;
258  }
259 
260  m_Waypoint = AIWaypoint.Cast(spawnedEntity);
261  if (!m_Waypoint)
262  {
263  Print(string.Format("ScenarioFramework Action: Waypoint not found for Action %1.", this), LogLevel.ERROR);
264  return;
265  }
266 
267  m_AIGroup.GetOnWaypointCompleted().Insert(OnWaypointCompleted);
268  }
269 
270  //------------------------------------------------------------------------------------------------
271  void OnWaypointSpawned(SCR_ScenarioFrameworkLayerBase layer)
272  {
273  m_AIGroup.GetOnWaypointCompleted().Insert(OnWaypointCompleted);
274  layer.GetOnAllChildrenSpawned().Remove(OnWaypointSpawned);
275 
276  IEntity spawnedEntity = layer.GetSpawnedEntity();
277  if (!spawnedEntity)
278  {
279  Print(string.Format("ScenarioFramework Action: Entity not found for Action %1.", this), LogLevel.ERROR);
280  return;
281  }
282 
283  m_Waypoint = AIWaypoint.Cast(spawnedEntity);
284  if (!m_Waypoint)
285  {
286  Print(string.Format("ScenarioFramework Action: Waypoint not found for Action %1.", this), LogLevel.ERROR);
287  return;
288  }
289 
290  m_AIGroup.GetOnWaypointCompleted().Insert(OnWaypointCompleted);
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  void OnWaypointCompleted(AIWaypoint waypoint)
295  {
296  if (waypoint != m_Waypoint)
297  return;
298 
299  m_AIGroup.GetOnWaypointCompleted().Remove(OnWaypointCompleted);
300 
301  foreach (SCR_ScenarioFrameworkActionBase action : m_aActionsOnWaypointCompleted)
302  {
303  action.Init(m_IEntity);
304  }
305  }
306 }
307 
308 //------------------------------------------------------------------------------------------------
311 class SCR_ScenarioFrameworkAIActionOnThreatStateChanged : SCR_ScenarioFrameworkAIAction
312 {
313  [Attribute(defvalue: EAIThreatState.THREATENED.ToString(), UIWidgets.ComboBox, "On what Threat State will actions be activated", "", ParamEnumArray.FromEnum(EAIThreatState), category: "Common")]
314  EAIThreatState m_eAIThreatState;
315 
316  [Attribute(desc: "Actions that will be executed upon provided waypoint is completed for provided AI group")];
317  ref array<ref SCR_ScenarioFrameworkActionBase> m_aActionsOnThreatStateChanged;
318 
319  ref array<ref SCR_AIThreatSystem> m_aAIThreatSystems = {};
320 
321  //------------------------------------------------------------------------------------------------
322  override void OnActivate()
323  {
324  array<AIAgent> agents = {};
325  m_AIGroup.GetAgents(agents);
326 
327  foreach (int i, AIAgent agent : agents)
328  {
329  IEntity agentEntity = agent.GetControlledEntity();
330  if (!agentEntity)
331  continue;
332 
333  SCR_AICombatComponent combatComponent = SCR_AICombatComponent.Cast(agentEntity.FindComponent(SCR_AICombatComponent));
334  if (!combatComponent)
335  continue;
336 
337  SCR_AIInfoComponent infoComponent = combatComponent.GetAIInfoComponent();
338  if (!infoComponent)
339  continue;
340 
341  SCR_AIThreatSystem threatSystem = infoComponent.GetThreatSystem();
342  if (!threatSystem)
343  continue;
344 
345  m_aAIThreatSystems.Insert(threatSystem);
346  threatSystem.GetOnThreatStateChanged().Insert(OnThreatStateChanged);
347  }
348  }
349 
350  //------------------------------------------------------------------------------------------------
351  void OnThreatStateChanged(EAIThreatState prevState, EAIThreatState newState)
352  {
353  if (newState != m_eAIThreatState)
354  return;
355 
356  foreach(SCR_AIThreatSystem threatSystem : m_aAIThreatSystems)
357  {
358  threatSystem.GetOnThreatStateChanged().Remove(OnThreatStateChanged);
359  }
360 
361  foreach (SCR_ScenarioFrameworkActionBase action : m_aActionsOnThreatStateChanged)
362  {
363  action.Init(m_IEntity);
364  }
365  }
366 }
367 
368 //------------------------------------------------------------------------------------------------
371 class SCR_ScenarioFrameworkAIActionSetSkill : SCR_ScenarioFrameworkAIAction
372 {
373  [Attribute(defvalue: EAISkill.REGULAR.ToString(), UIWidgets.ComboBox, "AI skill in combat", "", ParamEnumArray.FromEnum(EAISkill), category: "Common")]
374  EAISkill m_eAISkill;
375 
376  //------------------------------------------------------------------------------------------------
377  override void OnActivate()
378  {
379  array<AIAgent> agents = {};
380  m_AIGroup.GetAgents(agents);
381 
382  foreach (AIAgent agent : agents)
383  {
384  IEntity agentEntity = agent.GetControlledEntity();
385  if (!agentEntity)
386  continue;
387 
388  SCR_AICombatComponent combatComponent = SCR_AICombatComponent.Cast(agentEntity.FindComponent(SCR_AICombatComponent));
389  if (combatComponent)
390  combatComponent.SetAISkill(m_eAISkill);
391  }
392  }
393 }
394 
395 //------------------------------------------------------------------------------------------------
398 class SCR_ScenarioFrameworkAIActionSetCombatType : SCR_ScenarioFrameworkAIAction
399 {
400  [Attribute(defvalue: EAICombatType.NORMAL.ToString(), UIWidgets.ComboBox, "AI combat type", "", ParamEnumArray.FromEnum(EAICombatType), category: "Common")]
401  EAICombatType m_eAICombatType;
402 
403  //------------------------------------------------------------------------------------------------
404  override void OnActivate()
405  {
406  array<AIAgent> agents = {};
407  m_AIGroup.GetAgents(agents);
408 
409  foreach (AIAgent agent : agents)
410  {
411  IEntity agentEntity = agent.GetControlledEntity();
412  if (!agentEntity)
413  continue;
414 
415  SCR_AICombatComponent combatComponent = SCR_AICombatComponent.Cast(agentEntity.FindComponent(SCR_AICombatComponent));
416  if (combatComponent)
417  combatComponent.SetCombatType(m_eAICombatType);
418  }
419  }
420 }
421 
422 //------------------------------------------------------------------------------------------------
425 class SCR_ScenarioFrameworkAIActionSetHoldFire : SCR_ScenarioFrameworkAIAction
426 {
427  [Attribute(defvalue: "1", desc: "If AI in the group should hold fire")]
428  bool m_bHoldFire;
429 
430  //------------------------------------------------------------------------------------------------
431  override void OnActivate()
432  {
433  array<AIAgent> agents = {};
434  m_AIGroup.GetAgents(agents);
435 
436  foreach (AIAgent agent : agents)
437  {
438  IEntity agentEntity = agent.GetControlledEntity();
439  if (!agentEntity)
440  continue;
441 
442  SCR_AICombatComponent combatComponent = SCR_AICombatComponent.Cast(agentEntity.FindComponent(SCR_AICombatComponent));
443  if (combatComponent)
444  combatComponent.SetHoldFire(m_bHoldFire);
445  }
446  }
447 }
448 
449 //------------------------------------------------------------------------------------------------
452 class SCR_ScenarioFrameworkAIActionSetPerceptionFactor : SCR_ScenarioFrameworkAIAction
453 {
454  [Attribute(defvalue: "1", uiwidget: UIWidgets.EditBox, desc: "Sets perception ability. Affects speed at which perception detects targets. Bigger value means proportionally faster detection.", params: "0 100 0.001", category: "Common")]
455  float m_fPerceptionFactor;
456 
457  //------------------------------------------------------------------------------------------------
458  override void OnActivate()
459  {
460  array<AIAgent> agents = {};
461  m_AIGroup.GetAgents(agents);
462 
463  foreach (AIAgent agent : agents)
464  {
465  IEntity agentEntity = agent.GetControlledEntity();
466  if (!agentEntity)
467  continue;
468 
469  SCR_AICombatComponent combatComponent = SCR_AICombatComponent.Cast(agentEntity.FindComponent(SCR_AICombatComponent));
470  if (combatComponent)
471  combatComponent.SetPerceptionFactor(m_fPerceptionFactor);
472  }
473  }
474 }
475 
476 //------------------------------------------------------------------------------------------------
479 class SCR_ScenarioFrameworkAIActionSetFormation : SCR_ScenarioFrameworkAIAction
480 {
481  [Attribute(defvalue: SCR_EAIGroupFormation.Wedge.ToString(), UIWidgets.ComboBox, "AI formation", "", ParamEnumArray.FromEnum(SCR_EAIGroupFormation), category: "Common")]
483 
484  //------------------------------------------------------------------------------------------------
485  override void OnActivate()
486  {
487  AIFormationComponent formComp = AIFormationComponent.Cast(m_AIGroup.FindComponent(AIFormationComponent));
488  if (!formComp)
489  {
490  Print(string.Format("ScenarioFramework Action: AI Formation Component not found for Action %1.", this), LogLevel.ERROR);
491  return;
492  }
493 
494  formComp.SetFormation(SCR_Enum.GetEnumName(SCR_EAIGroupFormation, m_eAIGroupFormation));
495  }
496 }
497 
498 //------------------------------------------------------------------------------------------------
500 //[BaseContainerProps(), SCR_ContainerAIActionTitle()]
501 class SCR_ScenarioFrameworkAIActionSetCharacterStance : SCR_ScenarioFrameworkAIAction
502 {
503  [Attribute(defvalue: ECharacterStance.STAND.ToString(), UIWidgets.ComboBox, "AI character stance", "", ParamEnumArray.FromEnum(ECharacterStance), category: "Common")]
504  ECharacterStance m_eAICharacterStance;
505 
506  //------------------------------------------------------------------------------------------------
507  override void OnActivate()
508  {
509  array<AIAgent> agents = {};
510  m_AIGroup.GetAgents(agents);
511 
512  foreach (AIAgent agent : agents)
513  {
514  IEntity agentEntity = agent.GetControlledEntity();
515  if (!agentEntity)
516  continue;
517 
518  SCR_AIInfoComponent infoComponent = SCR_AIInfoComponent.Cast(agentEntity.FindComponent(SCR_AIInfoComponent));
519  if (infoComponent)
520  infoComponent.SetStance(m_eAICharacterStance);
521  }
522  }
523 }
524 
525 //------------------------------------------------------------------------------------------------
527 //[BaseContainerProps(), SCR_ContainerAIActionTitle()]
528 class SCR_ScenarioFrameworkAIActionSetMovementType : SCR_ScenarioFrameworkAIAction
529 {
530  [Attribute(defvalue: EMovementType.WALK.ToString(), UIWidgets.ComboBox, "AI group formation", "", ParamEnumArray.FromEnum(EMovementType), category: "Common")]
531  EMovementType m_eAIMovementType;
532 
533  //------------------------------------------------------------------------------------------------
534  override void OnActivate()
535  {
536  array<AIAgent> agents = {};
537  m_AIGroup.GetAgents(agents);
538 
539  foreach (AIAgent agent : agents)
540  {
541  IEntity agentEntity = agent.GetControlledEntity();
542  if (!agentEntity)
543  continue;
544 
545  SCR_AIInfoComponent infoComponent = SCR_AIInfoComponent.Cast(agentEntity.FindComponent(SCR_AIInfoComponent));
546  if (infoComponent)
547  infoComponent.SetMovementType(m_eAIMovementType);
548  }
549  }
550 }
SCR_Enum
Definition: SCR_Enum.c:1
OnWaypointCompleted
void OnWaypointCompleted(AIWaypoint waypoint)
Definition: SCR_AIGroupUtilityComponent.c:216
SCR_ContainerAIActionTitle
Definition: SCR_ScenarioFrameworkAIActions.c:2
EMovementType
EMovementType
Definition: EMovementType.c:12
ECharacterStance
ECharacterStance
Definition: ECharacterStance.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
BaseContainerProps
SCR_ContainerAIActionTitle BaseContainerCustomTitle BaseContainerProps()
AI Actions that will be executed on AIs spawned from that AI slot.
m_eAICombatType
EAICombatType m_eAICombatType
Definition: SCR_ScenarioFrameworkSlotAI.c:39
Init
void Init(IEntity entity=null, vector worldPos=vector.Zero, float timestamp=0.0, EAITargetInfoCategory category=0)
Definition: SCR_AITargetInfo.c:27
OnActivate
override void OnActivate()
Definition: SCR_CharacterCommandLoiter.c:23
SCR_EAIGroupFormation
SCR_EAIGroupFormation
Definition: SCR_AIGroup.c:2337
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_Waypoint
protected AIWaypoint m_Waypoint
Definition: SCR_AmbientPatrolSpawnPointComponent.c:48
SCR_ContainerActionTitle
SCR_ContainerActionTitle BaseContainerCustomTitle SCR_ContainerActionTitle()] class SCR_ScenarioFrameworkActionBase
Definition: SCR_ScenarioFrameworkActions.c:43
m_AIGroup
SCR_AIGroup m_AIGroup
Definition: SCR_ScenarioFrameworkSlotAI.c:48
m_eAIGroupFormation
SCR_EAIGroupFormation m_eAIGroupFormation
Definition: SCR_ScenarioFrameworkSlotAI.c:27
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_ScenarioFrameworkLayerBase
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_ScenarioFrameworkLayerBase.c:875
m_fPerceptionFactor
float m_fPerceptionFactor
Definition: SCR_ScenarioFrameworkSlotAI.c:42
m_eAISkill
EAISkill m_eAISkill
Definition: SCR_ScenarioFrameworkSlotAI.c:36
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_ScenarioFrameworkGet
Definition: SCR_ScenarioFrameworkActionsGetters.c:26
SCR_AIThreatSystem
Definition: SCR_AIThreatSystem.c:17
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180