Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIProcessFailedMovementResult.c
Go to the documentation of this file.
1 
2 class SCR_AIProcessFailedMovementResult : AITaskScripted
3 {
4  static const string PORT_MOVE_RESULT = "MoveResult";
5  static const string PORT_VEHICLE_USED = "VehicleUsed";
6  static const string PORT_IS_WAYPOINT_RELEATED = "IsWaypointReleated";
7  static const string PORT_MOVE_LOCATION = "MoveLocation";
8 
9  SCR_AIGroup m_Group;
10  SCR_AIGroupUtilityComponent m_GroupUtilityComponent;
11 
12  //------------------------------------------------------------------------------------------------
13  override void OnInit(AIAgent owner)
14  {
15  SCR_AIGroup group = SCR_AIGroup.Cast(owner);
16  if (!group)
17  return;
18 
19  m_Group = group;
20  m_GroupUtilityComponent = SCR_AIGroupUtilityComponent.Cast(m_Group.FindComponent(SCR_AIGroupUtilityComponent));
21  }
22 
23  //------------------------------------------------------------------------------------------------
24  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
25  {
26  int moveResult;
27  if (!GetVariableIn(PORT_MOVE_RESULT, moveResult))
28  {
29  NodeError(this, owner, "Missing move result for SCR_AIProcessFailedMovementResult node");
30  return ENodeResult.RUNNING;
31  }
32 
33 #ifdef WORKBENCH
34  PrintDebug(owner, string.Format("Move failed with result %1", SCR_Enum.GetEnumName(EMoveRequestResult, moveResult)));
35 #endif
36 
37  // Exit with error (and running status for debug) if we receive not-failed move result
38  if (moveResult == EMoveRequestResult.Uninitialized || moveResult == EMoveRequestResult.Running || moveResult == EMoveRequestResult.Succeeded || moveResult == EMoveRequestResult.Aborted)
39  {
40  NodeError(this, owner, string.Format("Unexpected move result for SCR_AIProcessFailedMovementResult node: %1", SCR_Enum.GetEnumName(EMoveRequestResult, moveResult)));
41  return ENodeResult.RUNNING;
42  }
43 
44  IEntity vehicleUsed;
45  GetVariableIn(PORT_VEHICLE_USED, vehicleUsed);
46 
47  bool isWaypointReleated;
48  GetVariableIn(PORT_IS_WAYPOINT_RELEATED, isWaypointReleated);
49 
50  vector moveLocation;
51  GetVariableIn(PORT_MOVE_LOCATION, moveLocation);
52 
53  bool useVehicle;
54  if (vehicleUsed)
55  useVehicle = true;
56 
57  // Ivoke event about failed movement
58  m_GroupUtilityComponent.OnMoveFailed(moveResult, vehicleUsed, isWaypointReleated, moveLocation);
59 
60  // Failed movement
61  if (moveResult == EMoveRequestResult.Failed)
62  {
63  if (isWaypointReleated)
64  {
65  SCR_AIActivityBase activity = SCR_AIActivityBase.Cast(m_GroupUtilityComponent.GetCurrentAction());
66 
67  // Just fail action if failed move is a result or removed waypoint
68  if (activity && !activity.m_RelatedWaypoint)
69  {
70 #ifdef WORKBENCH
71  PrintDebug(owner, string.Format("Failed move as result of deleted waypoint %1", moveLocation));
72 #endif
73  FailAction();
74  return ENodeResult.FAIL;
75  }
76 
77  // If wp related and wp is the same we just return running
78  // As a result group will be stuck to allow us to debug it
79  NodeError(this, owner, string.Format("Failed move to waypoint %1", moveLocation));
80  return ENodeResult.RUNNING;
81  }
82 
83  FailAction();
84 #ifdef WORKBENCH
85  PrintDebug(owner, string.Format("Failed move while following the entity %1", moveLocation));
86 #endif
87  // If result is not waypoint related we just fail
88  return ENodeResult.FAIL;
89  }
90 
91  // If stopped or vehicle is not used, complete waypoint if related and fail action
92  if (moveResult == EMoveRequestResult.Stopped || !vehicleUsed)
93  {
94 #ifdef WORKBENCH
95  PrintDebug(owner, string.Format("Move failed with result %1 to location %2, failing action.", SCR_Enum.GetEnumName(EMoveRequestResult, moveResult), moveLocation));
96 #endif
97  if (isWaypointReleated)
98  CompleteWaypoint();
99 
100  // Fail action
101  FailAction();
102 
103  return ENodeResult.RUNNING;
104  }
105 #ifdef WORKBENCH
106  PrintDebug(owner, string.Format("Move failed with result %1 to location %2, retrying without vehicle.", SCR_Enum.GetEnumName(EMoveRequestResult, moveResult), moveLocation));
107 #endif
108  // Exit vehicle and try again
109  m_Group.RemoveUsableVehicle(vehicleUsed);
110  useVehicle = false;
111 
112  // Don't use vehicle in next try
113  SCR_AIMoveActivity activity = SCR_AIMoveActivity.Cast(m_GroupUtilityComponent.GetCurrentAction());
114  if (activity)
115  activity.m_bUseVehicles.m_Value = false;
116 
117  // Fail a node to enable tree to try again
118  return ENodeResult.FAIL;
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  void PrintDebug(AIAgent owner, string message)
123  {
124 #ifdef WORKBENCH
125  if (!DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_PRINT_DEBUG))
126  return;
127 
128  Print(string.Format("%1: %2", owner.ToString(), message));
129 #endif
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  void FailAction()
134  {
135  AIActionBase currentAction = m_GroupUtilityComponent.GetExecutedAction();
136  if (currentAction)
137  currentAction.Fail();
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  void CompleteWaypoint()
142  {
143  AIWaypoint waypoint = m_Group.GetCurrentWaypoint();
144  if (waypoint)
145  m_Group.CompleteWaypoint(waypoint);
146  }
147 
148  //------------------------------------------------------------------------------------------------
149  override protected bool CanReturnRunning() { return true; }
150 
151  //------------------------------------------------------------------------------------------------
152  protected static ref TStringArray s_aVarsOut = {};
153  override TStringArray GetVariablesOut() { return s_aVarsOut; }
154 
155  //------------------------------------------------------------------------------------------------
156  protected static ref TStringArray s_aVarsIn = {PORT_MOVE_RESULT, PORT_VEHICLE_USED, PORT_IS_WAYPOINT_RELEATED, PORT_MOVE_LOCATION};
157  override TStringArray GetVariablesIn() { return s_aVarsIn; }
158 
159  //------------------------------------------------------------------------------------------------
160  protected override string GetOnHoverDescription()
161  {
162  return "Processes failed movement result for proper BT reaction, calls group's failed move invoker";
163  }
164 }
SCR_Enum
Definition: SCR_Enum.c:1
SCR_AIProcessFailedMovementResult
Definition: SCR_AIProcessFailedMovementResult.c:2
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
m_Group
protected SCR_AIGroup m_Group
Definition: SCR_CallsignGroupComponent.c:10
AIActionBase
Definition: AIActionBase.c:12
SCR_AIActivityBase
Definition: SCR_AIActivity.c:1
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition: NodeError.c:3
SCR_AIMoveActivity
Definition: SCR_AIMoveActivity.c:1
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3