Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIDecoTestCanGroupDriveVehicle.c
Go to the documentation of this file.
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
15 if (!utility)
16 return false;
17
18 array<IEntity> vehicles = {};
19 array<AIAgent> agents = {};
20 utility.m_VehicleMgr.GetAllVehicleEntities(vehicles);
21 if (vehicles.IsEmpty())
22 return false;
23
24 int agentsCount = group.GetAgents(agents); // number of agents we need to find compartments for
25 if (agents.IsEmpty())
26 return false;
27
28 IEntity vehicleToUse;
29 foreach (AIAgent ag: agents)
30 {
31 ChimeraCharacter agentEntity = ChimeraCharacter.Cast(ag.GetControlledEntity());
32 if (!agentEntity)
33 continue;
34 IEntity vehicleOfAgent = CompartmentAccessComponent.GetVehicleIn(agentEntity);
35 if (!vehicleOfAgent)
36 continue;
37 SCR_AIGroupVehicle groupVehicle = utility.m_VehicleMgr.FindVehicle(vehicleOfAgent);
38 if (!groupVehicle)
39 continue;
40 SCR_AIVehicleUsageComponent vehicleUsage = groupVehicle.GetVehicleUsageComponent();
41 if (!vehicleUsage)
42 continue;
43 if (!vehicleUsage.CanBePiloted())
44 continue;
45 CompartmentAccessComponent compAcc = agentEntity.GetCompartmentAccessComponent();
46 if (!compAcc)
47 continue;
48 agentsCount --;
49 if (!PilotCompartmentSlot.Cast(compAcc.GetCompartment()))
50 continue;
51 vehicleToUse = vehicleOfAgent; // group agent is driver inside some of groups registered vehicle
52 }
53
54 if (agentsCount < 1)
55 return true;
56
57 // we will use vehicles array and search for available compartments only in vehicles that have available driver seat
58 BaseCompartmentSlot compartment;
59 ref array<BaseCompartmentSlot> compartments = {};
61
62 if (!vehicleToUse && !SCR_AICompartmentHandling.FindAvailableCompartmentInVehicles(vehicles, ECompartmentType.PILOT, compartment, vehicleToUse))
63 return false; // no available driver
64
65 while (!vehicles.IsEmpty() && agentsCount > 0 && vehicleToUse)
66 {
67 SCR_AIGroupVehicle groupVehicle = utility.m_VehicleMgr.FindVehicle(vehicleToUse);
68 if (!groupVehicle)
69 break;
70
71 SCR_AIVehicleUsageComponent vehicleUsage = groupVehicle.GetVehicleUsageComponent();
72 if (vehicleUsage && vehicleUsage.CanBePiloted())
73 {
75 if (!compMan)
76 break;
77
78 compMan.GetCompartments(compartments);
79 foreach (BaseCompartmentSlot comp: compartments)
80 {
81 if (!comp.GetOccupant() && comp.IsCompartmentAccessible())
82 agentsCount --;
83 if (agentsCount == 0)
84 break;
85 }
86 }
87
88 vehicles.Remove(vehicles.Find(vehicleToUse));
89 if (!SCR_AICompartmentHandling.FindAvailableCompartmentInVehicles(vehicles, ECompartmentType.PILOT, compartment, vehicleToUse))
90 break; // no vehicle with available driver
91 }
92
93 return agentsCount == 0;
94 }
95};
ECompartmentType
proto external Managed FindComponent(typename typeName)
override bool TestFunction(AIAgent agent, IEntity controlled)
Decorator test that checks vehicles registered on group for availability of compartments for group me...
SCR_AIGroupUtilityComponent GetGroupUtilityComponent()
ref SCR_AIGroupVehicleManager m_VehicleMgr
This class is used for keeping track of vehicles assigned to group.
SCR_AIVehicleUsageComponent GetVehicleUsageComponent()
SCR_AIGroupVehicle FindVehicle(IEntity vehicleEntity)
void GetAllVehicleEntities(array< IEntity > outAllVehicles)
bool CanBePiloted()
AI can use the pilot compartments on this vehicle.