DayZ 1.24
Loading...
Searching...
No Matches
PluginDayZCreatureAIDebug.c
Go to the documentation of this file.
4
6{
8
15
19
23
25
26 const int m_iMaxAnimEventsCount = 50;
28
32
34 {
35 m_AnimPredictions.Clear();
36 m_AnimTags.Clear();
37 }
38
39 void OnAnimationEvent(string evType, int userInt, string userString)
40 {
41 if (m_EventsFilter.Find(evType) != -1)
42 return;
43
45
47 m_AnimEvents.Remove(m_AnimEvents.Count() - 1);
48 }
49
54
59}
60
62{
71 COUNT
72}
73
75{
76 int m_iDebugMenu = -1;
77
79 string m_sDebugEntityName = "";
81
83 bool m_IsActive = false;
84 bool m_ShowDbgUI = false;
85
86 bool m_bIsCaptureMode = false;
87 bool m_bEditMode = false;
88 bool m_bAIEnabled = true;
89 bool m_bShowAnimEvents = false;
90
91 bool m_bBulkSet = false;
94
96
98 {
99 }
100
102 {
103 }
104
105 override void OnInit()
106 {
107 }
108
109 override void OnDestroy()
110 {
111 }
112
114 {
115 int actMenuValue = DiagMenu.GetEngineValue(DayZCreatureAIConstants.DEBUG_SHOWDEBUGPLUGIN);
117 {
120 }
121 }
122
123 override void OnUpdate(float delta_time)
124 {
125 if (!GetGame().IsDedicatedServer())
127 }
128
129 string GetStrValue(int index)
130 {
131 string strVal;
132 switch (m_EntityAnimDbg.GetVariableType(index))
133 {
135 int valInt = m_EntityAnimDbg.GetVariableInt(index);
136 strVal = valInt.ToString();
137 break;
139 float valFloat = m_EntityAnimDbg.GetVariableFloat(index);
140 strVal = valFloat.ToString();
141 break;
143 bool valBool = m_EntityAnimDbg.GetVariableBool(index);
144 if (valBool)
145 strVal = "true";
146 else
147 strVal = "false";
148 break;
149 default:
150 strVal = "unk";
151 }
152 return strVal;
153 }
154
156 {
157 string strValType;
158 switch (m_EntityAnimDbg.GetVariableType(index))
159 {
161 strValType = "int";
162 break;
164 strValType = "float";
165 break;
167 strValType = "bool";
168 break;
169 default:
170 strValType = "unk";
171 }
172
173 return strValType;
174 }
175
177 {
179 m_EntityAnimDbg.SetCreature(DayZCreature.Cast(obj));
180
181 m_DebugEntity = DayZCreatureAI.Cast(obj);
182 m_sDebugEntityName = obj.GetType();
183
184
185 int varCount = m_EntityAnimDbg.GetVariableCount();
186 int cmdCount = m_EntityAnimDbg.GetCommandCount();
187 int toAddCount = 0;
188
190 {
192 for (int idxVar = 0; idxVar < toAddCount; idxVar++)
193 m_SetVariableCheckStates.Insert(false);
194 }
195
196 if (m_SetCommandCheckStates.Count() < cmdCount)
197 {
199 for (int idxCmd = 0; idxCmd < toAddCount; idxCmd++)
200 m_SetCommandCheckStates.Insert(false);
201 }
202 }
203
205 {
209
212 }
213
214 void SetValueInt(int index, int value)
215 {
216 m_EntityAnimDbg.SetVariableInt(index, value);
217 }
218
219 void SetValueFloat(int index, float value)
220 {
221 m_EntityAnimDbg.SetVariableFloat(index, value);
222 }
223
224 void SetValueBool(int index, bool value)
225 {
226 m_EntityAnimDbg.SetVariableBool(index, value);
227 }
228
230 {
231 int commandId = m_EntityAnimDbg.GetCommandID(commandIdx);
232 m_EntityAnimDbg.ActivateCommand(commandId, userInt, userFloat);
233 }
234
235 void EnableAI(bool enable)
236 {
237 if (m_DebugEntity.IsInherited(DayZCreatureAI))
238 {
240 if (enable)
241 {
242#ifdef DIAG_DEVELOPER
243 creatureAI.DebugRestoreAIControl();
244#endif
245 }
246 else
247 {
248#ifdef DIAG_DEVELOPER
249 creatureAI.DebugDisableAIControl();
250#endif
251 }
252 }
253 }
254
256 {
257 return m_EntityAnimDbg.GetVariableType(index);
258 }
259
261 {
262 int varCount = m_EntityAnimDbg.GetVariableCount();
263 for (int i = 0; i < varCount; i++)
264 {
266 DbgUI.Text(m_EntityAnimDbg.GetVariableName(i) + ": " + GetStrValue(i));
268 }
269 }
270
272 {
273 const int INPUT_BOX_SIZE = 35;
274
275 DbgUI.PushID_Str("VariablesEdit");
276
277 int varCount = m_EntityAnimDbg.GetVariableCount();
278 for (int i = 0; i < varCount; i++)
279 {
281
283
284 bool result;
285 DbgUI.Check("", result);
287
288 DbgUI.SameLine();
289 bool setButtonPressed = DbgUI.Button("Set");
290
291 DbgUI.SameLine();
292
293 string strUserVal;
295
296 DbgUI.SameLine();
297 DbgUI.Text(m_EntityAnimDbg.GetVariableName(i));
298
301
302 DbgUI.PopID();
303
305 }
306
307 DbgUI.PopID();
308 }
309
311 {
312 const int INPUT_BOX_SIZE = 35;
313
314 DbgUI.PushID_Str("CommandsEdit");
315 int cmdCount = m_EntityAnimDbg.GetCommandCount();
316 for (int i = 0; i < cmdCount; i++)
317 {
319
321
322 bool result;
323 DbgUI.Check("", result);
325
326 DbgUI.SameLine();
327 bool setButtonPressed = DbgUI.Button("Set");
328
329 DbgUI.SameLine();
330 string strUserInt;
332
333 DbgUI.SameLine();
334 string strUserFloat;
336
337 DbgUI.SameLine();
338 DbgUI.Text(m_EntityAnimDbg.GetCommandName(i) + "[" + m_EntityAnimDbg.GetCommandID(i) + "]");
339
342
343 DbgUI.PopID();
344
346 }
347
348 DbgUI.PopID();
349 }
350
352 {
353 bool buttonPressed = false;
354 if (m_bAIEnabled)
355 buttonPressed = DbgUI.Button("Disable AI");
356 else
357 buttonPressed = DbgUI.Button("Enable AI");
358
359 if (buttonPressed)
360 {
362
364 }
365 }
366
368 {
369 m_bBulkSet = false;
370
371 if (DbgUI.Button("Bulk set"))
372 m_bBulkSet = true;
373 }
374
376 {
377 DbgUI.PushID_Str("AnimEvents");
378
379 const int panelMinSizeX = 350;
380
381 DbgUI.Panel("MinimumSize", panelMinSizeX, 1);
382
383 string strTags;
384 for (int tagIdx = 0; tagIdx < m_EntityAnimDbg.m_AnimTags.Count(); ++tagIdx)
385 {
386 if (tagIdx != 0)
387 strTags += ", ";
388
389 strTags += m_EntityAnimDbg.m_AnimTags[tagIdx].param1;
390 }
391
392 string strPredictions;
393 for (int predIdx = 0; predIdx < m_EntityAnimDbg.m_AnimPredictions.Count(); ++predIdx)
394 {
395 if (predIdx != 0)
396 strPredictions += ", ";
397
398 strPredictions += m_EntityAnimDbg.m_AnimPredictions[predIdx].param1;
399 }
400
401 DbgUI.PushID_Str("AnimTagsDisplay");
403 DbgUI.PopID();
404
405 DbgUI.PushID_Str("AnimPredictionsDisplay");
407 DbgUI.PopID();
408
409 string strFilter;
411
412 m_EntityAnimDbg.m_EventsFilter.Clear();
413 strFilter.Split(" ", m_EntityAnimDbg.m_EventsFilter);
414
415 DbgUI.Button("TakeMyFocus");
416
417 const int evDisplayCount = 15;
418 int evToDisplayCount = (int)Math.Min(m_EntityAnimDbg.m_AnimEvents.Count(), evDisplayCount);
419
420 for (int evIdx = 0; evIdx < evToDisplayCount; ++evIdx)
421 {
423 if (m_EntityAnimDbg.m_AnimEvents[evIdx].param2.Length() > 0)
424 DbgUI.Text((m_EntityAnimDbg.m_AnimEvents[evIdx].param1 / 1000.0).ToString() + " - " + m_EntityAnimDbg.m_AnimEvents[evIdx].param2);
425 DbgUI.PopID();
426 }
427
428 DbgUI.PopID();
429 }
430
431 void OnGUI(bool show)
432 {
433 const int windowPosX = 0;
434 const int windowPosY = 300;
435 const int mainPanelSizeX = 200;
436 const int mainPanelSizeY = 1;
437 const int margin = 10;
438
440 DbgUI.Begin("CretureAI debug", windowPosX, windowPosY);
441 if (show)
442 {
443 if (m_EntityAnimDbg == NULL)
444 {
445 if (m_bIsCaptureMode == true)
446 DbgUI.Text("Capturing...");
447 else
448 {
449 if (DbgUI.Button("Capture"))
450 m_bIsCaptureMode = true;
451 }
452
453 // Clear additional windows
454 DbgUI.Begin("CreatureAI EditMenu");
455 DbgUI.End();
456
457 DbgUI.Begin("CreatureAI AnimEvents");
458 DbgUI.End();
459 }
460 else
461 {
462 DbgUI.Panel("MinimumSize", mainPanelSizeX, mainPanelSizeY);
463
465 DbgUI.SameLine();
466 bool btnReleasePressed = DbgUI.Button("Release");
467
468 DbgUI.Check("Edit", m_bEditMode);
469 DbgUI.Check("ShowAnimEvents", m_bShowAnimEvents);
470
471#ifdef _DAYZ_CREATURE_DEBUG_SHADOW
472 if (!GetGame().IsMultiplayer())
473 {
474 DbgUI.SameLine();
475 if (DbgUI.Button("CreateShadow"))
477 }
478#endif
479
480 if (!GetGame().IsMultiplayer())
481 {
482 const int simLODInputSize = 20;
483 int simLOD;
485 DbgUI.SameLine();
486 if (DbgUI.Button("UpdateSimulationPrecision"))
488 }
489
492 else
493 {
495 DbgUI.Begin("CreatureAI EditMenu", windowPosX + mainPanelSizeX + margin, windowPosY);
496 if (m_bEditMode)
497 {
501 DbgUI.Spacer(20);
503 }
504 DbgUI.End();
505
506 DbgUI.Begin("CreatureAI AnimEvents", windowPosX + mainPanelSizeX + margin, windowPosY);
509 DbgUI.End();
510 }
511 }
512 }
513 DbgUI.End();
515 }
516
518 {
520
521 if (GetGame().IsMultiplayer() && GetGame().IsClient())
523 }
524
526 {
527 switch (mode)
528 {
529 case 0:
530 {
531 Hide();
532 } break;
533 case 1:
534 {
535 Show();
536 } break;
537 }
538 }
539
540 void Show()
541 {
542 m_IsActive = true;
543
544 m_TickTimer = new Timer();
545 m_TickTimer.Run(0.1, this, "OnGUITimer", NULL, true);
546 }
547
548 void Hide()
549 {
550 m_IsActive = false;
552 OnGUI(false);
553 }
554
556 {
557 if (m_IsActive == false)
558 return;
559
560 const float MAX_RAYCAST_RANGE = 1000;
562 {
563 vector dir = GetGame().GetPointerDirection();
564 vector pos = GetGame().GetCurrentCameraPosition();
565
566 // Raycast
567 vector from = pos;
568 vector to = pos + (dir * MAX_RAYCAST_RANGE);
573
575 {
576 for (int i = 0; i < objects.Count(); i++)
577 {
578 Object obj = objects.Get(i);
579 if (obj && obj.IsInherited(DayZCreature))
580 {
581 m_bIsCaptureMode = false;
583 return;
584 }
585 }
586 }
587 }
588 }
589
593
595 {
596 InitDebugObject(obj);
597 if (GetGame().IsMultiplayer())
599 }
600
601#ifdef _DAYZ_CREATURE_DEBUG_SHADOW
603 {
604 auto shadowEntity = GetGame().CreateObject(m_sDebugEntityName, m_DebugEntity.GetPosition(), false, true);
605 m_DebugEntity.DebugSetShadow(shadowEntity);
606 }
607#endif
608
610 {
611 m_DebugEntity.UpdateSimulationPrecision(simLOD);
612 }
613
615 {
617 if (GetGame().IsMultiplayer())
619 }
620
622 {
623 switch (GetVariableType(index))
624 {
626 int intValue = strVal.ToInt();
627 if (GetGame().IsMultiplayer())
629 else
631 break;
633 float floatValue = strVal.ToFloat();
634 if (GetGame().IsMultiplayer())
636 else
638 break;
640 bool boolValue;
641 strVal.ToLower();
642 if (strVal.Contains("true"))
643 boolValue = true;
644 else if (strVal.Contains("false"))
645 boolValue = false;
646 else
647 boolValue = (bool)strVal.ToInt();
648
649 if (GetGame().IsMultiplayer())
651 else
653 break;
654 }
655 }
656
658 {
659 if (GetGame().IsMultiplayer())
661 else
663
664 }
665
667 {
668 if (GetGame().IsMultiplayer())
670 else
672 }
673
677
679 {
680 int count = m_SyncMessages.Count();
681 if (count > 0)
682 {
684 m_SyncMessages.InsertAt(paramCount, 0);
685
686 GetGame().GetPlayer().RPC(ERPCs.DEV_RPC_PLUGIN_DZCREATURE_DEBUG, m_SyncMessages, true);
687
688 m_SyncMessages.Clear();
689 }
690 }
691
693 {
694 if (rpc_type == ERPCs.DEV_RPC_PLUGIN_DZCREATURE_DEBUG)
696 }
697
699 {
701
702 if (ctx.Read(count))
703 {
705 for (int i = 0; i < count.param1; ++i)
706 {
707 if (ctx.Read(type))
708 {
709 switch (type.param1)
710 {
711 case PluginDayZCreatureAIDebugSyncMessageType.INIT_DEBUG_OBJECT:
713 break;
714 case PluginDayZCreatureAIDebugSyncMessageType.RELEASE_DEBUG_OBJECT:
716 break;
719 break;
720 case PluginDayZCreatureAIDebugSyncMessageType.SET_VALUE_FLOAT:
722 break;
725 break;
726 case PluginDayZCreatureAIDebugSyncMessageType.ACTIVATE_COMMAND:
728 break;
731 break;
734 break;
735 }
736 }
738 }
739 }
740 }
741
743 {
745 Param1<Object> object = new Param1<Object>(obj);
746
747 m_SyncMessages.Insert(type);
748 m_SyncMessages.Insert(object);
749 }
750
752 {
753 Param1<Object> object = new Param1<Object>(NULL);
754 if (ctx.Read(object))
755 InitDebugObject(object.param1);
756 }
757
759 {
761
762 m_SyncMessages.Insert(type);
763 }
764
769
771 {
774
775 m_SyncMessages.Insert(type);
777 }
778
780 {
782
783 if (ctx.Read(paramValue))
784 SetValueInt(paramValue.param1, paramValue.param2);
785 }
786
788 {
791
792 m_SyncMessages.Insert(type);
794 }
795
803
805 {
808
809 m_SyncMessages.Insert(type);
811 }
812
814 {
816
817 if (ctx.Read(paramValue))
818 SetValueBool(paramValue.param1, paramValue.param2);
819 }
820
829
831 {
833
834 if (ctx.Read(command))
835 ActivateCommand(command.param1, command.param2, command.param3);
836 }
837
839 {
841 if (enable)
842 type.param1 = PluginDayZCreatureAIDebugSyncMessageType.ENABLE_AI;
843 else
844 type.param1 = PluginDayZCreatureAIDebugSyncMessageType.DISABLE_AI;
845
846 m_SyncMessages.Insert(type);
847 }
848
850 {
851 EnableAI(true);
852 }
853
855 {
856 EnableAI(false);
857 }
858}
Param3 int
DayZCreatureAnimScriptDebugVarType
Definition DayZCreature.c:2
DayZCreatureAIConstants
@ COUNT
ERPCs
Definition ERPCs.c:2
bool m_IsActive
PlayerBase GetPlayer()
ref array< bool > m_SetCommandCheckStates
Param4< float, string, int, string > DayZCreatureAnimScriptDebugAnimEventData
class DayZCreatureAnimScriptDebug SET_VALUE_INT
ref DayZCreatureAnimScriptDebug m_EntityAnimDbg
string GetStrValueType(int index)
Param1< string > DayZCreatureAnimScriptDebugAnimPredictionData
class DayZCreatureAnimScriptDebug ACTIVATE_COMMAND
void SyncReceiveDisableAI(ParamsReadContext ctx)
void PluginDayZCreatureAIDebug()
class DayZCreatureAnimScriptDebug INIT_DEBUG_OBJECT
void GUIAction_ActivateCommand(int commandIdx, int userInt, float userFloat)
Param1< string > DayZCreatureAnimScriptDebugAnimTagData
bool m_bIsCaptureMode
void SyncSetValueBool(int index, bool value)
ref Timer m_TickTimer
void SendSyncMessages()
class DayZCreatureAnimScriptDebug SET_VALUE_BOOL
void OnRpc(PlayerBase player, int rpc_type, ParamsReadContext ctx)
string GetStrValue(int index)
class DayZCreatureAnimScriptDebug RELEASE_DEBUG_OBJECT
void SetDebugShowMode(int mode)
void SetValueInt(int index, int value)
void ActivateCommand(int commandIdx, int userInt, float userFloat)
void OnGUI_AnimEvents()
void ~PluginDayZCreatureAIDebug()
void GUIAction_InitDebugObject(Object obj)
void SyncSetValueInt(int index, int value)
bool m_bShowAnimEvents
void GUIAction_SetValue(int index, string strVal)
void CheckShowMode()
void OnGUI_BulkSet()
void SetValueFloat(int index, float value)
DayZCreatureAI m_DebugEntity
void EnableAI(bool enable)
void SetValueBool(int index, bool value)
void SyncInitDebugObject(Object obj)
class DayZCreatureAnimScriptDebug SET_VALUE_FLOAT
void SyncReceiveInitDebugObject(ParamsReadContext ctx)
class DayZCreatureAnimScriptDebug ENABLE_AI
class DayZCreatureAnimScriptDebug m_iDebugMenu
DayZCreatureAnimScriptDebugVarType GetVariableType(int index)
void ReleaseDebugObject()
void SyncEnableAI(bool enable)
bool m_bAIEnabled
void SyncReceiveReleaseDebugObject(ParamsReadContext ctx)
void OnGUI_VariablesEdit()
void SyncReceiveEnableAI(ParamsReadContext ctx)
void InitDebugObject(Object obj)
void OnGUI(bool show)
void SyncActivateCommand(int commandIdx, int userInt, float userFloat)
void OnGUI_CommandsEdit()
string m_sDebugEntityName
void SyncReceiveValueInt(ParamsReadContext ctx)
void OnGUI_Variables()
void GUIAction_UpdateSimulationPrecision(int simLOD)
void GUIAction_ReleaseDebugObject()
void OnGUI_AIControlEdit()
void SyncReceiveValueFloat(ParamsReadContext ctx)
void SyncReceiveMessage(ParamsReadContext ctx)
void SyncReleaseDebugObject()
ref array< ref Param > m_SyncMessages
ref array< bool > m_SetVariableCheckStates
void SyncReceiveValueBool(ParamsReadContext ctx)
void SyncReceiveActivateCommand(ParamsReadContext ctx)
void GUIAction_EnableAI(bool enable)
void SyncSetValueFloat(int index, float value)
class DayZCreatureAnimScriptDebug DISABLE_AI
class PresenceNotifierNoiseEvents windowPosX
dbgUI settings
const int mainPanelSizeX
const int margin
const int mainPanelSizeY
const int windowPosY
do not process rotations !
Definition DayZAnimal.c:573
proto native int GetVariableType(int index)
proto native owned string GetVariableName(int index)
proto native float GetVariableFloat(int index)
proto native int GetVariableInt(int index)
ref array< ref DayZCreatureAnimScriptDebugAnimEventData > m_AnimEvents
proto native bool SetVariableBool(int index, bool value)
proto native int SetVariableInt(int index, int value)
proto native owned string GetCommandName(int index)
proto native int GetCommandCount()
ref array< ref DayZCreatureAnimScriptDebugAnimTagData > m_AnimTags
proto native void ActivateCommand(int index, int userInt, float userFloat)
void OnAnimationPrediction(string predName)
proto native void SetCreature(DayZCreature creature)
proto native bool GetVariableBool(int index)
proto native int GetCommandID(int index)
void OnAnimationEvent(string evType, int userInt, string userString)
proto native float SetVariableFloat(int index, float value)
ref array< ref DayZCreatureAnimScriptDebugAnimPredictionData > m_AnimPredictions
proto native int GetVariableCount()
static proto bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, set< Object > results=NULL, Object with=NULL, Object ignore=NULL, bool sorted=false, bool ground_only=false, int iType=ObjIntersectView, float radius=0.0, CollisionFlags flags=CollisionFlags.NEARESTCONTACT)
Raycasts world by given parameters.
Definition DbgUI.c:60
Definition EnMath.c:7
void OnDestroy()
void OnInit()
ref Timer m_TickTimer
status refresh timer
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
static proto native void Panel(string label, int width, int height, int color=0xaa555555)
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void PopID()
static proto native bool Button(string txt, int minWidth=0)
static proto native void Text(string label)
static proto void InputText(string txt, out string value, int pxWidth=150)
static proto native void SameLine()
static proto void InputInt(string txt, out int value, int pxWidth=150)
static proto void BeginCleanupScope()
static proto native void PushID_Int(int int_id)
static proto native void Spacer(int height)
static proto native void PushID_Str(string str_id)
static proto void Check(string label, out bool checked)
static proto native void EndCleanupScope()
static proto int GetEngineValue(int id)
Get value at the given engine id.
static proto float Min(float x, float y)
Returns smaller of two given values.
proto native void OnUpdate()
Definition tools.c:333
proto native float GetWorldTime()