9 protected bool m_bRequestClose =
false;
11 protected string m_sWindowTitle;
13 protected bool m_bShowPerception;
23 bool Update(
float timeSlice)
30 if (m_sWindowTitle.IsEmpty())
32 string entityPtrStr = GetEntityShortName(objForTitle);
33 m_sWindowTitle =
string.Format(
"DbgPnl %1", entityPtrStr);
36 DbgUI.Begin(m_sWindowTitle);
38 SCR_AIInfoBaseComponent baseInfoComp;
39 SCR_AIInfoComponent infoComp;
40 SCR_AIGroupInfoComponent groupInfoComp;
41 SCR_AIGroupUtilityComponent groupUtilityComp;
42 SCR_MailboxComponent mailboxComp;
43 PerceptionComponent perception;
44 PerceivableComponent perceivable;
45 SCR_AIBaseUtilityComponent utilityComp;
46 SCR_AIUtilityComponent unitUtilityComp;
47 SCR_AICombatComponent combatComp;
51 DbgUI.Text(
"The target doesn't exist!");
56 string agentName = GetAgentDebugName();
57 DbgUI.Text(agentName);
61 baseInfoComp = SCR_AIInfoBaseComponent.Cast(
m_Agent.FindComponent(SCR_AIInfoBaseComponent));
62 infoComp = SCR_AIInfoComponent.Cast(baseInfoComp);
63 groupInfoComp = SCR_AIGroupInfoComponent.Cast(baseInfoComp);
64 mailboxComp = SCR_MailboxComponent.Cast(
m_Agent.FindComponent(SCR_MailboxComponent));
65 utilityComp = SCR_AIBaseUtilityComponent.Cast(
m_Agent.FindComponent(SCR_AIBaseUtilityComponent));
66 groupUtilityComp = SCR_AIGroupUtilityComponent.Cast(utilityComp);
67 unitUtilityComp = SCR_AIUtilityComponent.Cast(utilityComp);
73 combatComp = SCR_AICombatComponent.Cast(
m_Entity.FindComponent(SCR_AICombatComponent));
74 perception = PerceptionComponent.Cast(
m_Entity.FindComponent(PerceptionComponent));
75 perceivable = PerceivableComponent.Cast(
m_Entity.FindComponent(PerceivableComponent));
79 DbgUI.Text(
string.Format(
"LOD: %1",
m_Agent.GetLOD()));
83 string strUnitState =
string.Format(
"Unit State: %1", EnumFlagsToString(EUnitState, infoComp.GetUnitStates()));
84 string strUnitRoles =
string.Format(
"Unit Roles: %1", EnumFlagsToString(EUnitRole, infoComp.GetRoles()));
85 string strUnitBusy =
string.Format(
"Unit Busy: %1",
typename.EnumToString(EUnitAIState, infoComp.GetAIState()));
86 DbgUI.Text(strUnitState);
87 DbgUI.Text(strUnitRoles);
88 DbgUI.Text(strUnitBusy);
90 else if (groupInfoComp)
92 DbgUI.Text(
string.Format(
"Control Mode: %1",
typename.EnumToString(EGroupControlMode, groupInfoComp.GetGroupControlMode())));
97 EAICombatType combatType = combatComp.GetCombatType();
98 BaseTarget currentEnemy = combatComp.GetCurrentTarget();
99 EAICombatActions allowedActions = combatComp.GetAllowedActions();
100 DbgUI.Text(
string.Format(
"Combat Type: %1",
typename.EnumToString(EAICombatType, combatType)));
101 DbgUI.Text(
string.Format(
"Enemy: %1", currentEnemy.ToString()));
102 DbgUI.Text(
string.Format(
"Allowed actions: %1", EnumFlagsToString(EAICombatActions, allowedActions)));
107 int nRxMessages = mailboxComp.GetMessageCount();
108 int nRxOrders = mailboxComp.GetOrderCount();
109 int nRxDangers =
m_Agent.GetDangerEventsCount();
110 DbgUI.Text(
string.Format(
"Mailbox Queue: Msg: %1, Order: %2, Dngr: %3", nRxMessages, nRxOrders, nRxDangers));
119 EAIThreatState threatState = unitUtilityComp.m_ThreatSystem.GetState();
120 DbgUI.Text(
string.Format(
"Threat: %1 %2", unitUtilityComp.m_ThreatSystem.GetThreatMeasure().ToString(6, 3),
typename.EnumToString(EAIThreatState, threatState)));
123 AIActionBase currentAction = utilityComp.GetCurrentAction();
125 DbgUI.Text(
"Current Action: null");
128 DbgUI.Text(
"Current Action:");
129 float actionPriority = currentAction.Evaluate() + currentAction.EvaluatePriorityLevel();
130 string currentActionStr =
string.Format(
" > %1 %2", actionPriority.ToString(5, 1), currentAction.Type().ToString());
131 DbgUI.Text(currentActionStr);
135 array<string> spinnerStrings = {
"[|]",
"[/]",
"[-]",
"[\\]"};
136 string strSpinner = spinnerStrings[utilityComp.DiagGetCounter() % spinnerStrings.Count()];
138 DbgUI.Text(
string.Format(
"%1 Actions:", strSpinner));
139 array<ref AIActionBase> allActions = {};
140 utilityComp.GetActions(allActions);
143 string actionStr = GetActionString(action, i);
144 DbgUI.Text(actionStr);
149 array<AIActionBase> subactions = {};
150 compositeAction.GetSubactions(subactions);
153 string subactionStr =
" " + GetActionString(subaction, i);
154 DbgUI.Text(subactionStr);
162 if (groupUtilityComp)
164 DbgUI.Text(groupUtilityComp.m_FireteamMgr.DiagGetFireteamsData());
170 int dumpDbgMsgsDuration;
172 DbgUI.Text(
"Dump Debug Messages:");
174 DbgUI.Combo(
"Age", dumpDbgMsgsDuration, {
"All",
"120 sec",
"30 sec",
"5 sec"});
176 int dbgMsgTypeSelection;
177 array<string> dbgMsgTypeNames = {};
179 dbgMsgTypeNames.InsertAt(
"All", 0);
181 DbgUI.Combo(
"Type", dbgMsgTypeSelection, dbgMsgTypeNames);
182 dbgMsgType = dbgMsgTypeSelection - 1;
183 bool useDbgMsgTypeFilter = dbgMsgTypeSelection != 0;
186 bool dumpMsgs = DbgUI.Button(
"Dump");
190 int msgAgeThresholdMs;
191 switch (dumpDbgMsgsDuration)
193 case 0: msgAgeThresholdMs = -1;
break;
194 case 1: msgAgeThresholdMs = 120*1000;
break;
195 case 2: msgAgeThresholdMs = 30*1000;
break;
196 case 3: msgAgeThresholdMs = 5*1000;
break;
199 baseInfoComp.DumpDebugMessages(useTypeFilter: useDbgMsgTypeFilter, msgTypeFilter: dbgMsgType, ageThresholdMs: msgAgeThresholdMs);
207 DbgUI.Text(
"Breakpoint At:");
209 bool rqBreak = DbgUI.Button(
"Utility Comp.");
210 if (rqBreak && utilityComp)
212 utilityComp.DiagSetBreakpoint();
219 bool showPerceivable;
220 DbgUI.Check(
"Show Perceivable", showPerceivable);
223 ShowPerceivableComponent(perceivable);
228 if (perception && combatComp)
230 DbgUI.Check(
"Show Targets", m_bShowPerception);
231 if (m_bShowPerception)
233 ShowPerceptionEnemies(
m_Entity, perception, combatComp);
238 if (unitUtilityComp && unitUtilityComp.m_CombatMoveState)
240 bool showCombatMoveState;
241 DbgUI.Check(
"Show combat move state", showCombatMoveState);
242 if (showCombatMoveState)
244 ShowCombatMoveState(unitUtilityComp.m_CombatMoveState);
250 m_bRequestClose = DbgUI.Button(
"Close");
254 bool locate = DbgUI.Button(
"Locate");
257 array<string> locateTexts = {
"I am here!",
"Look at me!",
"Hey! Look here!",
"Here I am!"};
260 ent =
m_Agent.GetControlledEntity();
272 bool forceDeath = DbgUI.Button(
"Kill");
275 CharacterControllerComponent cntrlComp = CharacterControllerComponent.Cast(
m_Entity.FindComponent(CharacterControllerComponent));
277 cntrlComp.ForceDeath();
283 return m_bRequestClose;
286 string GetActionString(
AIActionBase action,
int actionId)
288 float actionPriority = action.Evaluate() + action.EvaluatePriorityLevel();
289 string strState =
string.Format(
"(%1)",
typename.EnumToString(
EAIActionState, action.GetActionState()) );
294 debugText = scrActionBase.GetDebugPanelText();
296 string actionStr =
string.Format(
" %1 %2 %3 %4 %5", actionId, strState, actionPriority.ToString(5, 1), action.Type().ToString(), debugText);
302 void ShowPerceptionEnemies(IEntity myEntity, PerceptionComponent perception, SCR_AICombatComponent combatComponent)
304 vector myPos = myEntity.GetOrigin();
311 DbgUI.Check(
" Show Unknown", showUnknown);
312 DbgUI.Check(
" Show Friendly", showFriendly);
313 DbgUI.Check(
" Show Enemy", showEnemy);
316 array<ETargetCategory> targetCategories = {};
327 FactionAffiliationComponent myFactionComp = FactionAffiliationComponent.Cast(myEntity.FindComponent(FactionAffiliationComponent));
328 Faction myFaction = myFactionComp.GetAffiliatedFaction();
330 BaseTarget selectedTarget = combatComponent.GetCurrentTarget();
332 DbgUI.Text(
"[ID Category TimeSinceSeen Dngr Type (Exp TraceFraction) (Detect Ident Sound)]");
334 array<BaseTarget> targets = {};
339 perception.GetTargetsList(targets, targetCategory);
340 foreach (
int i,
BaseTarget baseTarget : targets)
342 IEntity targetEntity = baseTarget.GetTargetEntity();
354 EntityPrefabData prefabData = targetEntity.GetPrefabData();
355 ResourceName prefabName = prefabData.GetPrefabName();
377 string strTimeSinceSeenOrDetected =
string.Format(
"(%1 %2)",
378 baseTarget.GetTimeSinceSeen().ToString(4, 1),
379 baseTarget.GetTimeSinceDetected().ToString(4, 1));
381 if (baseTarget.IsEndangering())
382 strState = strState +
"DNGR ";
383 if (baseTarget.IsDisarmed())
384 strState = strState +
"DISARMED ";
386 array<string> substrings = {};
388 string strPrefabName =
string.Empty;
389 if (!prefabName.IsEmpty())
391 prefabName.Split(
"/", substrings,
true);
392 if (!substrings.IsEmpty())
393 strPrefabName = substrings[substrings.Count()-1];
396 string strSelected =
" ";
397 if (selectedTarget == baseTarget)
400 string strDistance = vector.Distance(myPos, targetEntity.GetOrigin()).ToString(5, 2);
402 string strType =
typename.EnumToString(
EAIUnitType, baseTarget.GetUnitType());
404 float recognitionDetect;
405 float recognitionIdentify;
406 baseTarget.GetAccumulatedRecognition(recognitionDetect, recognitionIdentify);
409 float emittedSoundPower = baseTarget.GetPerceivableComponent().GetSoundPower();
410 float targetDistance = baseTarget.GetDistance();
411 float observedSoundIntensity = -999;
412 if (targetDistance != 0)
413 observedSoundIntensity = emittedSoundPower / (4.0 * Math.PI * targetDistance * targetDistance);
414 string strSoundIntensity;
415 if (observedSoundIntensity != 0)
416 strSoundIntensity =
string.Format(
"%1 dB", (10*Math.Log10(observedSoundIntensity/1e-12)).ToString(5,1));
418 strSoundIntensity =
"-inf dB";
420 string strExposure =
string.Format(
"(%1 %2) ", baseTarget.GetExposure().ToString(3,2), baseTarget.GetTraceFraction().ToString(3, 2));
422 string strRecognition =
string.Format(
"(%1 %2 %3)", recognitionDetect.ToString(3, 2), recognitionIdentify.ToString(3, 2), strSoundIntensity);
424 string str =
string.Format(
"%1 %2 %3 %4s %5 %6 %7 %8",
428 strTimeSinceSeenOrDetected,
435 DbgUI.Text(
string.Format(
"%1 %2 %3", targetId, GetEntityShortName(targetEntity), strPrefabName));
437 bool showRecognition =
false;
438 DbgUI.Check(
string.Format(
"%1 Recognition", targetId), showRecognition);
442 DbgUI.Text(
string.Format(
"%1 Exp: %2, Rec: Detect: %3 Identify: %4",
443 targetId, baseTarget.GetExposure().ToString(3, 2), recognitionDetect.ToString(3, 2), recognitionIdentify.ToString(3, 2)));
446 int plotHeight = 150;
447 int plotHistory = 800;
448 DbgUI.PlotLive(
string.Format(
"%1 Detection", targetId), plotWidth, plotHeight, recognitionDetect, 300);
449 DbgUI.PlotLive(
string.Format(
"%1 Identification", targetId), plotWidth, plotHeight, recognitionIdentify, 300);
457 void ShowPerceivableComponent(PerceivableComponent p)
459 DbgUI.Text(
"Recognition Factors:");
460 DbgUI.Text(
string.Format(
" Visual: %1", p.GetVisualRecognitionFactor()));
461 DbgUI.Text(
string.Format(
" Illumination: %1", p.GetIlluminationFactor()));
462 DbgUI.Text(
string.Format(
" Sound pwr: %1 dB", 10*Math.Log10(p.GetSoundPower()/1e-12)));
463 DbgUI.Text(
string.Format(
"Est. visual size: %1", p.GetEstimatedVisualSize()));
464 DbgUI.Text(
string.Format(
"Ambient LV: %1", p.GetAmbientLV()));
467 void ShowCombatMoveState(SCR_AICombatMoveState s)
474 strRqType = s.GetRequest().ToString();
483 DbgUI.Text(
string.Format(
"Request Type: %1", strRqType));
484 DbgUI.Text(
string.Format(
"Request State: %1", strRqState));
485 DbgUI.Text(
string.Format(
"TimerRequest: %1", s.m_fTimerRequest_s.ToString(5,2)));
486 DbgUI.Text(
string.Format(
"TimerInCover: %1", s.m_fTimerInCover_s.ToString(5,2)));
487 DbgUI.Text(
string.Format(
"TimerStopped: %1", s.m_fTimerStopped_s.ToString(5,2)));
491 str = str +
"IN_COVER ";
492 if (s.m_bExposedInCover)
493 str = str +
"EXPOSED_IN_COVER ";
494 if (s.m_bAimAtTarget)
495 str = str +
"AIM_AT_TARGET";
501 string GetAgentDebugName()
506 string company, platoon, squad, character, format, returnString;
507 m_Group.GetCallsigns(company, platoon, squad, character, format);
508 returnString.Format(format, company, platoon, squad, character);
515 SCR_CallsignCharacterComponent callsignComp = SCR_CallsignCharacterComponent.Cast(
m_Agent.GetControlledEntity().FindComponent(SCR_CallsignCharacterComponent));
517 FactionAffiliationComponent factionComp = FactionAffiliationComponent.Cast(
m_Agent.GetControlledEntity().FindComponent(FactionAffiliationComponent));
523 string faction = factionComp.GetAffiliatedFaction().GetFactionKey();
524 str = str +
string.Format(
"[%1] ", faction);
529 string company, platoon, squad, character, format;
530 bool setCallsign = callsignComp.GetCallsignNames(company, platoon, squad, character, format);
533 string callsign = WidgetManager.Translate(format, company, platoon, squad, character);
534 str = str +
string.Format(
" %1", callsign);
546 static string EnumFlagsToString(
typename t,
int value)
548 int tVarCount = t.GetVariableCount();
550 for (
int i = 0; i < tVarCount; i++)
553 t.GetVariableValue(
null, i, flag);
555 strOut = strOut +
string.Format(
"%1 ",
typename.EnumToString(t, flag));
560 static string GetEntityShortName(IEntity entity)
562 string entityRawName =
string.Format(
"%1", entity);
563 int _a = entityRawName.IndexOf(
"<");
564 int _b = entityRawName.IndexOfFrom(_a,
">");
565 string entityPtrStr = entityRawName.Substring(_a+1, _b - _a - 1);