Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIPerformSmartuserAction.c
Go to the documentation of this file.
1 class SCR_AIPerformSmartUserAction : AITaskScripted
2 {
3  [Attribute( defvalue: "", uiwidget: UIWidgets.EditBox, desc: "Insert UserAction class name" )]
4  protected string m_sUserAction;
5 
6  [Attribute( defvalue: "0", uiwidget: UIWidgets.CheckBox, desc: "Perform OnAbort? If false, performs action OnSimulate. If true OnSimulate returns RUNNING" )]
7  protected bool m_bPerformOnAbort;
8 
9  protected bool m_bHasAborted;
10 
11  static const string USER_ACTION_PORT = "UserAction";
12  static const string TARGET_ENTITY_PORT = "TargetEntity";
13 
14  //------------------------------------------------------------------------------------------------
15  protected static ref TStringArray s_aVarsIn = {
16  USER_ACTION_PORT,
17  TARGET_ENTITY_PORT
18  };
19 
20  //------------------------------------------------------------------------------------------------
21  override TStringArray GetVariablesIn()
22  {
23  return s_aVarsIn;
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  override void OnInit(AIAgent owner)
28  {
29  m_bHasAborted = false;
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
34  {
35  if (m_bPerformOnAbort)
36  return ENodeResult.RUNNING;
37  return PerformAction(owner, true);
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  private ENodeResult PerformAction(AIAgent owner, bool turnActionOn)
42  {
43  IEntity targetEntity;
44  string userActionString;
45  typename userAction;
46  GetVariableIn(TARGET_ENTITY_PORT, targetEntity);
47  if (!GetVariableIn(USER_ACTION_PORT, userActionString))
48  userActionString = m_sUserAction;
49 
50  IEntity controlledEntity = owner.GetControlledEntity();
51  if (!controlledEntity)
52  return ENodeResult.FAIL;
53 
54  if (!targetEntity)
55  return ENodeResult.FAIL;
56 
57  userAction = userActionString.ToType();
58  if (!userAction)
59  return ENodeResult.FAIL;
60 
61  array<BaseUserAction> outActions = {};
62  ScriptedUserAction action;
63  GetActions(targetEntity, outActions);
64  foreach (BaseUserAction baseAction : outActions)
65  {
66  action = ScriptedUserAction.Cast(baseAction);
67  if (action && userAction == action.Type() && action.CanBePerformedScript(controlledEntity))
68  {
69  SCR_UserActionWithOccupancy actionWithOccupancy = SCR_UserActionWithOccupancy.Cast(action);
70  if (actionWithOccupancy)
71  {
72  if (turnActionOn && actionWithOccupancy.IsOccupied()) // action is already ON and we wanted to turn on
73  return ENodeResult.FAIL;
74  else if (!turnActionOn && !actionWithOccupancy.IsOccupied()) // action is not ON and we wanted to turn it off
75  return ENodeResult.FAIL;
76  };
77  action.PerformAction(targetEntity, controlledEntity);
78  return ENodeResult.SUCCESS;
79  }
80  }
81  return ENodeResult.FAIL;
82  }
83 
84  override void OnAbort(AIAgent owner, Node nodeCausingAbort)
85  {
86  if (m_bPerformOnAbort && !m_bHasAborted)
87  {
88  PerformAction(owner, false);
89  m_bHasAborted = true;
90  }
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  private void GetActions(IEntity targetEntity, notnull out array<BaseUserAction> outActions)
95  {
96  if (!targetEntity)
97  return;
98 
99  ActionsManagerComponent actionOnEntity = ActionsManagerComponent.Cast(targetEntity.FindComponent(ActionsManagerComponent));
100 
101  if (!actionOnEntity)
102  return;
103 
104  actionOnEntity.GetActionsList(outActions);
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  protected override bool VisibleInPalette()
109  {
110  return true;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  protected override bool CanReturnRunning()
115  {
116  return true;
117  }
118 
119  // -----------------------------------------------------------------------------------------------
120  protected override string GetOnHoverDescription()
121  {
122  return "Performs specified smart action on target entity. Both must be specified. It can either perform it OnSimulate (default) or OnAbort.";
123  }
124 };
ScriptedUserAction
Definition: ScriptedUserAction.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_UserActionWithOccupancy
Definition: SCR_UserActionWithOccupancy.c:1
BaseUserAction
Definition: BaseUserAction.c:12
SCR_AIPerformSmartUserAction
Definition: SCR_AIPerformSmartuserAction.c:1