Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIAction.c
Go to the documentation of this file.
2 {
3  // Priority levels
4  const static float PRIORITY_LEVEL_NORMAL = 0;
5  const static float PRIORITY_LEVEL_PLAYER = 1000;
6  const static float PRIORITY_LEVEL_GAMEMASTER = 2000;
7  // Unit behaviors
8  const static float PRIORITY_BEHAVIOR_RETREAT_MELEE = 190 + PRIORITY_LEVEL_PLAYER;
9  const static float PRIORITY_BEHAVIOR_GET_OUT_VEHICLE_HIGH_PRIORITY = 162 + PRIORITY_LEVEL_PLAYER; // High priority get out for evacuations of vehicles
10  const static float PRIORITY_BEHAVIOR_MOVE_FROM_DANGER = 160 + PRIORITY_LEVEL_PLAYER;
11  const static float PRIORITY_BEHAVIOR_ATTACK_HIGH_PRIORITY = 120; // Attack high priority
12  const static float PRIORITY_BEHAVIOR_PICKUP_INVENTORY_ITEMS = 118;
13  const static float PRIORITY_BEHAVIOR_HEAL_HIGH_PRIORITY = 115; // Heal yourself in critical situation
14  const static float PRIORITY_BEHAVIOR_OBSERVE_UNKNOWN_FIRE_HIGH_PRIORITY = 113; // Unknown fire at close range
15  const static float PRIORITY_BEHAVIOR_THROW_GRENADE = 112;
16  const static float PRIORITY_BEHAVIOR_MEDIC_HEAL = 111;
17  const static float PRIORITY_BEHAVIOR_RETREAT_FROM_TARGET = 110; // (when attack exists, retreat does not, and the other way)
18  const static float PRIORITY_BEHAVIOR_PROVIDE_AMMO = 100;
19  const static float PRIORITY_BEHAVIOR_ATTACK_SELECTED = 90; // Attack selected
20  const static float PRIORITY_BEHAVIOR_HEAL_WAIT = 83;
21  const static float PRIORITY_BEHAVIOR_MOVE_FROM_VEHICLE_HORN = 72;
22  const static float PRIORITY_BEHAVIOR_ATTACK_NOT_SELECTED = 70; // Attack not selected
23  const static float PRIORITY_BEHAVIOR_MOVE_FROM_UNKNOWN_FIRE = 68;
24  const static float PRIORITY_BEHAVIOR_OBSERVE_UNKNOWN_FIRE = 66; // Stare at gunfire origin. !!! Priority of this must be higher than move and investigate!
25  const static float PRIORITY_BEHAVIOR_HEAL = 65;
26  const static float PRIORITY_BEHAVIOR_MOVE_AND_INVESTIGATE = 64;
27  const static float PRIORITY_BEHAVIOR_DEFEND = 62; // Defend selected waypoint
28  const static float PRIORITY_BEHAVIOR_FIND_FIRE_POSITION = 61;
29  const static float PRIORITY_BEHAVIOR_MOVE_INDIVIDUALLY = 60;
30  const static float PRIORITY_BEHAVIOR_VEHICLE = 51;
31  const static float PRIORITY_BEHAVIOR_GET_OUT_VEHICLE = 51;
32  const static float PRIORITY_BEHAVIOR_PERFORM_ACTION = 30;
33  const static float PRIORITY_BEHAVIOR_MOVE = 30;
34  const static float PRIORITY_BEHAVIOR_MOVE_IN_FORMATION = 30;
35  //const static float PRIORITY_BEHAVIOR_
36 
37  // Sequence of actions specific for dismounting turret and getting back
38  const static float PRIORITY_BEHAVIOR_DISMOUNT_TURRET = 300;
39  const static float PRIORITY_BEHAVIOR_DISMOUNT_TURRET_INVESTIGATE = 21;
40  const static float PRIORITY_BEHAVIOR_DISMOUNT_TURRET_GET_IN = 20;
41 
42  // Group activities
43  const static float PRIORITY_ACTIVITY_RESUPPLY = 100;
44  const static float PRIORITY_ACTIVITY_HEAL = 80;
45  const static float PRIORITY_ACTIVITY_ATTACK_CLUSTER = 70;
46  const static float PRIORITY_ACTIVITY_SEEK_AND_DESTROY = 60;
47  const static float PRIORITY_ACTIVITY_INVESTIGATE_CLUSTER = 55;
48  const static float PRIORITY_ACTIVITY_DEFEND_FROM_CLUSTER = 55;
49  const static float PRIORITY_ACTIVITY_MOVE = 50;
50  const static float PRIORITY_ACTIVITY_PERFORM_ACTION = 50;
51  const static float PRIORITY_ACTIVITY_DEFEND = 50;
52  const static float PRIORITY_ACTIVITY_GET_IN = 50;
53  const static float PRIORITY_ACTIVITY_GET_OUT = 50;
54  const static float PRIORITY_ACTIVITY_FOLLOW = 50;
55 
56 
57  // TODO: Get rid of flags we don't neccesarily need
58  bool m_bIsInterruptable = true;
59  protected ref SCR_BTParam<float> m_fPriorityLevel = new SCR_BTParam<float>(SCR_AIActionTask.PRIORITY_LEVEL_PORT); // used when utility component calls Evaluate() on action, adds level of priority
60 
61  ResourceName m_sBehaviorTree;
62 
63  ResourceName m_sAbortBehaviorTree;
64 
65  ref ScriptInvoker m_OnActionCompleted = new ScriptInvoker();
66  ref ScriptInvoker m_OnActionFailed = new ScriptInvoker();
67 
68  // Array with parameters which must be exposed to scripts.
69  // For example see how m_bPrioritize is used here.
70  ref array<SCR_BTParamBase> m_aParams = {};
71 
72  //-------------------------------------------------------------------------------------
73  override float EvaluatePriorityLevel()
74  {
75  return m_fPriorityLevel.m_Value;
76  }
77 
78  //---------------------------------------------------------------------------------------------------------------------------------
79  void SetPriorityLevel(int priority)
80  {
81  m_fPriorityLevel.m_Value = priority;
82  }
83 
84  //-------------------------------------------------------------------------------------
85 
86  #ifdef AI_DEBUG
87  protected void AddDebugMessage(string str);
88  #endif
89 
90  //-------------------------------------------------------------------------------------
91  override void OnSetActionState(EAIActionState state)
92  {
93  #ifdef AI_DEBUG
94  AddDebugMessage(string.Format("SetActionState: %1, %2", typename.EnumToString(EAIActionState, state), GetActionDebugInfo()));
95  #endif
96  }
97 
98  //-------------------------------------------------------------------------------------
99  override void OnSetSuspended(bool suspended)
100  {
101  #ifdef AI_DEBUG
102  AddDebugMessage(string.Format("SetSuspended: %1, %2", suspended, GetActionDebugInfo()));
103  #endif
104  }
105 
106  //-------------------------------------------------------------------------------------
107  override void OnComplete()
108  {
109  #ifdef AI_DEBUG
110  AddDebugMessage(string.Format("Complete: %1", GetActionDebugInfo()));
111  #endif
112  OnActionCompleted();
113  m_OnActionCompleted.Invoke(this);
114  }
115 
116  //-------------------------------------------------------------------------------------
117  override void OnFail()
118  {
119  #ifdef AI_DEBUG
120  AddDebugMessage(string.Format("Fail: %1", GetActionDebugInfo()));
121  #endif
122  OnActionFailed();
123  m_OnActionFailed.Invoke(this);
124  }
125 
126  //-------------------------------------------------------------------------------------
127  override void OnActionRemoved()
128  {
129  #ifdef AI_DEBUG
130  AddDebugMessage(string.Format("Fail: %1", GetActionDebugInfo()));
131  #endif
132  }
133 
134  // Called for basic info to print out for specific behaviors - to override
135  string GetActionDebugInfo()
136  {
137  return this.ToString();
138  }
139 
140  string GetDebugPanelText() { return string.Empty; }
141 
142  // Called after behavior was selected after different behavior
143  override void OnActionSelected() {SetActionState(EAIActionState.RUNNING);}
144 
145  // Called after behavior different behavior was selected instead of this one
146  override void OnActionDeselected() {SetActionState(EAIActionState.EVALUATED);}
147 
148  // Called each frame behavior was selected, before it's executed in the behavior tree
149  void OnActionExecuted() { }
150 
151  // Called when utility component recognizes completion of the behavior
152  void OnActionCompleted() {SetActionState(EAIActionState.COMPLETED);}
153 
154  // Called when utility component recognizes failure of the behavior
155  void OnActionFailed() {SetActionState(EAIActionState.FAILED);}
156 
157  //-------------------------------------------------------------------------------------
158  bool IsActionInterruptable()
159  {
160  return m_bIsInterruptable || GetActionState() != EAIActionState.RUNNING;
161  }
162 
163  //-------------------------------------------------------------------------------------
164  void SetActionInterruptable(bool IsInterruptable)
165  {
166  m_bIsInterruptable = IsInterruptable;
167  }
168 
169  //---------------------------------------------------------------------------------------------------
170  // These methods are used by SCR_AIGetActionParameters and SCR_AISetActionParameters.
171  // They help move data between action and behavior tree variables.
172 
173  void SetParametersToBTVariables(SCR_AIActionTask node)
174  {
175  foreach (SCR_BTParamBase param : m_aParams)
176  param.SetVariableOut(node);
177  }
178 
179  //-------------------------------------------------------------------------------------
180  void GetParametersFromBTVariables(SCR_AIActionTask node)
181  {
182  foreach (SCR_BTParamBase param : m_aParams)
183  param.GetVariableIn(node);
184  }
185 
186  //-------------------------------------------------------------------------------------
187  // Returns array with port names of all parameters of this action.
188  TStringArray GetPortNames()
189  {
190  TStringArray namesOut = {};
191  foreach (SCR_BTParamBase p : m_aParams)
192  namesOut.Insert(p.m_sPortName);
193  return namesOut;
194  }
195 
196  //-------------------------------------------------------------------------------------
198  float GetRestrictedPriorityLevel(float minimumLevel = PRIORITY_LEVEL_NORMAL)
199  {
200  return Math.Clamp(Math.Max(EvaluatePriorityLevel(), minimumLevel), PRIORITY_LEVEL_NORMAL, PRIORITY_LEVEL_PLAYER);
201  }
202 };
SCR_AIActionBase
Definition: SCR_AIAction.c:1
SCR_BTParamBase
Base BT parameter class to be used in SCR_AIActionParams.
Definition: SCR_BTParam.c:7
m_fPriorityLevel
float m_fPriorityLevel
Definition: SendGoalMessage.c:3
AIActionBase
Definition: AIActionBase.c:12
m_aParams
protected ref array< ref SCR_BaseFormatParam > m_aParams
Definition: SCR_FormatUIInfo.c:3
SCR_AIActionTask
Definition: SCR_AIBehaviorTask.c:1
EAIActionState
EAIActionState
Definition: EAIActionState.c:12