Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MailboxComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/AIComponent", description: "Scripted m_Mailbox component", icon: HYBRID_COMPONENT_ICON)]
2 class SCR_MailboxComponentClass : AICommunicationComponentClass
3 {
4 }
5 
6 class SCR_MailboxComponent : AICommunicationComponent
7 {
8  #ifdef AI_MAILBOX_OVERFLOW_DETECTION
9  protected int m_iMailboxOverflowCount = 0;
10  #endif
11 
12  //------------------------------------------------------------------------------------------------
16  AIMessage ReadMessage(bool remove)
17  {
18  /*
19  // Disabled for now
20  #ifdef AI_MAILBOX_OVERFLOW_DETECTION
21  if (GetMessageCount() > 100 && m_iMailboxOverflowCount < 5)
22  {
23  LogMailboxStatistics(LogLevel.WARNING);
24  m_iMailboxOverflowCount++;
25  }
26  #endif
27  */
28 
29  AIMessage msg = GetMessage(0);
30 
31  if (msg && remove)
32  RemoveMessage(0);
33 
34  return msg;
35  }
36 
37  //------------------------------------------------------------------------------------------------
40  AIOrder ReadOrder(bool remove)
41  {
42  AIOrder order = GetOrder(0);
43 
44  if (order && remove)
45  RemoveOrder(0);
46 
47  return order;
48  }
49 
50  //------------------------------------------------------------------------------------------------
53  void LogMessageStatistics(LogLevel logLevel = LogLevel.NORMAL)
54  {
55  map<typename, int> msgTypeCount = new map<typename, int>();
56  int msgCount = GetMessageCount();
57  for (int i = 0; i < msgCount; i++)
58  {
59  AIMessage msg = GetMessage(i);
60  if (!msg)
61  continue;
62  typename msgFinalType = msg.Type();
63  int nMsgsOfType = msgTypeCount.Get(msgFinalType);
64  nMsgsOfType++;
65  msgTypeCount.Set(msgFinalType, nMsgsOfType);
66  }
67 
68  Print(string.Format("SCR_MailboxComponent statistics: count: %1, %2, %3", GetMessageCount(), this, GetAIAgent()), logLevel);
69  foreach (typename t, int count : msgTypeCount)
70  {
71  Print(string.Format(" %1: %2", t, count), logLevel);
72  }
73  Print(string.Format(" Total: %1", GetMessageCount()), logLevel);
74  }
75 
76  //------------------------------------------------------------------------------------------------
79  {
80  return IsActive();
81  }
82 
83  #ifdef AI_DEBUG
84 
85  //------------------------------------------------------------------------------------------------
88  void DebugLogBroadcastMessage(AIMessage message)
89  {
90  AIAgent agent = GetAIAgent();
91  SCR_AIMessageBase msgBase = SCR_AIMessageBase.Cast(message);
92 
93  string debugTextBasic = string.Format("----> SendMessage: %1 --> %2:\n", agent, message.GetReceiver());
94 
95  string debugText;
96  if (msgBase)
97  debugText = debugTextBasic + msgBase.GetDebugText();
98  else
99  debugText = debugTextBasic + string.Format("\t%1", message);
100 
101  SCR_AIDebug.DebugLog(debugText);
102  AddDebugMessage(debugText);
103  }
104 
105  //------------------------------------------------------------------------------------------------
108  void DebugLogOnReceived(AIMessage message)
109  {
110  AIAgent agent = GetAIAgent();
111 
112  AIAgent sender = message.GetSender();
113 
114  string debugTextBasic = string.Format("<---- RecvMessage: %1 <-- %2\n", agent, sender);
115 
116  SCR_AIMessageBase msgBase = SCR_AIMessageBase.Cast(message);
117 
118  string debugText;
119  if (msgBase)
120  debugText = debugTextBasic + msgBase.GetDebugText();
121  else
122  debugText = debugTextBasic + string.Format("\t%1", message);
123 
124  SCR_AIDebug.DebugLog(debugText);
125  AddDebugMessage(debugText);
126  }
127 
128  //--------------------------------------------------------------------------------------------
129  protected void AddDebugMessage(string str)
130  {
131  SCR_AIInfoBaseComponent infoComp = SCR_AIInfoBaseComponent.Cast(GetAIAgent().FindComponent(SCR_AIInfoBaseComponent));
132  infoComp.AddDebugMessage(str, msgType: EAIDebugMsgType.MAILBOX);
133  }
134  #endif // AI_DEBUG
135 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_MailboxComponentClass
Definition: SCR_MailboxComponent.c:2
EAIDebugMsgType
EAIDebugMsgType
Definition: SCR_AIDebugMessage.c:1
LogMessageStatistics
void LogMessageStatistics(LogLevel logLevel=LogLevel.NORMAL)
Definition: SCR_MailboxComponent.c:53
ReadMessage
SCR_MailboxComponentClass AICommunicationComponentClass ReadMessage(bool remove)
Definition: SCR_MailboxComponent.c:16
ReadOrder
AIOrder ReadOrder(bool remove)
Definition: SCR_MailboxComponent.c:40
GetMessage
string GetMessage()
Definition: SCR_BrowserHoverTooltipComponent.c:285
IsCommunicationEnabled
bool IsCommunicationEnabled()
Definition: SCR_MailboxComponent.c:78
SCR_AIDebug
Game core which persists through whole game and stores various data for AI debugging.
Definition: SCR_AIDebug.c:3
GetOrder
int GetOrder()
Definition: SCR_Faction.c:78
IsActive
bool IsActive()
Definition: SCR_LoadoutSaveBlackListHolder.c:82
SCR_AIMessageBase
Definition: SCR_AIMessage.c:44
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180