Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDebug.c
Go to the documentation of this file.
1 [BaseContainerProps(configRoot: true)]
3 class 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  //------------------------------------------------------------------------------------------------
13  static SCR_AIDebug GetInstance()
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 }
s_Instance
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
SCR_AIDebug
Game core which persists through whole game and stores various data for AI debugging.
Definition: SCR_AIDebug.c:3
SCR_AIBehaviorBase
Definition: SCR_AIBehavior.c:1
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468