Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDebugInfoComponent.c
Go to the documentation of this file.
1 class SCR_AIDebugInfoComponent : ScriptedWidgetComponent
2 {
3  Widget m_wRoot;
4  TextWidget m_wBehavior;
5  TextWidget m_wCombat;
6  TextWidget m_wOrder;
7  TextWidget m_wTarget;
8  TextWidget m_wThreat;
9  TextWidget m_wTable;
10  TextWidget m_wAIInfo;
11 
12  CameraBase m_Camera;
13  IEntity m_TargetAI;
14  IEntity m_FixedAI;
15  SCR_AIUtilityComponent m_UtilityComponent;
16  SCR_AICombatComponent m_CombatComponent;
17  SCR_AIInfoComponent m_InfoComponent;
18  CameraManager m_CameraManager;
19 
20  const float OFFSET_X = 60;
21  const float OFFSET_Y = 0;
22 
23  //------------------------------------------------------------------------------------------------
24  override void HandlerAttached(Widget w)
25  {
26  m_wRoot = w;
27 
28  Widget parent = w.FindAnyWidget("Behavior");
29  if (parent)
30  m_wBehavior = TextWidget.Cast(parent.FindAnyWidget("Value"));
31 
32  parent = w.FindAnyWidget("Order");
33  if (parent)
34  m_wOrder = TextWidget.Cast(parent.FindAnyWidget("Value"));
35 
36  parent = w.FindAnyWidget("Target");
37  if (parent)
38  m_wTarget = TextWidget.Cast(parent.FindAnyWidget("Value"));
39 
40  parent = w.FindAnyWidget("Threat");
41  if (parent)
42  m_wThreat = TextWidget.Cast(parent.FindAnyWidget("Value"));
43 
44  parent = w.FindAnyWidget("BehaviorTable");
45  if (parent)
46  m_wTable = TextWidget.Cast(parent.FindAnyWidget("Value"));
47 
48  parent = w.FindAnyWidget("CombatComponent");
49  if (parent)
50  m_wCombat = TextWidget.Cast(parent.FindAnyWidget("Value"));
51 
52  parent = w.FindAnyWidget("AIInfoComponent");
53  if (parent)
54  m_wAIInfo = TextWidget.Cast(parent.FindAnyWidget("Value"));
55 
56  if (GetGame().InPlayMode())
57  m_wRoot.SetVisible(false);
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  void SelectAIAsFixed()
62  {
63  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SELECT_FIXED_AGENT))
64  {
65  m_FixedAI = m_TargetAI;
66  }
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  bool UpdateUI()
71  {
72  if (!m_CameraManager)
73  m_CameraManager = GetGame().GetCameraManager();
74 
75  if (!m_CameraManager || !m_wRoot)
76  return false;
77 
78  m_Camera = m_CameraManager.CurrentCamera();
79  if (!m_Camera)
80  return false;
81 
82  IEntity target = m_Camera.GetCursorTarget();
83 
84  if (!DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SELECT_FIXED_AGENT))
85  m_FixedAI = null;
86 
87  if ((!m_TargetAI || m_TargetAI != target || !m_UtilityComponent) && !m_FixedAI)
88  {
89  ChimeraCharacter character = ChimeraCharacter.Cast(target);
90  if (!character)
91  {
92  m_wRoot.SetVisible(false);
93  return false;
94  }
95 
96  AIControlComponent comp = AIControlComponent.Cast(character.FindComponent(AIControlComponent));
97  if (!comp)
98  {
99  m_wRoot.SetVisible(false);
100  return false;
101  }
102  SCR_ChimeraAIAgent agent = SCR_ChimeraAIAgent.Cast(comp.GetAIAgent());
103  if (!agent)
104  {
105  m_wRoot.SetVisible(false);
106  return false;
107  }
108 
109  m_UtilityComponent = SCR_AIUtilityComponent.Cast(agent.FindComponent(SCR_AIUtilityComponent));
110  if (!m_UtilityComponent)
111  {
112  m_wRoot.SetVisible(false);
113  return false;
114  }
115 
116  m_CombatComponent = SCR_AICombatComponent.Cast(agent.GetControlledEntity().FindComponent(SCR_AICombatComponent));
117  if (!m_CombatComponent)
118  {
119  m_wRoot.SetVisible(false);
120  return false;
121  }
122 
123  m_InfoComponent = agent.m_InfoComponent;
124  if (!m_InfoComponent)
125  {
126  m_wRoot.SetVisible(false);
127  return false;
128  }
129 
130  m_TargetAI = target;
131  }
132 
133  SelectAIAsFixed();
134  if (!m_UtilityComponent)
135  {
136  m_FixedAI = null;
137  return false;
138  }
139  if (m_FixedAI)
140  target = m_FixedAI;
141 
142  m_wRoot.SetVisible(true);
143  vector boundMin, boundMax;
144  target.GetWorldBounds(boundMin, boundMax);
145  vector entityCenter = (boundMax + boundMin) * 0.5;
146 
147  vector pos = GetGame().GetWorkspace().ProjWorldToScreen(entityCenter, target.GetWorld());
148  if (!m_FixedAI)
149  FrameSlot.SetPos(m_wRoot.GetChildren(), pos[0] + OFFSET_X, pos[1]);
150  else
151  FrameSlot.SetPos(m_wRoot.GetChildren(), 0, 60); // moved because there is a toolbar in zeus
152 
153  if (m_wBehavior && m_UtilityComponent.m_CurrentBehavior)
154  {
155  typename type = m_UtilityComponent.m_CurrentBehavior.Type();
156  m_wBehavior.SetText(type.ToString());
157  }
158 
159  if (m_wOrder)
160  {
161  // @TODO: Get this back
162  /*
163  string name = SCR_AIDebug.GetBehaviorName(m_UtilityComponent.m_);
164  m_wBehavior.SetText(name);
165  SCR_AIDebug.GetOrderName(m_wOrder);
166  */
167  }
168 
169  if (m_wThreat && m_UtilityComponent.m_ThreatSystem != null)
170  {
171  //order has to corespond to layout
172  m_UtilityComponent.m_ThreatSystem.DebugPrintToWidget(m_wThreat);
173  }
174 
175  if (m_wTable)
176  {
177  array<string> results = GetSortedBehaviors();
178  string finalString;
179  int resultsCount = results.Count();
180  for (int i = 0; i < resultsCount; i++)
181  {
182  finalString = finalString + results[i];
183  if (i + 1 < resultsCount)
184  finalString = finalString + "\n";
185  }
186  m_wTable.SetText(finalString);
187  }
188 
189  if (m_wCombat)
190  {
191  m_CombatComponent.DebugPrintToWidget(m_wCombat);
192  }
193 
194  if (m_wAIInfo)
195  {
196  m_InfoComponent.DebugPrintToWidget(m_wAIInfo);
197  }
198 
199  return false;
200  }
201 
202  // Create table with results
203  ref array<string> GetSortedBehaviors()
204  {
205  array<string> results = {};
206  array<ref AIActionBase> actions = {};
207 
208  m_UtilityComponent.GetActions(actions);
209 
210  string resultString;
211  float highScore;
212  int highIndex;
213  while (!actions.IsEmpty())
214  {
215  highScore = -float.MAX;
216  highIndex = -1;
217  foreach (int i, AIActionBase action : actions)
218  {
219  float score = action.Evaluate();
220  if (score > highScore)
221  {
222  highScore = score;
223  highIndex = i;
224  }
225  }
226 
227  resultString = actions[highIndex].Type().ToString() + " " + Math.Round(highScore);
228  results.Insert(resultString);
229 
230  actions.RemoveOrdered(highIndex);
231  }
232 
233  return results;
234  }
235 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Camera
protected SCR_ManualCamera m_Camera
Definition: SCR_BaseManualCameraComponent.c:14
AIActionBase
Definition: AIActionBase.c:12
SCR_ChimeraAIAgent
Definition: SCR_ChimeraAIAgent.c:5
m_CombatComponent
SCR_AICombatComponent m_CombatComponent
Definition: SCR_AIUtilityComponent.c:12
SCR_AIDebugInfoComponent
Definition: SCR_AIDebugInfoComponent.c:1
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3