Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AICompositeActionParallel.c
Go to the documentation of this file.
1class SCR_AICompositeActionParallel : SCR_AIActionBase
2{
3 protected ref array<ref AIActionBase> m_aSubactions = {};
4
5 void GetSubactions(notnull array<AIActionBase> outSubactions)
6 {
7 outSubactions.Clear();
8 foreach (auto a : m_aSubactions)
9 outSubactions.Insert(a);
10 }
11
12 void AddAction(AIActionBase subaction)
13 {
14 // Bail if already added
15 foreach (auto a : m_aSubactions)
16 {
17 if (a == subaction)
18 return;
19 }
20
21 m_aSubactions.Insert(subaction);
22
23 // If we add an action to an action which is running already, then it must switch to proper state
24 if (GetActionState() == EAIActionState.RUNNING)
25 {
26 subaction.OnActionSelected();
27 }
28 }
29
30 override float CustomEvaluate()
31 {
32 // Evaluate all subactions, return max priority
33
34 float maxPriority = 0;
35 int nValidActions = 0;
36
37 for (int i = m_aSubactions.Count()-1; i >= 0; i--)
38 {
39 AIActionBase action = m_aSubactions[i];
40
41 EAIActionState state = action.GetActionState();
42
43 if (state == EAIActionState.COMPLETED)
44 {
45 // Remove
46 action.OnActionRemoved();
47 m_aSubactions.Remove(i);
48 }
49 else if (state == EAIActionState.FAILED)
50 {
51 // Remove
52 action.OnActionRemoved();
53 m_aSubactions.Remove(i);
54 }
55 else
56 {
57 float priority = action.Evaluate();
58 if (priority > maxPriority)
59 maxPriority = priority;
60
61 nValidActions++;
62 }
63 }
64
65 // Complete the parallel action once there are no valid actions left
66 if (nValidActions == 0)
67 {
68 Complete();
69 return 0;
70 }
71
72 return maxPriority;
73 }
74
75 override void OnActionSelected()
76 {
77 super.OnActionSelected();
78
79 foreach (AIActionBase action : m_aSubactions)
80 {
81 EAIActionState state = action.GetActionState();
82
83 if (state == EAIActionState.FAILED || state == EAIActionState.COMPLETED)
84 continue;
85
86 action.OnActionSelected();
87 }
88 }
89
90 override void OnActionDeselected()
91 {
92 super.OnActionDeselected();
93
94 foreach (AIActionBase action : m_aSubactions)
95 {
96 EAIActionState state = action.GetActionState();
97
98 if (state == EAIActionState.FAILED || state == EAIActionState.COMPLETED)
99 continue;
100
101 action.OnActionDeselected();
102 }
103 }
104
105 override void OnActionRemoved()
106 {
107 super.OnActionRemoved();
108 foreach (AIActionBase action : m_aSubactions)
109 {
110 action.OnActionRemoved();
111 }
112 }
113}
ref array< ref AIActionBase > m_aSubactions
void GetSubactions(notnull array< AIActionBase > outSubactions)
EAIActionState