Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIPerformSmartuserAction.c
Go to the documentation of this file.
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 = {
18 };
19
20 //------------------------------------------------------------------------------------------------
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 {
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 {
87 {
88 ENodeResult result = PerformAction(owner, false);
89 m_bHasAborted = true;
90 if (result != ENodeResult.SUCCESS)
92 }
93 }
94
95 //------------------------------------------------------------------------------------------------
96 protected void ForceAbortAllActions(AIAgent owner)
97 {
98 // Right now it only aborts loitering; If other smart actions cause the AI to get stuck, they should be added here too
99 IEntity controlledEntity = owner.GetControlledEntity();
100 if (!controlledEntity)
101 return;
102
103 SCR_CharacterCommandHandlerComponent cmd = SCR_CharacterCommandHandlerComponent.Cast(controlledEntity.FindComponent(SCR_CharacterCommandHandlerComponent));
104 if (cmd && cmd.IsLoitering())
105 {
106 cmd.StopLoitering(false);
107 }
108 }
109 //-----------------------------------------------------------------------------------------------
110 private void GetActions(IEntity targetEntity, notnull out array<BaseUserAction> outActions)
111 {
112 if (!targetEntity)
113 return;
114
116
117 if (!actionOnEntity)
118 return;
119
120 actionOnEntity.GetActionsList(outActions);
121 }
122
123 //------------------------------------------------------------------------------------------------
124 protected static override bool VisibleInPalette()
125 {
126 return true;
127 }
128
129 //------------------------------------------------------------------------------------------------
130 protected static override bool CanReturnRunning()
131 {
132 return true;
133 }
134
135 // -----------------------------------------------------------------------------------------------
136 protected static override string GetOnHoverDescription()
137 {
138 return "Performs specified smart action on target entity. Both must be specified. It can either perform it OnSimulate (default) or OnAbort.";
139 }
140};
array< ref SCR_MenuActionPreset > GetActions()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto bool GetVariableIn(string name, out void val)
override void OnInit(AIAgent owner)
static override string GetOnHoverDescription()
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385
@ PerformAction