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