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_AILeaveStaticVehicles.c
Go to the documentation of this file.
1
class
SCR_AILeaveStaticVehicles
:
AITaskScripted
2
{
3
[
Attribute
(defvalue:
"100"
, uiwidget:
UIWidgets
.EditBox,
desc
:
"Update time of checks [ms]"
)]
4
protected
float
m_fUpdateInterval_ms
;
5
6
static
const
string
NODE_NAME
=
"SCR_AILeaveStaticVehicles"
;
7
8
protected
float
m_fNextUpdate_ms
;
9
protected
ref array<AIAgent>
m_aAgents
= {};
10
protected
ref array<AIAgent>
m_aInformedAgents
= {};
11
protected
ref array<ref SCR_AIGroupVehicle>
m_aUsedVehicles
= {};
12
protected
ref array<ref SCR_AIGroupVehicle>
m_aVehiclesToLeave
= {};
13
protected
SCR_AIGroup
m_Group
;
14
protected
SCR_AIGroupUtilityComponent
m_Utility
;
15
protected
int
m_iStateOfExecution
;
16
17
protected
static
int
STATE_TESTING_STATE
= 0;
// testing initial setup
18
protected
static
int
STATE_SENDING_SIGNALS
= 1;
// sending signals to agents
19
protected
static
int
STATE_WAITING
= 2;
// waiting for agents to obey
20
protected
static
int
STATE_FINISHED
= 3;
// done everything
21
22
//----------------------------------------------------------------------------------------------------------------------------------------------
23
override
void
OnEnter
(AIAgent owner)
24
{
25
m_Group
=
SCR_AIGroup
.Cast(owner);
26
if
(!
m_Group
)
27
{
28
SCR_AgentMustBeAIGroup
(
this
, owner);
29
return
;
30
}
31
m_Utility
=
SCR_AIGroupUtilityComponent
.Cast(
m_Group
.FindComponent(
SCR_AIGroupUtilityComponent
));
32
if
(!
m_Utility
)
33
return
;
34
m_aAgents
.Clear();
35
m_aInformedAgents
.Clear();
36
m_aUsedVehicles
.Clear();
37
m_Utility
.m_OnAgentLifeStateChanged.Remove(
OnAgentLifeStateChanged
);
38
m_Utility
.m_OnAgentLifeStateChanged.Insert(
OnAgentLifeStateChanged
);
39
m_iStateOfExecution
=
STATE_TESTING_STATE
;
40
}
41
42
//----------------------------------------------------------------------------------------------------------------------------------------------
43
override
ENodeResult
EOnTaskSimulate
(AIAgent owner,
float
dt)
44
{
45
if
(!
m_Group
|| !
m_Utility
)
46
return
ENodeResult
.FAIL;
47
48
float
currentTime_ms =
GetGame
().GetWorld().GetWorldTime();
49
if
(currentTime_ms <
m_fNextUpdate_ms
)
50
return
ENodeResult
.RUNNING;
51
m_fNextUpdate_ms
= currentTime_ms +
m_fUpdateInterval_ms
;
52
53
switch
(
m_iStateOfExecution
)
54
{
55
case
STATE_TESTING_STATE
:
56
{
57
return
Testing_State
(
true
);
58
}
59
case
STATE_SENDING_SIGNALS
:
60
{
61
return
SendingMessages_State
();
62
}
63
case
STATE_WAITING
:
64
{
65
return
Waiting_State
();
66
}
67
case
STATE_FINISHED
:
68
{
69
return
Finished_State
();
70
}
71
}
72
return
ENodeResult
.RUNNING;
73
}
74
75
//----------------------------------------------------------------------------------------------------------------------------------------------
76
protected
ENodeResult
Testing_State
(
bool
isScheduled)
77
{
78
m_Group
.GetAgents(
m_aAgents
);
79
if
(isScheduled)
80
{
81
// check that AIAgents arent just moving in/out of compartments
82
foreach
(AIAgent agent:
m_aAgents
)
83
{
84
ChimeraCharacter
chChar =
ChimeraCharacter
.Cast(agent.GetControlledEntity());
85
if
(!chChar)
86
continue
;
87
CompartmentAccessComponent compAcc = chChar.GetCompartmentAccessComponent();
88
if
(!compAcc)
89
continue
;
90
bool
inTransition = compAcc.IsGettingIn() || compAcc.IsGettingOut();
91
if
(inTransition)
92
return
ENodeResult
.RUNNING;
93
}
94
}
95
96
m_aVehiclesToLeave
.Clear();
97
m_Utility
.m_VehicleMgr.GetAllVehicles(
m_aUsedVehicles
);
98
99
foreach
(
SCR_AIGroupVehicle
groupVehicle :
m_aUsedVehicles
)
100
{
101
if
(!groupVehicle)
102
continue
;
103
// we skip group helicopters and static turrets
104
SCR_AIVehicleUsageComponent
vehicleUsage = groupVehicle.GetVehicleUsageComponent();
105
if
(groupVehicle.IsStatic() || !groupVehicle.CanMove() || (vehicleUsage && !vehicleUsage.
CanBePiloted
()))
106
{
107
m_aVehiclesToLeave
.Insert(groupVehicle);
108
continue
;
109
}
110
}
111
bool
willTryToLeave =
m_aVehiclesToLeave
.Count() > 0;
112
if
(willTryToLeave)
113
m_iStateOfExecution
=
STATE_SENDING_SIGNALS
;
114
else
115
m_iStateOfExecution
=
STATE_FINISHED
;
116
return
ENodeResult
.RUNNING;
117
}
118
119
//----------------------------------------------------------------------------------------------------------------------------------------------
120
protected
ENodeResult
SendingMessages_State
()
121
{
122
if
(
m_aVehiclesToLeave
.Count() == 0)
123
{
124
m_iStateOfExecution
=
STATE_FINISHED
;
125
return
ENodeResult
.RUNNING;
126
};
127
m_aInformedAgents
.Clear();
128
AICommunicationComponent myComms =
m_Utility
.m_Owner.GetCommunicationComponent();
129
foreach
(
SCR_AIGroupVehicle
groupVehicle :
m_aVehiclesToLeave
)
130
{
131
int
vehicleHandleId = groupVehicle.GetSubgroupHandleId();
132
array<AIAgent> agentsOfHandler = {};
133
m_Utility
.m_GroupMovementComponent.GetAgentsInHandler(agentsOfHandler, vehicleHandleId);
134
135
foreach
(
int
index
, AIAgent agent : agentsOfHandler)
136
{
137
SCR_AIMessageHandling.SendDismountMessage(agent, groupVehicle.GetEntity(),
index
, null, myComms,
NODE_NAME
);
138
m_aInformedAgents
.Insert(agent);
139
}
140
}
141
if
(
m_aInformedAgents
.IsEmpty())
142
m_iStateOfExecution
=
STATE_FINISHED
;
143
m_iStateOfExecution
=
STATE_WAITING
;
144
return
ENodeResult
.RUNNING;
145
146
}
147
148
//----------------------------------------------------------------------------------------------------------------------------------------------
149
protected
ENodeResult
Waiting_State
()
150
{
151
foreach
(AIAgent agent :
m_aInformedAgents
)
152
{
153
SCR_ChimeraAIAgent
chimAg =
SCR_ChimeraAIAgent
.Cast(agent);
154
if
(!chimAg)
155
continue
;
156
SCR_AIInfoComponent
info = chimAg.m_InfoComponent;
157
if
(!info)
158
continue
;
159
if
(info.
HasUnitState
(EUnitState.IN_VEHICLE))
160
return
ENodeResult
.RUNNING;
161
}
162
m_iStateOfExecution
=
STATE_FINISHED
;
163
return
ENodeResult
.RUNNING;
164
}
165
166
//----------------------------------------------------------------------------------------------------------------------------------------------
167
protected
ENodeResult
Finished_State
()
168
{
169
return
ENodeResult
.SUCCESS;
170
}
171
172
//----------------------------------------------------------------------------------------------------------------------------------------------
173
protected
void
CancelOrders
()
174
{
175
AICommunicationComponent myComms =
m_Utility
.m_Owner.GetCommunicationComponent();
176
for
(
int
index
=
m_aInformedAgents
.Count() - 1;
index
>=0;
index
--)
177
{
178
if
(
m_aInformedAgents
[
index
])
179
SCR_AIMessageHandling.SendCancelMessage(
m_aInformedAgents
[
index
], null, myComms,
NODE_NAME
);
180
m_aInformedAgents
.Remove(
index
);
181
}
182
}
183
184
//----------------------------------------------------------------------------------------------------------------------------------------------
185
override
void
OnAbort
(AIAgent owner,
Node
nodeCausingAbort)
186
{
187
if
(!
m_Utility
)
188
return
;
189
m_Utility
.m_OnAgentLifeStateChanged.Remove(
OnAgentLifeStateChanged
);
190
switch
(
m_iStateOfExecution
)
191
{
192
case
STATE_SENDING_SIGNALS
:
193
{
194
CancelOrders
();
195
break
;
196
}
197
case
STATE_WAITING
:
198
{
199
CancelOrders
();
200
break
;
201
}
202
case
STATE_FINISHED
:
203
{
204
return
;
205
}
206
}
207
}
208
209
//----------------------------------------------------------------------------------------------------------------------------------------------
210
void
OnAgentLifeStateChanged
(AIAgent incapacitatedAgent,
SCR_AIInfoComponent
infoIncap,
IEntity
vehicle,
ECharacterLifeState
lifeState)
211
{
212
if
(vehicle && infoIncap.
HasUnitState
(EUnitState.IN_VEHICLE) &&
m_iStateOfExecution
!=
STATE_FINISHED
)
213
Testing_State
(
false
);
214
else
if
(
m_aInformedAgents
.Find(incapacitatedAgent) > -1)
215
m_iStateOfExecution
=
STATE_SENDING_SIGNALS
;
216
}
217
218
//----------------------------------------------------------------------------------------------------------------------------------------------
219
static
override
bool
VisibleInPalette
()
220
{
221
return
true
;
222
};
223
224
//----------------------------------------------------------------------------------------------------------------------------------------
225
static
override
string
GetOnHoverDescription
()
226
{
227
return
"LeaveStaticVehicles: goes over the array of known vehicles and group members leave all static or broken vehicles. Is running while change is ongoing."
;
228
};
229
230
//----------------------------------------------------------------------------------------------------------------------------------------
231
static
override
bool
CanReturnRunning
()
232
{
233
return
true
;
234
};
235
};
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
SCR_AgentMustBeAIGroup
void SCR_AgentMustBeAIGroup(Node node, AIAgent owner)
Definition
NodeError.c:14
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition
SCR_DestructionSynchronizationComponent.c:17
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
AITaskScripted
Definition
AITaskScripted.c:13
ChimeraCharacter
Definition
ChimeraCharacter.c:13
IEntity
Definition
IEntity.c:13
Node
Definition
Node.c:13
SCR_AIGroup
Definition
SCR_AIGroup.c:75
SCR_AIGroupUtilityComponent
Definition
SCR_AIGroupUtilityComponent.c:18
SCR_AIGroupVehicle
This class is used for keeping track of vehicles assigned to group.
Definition
SCR_AIGroupVehicle.c:3
SCR_AIInfoComponent
Definition
SCR_AIInfoComponent.c:46
SCR_AIInfoComponent::HasUnitState
bool HasUnitState(EUnitState state)
Definition
SCR_AIInfoComponent.c:261
SCR_AILeaveStaticVehicles
Definition
SCR_AILeaveStaticVehicles.c:2
SCR_AILeaveStaticVehicles::OnAgentLifeStateChanged
void OnAgentLifeStateChanged(AIAgent incapacitatedAgent, SCR_AIInfoComponent infoIncap, IEntity vehicle, ECharacterLifeState lifeState)
Definition
SCR_AILeaveStaticVehicles.c:210
SCR_AILeaveStaticVehicles::SendingMessages_State
ENodeResult SendingMessages_State()
Definition
SCR_AILeaveStaticVehicles.c:120
SCR_AILeaveStaticVehicles::m_Utility
SCR_AIGroupUtilityComponent m_Utility
Definition
SCR_AILeaveStaticVehicles.c:14
SCR_AILeaveStaticVehicles::VisibleInPalette
static override bool VisibleInPalette()
Definition
SCR_AILeaveStaticVehicles.c:219
SCR_AILeaveStaticVehicles::OnEnter
override void OnEnter(AIAgent owner)
Definition
SCR_AILeaveStaticVehicles.c:23
SCR_AILeaveStaticVehicles::STATE_SENDING_SIGNALS
static int STATE_SENDING_SIGNALS
Definition
SCR_AILeaveStaticVehicles.c:18
SCR_AILeaveStaticVehicles::Finished_State
ENodeResult Finished_State()
Definition
SCR_AILeaveStaticVehicles.c:167
SCR_AILeaveStaticVehicles::CanReturnRunning
static override bool CanReturnRunning()
Definition
SCR_AILeaveStaticVehicles.c:231
SCR_AILeaveStaticVehicles::m_aUsedVehicles
ref array< ref SCR_AIGroupVehicle > m_aUsedVehicles
Definition
SCR_AILeaveStaticVehicles.c:11
SCR_AILeaveStaticVehicles::Testing_State
ENodeResult Testing_State(bool isScheduled)
Definition
SCR_AILeaveStaticVehicles.c:76
SCR_AILeaveStaticVehicles::EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition
SCR_AILeaveStaticVehicles.c:43
SCR_AILeaveStaticVehicles::Waiting_State
ENodeResult Waiting_State()
Definition
SCR_AILeaveStaticVehicles.c:149
SCR_AILeaveStaticVehicles::m_fUpdateInterval_ms
float m_fUpdateInterval_ms
Definition
SCR_AILeaveStaticVehicles.c:4
SCR_AILeaveStaticVehicles::m_fNextUpdate_ms
float m_fNextUpdate_ms
Definition
SCR_AILeaveStaticVehicles.c:8
SCR_AILeaveStaticVehicles::OnAbort
override void OnAbort(AIAgent owner, Node nodeCausingAbort)
Definition
SCR_AILeaveStaticVehicles.c:185
SCR_AILeaveStaticVehicles::STATE_FINISHED
static int STATE_FINISHED
Definition
SCR_AILeaveStaticVehicles.c:20
SCR_AILeaveStaticVehicles::STATE_TESTING_STATE
static int STATE_TESTING_STATE
Definition
SCR_AILeaveStaticVehicles.c:17
SCR_AILeaveStaticVehicles::CancelOrders
void CancelOrders()
Definition
SCR_AILeaveStaticVehicles.c:173
SCR_AILeaveStaticVehicles::m_aVehiclesToLeave
ref array< ref SCR_AIGroupVehicle > m_aVehiclesToLeave
Definition
SCR_AILeaveStaticVehicles.c:12
SCR_AILeaveStaticVehicles::m_aInformedAgents
ref array< AIAgent > m_aInformedAgents
Definition
SCR_AILeaveStaticVehicles.c:10
SCR_AILeaveStaticVehicles::STATE_WAITING
static int STATE_WAITING
Definition
SCR_AILeaveStaticVehicles.c:19
SCR_AILeaveStaticVehicles::m_Group
SCR_AIGroup m_Group
Definition
SCR_AILeaveStaticVehicles.c:13
SCR_AILeaveStaticVehicles::m_aAgents
ref array< AIAgent > m_aAgents
Definition
SCR_AILeaveStaticVehicles.c:9
SCR_AILeaveStaticVehicles::GetOnHoverDescription
static override string GetOnHoverDescription()
Definition
SCR_AILeaveStaticVehicles.c:225
SCR_AILeaveStaticVehicles::m_iStateOfExecution
int m_iStateOfExecution
Definition
SCR_AILeaveStaticVehicles.c:15
SCR_AILeaveStaticVehicles::NODE_NAME
static const string NODE_NAME
Definition
SCR_AILeaveStaticVehicles.c:6
SCR_AIVehicleUsageComponent
Definition
SCR_AIVehicleUsageComponent.c:30
SCR_AIVehicleUsageComponent::CanBePiloted
bool CanBePiloted()
AI can use the pilot compartments on this vehicle.
Definition
SCR_AIVehicleUsageComponent.c:73
SCR_ChimeraAIAgent
Definition
SCR_ChimeraAIAgent.c:6
UIWidgets
Definition
attributes.c:40
ENodeResult
ENodeResult
Definition
ENodeResult.c:13
ECharacterLifeState
ECharacterLifeState
Definition
ECharacterLifeState.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
scripts
Game
AI
ScriptedNodes
Vehicles
SCR_AILeaveStaticVehicles.c
Generated by
1.17.0