Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_AIDebugVisualization.c
Go to the documentation of this file.
1
class
SCR_AIDebugVisualizationClass
: GenericEntityClass
2
{
3
};
4
8
9
class
SCR_AIDebugVisualization
:
GenericEntity
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
21
s_Instance =
SCR_AIDebugVisualization
.Cast(
GetGame
().
SpawnEntity
(
SCR_AIDebugVisualization
,
GetGame
().
GetWorld
()));
22
}
23
24
//------------------------------------------------------------------------------------------------
25
static
SCR_AIDebugVisualization
GetInstance
()
26
{
27
if
(!s_Instance)
28
s_Instance =
SCR_AIDebugVisualization
.Cast(
GetGame
().
SpawnEntity
(
SCR_AIDebugVisualization
,
GetGame
().
GetWorld
()));
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
40
SCR_AIDebugVisualization
inst =
GetInstance
();
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;
59
foreach
(
SCR_AIAgentDebugPanel
p :
m_aPanels
)
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
{
76
foreach
(
SCR_AIMessageVisualization
vis :
m_aElements
)
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
{
150
ShowPerceptionPanel
();
151
}
152
}
153
154
//-------------------------------------------------------------------------------------------
155
void
ShowPerceptionPanel
()
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
201
SCR_BaseEditableEntityFilter
filter =
SCR_BaseEditableEntityFilter
.
GetInstance
(
EEditableEntityState
.SELECTED);
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
//------------------------------------------------------------------------------------------------
243
void
SCR_AIDebugVisualization
(
IEntitySource
src,
IEntity
parent)
244
{
245
s_Instance =
this
;
246
247
SetEventMask
(
EntityEvent
.FRAME);
248
ConnectToDiagSystem
();
249
SetFlags
(
EntityFlags
.ACTIVE,
true
);
250
}
251
252
//------------------------------------------------------------------------------------------------
253
void
~SCR_AIDebugVisualization
()
254
{
255
DisconnectFromDiagSystem
();
256
if
(
m_aElements
)
257
m_aElements
.Clear();
258
m_aElements
= null;
259
}
260
};
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition
DebugMenuID.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
EAIDebugCategory
EAIDebugCategory
Definition
SCR_AIWorld.c:12
SpawnEntity
IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
Definition
SCR_CatalogEntitySpawnerComponent.c:1008
SCR_EditableGroupComponent
void SCR_EditableGroupComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition
SCR_EditableGroupComponent.c:881
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
ChimeraWorld
Definition
ChimeraWorld.c:13
Color
Definition
Color.c:13
DbgUI
Definition
DbgUI.c:66
Debug
Definition
Debug.c:13
DiagMenu
Diagnostic and developer menu system.
Definition
DiagMenu.c:18
GenericEntity
Definition
GenericEntity.c:16
GenericEntity::DisconnectFromDiagSystem
void DisconnectFromDiagSystem()
GenericEntity::ConnectToDiagSystem
void ConnectToDiagSystem()
IEntity::IEntity
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
IEntity::SetEventMask
proto external EntityEvent SetEventMask(EntityEvent e)
IEntity::GetWorld
proto external BaseWorld GetWorld()
IEntity::SetFlags
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
IEntitySource
Definition
IEntitySource.c:13
Math
Definition
Math.c:13
SCR_AIAgentDebugPanel
Definition
SCR_AIAgentDebugPanel.c:5
SCR_AIDebugVisualizationClass
Definition
SCR_AIDebugVisualization.c:2
SCR_AIDebugVisualization::GetInstance
static SCR_AIDebugVisualization GetInstance()
Definition
SCR_AIDebugVisualization.c:25
SCR_AIDebugVisualization::Init
static void Init()
Definition
SCR_AIDebugVisualization.c:16
SCR_AIDebugVisualization::ShowPerceptionPanel
void ShowPerceptionPanel()
Definition
SCR_AIDebugVisualization.c:155
SCR_AIDebugVisualization::~SCR_AIDebugVisualization
void ~SCR_AIDebugVisualization()
Definition
SCR_AIDebugVisualization.c:253
SCR_AIDebugVisualization::VisualizeMessage
static void VisualizeMessage(IEntity entity, string message, EAIDebugCategory category, float showTime, Color color=Color.White, float fontSize=16, bool ignoreCategory=false)
Definition
SCR_AIDebugVisualization.c:34
SCR_AIDebugVisualization::GetSelectedAiAgentOrEntity
bool GetSelectedAiAgentOrEntity(out AIAgent outAgent, out IEntity outEntity)
Definition
SCR_AIDebugVisualization.c:198
SCR_AIDebugVisualization::SCR_AIDebugVisualization
void SCR_AIDebugVisualization(IEntitySource src, IEntity parent)
Definition
SCR_AIDebugVisualization.c:243
SCR_AIDebugVisualization::EOnDiag
void EOnDiag(IEntity owner, float timeSlice)
Definition
SCR_AIDebugVisualization.c:91
SCR_AIDebugVisualization::m_aElements
ref array< ref SCR_AIMessageVisualization > m_aElements
Definition
SCR_AIDebugVisualization.c:12
SCR_AIDebugVisualization::RemoveVisualization
void RemoveVisualization(IEntity entity)
Definition
SCR_AIDebugVisualization.c:74
SCR_AIDebugVisualization::m_aPanels
ref array< ref SCR_AIAgentDebugPanel > m_aPanels
Definition
SCR_AIDebugVisualization.c:13
SCR_AIDebugVisualization::ShowAiAgentDebugPanel
void ShowAiAgentDebugPanel(AIAgent agent, IEntity entity)
Definition
SCR_AIDebugVisualization.c:56
SCR_AIMessageVisualization
Definition
SCR_AIMessageVisualization.c:2
SCR_BaseEditableEntityFilter
Definition
SCR_BaseEditableEntityFilter.c:14
SCR_BaseEditableEntityFilter::GetInstance
static SCR_BaseEditableEntityFilter GetInstance(EEditableEntityState state, bool showError=false)
Definition
SCR_BaseEditableEntityFilter.c:54
SCR_BaseEditableEntityFilter::GetEntities
int GetEntities(out set< SCR_EditableEntityComponent > entities, bool includeChildren=false, bool evaluate=true)
Definition
SCR_BaseEditableEntityFilter.c:139
SCR_EditableEntityComponent
Definition
SCR_EditableEntityComponent.c:14
SCR_EntityHelper
Definition
SCR_EntityHelper.c:2
vector
Definition
vector.c:13
EEditableEntityState
EEditableEntityState
Definition
EEditableEntityState.c:38
EntityEvent
EntityEvent
Various entity events.
Definition
EntityEvent.c:14
EntityFlags
EntityFlags
Various entity flags.
Definition
EntityFlags.c:14
scripts
Game
AI
SCR_AIDebugVisualization.c
Generated by
1.17.0