Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIDebug.c
Go to the documentation of this file.
1
2[BaseContainerProps(configRoot: true)]
3class SCR_AIDebug : SCR_GameCoreBase
4{
5 const string logFileName = "$logs:ai_script.log";
6
7 protected static ref SCR_AIDebug s_Instance;
8
9 protected ref FileHandle m_FileHandle;
10
11 //------------------------------------------------------------------------------------------------
14 {
15 return s_Instance;
16 }
17
18 //------------------------------------------------------------------------------------------------
19 override void OnGameStart()
20 {
21 s_Instance = this;
22
23 #ifdef AI_DEBUG
24 m_FileHandle = FileIO.OpenFile(logFileName, FileMode.WRITE);
25 if (!m_FileHandle)
26 Print("SCR_AIDebug: Failed to create log file", LogLevel.ERROR);
27 #endif
28 }
29
30 //------------------------------------------------------------------------------------------------
31 override void OnGameEnd()
32 {
33 if (m_FileHandle)
34 {
35 m_FileHandle.Close();
36 m_FileHandle = null;
37 }
38
39 if (s_Instance)
40 {
41 s_Instance = null;
42 }
43 }
44
45 //------------------------------------------------------------------------------------------------
49 static string GetBehaviorName(SCR_AIBehaviorBase behavior)
50 {
51 if (!behavior)
52 return "";
53
54 return behavior.Type().ToString();
55 }
56
57 #ifdef AI_DEBUG
58 //------------------------------------------------------------------------------------------------
62 static void DebugLog(string str, LogLevel logLevel = LogLevel.DEBUG)
63 {
64 SCR_AIDebug inst = GetInstance();
65
66 if(!inst.m_FileHandle)
67 return;
68
69 // Resolve out log level
70 bool copyToStdLog = false;
71 string logLevelStr;
72 switch(logLevel)
73 {
74 case LogLevel.SPAM: logLevelStr = "S"; break;
75 case LogLevel.VERBOSE: logLevelStr = "v"; break;
76 case LogLevel.DEBUG: logLevelStr = "D"; break;
77 case LogLevel.NORMAL: logLevelStr = "N"; break;
78 case LogLevel.WARNING: logLevelStr = "W"; copyToStdLog = true; break;
79 case LogLevel.ERROR: logLevelStr = "E"; copyToStdLog = true; break;
80 case LogLevel.FATAL: logLevelStr = "F"; copyToStdLog = true; break;
81 }
82
83 // Get time
84 int hr, min, sec;
85 System.GetHourMinuteSecond(hr, min, sec);
86 int ticks = System.GetTickCount();
87
88 // Format string
89 string formattedStr = string.Format(
90 "%1:%2:%3 %4 (%5): %6",
91 hr.ToString(2),
92 min.ToString(2),
93 sec.ToString(2),
94 ticks,
95 logLevelStr,
96 str
97 );
98
99 inst.m_FileHandle.Write(formattedStr);
100 inst.m_FileHandle.Write("\n");
101
102 if (copyToStdLog)
103 Print(str, logLevel);
104 }
105 #endif
106}
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
void SCR_AIBehaviorBase(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity)
Game core which persists through whole game and stores various data for AI debugging.
Definition SCR_AIDebug.c:4
static string GetBehaviorName(SCR_AIBehaviorBase behavior)
Definition SCR_AIDebug.c:49
ref FileHandle m_FileHandle
Definition SCR_AIDebug.c:9
static ref SCR_AIDebug s_Instance
Definition SCR_AIDebug.c:7
override void OnGameEnd()
Definition SCR_AIDebug.c:31
static SCR_AIDebug GetInstance()
Definition SCR_AIDebug.c:13
override void OnGameStart()
Definition SCR_AIDebug.c:19
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
FileMode
Mode for opening file. See FileSystem::Open.
Definition FileMode.c:14