Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AISendMessage.c
Go to the documentation of this file.
1 class SCR_AISendMessageBase: AITaskScripted
3 {
4  // Constants
5  static const string PORT_RECEIVER = "Receiver";
6  static const string PORT_STRING = "StringIn";
7 
8  // Variables
9  protected AICommunicationComponent m_Mailbox;
10  AIAgent m_Receiver;
11 
12  [Attribute("", UIWidgets.EditBox, "String value", "")]
13  string m_string;
14 
15 
16  protected static ref TStringArray s_aVarsInBase = {
17  PORT_RECEIVER,
18  PORT_STRING
19  };
20  override TStringArray GetVariablesIn()
21  {
22  return s_aVarsInBase;
23  }
24 
25  override void OnInit(AIAgent owner)
26  {
27  m_Mailbox = owner.GetCommunicationComponent();
28  }
29 
30  // Validates owner, mailbox, reads RECEIVER port.
31  protected bool InitSendMessageInputs(AIAgent owner)
32  {
33  if (! owner)
34  {
35  Print("No owner of the task send message! Something wrong!", LogLevel.ERROR);
36  return false;
37  };
38 
39  if (!m_Mailbox)
40  {
41  Print("Owner of the task has no AICommunicationComponent!", LogLevel.ERROR);
42  return false;
43  };
44 
45  GetVariableIn(PORT_RECEIVER,m_Receiver);
46  if (! m_Receiver)
47  {
48  m_Receiver = owner;
49  };
50  return true;
51  }
52 
54  protected ENodeResult SendMessage(AIAgent owner, AIMessage msg)
55  {
56  #ifdef AI_DEBUG
57  SCR_MailboxComponent mailboxComp = SCR_MailboxComponent.Cast(m_Mailbox);
58  if (mailboxComp)
59  mailboxComp.DebugLogBroadcastMessage(msg);
60  #endif
61 
62  if (m_Mailbox.RequestBroadcast(msg, m_Receiver))
63  return ENodeResult.SUCCESS;
64  else
65  {
66  PrintFormat("Unable to send message from %1 to %2", owner, m_Receiver);
67  return ENodeResult.FAIL;
68  };
69  }
70 };
71 
74 {
75  static const string PORT_ENTITY = "EntityIn";
76  static const string PORT_INTEGER = "IntegerIn";
77  static const string PORT_VECTOR = "VectorIn";
78  static const string PORT_BOOL = "BoolIn";
79  static const string PORT_FLOAT = "FloatIn";
80  static const string PORT_TYPENAME = "TypenameIn";
81  static const string PORT_SMARTACTION = "SmartActionComponent";
82  static const string PORT_PRIORITY_LEVEL = "PriorityLevel";
83 
84 
85  [Attribute("0", UIWidgets.EditBox, "Integer value", "")]
86  int m_integer;
87 
88  [Attribute("0", UIWidgets.EditBox, "Vector value", "")]
89  vector m_vector;
90 
91  [Attribute("0", UIWidgets.CheckBox, "Bool value", "")]
92  bool m_bool;
93 
94  protected SCR_AIWorld m_aiWorld;
95 
96  // Sets up input variables, as array of strings
97  protected static ref TStringArray s_aVarsIn = {
98  PORT_RECEIVER,
99  PORT_STRING,
100  PORT_ENTITY,
101  PORT_INTEGER,
102  PORT_VECTOR,
103  PORT_BOOL,
104  PORT_FLOAT,
105  PORT_TYPENAME,
106  PORT_PRIORITY_LEVEL
107  };
108  override TStringArray GetVariablesIn()
109  {
110  return s_aVarsIn;
111  }
112 
113  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
114  {
115  if (InitSendMessageInputs(owner))
116  return ENodeResult.SUCCESS;
117 
118  return ENodeResult.FAIL;
119  }
120 
121  // Also validates AIWorld
122  override protected bool InitSendMessageInputs(AIAgent owner)
123  {
124  if (!super.InitSendMessageInputs(owner))
125  return false;
126 
127  if(!m_aiWorld)
128  {
129  m_aiWorld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
130  if (!m_aiWorld)
131  {
132  Print("Cannot find AIWorld to read config of messages!", LogLevel.ERROR);
133  return false;
134  }
135  };
136 
137  return true;
138  }
139 
140  override bool VisibleInPalette()
141  {
142  return false;
143  }
144 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_AISendMessageBase
Base class for nodes sending message.
Definition: SCR_AISendMessage.c:2
SCR_AIWorld
Definition: SCR_AIWorld.c:23
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_AISendMessageGeneric
Class for generic nodes with extra input ports which send messages.
Definition: SCR_AISendMessage.c:73
m_Mailbox
SCR_MailboxComponent m_Mailbox
Definition: SCR_AIGroupUtilityComponent.c:15