Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDecoTestCanGroupDriveVehicle.c
Go to the documentation of this file.
1 class SCR_AIDecoTestCanGroupDriveVehicle: DecoratorTestScripted
2 {
3  //------------------------------------------------------------------------------------------------
5  // "CanDrive" is true if there is available driver seat and entire group fits in the car(s) with available driver seats
6  // TODO: this node as decorator may check this potentially every frame and have big performance impact! Could be hidden
7  // into some component that reacts on Events of compartments
8  protected override bool TestFunction(AIAgent agent, IEntity controlled)
9  {
10  SCR_AIGroup group = SCR_AIGroup.Cast(agent);
11  if (!group)
12  return false;
13  array<IEntity> vehicles = {};
14  array<AIAgent> agents = {};
15  group.GetUsableVehicles(vehicles);
16  if (vehicles.IsEmpty())
17  return false;
18  int agentsCount = group.GetAgents(agents);
19  if (agents.IsEmpty())
20  return false;
21  IEntity vehicleToUse;
22  foreach (AIAgent ag: agents)
23  {
24  IEntity agentEntity = ag.GetControlledEntity();
25  if (!agentEntity)
26  continue;
27  IEntity vehicleOfAgent = CompartmentAccessComponent.GetVehicleIn(agentEntity);
28  if (vehicles.Find(vehicleOfAgent) < 0)
29  continue;
30  agentsCount --;
31  CompartmentAccessComponent compAcc = CompartmentAccessComponent.Cast(agentEntity.FindComponent(CompartmentAccessComponent));
32  if (!compAcc)
33  continue;
34  if (!PilotCompartmentSlot.Cast(compAcc.GetCompartment()))
35  continue;
36  vehicleToUse = vehicleOfAgent; // group agent is driver inside some of groups registered vehicle
37  }
38 
39  if (agentsCount < 1)
40  return true;
41  // we will use vehicles array and search for available compartments only in vehicles that have available driver seat
42  BaseCompartmentSlot compartment;
43  ref array<BaseCompartmentSlot> compartments = {};
44  BaseCompartmentManagerComponent compMan;
45  if (!vehicleToUse && !SCR_AICompartmentHandling.FindAvailableCompartmentInVehicles(vehicles, ECompartmentType.Pilot, compartment, vehicleToUse))
46  return false; // no available driver
47 
48  while (!vehicles.IsEmpty() && agentsCount > 0 && vehicleToUse)
49  {
50  compMan = BaseCompartmentManagerComponent.Cast(vehicleToUse.FindComponent(BaseCompartmentManagerComponent));
51  if (!compMan)
52  break;
53  compMan.GetCompartments(compartments);
54  foreach (BaseCompartmentSlot comp: compartments)
55  {
56  if (!comp.GetOccupant() && comp.IsCompartmentAccessible())
57  agentsCount --;
58  if (agentsCount == 0)
59  break;
60  }
61  vehicles.Remove(vehicles.Find(vehicleToUse));
62  if (!SCR_AICompartmentHandling.FindAvailableCompartmentInVehicles(vehicles, ECompartmentType.Pilot, compartment, vehicleToUse))
63  break; // no vehicle with available driver
64  }
65  return agentsCount == 0;
66  }
67 };
ECompartmentType
ECompartmentType
Definition: ECompartmentType.c:7
PilotCompartmentSlot
Definition: PilotCompartmentSlot.c:12
SCR_AIDecoTestCanGroupDriveVehicle
Definition: SCR_AIDecoTestCanGroupDriveVehicle.c:1
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_AICompartmentHandling
Definition: SCR_AIUtils.c:76