Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIFindAvailableVehicle.c
Go to the documentation of this file.
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;
19 private ref array<BaseCompartmentSlot> m_CompartmentSlots = {};
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();
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);
55 return ENodeResult.SUCCESS;
56 }
57 else // perform new search for vehicle entity
58 {
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);
71 {
72 if (m_bReserveCompartment)
73 m_group.AllocateCompartment(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 //------------------------------------------------------------------------------------------------
85 {
87 if (!compComp)
88 return true;
89
90 compComp.GetCompartments(m_CompartmentSlots);
91 if (m_CompartmentSlots.IsEmpty())
92 return true;
93
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 {
116 m_Compartment = pilotCompartment;
117 return false;
118 }
119
120 if (turretCompartment)
121 {
124 m_Compartment = turretCompartment;
125 return false;
126 }
127
128 if (cargoCompartment)
129 {
132 m_Compartment = cargoCompartment;
133 return false;
134 }
135 return true; //continue search
136 }
137
138 //------------------------------------------------------------------------------------------------
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 };
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 };
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
void SCR_AgentMustBeAIGroup(Node node, AIAgent owner)
Definition NodeError.c:14
proto external Managed FindComponent(typename typeName)
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
proto void ClearVariable(string name)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
override void OnInit(AIAgent owner)
SCR_AIBoardingParameters m_WaypointParameter
override TStringArray GetVariablesOut()
static override string GetOnHoverDescription()
void SetVariablesOut(AIAgent owner, IEntity vehicleOut, ECompartmentType compartmentTypeOut, BaseCompartmentSlot compartment)
SCR_AIGroupUtilityComponent m_groupUtilityCompoment
SCR_AIGroupUtilityComponent GetGroupUtilityComponent()
void AddUsableVehicle(notnull SCR_AIVehicleUsageComponent vehicleUsageComp)
bool CanBePiloted()
AI can use the pilot compartments on this vehicle.
static SCR_AIVehicleUsageComponent FindOnNearestParent(notnull IEntity ent, out IEntity componentOwner)
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385
EQueryEntitiesFlags