Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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_AIBoardingWaypointParameters m_WaypointParameter;
24  protected SCR_AIGroupUtilityComponent m_groupUtilityCompoment;
25 
26  //------------------------------------------------------------------------------------------------
27  override void OnInit(AIAgent owner)
28  {
29  m_world = owner.GetWorld();
30  m_groupUtilityCompoment = SCR_AIGroupUtilityComponent.Cast(owner.FindComponent(SCR_AIGroupUtilityComponent));
31  m_group = SCR_AIGroup.Cast(owner);
32  if (!m_group)
33  {
34  SCR_AgentMustBeAIGroup(this, owner);
35  };
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
40  {
41  if (!m_world || !m_group)
42  return ENodeResult.FAIL;
43 
44  if (!m_VehicleToTestForCompartments && GetVariableIn(PORT_VEHICLE_IN, m_VehicleToTestForCompartments)) // reading the vehicle to test from outside of the node (another search)
45  if (!GetVariableIn(PORT_SEARCH_PARAMS, m_WaypointParameter))
46  return ENodeResult.FAIL;
47 
48  if (m_VehicleToTestForCompartments && !HasNoAvailableCompartment(m_VehicleToTestForCompartments)) // the vehicle was found already, does it have available compartment?
49  {
50  if (m_bReserveCompartment)
51  m_group.AllocateCompartment(m_Compartment);
52  SetVariablesOut(owner, m_VehicleToTestForCompartments, m_CompartmentType, m_Compartment);
53  return ENodeResult.SUCCESS;
54  }
55  else // perform new search for vehicle entity
56  {
57  m_VehicleToTestForCompartments = null;
58  vector center;
59  float radius;
60  GetVariableIn(PORT_CENTER_OF_SEARCH, center);
61  GetVariableIn(PORT_RADIUS, radius);
62  GetVariableIn(PORT_SEARCH_PARAMS, m_WaypointParameter);
63 
64  if (!m_WaypointParameter) // waypoint can be deleted in the meantime
65  return ENodeResult.FAIL;
66 
67  m_world.QueryEntitiesBySphere(center, radius, HasNoAvailableCompartment, FilterEntities, EQueryEntitiesFlags.DYNAMIC);
68  if (m_VehicleToTestForCompartments)
69  {
70  if (m_bReserveCompartment)
71  m_group.AllocateCompartment(m_Compartment);
72  SetVariablesOut(owner, m_VehicleToTestForCompartments, m_CompartmentType, m_Compartment);
73  return ENodeResult.SUCCESS;
74  }
75  ClearVariable(PORT_VEHICLE_OUT);
76  ClearVariable(PORT_ROLE_OUT);
77  };
78  return ENodeResult.FAIL;
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  bool HasNoAvailableCompartment(IEntity ent)
83  {
84  BaseCompartmentManagerComponent compComp = BaseCompartmentManagerComponent.Cast(ent.FindComponent(BaseCompartmentManagerComponent));
85  if (!compComp)
86  return true;
87 
88  compComp.GetCompartments(m_CompartmentSlots);
89  if (m_CompartmentSlots.IsEmpty())
90  return true;
91 
92  BaseCompartmentSlot pilotCompartment, turretCompartment, cargoCompartment;
93 
94  foreach (BaseCompartmentSlot slot : m_CompartmentSlots)
95  {
96  if (slot.GetOccupant() || !slot.IsCompartmentAccessible() || slot.IsReserved())
97  continue;
98  if (m_WaypointParameter.m_bIsDriverAllowed && PilotCompartmentSlot.Cast(slot))
99  pilotCompartment = slot;
100  else if (m_WaypointParameter.m_bIsGunnerAllowed && TurretCompartmentSlot.Cast(slot))
101  turretCompartment = slot;
102  else if (m_WaypointParameter.m_bIsCargoAllowed && CargoCompartmentSlot.Cast(slot))
103  cargoCompartment = slot;
104  }
105  // going through priorities: pilot > turret > cargo
106  if (pilotCompartment)
107  {
108  m_CompartmentType = ECompartmentType.Pilot;
109  m_VehicleToTestForCompartments = ent;
110  m_Compartment = pilotCompartment;
111  return false;
112  }
113 
114  if (turretCompartment)
115  {
116  m_CompartmentType = ECompartmentType.Turret;
117  m_VehicleToTestForCompartments = ent;
118  m_Compartment = turretCompartment;
119  return false;
120  }
121 
122  if (cargoCompartment)
123  {
124  m_CompartmentType = ECompartmentType.Cargo;
125  m_VehicleToTestForCompartments = ent;
126  m_Compartment = cargoCompartment;
127  return false;
128  }
129  return true; //continue search
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  bool FilterEntities(IEntity ent)
134  {
135 
136  if (ent.FindComponent(BaseCompartmentManagerComponent))
137  return true;
138 
139  return false;
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  void SetVariablesOut(AIAgent owner, IEntity vehicleOut, ECompartmentType compartmentTypeOut, BaseCompartmentSlot compartment)
144  {
145  SetVariableOut(PORT_VEHICLE_OUT, vehicleOut);
146  SetVariableOut(PORT_ROLE_OUT, compartmentTypeOut);
147  SetVariableOut(PORT_COMPARTMENT_OUT, compartment);
148  if (m_bAddToList)
149  {
150  SCR_AIGroup group = SCR_AIGroup.Cast(owner);
151  if (group)
152  group.AddUsableVehicle(vehicleOut);
153  }
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  protected static ref TStringArray s_aVarsOut = {
158  PORT_VEHICLE_OUT,
159  PORT_ROLE_OUT,
160  PORT_COMPARTMENT_OUT
161  };
162  override TStringArray GetVariablesOut()
163  {
164  return s_aVarsOut;
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  protected static ref TStringArray s_aVarsIn = {
169  PORT_CENTER_OF_SEARCH,
170  PORT_RADIUS,
171  PORT_SEARCH_PARAMS,
172  PORT_VEHICLE_IN
173  };
174  override TStringArray GetVariablesIn()
175  {
176  return s_aVarsIn;
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  override bool VisibleInPalette()
181  {
182  return true;
183  }
184 
185  //------------------------------------------------------------------------------------------------
186  override string GetOnHoverDescription()
187  {
188  return "SCR_AIFindAvailableVehicle: finds within radius of origin available compartments of vehicles with priority pilot>turret>cargo";
189  }
190 };
SCR_AgentMustBeAIGroup
void SCR_AgentMustBeAIGroup(Node node, AIAgent owner)
Definition: NodeError.c:14
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
ECompartmentType
ECompartmentType
Definition: ECompartmentType.c:7
PilotCompartmentSlot
Definition: PilotCompartmentSlot.c:12
SCR_AIFindAvailableVehicle
Definition: SCR_AIFindAvailableVehicle.c:1
SCR_AIBoardingWaypointParameters
Definition: SCR_BoardingWaypoint.c:5
Attribute
typedef Attribute
Post-process effect of scripted camera.
TurretCompartmentSlot
Definition: TurretCompartmentSlot.c:12
CargoCompartmentSlot
Definition: CargoCompartmentSlot.c:12
SCR_AIGroup
Definition: SCR_AIGroup.c:68