Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_AITalk.c
Go to the documentation of this file.
1
class
SCR_AITalk
:
AITaskScripted
2
{
3
static
const
string
PORT_SPEAKER =
"SpeakerIn"
;
4
static
const
string
PORT_TARGET =
"TargetIn"
;
5
static
const
string
PORT_LOCATION =
"LocationIn"
;
6
static
const
string
PORT_INT =
"EnumIn"
;
7
8
[
Attribute
(
"0"
,
UIWidgets
.ComboBox,
"Message type"
,
""
, ParamEnumArray.FromEnum(
ECommunicationType
) )]
9
protected
ECommunicationType
m_messageType
;
10
11
[
Attribute
(
"0"
,
UIWidgets
.ComboBox,
"Determines priority, timeout, and other values. See SCR_EAITalkRequestPreset"
, enums: ParamEnumArray.FromEnum(SCR_EAITalkRequestPreset))]
12
protected
SCR_EAITalkRequestPreset
m_ePreset
;
13
14
[
Attribute
(
"0"
,
UIWidgets
.CheckBox,
"When true, the node will be running until the request is finished, and will fail if the request fails."
)]
15
protected
bool
m_bSynchronous
;
16
17
[
Attribute
(
"0"
,
UIWidgets
.CheckBox,
"When true, request will be transmitted by speaker even if there is noone to potentially receive (hear) it."
)]
18
protected
bool
m_bTransmitIfNoReceivers
;
19
20
[
Attribute
(
"1"
,
UIWidgets
.CheckBox,
"When true, request will be transmitted by speaker being a passanger of a vehicle."
)]
21
protected
bool
m_bTransmitIfPassenger
;
22
23
protected
ref
SCR_AITalkRequest
m_Request
;
24
25
//-----------------------------------
26
override
ENodeResult
EOnTaskSimulate
(AIAgent owner,
float
dt)
27
{
28
if
(
m_Request
)
29
{
30
// We've sent a request, check its state ...
31
SCR_EAITalkRequestState
rqState =
m_Request
.m_eState;
32
if
(rqState ==
SCR_EAITalkRequestState
.IDLE || rqState ==
SCR_EAITalkRequestState
.TRANSMITTING)
33
return
ENodeResult
.RUNNING;
34
else
if
(rqState ==
SCR_EAITalkRequestState
.COMPLETED)
35
{
36
//_print(string.Format("Request completed: %1", m_Request.GetDebugString()));
37
Reset
();
38
return
ENodeResult
.SUCCESS;
39
}
40
else
if
(rqState ==
SCR_EAITalkRequestState
.FAILED)
41
{
42
//_print(string.Format("Request failed: %1", m_Request.GetDebugString()));
43
Reset
();
44
return
ENodeResult
.FAIL;
45
}
46
}
47
else
48
{
49
// Didn't send a request yet
50
IEntity
speaker;
51
bool
speakerPortConnected =
GetVariableIn
(PORT_SPEAKER, speaker);
52
if
(!speakerPortConnected)
53
{
54
// Port not connected - speaker is owner of node
55
speaker = owner;
56
}
57
else
if
(speakerPortConnected && !speaker)
58
{
59
// Port is connected but entity is null, failure
60
Reset
();
61
return
ENodeResult
.FAIL;
62
}
63
64
SCR_AICommsHandler
commsHandler =
FindCommsHandler
(speaker);
65
66
if
(!commsHandler)
67
{
68
// Could not find comms handler, it's impossible to transmit
69
string
callstackStr;
70
GetCallstackStr
(callstackStr);
71
Print
(
string
.Format(
"SCR_AITalk: was not able to find SCR_AICommsHandler for %1. BT: %2"
, speaker, callstackStr),
LogLevel
.ERROR);
72
Reset
();
73
return
ENodeResult
.FAIL;
74
}
75
76
// Check if we can bypass this (optimize out)
77
if
(commsHandler.
CanBypass
())
78
{
79
return
ENodeResult
.SUCCESS;
80
}
81
82
// Read ports
83
IEntity
rqTarget;
84
vector
rqPos;
85
int
rqEnum;
86
87
GetVariableIn
(PORT_TARGET, rqTarget);
88
GetVariableIn
(PORT_LOCATION, rqPos);
89
GetVariableIn
(PORT_INT, rqEnum);
90
91
// Create and fill request
92
SCR_AITalkRequest
rq =
new
SCR_AITalkRequest
(
m_messageType
, rqTarget, rqPos, rqEnum,
m_bTransmitIfNoReceivers
,
m_bTransmitIfPassenger
,
m_ePreset
);
93
94
commsHandler.
AddRequest
(rq);
95
96
//_print(string.Format("Added request: %1", rq.GetDebugString()));
97
98
if
(
m_bSynchronous
)
99
{
100
// If synchronous, we care about request result
101
102
// Store request, return running, wait until it's done
103
//_print("Synchronous, will wait for request result");
104
m_Request
= rq;
105
return
ENodeResult
.RUNNING;
106
}
107
else
108
{
109
// If asynchronous, we don't care about request result
110
//_print("Asynchronous, return success");
111
Reset
();
112
return
ENodeResult
.SUCCESS;
113
}
114
}
115
return
0;
116
}
117
118
//----------------------------------------------------------------------
120
protected
SCR_AICommsHandler
FindCommsHandler
(notnull
IEntity
speaker)
121
{
122
AIAgent speakerAgent = AIAgent.Cast(speaker);
123
AIGroup speakerGroup = AIGroup.Cast(speaker);
124
if
(speakerGroup)
125
{
126
// Speaker is group
127
// Find comms handler of leader agent
128
129
AIAgent leaderAgent = speakerGroup.GetLeaderAgent();
130
131
if
(!leaderAgent)
132
return
null;
133
134
SCR_AIUtilityComponent utility = SCR_AIUtilityComponent.Cast(leaderAgent.FindComponent(SCR_AIUtilityComponent));
135
if
(!utility)
136
return
null;
137
138
return
utility.m_CommsHandler;
139
}
140
else
if
(speakerAgent)
141
{
142
SCR_AIUtilityComponent utility = SCR_AIUtilityComponent.Cast(speakerAgent.FindComponent(SCR_AIUtilityComponent));
143
if
(!utility)
144
return
null;
145
return
utility.m_CommsHandler;
146
}
147
else
148
{
149
// Speaker is Entity
150
AIControlComponent contr = AIControlComponent.Cast(speaker.FindComponent(AIControlComponent));
151
if
(!contr)
152
return
null;
153
154
speakerAgent = contr.GetControlAIAgent();
155
if
(!speakerAgent)
156
return
null;
157
158
SCR_AIUtilityComponent utility = SCR_AIUtilityComponent.Cast(speakerAgent.FindComponent(SCR_AIUtilityComponent));
159
if
(!utility)
160
return
null;
161
return
utility.m_CommsHandler;
162
}
163
}
164
165
//----------------------------------------------------------------------
166
override
void
OnAbort
(AIAgent owner,
Node
nodeCausingAbort)
167
{
168
Reset
();
169
}
170
171
//----------------------------------------------------------------------
173
protected
void
Reset
()
174
{
175
m_Request
= null;
176
}
177
178
//----------------------------------------------------------------------
179
static
override
bool
VisibleInPalette
()
180
{
181
return
true
;
182
}
183
184
//----------------------------------------------------------------------
185
protected
static
ref
TStringArray
s_aVarsIn
= {
186
PORT_SPEAKER,
187
PORT_TARGET,
188
PORT_LOCATION,
189
PORT_INT
190
};
191
override
TStringArray
GetVariablesIn
()
192
{
193
return
s_aVarsIn
;
194
}
195
196
197
//----------------------------------------------------------------------
198
static
override
protected
bool
CanReturnRunning
()
199
{
200
return
true
;
201
}
202
203
//----------------------------------------------------------------------
204
protected
void
_print
(
string
str)
205
{
206
Print
(
string
.Format(
"SCR_AITalk %1: %2"
,
this
, str));
207
}
208
};
ECommunicationType
ECommunicationType
Definition
SCR_AISoundHandling.c:2
SCR_EAITalkRequestState
SCR_EAITalkRequestState
Definition
SCR_AITalkRequest.c:2
SCR_AITalkRequest
void SCR_AITalkRequest(ECommunicationType type, IEntity entity, vector pos, int enumSignal, bool transmitIfNoReceivers, bool transmitIfPassenger, SCR_EAITalkRequestPreset preset)
Definition
SCR_AITalkRequest.c:37
AITaskScripted
Definition
AITaskScripted.c:13
IEntity
Definition
IEntity.c:13
Node
Definition
Node.c:13
Node::GetVariableIn
proto bool GetVariableIn(string name, out void val)
Node::GetCallstackStr
proto void GetCallstackStr(out string val)
SCR_AICommsHandler
Definition
SCR_AICommsHandler.c:20
SCR_AICommsHandler::AddRequest
void AddRequest(SCR_AITalkRequest request)
Definition
SCR_AICommsHandler.c:53
SCR_AICommsHandler::CanBypass
bool CanBypass(SCR_AITalkRequest request=null)
Definition
SCR_AICommsHandler.c:120
SCR_AITalk
Definition
SCR_AITalk.c:2
SCR_AITalk::VisibleInPalette
static override bool VisibleInPalette()
Definition
SCR_AITalk.c:179
SCR_AITalk::m_bTransmitIfNoReceivers
bool m_bTransmitIfNoReceivers
Definition
SCR_AITalk.c:18
SCR_AITalk::EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition
SCR_AITalk.c:26
SCR_AITalk::FindCommsHandler
SCR_AICommsHandler FindCommsHandler(notnull IEntity speaker)
Finds comms handler of provided speaker.
Definition
SCR_AITalk.c:120
SCR_AITalk::_print
void _print(string str)
Definition
SCR_AITalk.c:204
SCR_AITalk::m_Request
ref SCR_AITalkRequest m_Request
Definition
SCR_AITalk.c:23
SCR_AITalk::s_aVarsIn
static ref TStringArray s_aVarsIn
Definition
SCR_AITalk.c:185
SCR_AITalk::OnAbort
override void OnAbort(AIAgent owner, Node nodeCausingAbort)
Definition
SCR_AITalk.c:166
SCR_AITalk::m_ePreset
SCR_EAITalkRequestPreset m_ePreset
Definition
SCR_AITalk.c:12
SCR_AITalk::m_messageType
ECommunicationType m_messageType
Definition
SCR_AITalk.c:9
SCR_AITalk::GetVariablesIn
override TStringArray GetVariablesIn()
Definition
SCR_AITalk.c:191
SCR_AITalk::Reset
void Reset()
Resets internal state, should be called on abort and such.
Definition
SCR_AITalk.c:173
SCR_AITalk::m_bTransmitIfPassenger
bool m_bTransmitIfPassenger
Definition
SCR_AITalk.c:21
SCR_AITalk::CanReturnRunning
bool CanReturnRunning()
Definition
SCR_AITalk.c:198
SCR_AITalk::m_bSynchronous
bool m_bSynchronous
Definition
SCR_AITalk.c:15
UIWidgets
Definition
attributes.c:40
vector
Definition
vector.c:13
ENodeResult
ENodeResult
Definition
ENodeResult.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
TStringArray
array< string > TStringArray
Definition
Types.c:385
scripts
Game
AI
ScriptedNodes
Messages
SCR_AITalk.c
Generated by
1.17.0