Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIDebugVisualization.c
Go to the documentation of this file.
1class SCR_AIDebugVisualizationClass: GenericEntityClass
2{
3};
4
8
10{
11 static SCR_AIDebugVisualization s_Instance;
12 protected ref array<ref SCR_AIMessageVisualization> m_aElements = {};
13 protected ref array<ref SCR_AIAgentDebugPanel> m_aPanels = {};
14
15 //------------------------------------------------------------------------------------------------
16 static void Init()
17 {
18 if (s_Instance)
19 SCR_EntityHelper.DeleteEntityAndChildren(s_Instance);
20
22 }
23
24 //------------------------------------------------------------------------------------------------
26 {
27 if (!s_Instance)
29
30 return s_Instance;
31 }
32
33 //------------------------------------------------------------------------------------------------
34 static void VisualizeMessage(IEntity entity, string message, EAIDebugCategory category, float showTime, Color color = Color.White, float fontSize = 16, bool ignoreCategory = false)
35 {
36 int i = DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_AI_DEBUG_CATEGORY);
37 if (category != DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_AI_DEBUG_CATEGORY) && !ignoreCategory)
38 return;
39
41
42 if (!inst || !entity || message == string.Empty)
43 return;
44
45 if (!color)
46 color = Color.FromInt(Color.WHITE);
47
48 inst.RemoveVisualization(entity);
49
50 // Create element
51 SCR_AIMessageVisualization visualization = new SCR_AIMessageVisualization(entity, message, showTime, Color.FromInt(color.PackToInt()), fontSize);
52 inst.m_aElements.Insert(visualization);
53 }
54
55 //------------------------------------------------------------------------------------------------
56 void ShowAiAgentDebugPanel(AIAgent agent, IEntity entity)
57 {
58 SCR_AIAgentDebugPanel existingPanel;
60 {
61 if ((p.m_Agent && p.m_Agent == agent) || (p.m_Entity && p.m_Entity == entity))
62 existingPanel = p;
63 }
64
65 // Do nothing if this agent already has a panel
66 if (existingPanel)
67 return;
68
69 SCR_AIAgentDebugPanel newPanel = new SCR_AIAgentDebugPanel(agent, entity);
70 m_aPanels.Insert(newPanel);
71 }
72
73 //------------------------------------------------------------------------------------------------
74 protected void RemoveVisualization(IEntity entity)
75 {
77 {
78 if (!vis)
79 continue;
80
81 if (vis.m_TargetEntity == entity)
82 {
83 m_aElements.RemoveItem(vis);
84 vis = null;
85 return;
86 }
87 }
88 }
89
90 //------------------------------------------------------------------------------------------------
91 override protected void EOnDiag(IEntity owner, float timeSlice)
92 {
93 // Update messages above AIs
94 bool enabled = DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_AI_DEBUG_CATEGORY);
95 if (enabled)
96 {
97 int count = m_aElements.Count();
98 for (int i = count - 1; i >=0; i--)
99 {
100 bool finished = m_aElements[i].Draw(timeSlice);
101 if (finished)
102 m_aElements.Remove(i);
103 }
104 }
105
106 // Update AI debug panels
107 bool openDebugPanel = DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_OPEN_DEBUG_PANEL);
108 if (openDebugPanel)
109 {
110 AIAgent selectedAgent;
111 IEntity selectedEntity;
112
113 if (GetSelectedAiAgentOrEntity(selectedAgent, selectedEntity))
114 ShowAiAgentDebugPanel(selectedAgent, selectedEntity);
115 else
116 Debug.Error("Nothing is selected! You must select something with Game Master first!");
117
118 DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_AI_OPEN_DEBUG_PANEL, false);
119 }
120
121 int count = m_aPanels.Count();
122 for (int i = count - 1; i >= 0; i--)
123 {
124 bool requestClose = m_aPanels[i].Update(timeSlice);
125 if (requestClose)
126 m_aPanels.Remove(i);
127 }
128
129 // Set BT breakpoint for selected AI agent
130 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SET_BT_BREAKPOINT))
131 {
132 AIAgent selectedAgent;
133 IEntity selectedEntity;
134 GetSelectedAiAgentOrEntity(selectedAgent, selectedEntity);
135 if (selectedAgent)
136 {
137 AIBehaviorTreeComponent btComp = AIBehaviorTreeComponent.Cast(selectedAgent.FindComponent(AIBehaviorTreeComponent));
138 if (btComp)
139 {
140 btComp.SetBtBreakpoint(true);
141 }
142 }
143
144 DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_AI_SET_BT_BREAKPOINT, false);
145 }
146
147 // Perception manager
148 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_PERCEPTION_PANEL))
149 {
151 }
152 }
153
154 //-------------------------------------------------------------------------------------------
156 {
157 DbgUI.Begin("Perception Panel");
158
159 DbgUI.Text("Values for tuning perception properties");
160
161 ChimeraWorld world = GetWorld();
162 BaseTimeAndWeatherManagerEntity twm = world.GetTimeAndWeatherManager();
163 if (!twm)
164 {
165 DbgUI.Text("BaseTimeAndWeatherManagerEntity not found!");
166 }
167 else
168 {
169 vector sunDir;
170 vector moonDir;
171 float moonPhase;
172 twm.GetCurrentSunMoonDirAndPhase(sunDir, moonDir, moonPhase);
173 float sunElevDeg = Math.RAD2DEG * Math.Asin(-sunDir[1]);
174 float moonElevDeg = Math.RAD2DEG * Math.Asin(-moonDir[1]);
175 DbgUI.Text(string.Format("Sun Elevation: %1 deg", sunElevDeg.ToString(5, 1)));
176 DbgUI.Text(string.Format("Moon ElevatioN: %1 deg", moonElevDeg.ToString(5, 1)));
177 DbgUI.Text(string.Format("Moon Phase: %1", moonPhase.ToString(4, 2)));
178 }
179
180 PerceptionManager pm = GetGame().GetPerceptionManager();
181 if (!pm)
182 {
183 DbgUI.Text("PerceptionManager not found!");
184 }
185 else
186 {
187 float directLV;
188 float ambientLV;
189 float totalLV;
190 pm.GetAmbientLV(directLV, ambientLV, totalLV);
191 DbgUI.Text(string.Format("Direct LV: %1, Ambient LV: %2, Total Ambient LV: %3", directLV, ambientLV, totalLV));
192 }
193
194 DbgUI.End();
195 }
196
197 //-------------------------------------------------------------------------------------------
198 protected bool GetSelectedAiAgentOrEntity(out AIAgent outAgent, out IEntity outEntity)
199 {
200 // Get first AI entity selected in Game Master
202 set<SCR_EditableEntityComponent> selectedEntities = new set<SCR_EditableEntityComponent>();
203 filter.GetEntities(selectedEntities);
204
205 if (selectedEntities.Count() == 0)
206 {
207 outAgent = null;
208 outEntity = null;
209 return false;
210 }
211
212 // Try to find a group
213 foreach (SCR_EditableEntityComponent comp : selectedEntities)
214 {
215 SCR_EditableGroupComponent editGroupComp = SCR_EditableGroupComponent.Cast(comp);
216 if (editGroupComp)
217 {
218 outAgent = AIAgent.Cast(editGroupComp.GetOwner());
219 outEntity = null;
220 return true;
221 }
222 }
223
224 // Group not found, select first unit
225 SCR_EditableCharacterComponent editCharacterComp = SCR_EditableCharacterComponent.Cast(selectedEntities[0]);
226 if (editCharacterComp)
227 {
228 outAgent = editCharacterComp.GetAgent();
229 if (outAgent)
230 outEntity = outAgent.GetControlledEntity();
231 else
232 outEntity = null;
233 return true;
234 }
235
236 // It's not an AI or group but could be a basic entity
237 outAgent = null;
238 outEntity = selectedEntities[0].GetOwner();
239 return true;
240 }
241
242 //------------------------------------------------------------------------------------------------
244 {
245 s_Instance = this;
246
249 SetFlags(EntityFlags.ACTIVE, true);
250 }
251
252 //------------------------------------------------------------------------------------------------
254 {
256 if (m_aElements)
257 m_aElements.Clear();
258 m_aElements = null;
259 }
260};
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
EAIDebugCategory
Definition SCR_AIWorld.c:12
IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
void SCR_EditableGroupComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition Color.c:13
Definition DbgUI.c:66
Definition Debug.c:13
Diagnostic and developer menu system.
Definition DiagMenu.c:18
void DisconnectFromDiagSystem()
void ConnectToDiagSystem()
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external BaseWorld GetWorld()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
Definition Math.c:13
static SCR_AIDebugVisualization GetInstance()
static void VisualizeMessage(IEntity entity, string message, EAIDebugCategory category, float showTime, Color color=Color.White, float fontSize=16, bool ignoreCategory=false)
bool GetSelectedAiAgentOrEntity(out AIAgent outAgent, out IEntity outEntity)
void SCR_AIDebugVisualization(IEntitySource src, IEntity parent)
void EOnDiag(IEntity owner, float timeSlice)
ref array< ref SCR_AIMessageVisualization > m_aElements
void RemoveVisualization(IEntity entity)
ref array< ref SCR_AIAgentDebugPanel > m_aPanels
void ShowAiAgentDebugPanel(AIAgent agent, IEntity entity)
static SCR_BaseEditableEntityFilter GetInstance(EEditableEntityState state, bool showError=false)
int GetEntities(out set< SCR_EditableEntityComponent > entities, bool includeChildren=false, bool evaluate=true)
EEditableEntityState
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14