15 static private const string LOG_DEBUG =
"Debug";
16 static private const string LOG_DEBUG_ACTION =
"Action";
17 static private const string LOG_DEBUG_SYMPTOM =
"Symptom";
18 static private const string LOG_DEBUG_INV_MOVE =
"Inv Move";
19 static private const string LOG_DEBUG_INV_RESERVATION =
"Inv Rrsv";
20 static private const string LOG_DEBUG_INV_HFSM =
"HFSM";
21 static private const string LOG_DEBUG_QUICKBAR =
"Quickbar";
22 static private const string LOG_DEBUG_BASEBUILDING =
"Base Building";
23 static private const string LOG_DEBUG_BLEEDING_CHANCES =
"Bleeding";
24 static private const string LOG_DEBUG_TRIGGER =
"Trigger";
25 static private const string LOG_DEBUG_PARTICLE =
"Particle";
26 static private const string LOG_DEBUG_TF =
"TestFramework";
27 static private const string LOG_DEBUG_WEIGHT =
"Weight";
28 static private const string LOG_DEBUG_MELEE =
"Melee";
29 static private const string LOG_DEBUG_WEATHER =
"Weather";
31 static private const string LOG_INFO =
"Info";
32 static private const string LOG_WARNING =
"Warning";
33 static private const string LOG_ERROR =
"Error";
34 static private const string LOG_DEFAULT =
"n/a";
38 static Widget m_DebugLayoutCanvas;
39 static CanvasWidget m_CanvasDebug;
43 static string GetDebugName(
Managed entity)
49 if (CastTo(obj, entity))
50 return obj.GetDebugNameNative();
52 return entity.GetDebugName();
55 static void InitCanvas()
57 if (!m_DebugLayoutCanvas)
59 m_DebugLayoutCanvas =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/debug/day_z_debugcanvas.layout");
60 m_CanvasDebug = CanvasWidget.Cast( m_DebugLayoutCanvas.FindAnyWidget(
"CanvasWidget" ) );
64 static void ClearCanvas()
67 m_CanvasDebug.Clear();
70 static void CanvasDrawLine(
float x1,
float y1,
float x2,
float y2,
float width,
int color)
73 m_CanvasDebug.DrawLine(x1, y1, x2, y2, width, color);
87 static void CanvasDrawPoint(
float x1,
float y1,
int color)
89 CanvasDrawLine(x1, y1, x1+1, y1, 1, color);
97 static void DestroyAllShapes()
99 for (
int i = 0; i < m_DebugShapes.Count(); ++i )
101 if ( m_DebugShapes.Get(i) )
103 m_DebugShapes.Get(i).Destroy();
107 m_DebugShapes.Clear();
110 static void RemoveShape(out
Shape shape)
113 for (
int i = 0; i < m_DebugShapes.Count(); i++ )
115 Shape found_shape = m_DebugShapes.Get(i);
117 if ( found_shape && found_shape == shape )
119 found_shape.Destroy();
120 m_DebugShapes.Remove(i);
136 static void Log(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
138 string res = LogMessage(LOG_DEBUG, plugin, entity, author, label, message);
141 if (res.Length() > 0)
148 static void ActionLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
150 string res = LogMessage(LOG_DEBUG_ACTION, plugin, entity, author, label, message);
153 if (res.Length() > 0)
160 static void SymptomLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
162 string res = LogMessage(LOG_DEBUG_SYMPTOM, plugin, entity, author, label, message);
165 if (res.Length() > 0)
172 static void InventoryMoveLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
174 string res = LogMessage(LOG_DEBUG_INV_MOVE, plugin, entity, author, label, message);
177 if (res.Length() > 0)
184 static void InventoryReservationLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
186 string res = LogMessage(LOG_DEBUG_INV_RESERVATION, plugin, entity, author, label, message);
189 if (res.Length() > 0)
196 static void InventoryHFSMLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
198 string res = LogMessage(LOG_DEBUG_INV_HFSM, plugin, entity, author, label, message);
201 if (res.Length() > 0)
208 static void QuickbarLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
210 string res = LogMessage(LOG_DEBUG_QUICKBAR, plugin, entity, author, label, message);
213 if (res.Length() > 0)
220 static void BaseBuildingLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
222 string res = LogMessage(LOG_DEBUG_BASEBUILDING, plugin, entity, author, label, message);
225 if (res.Length() > 0)
232 static void BleedingChancesLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
234 string res = LogMessage(LOG_DEBUG_BLEEDING_CHANCES, plugin, entity, author, label, message);
237 if (res.Length() > 0)
244 static void TriggerLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
246 string res = LogMessage(LOG_DEBUG_TRIGGER, plugin, entity, author, label, message);
249 if (res.Length() > 0)
256 static void ParticleLog(
string message = LOG_DEFAULT,
Managed caller =
null,
string function =
"",
Managed entity =
null)
258 string res = LogMessage(LOG_DEBUG_PARTICLE, GetDebugName(caller), GetDebugName(entity),
"",
function, message);
261 if (res.Length() > 0)
268 static void TFLog(
string message = LOG_DEFAULT,
TestFramework caller =
null,
string function =
"")
270 string res = LogMessage(LOG_DEBUG_TF, GetDebugName(caller),
"",
"",
function, message);
273 if (res.Length() > 0)
280 static void WeightLog(
string message = LOG_DEFAULT,
Managed caller =
null,
string function =
"",
Managed entity =
null)
294 static void MeleeLog(
Entity entity,
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT)
296 string logMessage =
string.Format(
"%1: %2", entity.GetSimulationTimeStamp(), message);
297 string res = LogMessage(LOG_DEBUG_MELEE, plugin, GetDebugName(entity), author, label, logMessage);
300 if (res.Length() > 0)
307 static void WeatherLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
314 string res = LogMessage(LOG_DEBUG_WEATHER, plugin, entity, author, label, message);
317 if (res.Length() > 0)
334 static void LogInfo(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
336 string res = LogMessage(LOG_INFO, plugin, entity, author, label, message);
339 if (res.Length() > 0)
356 static void LogWarning(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
358 string res = LogMessage(LOG_WARNING, plugin, entity, author, label, message);
361 if (res.Length() > 0)
378 static void LogError(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
380 string res = LogMessage(LOG_ERROR, plugin, entity, author, label, message);
383 if (res.Length() > 0)
390 static void LogArrayInt(
array<int> arr = NULL,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
397 for (
int i = 0; i < arr.Count(); i++)
399 res += LogMessage(LOG_DEBUG, plugin, entity, author, label, arr.Get(i).ToString());
403 if (res.Length() > 0)
410 static void LogArrayString(
array<string> arr = NULL,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
417 for (
int i = 0; i < arr.Count(); i++)
419 res += LogMessage(LOG_DEBUG, plugin, entity, author, label, arr.Get(i));
423 if (res.Length() > 0)
430 static void ReceivedLogMessageFromServer(
string message)
440 if (message.Length() > 0)
447 static void ClearScriptLogs()
461 m_DebugShapes.Insert(shape);
465 static Shape DrawCube(
vector pos,
float size = 1,
int color = 0x1fff7f7f)
470 float size_h = size * 0.5;
472 min[0] = min[0] - size_h;
473 min[1] = min[1] - size_h;
474 min[2] = min[2] - size_h;
476 max[0] = max[0] + size_h;
477 max[1] = max[1] + size_h;
478 max[2] = max[2] + size_h;
481 m_DebugShapes.Insert(shape);
487 Shape shape =
Shape.CreateSphere(color, flags, pos, size);
489 m_DebugShapes.Insert(shape);
495 Shape shape =
Shape.CreateFrustum(horizontalAngle, verticalAngle, length, color, flags);
497 m_DebugShapes.Insert(shape);
503 Shape shape =
Shape.CreateCylinder(color, flags, pos, radius, height);
505 m_DebugShapes.Insert(shape);
509 static array<Shape> DrawCone(
vector pos,
float lenght,
float halfAngle,
float offsetAngle,
int color = 0xFFFFFFFF,
int flags = 0)
514 Math3D.ConePoints(pos, lenght, halfAngle, offsetAngle, endL, endR);
517 shapes.Insert(
Debug.DrawLine(pos, endL, color, flags) );
519 shapes.Insert(
Debug.DrawLine(pos, endR, color, flags) );
521 shapes.Insert(
Debug.DrawLine(endL, endR, color, flags) );
523 shapes.Insert(
Debug.DrawLine(pos, pos +
Vector(
Math.Cos(offsetAngle), 0,
Math.Sin(offsetAngle)).Normalized() * lenght, color, flags) );
540 static Shape DrawLine(
vector from,
vector to,
int color = 0xFFFFFFFF,
int flags = 0)
546 Shape shape =
Shape.CreateLines(color, flags, pts, 2);
548 m_DebugShapes.Insert(shape);
553 static Shape DrawLines(
vector[] positions,
int count,
int color = 0xFFFFFFFF,
int flags = 0)
556 Shape shape =
Shape.CreateLines(color, flags, positions, count);
558 m_DebugShapes.Insert(shape);
562 static Shape DrawArrow(
vector from,
vector to,
float size = 0.5,
int color = 0xFFFFFFFF,
int flags = 0)
564 Shape shape =
Shape.CreateArrow(from, to, size, color, flags);
565 m_DebugShapes.Insert(shape);
575 static void GetBaseConfigClasses( out
TStringArray base_classes )
577 base_classes.Clear();
596 static void GetFiltredConfigClasses(
string search_string, out
TStringArray filtered_classes,
bool only_public =
true )
599 GetBaseConfigClasses( searching_in );
601 filtered_classes.Clear();
603 search_string.ToLower();
605 for (
int s = 0; s < searching_in.Count(); ++s )
607 string config_path = searching_in.Get(s);
609 int objects_count =
GetGame().ConfigGetChildrenCount(config_path);
610 for (
int i = 0; i < objects_count; i++)
613 GetGame().ConfigGetChildName(config_path, i, childName);
617 int scope =
GetGame().ConfigGetInt( config_path +
" " + childName +
" scope" );
624 string nchName = childName;
627 if ( nchName.Contains(search_string) != -1)
629 filtered_classes.Insert(childName);
638 static private bool m_EnabledLogs;
640 static private string LogMessage(
string level,
string plugin,
string entity,
string author,
string label,
string message)
645 bool is_server_log = (
GetGame().IsServer() &&
GetGame().IsMultiplayer() );
650 string date = GetDate();
651 string env =
"Client";
652 string msg =
string.Empty;
659 msg =
string.Format(
"%1 | %2 | %3 | %4 | %5 | %6 | %7", date, env, level, plugin, entity, label, message);
664 #ifdef DEVELOPER //not sendig log to clients on stable
665 Param1<string> msg_p =
new Param1<string>(msg);
677 static private void SaveLog(
string log_message)
692 #ifdef DIAG_DEVELOPER
693 Print(
string.Format(
"%1", log_message));
698 static void ClearLogs()
711 static string GetFileName()
716 static private string GetDate()
728 string date = month.ToStringLen(2) +
"-" + day.ToStringLen(2) +
" " + hour.ToStringLen(2) +
":" + minute.ToStringLen(2) +
":" + second.ToStringLen(2);
736 static bool m_DoLogs;
737 static bool m_DoActionDebugLog;
738 static bool m_DoSymptomDebugLog;
739 static bool m_DoInventoryMoveLog;
740 static bool m_DoInventoryReservationLog;
741 static bool m_DoInventoryHFSMLog;
742 static bool m_DoSyncLog;
743 static bool m_DoQuickbarLog;
744 static bool m_DoBaseBuildingLog;
745 static bool m_DoWeaponLog;
746 static bool m_DoWeatherLog;
747 static bool m_DoBleedingChanceLog;
751 #ifdef DIAG_DEVELOPER
757 m_DoActionDebugLog =
IsCLIParam(
"doActionLog");
758 m_DoSymptomDebugLog =
IsCLIParam(
"doSymptomLog");
759 m_DoInventoryMoveLog =
IsCLIParam(
"doInvMoveLog");
760 m_DoInventoryReservationLog =
IsCLIParam(
"doInvReservLog");
761 m_DoInventoryHFSMLog =
IsCLIParam(
"doInvHFSMLog");
763 m_DoQuickbarLog =
IsCLIParam(
"doQuickbarLog");
764 m_DoBaseBuildingLog =
IsCLIParam(
"doBaseBuildingLog");
769 static bool IsLogsEnable()
774 static void SetLogsEnabled(
bool enable)
779 static bool IsActionLogEnable()
781 return m_DoActionDebugLog;
784 static void ActionLogEnable(
bool enable)
786 m_DoActionDebugLog = enable;
789 static bool IsInventoryMoveLogEnable()
791 return m_DoInventoryMoveLog;
794 static void InventoryMoveLogEnable(
bool enable)
796 m_DoInventoryMoveLog = enable;
799 static bool IsInventoryReservationLogEnable()
801 return m_DoInventoryReservationLog;
804 static void InventoryReservationLogEnable(
bool enable)
806 m_DoInventoryReservationLog = enable;
809 static bool IsInventoryHFSMLogEnable()
811 return m_DoInventoryHFSMLog;
814 static void InventoryHFSMLogEnable(
bool enable)
816 m_DoInventoryHFSMLog = enable;
819 static bool IsSyncLogEnable()
824 static void SyncLogEnable(
bool enable)
826 m_DoSyncLog = enable;
829 static bool IsQuickbarLogEnable()
831 return m_DoQuickbarLog;
834 static void QuickbarLogEnable(
bool enable)
836 m_DoQuickbarLog = enable;
839 static bool IsBaseBuildingLogEnable()
841 return m_DoBaseBuildingLog;
844 static void BaseBuildingLogEnable(
bool enable)
846 m_DoBaseBuildingLog = enable;
849 static bool IsSymptomLogEnable()
851 return m_DoSymptomDebugLog;
854 static void SymptomLogEnable(
bool enable)
856 m_DoSymptomDebugLog = enable;
859 static bool IsWeaponLogEnable()
861 return m_DoWeaponLog;
864 static void WeaponLogEnable(
bool enable)
866 m_DoWeaponLog = enable;
869 static bool IsWeatherLogEnabled()
871 return m_DoWeatherLog;
874 static bool IsBleedingChancesLogEnable()
876 return m_DoBleedingChanceLog;
879 static void BleedingChancesLogEnable(
bool enable)
881 m_DoBleedingChanceLog = enable;
897 static WeightDebugType m_VerbosityFlags;
911 static void ClearWeightDebug()
916 static void PrintAll(
EntityAI entity)
923 for(
int i = 0; i < items.Count(); i++)
933 static void SetVerbosityFlags(WeightDebugType type)
935 m_VerbosityFlags = type;
943 int m_InventoryDepth;
944 string m_CalcDetails;
948 m_Classname = entity.GetType();
949 m_InventoryDepth = entity.GetHierarchyLevel();
952 void SetWeight(
float weight)
954 m_Weight = weight.ToString();
957 void SetCalcDetails(
string details)
959 m_CalcDetails = details;
963 void AddCalcDetails(
string details)
965 m_CalcDetails +=
"+ "+details;
971 for(
int i = 0; i < m_InventoryDepth;i++)
974 Print(spaces+
">" + m_Classname +
" Overall entity weight: "+ m_Weight +
" Calculation details:" + m_CalcDetails);