Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIDecoTestIsInVehicleCondition.c
Go to the documentation of this file.
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
30
31 array<AIAgent> agents = {};
32
33 ref array<IEntity> vehicles = {};
35 bool noAvailableVehicles = true;
36 foreach (IEntity vehicle: vehicles)
37 {
38 if (vehicle && VehicleHasEmptyCompartments(vehicle, allowance))
39 {
40 noAvailableVehicles = false;
41 break;
42 }
43 };
44
45 switch (completionType)
46 {
48 {
49 group.GetAgents(agents);
50 bool completeWaypoint = true;
51 foreach (AIAgent a: agents)
52 {
53 ChimeraCharacter character = ChimeraCharacter.Cast(a.GetControlledEntity());
54 if (character && !character.IsInVehicle())
55 {
56 if (vehicles.IsEmpty()) // i have character outside a vehicle, no known vehicles to use -> not complete waypoint
57 return false;
58 completeWaypoint = noAvailableVehicles; // i have character outside the vehicle, no available vehicles to use --> complete waypoint
59 break;
60 }
61 }
62 return completeWaypoint;
63 }
64 case EAIWaypointCompletionType.Leader :
65 {
66 ChimeraCharacter character = ChimeraCharacter.Cast(group.GetLeaderEntity());
67 if (!character)
68 return false;
69 if (character.IsInVehicle()) // leader is inside the vehicle --> complete waypoint
70 return true;
71 if (vehicles.IsEmpty()) // leader is outside, no known vehicles --> not complete waypoint
72 return false;
73 return noAvailableVehicles;
74 }
76 {
77 group.GetAgents(agents);
78 foreach (AIAgent a: agents)
79 {
80 ChimeraCharacter character = ChimeraCharacter.Cast(a.GetControlledEntity());
81 if (!character) // same logic as leader's
82 return false;
83 if (character.IsInVehicle())
84 return true;
85 if (vehicles.IsEmpty())
86 return false;
87 return noAvailableVehicles;
88 }
89 return false;
90 }
91 }
92 return false;
93 }
94
95 // returns true if there is compartment of required type that is yet unoccupied
96 bool VehicleHasEmptyCompartments(notnull IEntity vehicle, SCR_AIBoardingParameters allowedCompartmentTypes)
97 {
99 if (!compComp)
100 return false;
101
102 array<BaseCompartmentSlot> compartmentSlots = {};
103 compComp.GetCompartments(compartmentSlots);
104 ECompartmentType compartmentType;
105 foreach (BaseCompartmentSlot slot : compartmentSlots)
106 {
107 if (allowedCompartmentTypes.m_bIsDriverAllowed && PilotCompartmentSlot.Cast(slot))
108 compartmentType = ECompartmentType.PILOT;
109 else if (allowedCompartmentTypes.m_bIsGunnerAllowed && TurretCompartmentSlot.Cast(slot))
110 compartmentType = ECompartmentType.TURRET;
111 else if (allowedCompartmentTypes.m_bIsCargoAllowed && CargoCompartmentSlot.Cast(slot))
112 compartmentType = ECompartmentType.CARGO;
113 else
114 continue;
115
116 if (!slot.IsOccupied())
117 {
118 // PrintFormat("Found empty compartment %1 of type %2", slot, compartmentType);
119 return true;
120 }
121 }
122
123 return false;
124 }
125};
ECompartmentType
Definition Debug.c:13
bool VehicleHasEmptyCompartments(notnull IEntity vehicle, SCR_AIBoardingParameters allowedCompartmentTypes)
override bool TestFunction(AIAgent agent, IEntity controlled)
SCR_AIGroupUtilityComponent GetGroupUtilityComponent()
ref SCR_AIGroupVehicleManager m_VehicleMgr
void GetAllVehicleEntities(array< IEntity > outAllVehicles)