Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDecoTestIsInVehicleCondition.c
Go to the documentation of this file.
1 class SCR_AIDecoTestIsInVehicleCondition : DecoratorTestScripted
2 {
3  // this tests SCR_BoardingWaypoint waypoint completion condition: either characters are in vehicles or group usable vehicles are fully occupied
4  protected override bool TestFunction(AIAgent agent, IEntity controlled)
5  {
7  EAIWaypointCompletionType completionType;
8  AIWaypoint wp = AIWaypoint.Cast(controlled);
9  if (!wp)
10  return false;
11  completionType = wp.GetCompletionType();
12  SCR_BoardingWaypoint bwp = SCR_BoardingWaypoint.Cast(controlled);
13  if (bwp)
14  allowance = bwp.GetAllowance();
15  else
16  {
17  allowance.m_bIsCargoAllowed = true;
18  allowance.m_bIsGunnerAllowed = true;
19  allowance.m_bIsDriverAllowed = true;
20  }
21 
22  SCR_AIGroup group = SCR_AIGroup.Cast(agent);
23  if (!group)
24  {
25  Debug.Error("Running on AIAgent that is not a SCR_AIGroup group!");
26  return false;
27  }
28 
29  array<AIAgent> agents = {};
30 
31  ref array<IEntity> vehicles = {};
32  group.GetUsableVehicles(vehicles);
33 
34  bool noAvailableVehicles = true;
35  foreach (IEntity vehicle: vehicles)
36  {
37  if (vehicle && VehicleHasEmptyCompartments(vehicle, allowance))
38  {
39  noAvailableVehicles = false;
40  break;
41  }
42  };
43 
44  switch (completionType)
45  {
46  case EAIWaypointCompletionType.All :
47  {
48  group.GetAgents(agents);
49  bool completeWaypoint = true;
50  foreach (AIAgent a: agents)
51  {
52  ChimeraCharacter character = ChimeraCharacter.Cast(a.GetControlledEntity());
53  if (character && !character.IsInVehicle())
54  {
55  if (vehicles.IsEmpty()) // i have character outside a vehicle, no known vehicles to use -> not complete waypoint
56  return false;
57  completeWaypoint = noAvailableVehicles; // i have character outside the vehicle, no available vehicles to use --> complete waypoint
58  break;
59  }
60  }
61  return completeWaypoint;
62  }
63  case EAIWaypointCompletionType.Leader :
64  {
65  ChimeraCharacter character = ChimeraCharacter.Cast(group.GetLeaderEntity());
66  if (!character)
67  return false;
68  if (character.IsInVehicle()) // leader is inside the vehicle --> complete waypoint
69  return true;
70  if (vehicles.IsEmpty()) // leader is outside, no known vehicles --> not complete waypoint
71  return false;
72  return noAvailableVehicles;
73  }
74  case EAIWaypointCompletionType.Any :
75  {
76  group.GetAgents(agents);
77  foreach (AIAgent a: agents)
78  {
79  ChimeraCharacter character = ChimeraCharacter.Cast(a.GetControlledEntity());
80  if (!character) // same logic as leader's
81  return false;
82  if (character.IsInVehicle())
83  return true;
84  if (vehicles.IsEmpty())
85  return false;
86  return noAvailableVehicles;
87  }
88  return false;
89  }
90  }
91  return false;
92  }
93 
94  // returns true if there is compartment of required type that is yet unoccupied
95  bool VehicleHasEmptyCompartments(notnull IEntity vehicle, SCR_AIBoardingWaypointParameters allowedCompartmentTypes)
96  {
97  BaseCompartmentManagerComponent compComp = BaseCompartmentManagerComponent.Cast(vehicle.FindComponent(BaseCompartmentManagerComponent));
98  if (!compComp)
99  return false;
100 
101  array<BaseCompartmentSlot> compartmentSlots = {};
102  compComp.GetCompartments(compartmentSlots);
103  ECompartmentType compartmentType;
104  foreach (BaseCompartmentSlot slot : compartmentSlots)
105  {
106  if (allowedCompartmentTypes.m_bIsDriverAllowed && PilotCompartmentSlot.Cast(slot))
107  compartmentType = ECompartmentType.Pilot;
108  else if (allowedCompartmentTypes.m_bIsGunnerAllowed && TurretCompartmentSlot.Cast(slot))
109  compartmentType = ECompartmentType.Turret;
110  else if (allowedCompartmentTypes.m_bIsCargoAllowed && CargoCompartmentSlot.Cast(slot))
111  compartmentType = ECompartmentType.Cargo;
112  else
113  continue;
114 
115  if (!slot.AttachedOccupant())
116  {
117  // PrintFormat("Found empty compartment %1 of type %2", slot, compartmentType);
118  return true;
119  }
120  }
121 
122  return false;
123  }
124 };
ECompartmentType
ECompartmentType
Definition: ECompartmentType.c:7
PilotCompartmentSlot
Definition: PilotCompartmentSlot.c:12
SCR_BoardingWaypoint
Definition: SCR_BoardingWaypoint.c:12
SCR_AIBoardingWaypointParameters
Definition: SCR_BoardingWaypoint.c:5
TurretCompartmentSlot
Definition: TurretCompartmentSlot.c:12
SCR_AIDecoTestIsInVehicleCondition
Definition: SCR_AIDecoTestIsInVehicleCondition.c:1
CargoCompartmentSlot
Definition: CargoCompartmentSlot.c:12
SCR_AIGroup
Definition: SCR_AIGroup.c:68