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";
11 [
Attribute(
"0", UIWidgets.CheckBox,
"If found, add to list of usable vehicles?")]
14 [
Attribute(
"1", UIWidgets.CheckBox,
"If found, reserve compartment?")]
15 bool m_bReserveCompartment;
17 private BaseWorld m_world;
19 private ref array<BaseCompartmentSlot> m_CompartmentSlots = {};
20 protected IEntity m_VehicleToTestForCompartments;
21 protected BaseCompartmentSlot m_Compartment;
24 protected SCR_AIGroupUtilityComponent m_groupUtilityCompoment;
27 override void OnInit(AIAgent owner)
29 m_world = owner.GetWorld();
30 m_groupUtilityCompoment = SCR_AIGroupUtilityComponent.Cast(owner.FindComponent(SCR_AIGroupUtilityComponent));
39 override ENodeResult EOnTaskSimulate(AIAgent owner,
float dt)
41 if (!m_world || !m_group)
42 return ENodeResult.FAIL;
44 if (!m_VehicleToTestForCompartments && GetVariableIn(PORT_VEHICLE_IN, m_VehicleToTestForCompartments))
45 if (!GetVariableIn(PORT_SEARCH_PARAMS, m_WaypointParameter))
46 return ENodeResult.FAIL;
48 if (m_VehicleToTestForCompartments && !HasNoAvailableCompartment(m_VehicleToTestForCompartments))
50 if (m_bReserveCompartment)
51 m_group.AllocateCompartment(m_Compartment);
52 SetVariablesOut(owner, m_VehicleToTestForCompartments, m_CompartmentType, m_Compartment);
53 return ENodeResult.SUCCESS;
57 m_VehicleToTestForCompartments =
null;
60 GetVariableIn(PORT_CENTER_OF_SEARCH, center);
61 GetVariableIn(PORT_RADIUS, radius);
62 GetVariableIn(PORT_SEARCH_PARAMS, m_WaypointParameter);
64 if (!m_WaypointParameter)
65 return ENodeResult.FAIL;
67 m_world.QueryEntitiesBySphere(center, radius, HasNoAvailableCompartment, FilterEntities, EQueryEntitiesFlags.DYNAMIC);
68 if (m_VehicleToTestForCompartments)
70 if (m_bReserveCompartment)
71 m_group.AllocateCompartment(m_Compartment);
72 SetVariablesOut(owner, m_VehicleToTestForCompartments, m_CompartmentType, m_Compartment);
73 return ENodeResult.SUCCESS;
75 ClearVariable(PORT_VEHICLE_OUT);
76 ClearVariable(PORT_ROLE_OUT);
78 return ENodeResult.FAIL;
82 bool HasNoAvailableCompartment(IEntity ent)
84 BaseCompartmentManagerComponent compComp = BaseCompartmentManagerComponent.Cast(ent.FindComponent(BaseCompartmentManagerComponent));
88 compComp.GetCompartments(m_CompartmentSlots);
89 if (m_CompartmentSlots.IsEmpty())
92 BaseCompartmentSlot pilotCompartment, turretCompartment, cargoCompartment;
94 foreach (BaseCompartmentSlot slot : m_CompartmentSlots)
96 if (slot.GetOccupant() || !slot.IsCompartmentAccessible() || slot.IsReserved())
99 pilotCompartment = slot;
101 turretCompartment = slot;
103 cargoCompartment = slot;
106 if (pilotCompartment)
109 m_VehicleToTestForCompartments = ent;
110 m_Compartment = pilotCompartment;
114 if (turretCompartment)
117 m_VehicleToTestForCompartments = ent;
118 m_Compartment = turretCompartment;
122 if (cargoCompartment)
125 m_VehicleToTestForCompartments = ent;
126 m_Compartment = cargoCompartment;
133 bool FilterEntities(IEntity ent)
136 if (ent.FindComponent(BaseCompartmentManagerComponent))
143 void SetVariablesOut(AIAgent owner, IEntity vehicleOut,
ECompartmentType compartmentTypeOut, BaseCompartmentSlot compartment)
145 SetVariableOut(PORT_VEHICLE_OUT, vehicleOut);
146 SetVariableOut(PORT_ROLE_OUT, compartmentTypeOut);
147 SetVariableOut(PORT_COMPARTMENT_OUT, compartment);
152 group.AddUsableVehicle(vehicleOut);
157 protected static ref TStringArray s_aVarsOut = {
162 override TStringArray GetVariablesOut()
168 protected static ref TStringArray s_aVarsIn = {
169 PORT_CENTER_OF_SEARCH,
174 override TStringArray GetVariablesIn()
180 override bool VisibleInPalette()
186 override string GetOnHoverDescription()
188 return "SCR_AIFindAvailableVehicle: finds within radius of origin available compartments of vehicles with priority pilot>turret>cargo";