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_AIFindAvailableVehicle.c
Go to the documentation of this file.
1
class
SCR_AIFindAvailableVehicle
:
AITaskScripted
2
{
3
static
const
string
PORT_CENTER_OF_SEARCH =
"OriginIn"
;
4
static
const
string
PORT_RADIUS =
"RadiusIn"
;
5
static
const
string
PORT_VEHICLE_IN =
"VehicleIn"
;
6
static
const
string
PORT_VEHICLE_OUT =
"VehicleOut"
;
7
static
const
string
PORT_ROLE_OUT =
"RoleOut"
;
8
static
const
string
PORT_COMPARTMENT_OUT =
"CompartmentOut"
;
9
static
const
string
PORT_SEARCH_PARAMS =
"SearchParams"
;
10
11
[
Attribute
(
"0"
,
UIWidgets
.CheckBox,
"If found, add to list of usable vehicles?"
)]
12
bool
m_bAddToList;
13
14
[
Attribute
(
"1"
,
UIWidgets
.CheckBox,
"If found, reserve compartment?"
)]
15
bool
m_bReserveCompartment;
16
17
private
BaseWorld
m_world;
18
protected
SCR_AIGroup
m_group
;
19
private
ref array<BaseCompartmentSlot> m_CompartmentSlots = {};
20
protected
IEntity
m_VehicleToTestForCompartments
;
21
protected
BaseCompartmentSlot
m_Compartment
;
22
protected
ECompartmentType
m_CompartmentType
;
23
protected
SCR_AIBoardingParameters
m_WaypointParameter
;
24
protected
SCR_AIGroupUtilityComponent
m_groupUtilityCompoment
;
25
26
//------------------------------------------------------------------------------------------------
27
override
void
OnInit
(AIAgent owner)
28
{
29
m_world = owner.GetWorld();
30
m_group
=
SCR_AIGroup
.Cast(owner);
31
if
(!
m_group
)
32
{
33
SCR_AgentMustBeAIGroup
(
this
, owner);
34
}
35
m_groupUtilityCompoment
=
m_group
.GetGroupUtilityComponent();
36
m_VehicleToTestForCompartments
= null;
37
m_Compartment
= null;
38
}
39
40
//------------------------------------------------------------------------------------------------
41
override
ENodeResult
EOnTaskSimulate
(AIAgent owner,
float
dt)
42
{
43
if
(!m_world || !
m_group
)
44
return
ENodeResult
.FAIL;
45
46
if
(!
m_VehicleToTestForCompartments
&&
GetVariableIn
(PORT_VEHICLE_IN,
m_VehicleToTestForCompartments
))
// reading the vehicle to test from outside of the node (another search)
47
if
(!
GetVariableIn
(PORT_SEARCH_PARAMS,
m_WaypointParameter
))
48
return
ENodeResult
.FAIL;
49
50
if
(
m_VehicleToTestForCompartments
&& !
HasNoAvailableCompartment
(
m_VehicleToTestForCompartments
))
// the vehicle was found already, does it have available compartment?
51
{
52
if
(m_bReserveCompartment)
53
m_group
.AllocateCompartment(
m_Compartment
);
54
SetVariablesOut
(owner,
m_VehicleToTestForCompartments
,
m_CompartmentType
,
m_Compartment
);
55
return
ENodeResult
.SUCCESS;
56
}
57
else
// perform new search for vehicle entity
58
{
59
m_VehicleToTestForCompartments
= null;
60
vector
center;
61
float
radius;
62
GetVariableIn
(PORT_CENTER_OF_SEARCH, center);
63
GetVariableIn
(PORT_RADIUS, radius);
64
GetVariableIn
(PORT_SEARCH_PARAMS,
m_WaypointParameter
);
65
66
if
(!
m_WaypointParameter
)
// waypoint can be deleted in the meantime
67
return
ENodeResult
.FAIL;
68
69
m_world.QueryEntitiesBySphere(center, radius,
HasNoAvailableCompartment
,
FilterEntities
,
EQueryEntitiesFlags
.DYNAMIC);
70
if
(
m_VehicleToTestForCompartments
)
71
{
72
if
(m_bReserveCompartment)
73
m_group
.AllocateCompartment(
m_Compartment
);
74
SetVariablesOut
(owner,
m_VehicleToTestForCompartments
,
m_CompartmentType
,
m_Compartment
);
75
return
ENodeResult
.SUCCESS;
76
}
77
ClearVariable
(PORT_VEHICLE_OUT);
78
ClearVariable
(PORT_ROLE_OUT);
79
};
80
return
ENodeResult
.FAIL;
81
}
82
83
//------------------------------------------------------------------------------------------------
84
bool
HasNoAvailableCompartment
(
IEntity
ent)
85
{
86
BaseCompartmentManagerComponent
compComp =
BaseCompartmentManagerComponent
.Cast(ent.
FindComponent
(
BaseCompartmentManagerComponent
));
87
if
(!compComp)
88
return
true
;
89
90
compComp.GetCompartments(m_CompartmentSlots);
91
if
(m_CompartmentSlots.IsEmpty())
92
return
true
;
93
94
SCR_AIVehicleUsageComponent
vehicleUsage =
SCR_AIVehicleUsageComponent
.Cast(ent.
FindComponent
(
SCR_AIVehicleUsageComponent
));
95
if
(!vehicleUsage)
96
return
true
;
97
bool
canBePiloted = vehicleUsage.
CanBePiloted
();
98
BaseCompartmentSlot
pilotCompartment, turretCompartment, cargoCompartment;
99
100
foreach
(
BaseCompartmentSlot
slot : m_CompartmentSlots)
101
{
102
if
(slot.IsOccupied() || !slot.IsCompartmentAccessible() || slot.IsReserved())
103
continue
;
104
if
(
m_WaypointParameter
.m_bIsDriverAllowed &&
PilotCompartmentSlot
.Cast(slot) && canBePiloted)
//exclude helicopter pilot slots for now
105
pilotCompartment = slot;
106
else
if
(
m_WaypointParameter
.m_bIsGunnerAllowed &&
TurretCompartmentSlot
.Cast(slot))
107
turretCompartment = slot;
108
else
if
(
m_WaypointParameter
.m_bIsCargoAllowed &&
CargoCompartmentSlot
.Cast(slot))
109
cargoCompartment = slot;
110
}
111
// going through priorities: pilot > turret > cargo
112
if
(pilotCompartment)
113
{
114
m_CompartmentType
=
ECompartmentType
.PILOT;
115
m_VehicleToTestForCompartments
= ent;
116
m_Compartment
= pilotCompartment;
117
return
false
;
118
}
119
120
if
(turretCompartment)
121
{
122
m_CompartmentType
=
ECompartmentType
.TURRET;
123
m_VehicleToTestForCompartments
= ent;
124
m_Compartment
= turretCompartment;
125
return
false
;
126
}
127
128
if
(cargoCompartment)
129
{
130
m_CompartmentType
=
ECompartmentType
.CARGO;
131
m_VehicleToTestForCompartments
= ent;
132
m_Compartment
= cargoCompartment;
133
return
false
;
134
}
135
return
true
;
//continue search
136
}
137
138
//------------------------------------------------------------------------------------------------
139
bool
FilterEntities
(
IEntity
ent)
140
{
141
if
(ent.
FindComponent
(
BaseCompartmentManagerComponent
) && (
Turret
.Cast(ent) || SCR_AIVehicleUsability.VehicleCanMove(ent)) && !SCR_AIVehicleUsability.VehicleIsOnFire(ent))
142
return
true
;
143
144
return
false
;
145
}
146
147
//------------------------------------------------------------------------------------------------
148
void
SetVariablesOut
(AIAgent owner,
IEntity
vehicleOut,
ECompartmentType
compartmentTypeOut,
BaseCompartmentSlot
compartment)
149
{
150
SetVariableOut
(PORT_VEHICLE_OUT, vehicleOut);
151
SetVariableOut
(PORT_ROLE_OUT, compartmentTypeOut);
152
SetVariableOut
(PORT_COMPARTMENT_OUT, compartment);
153
154
if
(m_bAddToList)
155
{
156
SCR_AIGroup
group =
SCR_AIGroup
.Cast(owner);
157
if
(group)
158
{
159
SCR_AIVehicleUsageComponent
vehicleUsageComp =
SCR_AIVehicleUsageComponent
.
FindOnNearestParent
(vehicleOut, vehicleOut);
160
if
(vehicleUsageComp)
161
group.
GetGroupUtilityComponent
().
AddUsableVehicle
(vehicleUsageComp);
162
}
163
}
164
}
165
166
//------------------------------------------------------------------------------------------------
167
protected
static
ref
TStringArray
s_aVarsOut
= {
168
PORT_VEHICLE_OUT,
169
PORT_ROLE_OUT,
170
PORT_COMPARTMENT_OUT
171
};
172
override
TStringArray
GetVariablesOut
()
173
{
174
return
s_aVarsOut
;
175
}
176
177
//------------------------------------------------------------------------------------------------
178
protected
static
ref
TStringArray
s_aVarsIn
= {
179
PORT_CENTER_OF_SEARCH,
180
PORT_RADIUS,
181
PORT_SEARCH_PARAMS,
182
PORT_VEHICLE_IN
183
};
184
override
TStringArray
GetVariablesIn
()
185
{
186
return
s_aVarsIn
;
187
}
188
189
//------------------------------------------------------------------------------------------------
190
static
override
bool
VisibleInPalette
()
191
{
192
return
true
;
193
}
194
195
//------------------------------------------------------------------------------------------------
196
static
override
string
GetOnHoverDescription
()
197
{
198
return
"SCR_AIFindAvailableVehicle: finds within radius of origin available compartments of vehicles with priority pilot>turret>cargo"
;
199
}
200
};
ECompartmentType
ECompartmentType
Definition
ECompartmentType.c:8
SCR_AgentMustBeAIGroup
void SCR_AgentMustBeAIGroup(Node node, AIAgent owner)
Definition
NodeError.c:14
Turret
@ Turret
Definition
SCR_AIVehicleBehavior.c:5
AITaskScripted
Definition
AITaskScripted.c:13
BaseCompartmentManagerComponent
Definition
BaseCompartmentManagerComponent.c:13
BaseCompartmentSlot
Definition
BaseCompartmentSlot.c:2
BaseWorld
Definition
BaseWorld.c:13
CargoCompartmentSlot
Definition
CargoCompartmentSlot.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
Node::SetVariableOut
proto void SetVariableOut(string name, void val)
Node::GetVariableIn
proto bool GetVariableIn(string name, out void val)
Node::ClearVariable
proto void ClearVariable(string name)
PilotCompartmentSlot
Definition
PilotCompartmentSlot.c:13
SCR_AIBoardingParameters
Definition
SCR_BoardingWaypoint.c:6
SCR_AIFindAvailableVehicle
Definition
SCR_AIFindAvailableVehicle.c:2
SCR_AIFindAvailableVehicle::s_aVarsOut
static ref TStringArray s_aVarsOut
Definition
SCR_AIFindAvailableVehicle.c:167
SCR_AIFindAvailableVehicle::m_group
SCR_AIGroup m_group
Definition
SCR_AIFindAvailableVehicle.c:18
SCR_AIFindAvailableVehicle::VisibleInPalette
static override bool VisibleInPalette()
Definition
SCR_AIFindAvailableVehicle.c:190
SCR_AIFindAvailableVehicle::m_CompartmentType
ECompartmentType m_CompartmentType
Definition
SCR_AIFindAvailableVehicle.c:22
SCR_AIFindAvailableVehicle::s_aVarsIn
static ref TStringArray s_aVarsIn
Definition
SCR_AIFindAvailableVehicle.c:178
SCR_AIFindAvailableVehicle::EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition
SCR_AIFindAvailableVehicle.c:41
SCR_AIFindAvailableVehicle::FilterEntities
bool FilterEntities(IEntity ent)
Definition
SCR_AIFindAvailableVehicle.c:139
SCR_AIFindAvailableVehicle::OnInit
override void OnInit(AIAgent owner)
Definition
SCR_AIFindAvailableVehicle.c:27
SCR_AIFindAvailableVehicle::m_WaypointParameter
SCR_AIBoardingParameters m_WaypointParameter
Definition
SCR_AIFindAvailableVehicle.c:23
SCR_AIFindAvailableVehicle::GetVariablesIn
override TStringArray GetVariablesIn()
Definition
SCR_AIFindAvailableVehicle.c:184
SCR_AIFindAvailableVehicle::GetVariablesOut
override TStringArray GetVariablesOut()
Definition
SCR_AIFindAvailableVehicle.c:172
SCR_AIFindAvailableVehicle::GetOnHoverDescription
static override string GetOnHoverDescription()
Definition
SCR_AIFindAvailableVehicle.c:196
SCR_AIFindAvailableVehicle::HasNoAvailableCompartment
bool HasNoAvailableCompartment(IEntity ent)
Definition
SCR_AIFindAvailableVehicle.c:84
SCR_AIFindAvailableVehicle::SetVariablesOut
void SetVariablesOut(AIAgent owner, IEntity vehicleOut, ECompartmentType compartmentTypeOut, BaseCompartmentSlot compartment)
Definition
SCR_AIFindAvailableVehicle.c:148
SCR_AIFindAvailableVehicle::m_groupUtilityCompoment
SCR_AIGroupUtilityComponent m_groupUtilityCompoment
Definition
SCR_AIFindAvailableVehicle.c:24
SCR_AIFindAvailableVehicle::m_VehicleToTestForCompartments
IEntity m_VehicleToTestForCompartments
Definition
SCR_AIFindAvailableVehicle.c:20
SCR_AIFindAvailableVehicle::m_Compartment
BaseCompartmentSlot m_Compartment
Definition
SCR_AIFindAvailableVehicle.c:21
SCR_AIGroup
Definition
SCR_AIGroup.c:75
SCR_AIGroup::GetGroupUtilityComponent
SCR_AIGroupUtilityComponent GetGroupUtilityComponent()
Definition
SCR_AIGroup.c:208
SCR_AIGroupUtilityComponent
Definition
SCR_AIGroupUtilityComponent.c:18
SCR_AIGroupUtilityComponent::AddUsableVehicle
void AddUsableVehicle(notnull SCR_AIVehicleUsageComponent vehicleUsageComp)
Definition
SCR_AIGroupUtilityComponent.c:959
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_AIVehicleUsageComponent::FindOnNearestParent
static SCR_AIVehicleUsageComponent FindOnNearestParent(notnull IEntity ent, out IEntity componentOwner)
Definition
SCR_AIVehicleUsageComponent.c:140
TurretCompartmentSlot
Definition
TurretCompartmentSlot.c:13
UIWidgets
Definition
attributes.c:40
vector
Definition
vector.c:13
ENodeResult
ENodeResult
Definition
ENodeResult.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
TStringArray
array< string > TStringArray
Definition
Types.c:385
EQueryEntitiesFlags
EQueryEntitiesFlags
Definition
EQueryEntitiesFlags.c:13
scripts
Game
AI
ScriptedNodes
Vehicles
SCR_AIFindAvailableVehicle.c
Generated by
1.17.0