Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AISelectDoorOperatorAgent.c
Go to the documentation of this file.
2{
3 // Inputs
4 protected static const string PORT_VEHICLE_ENTITY = "VehicleEntity";
5 protected static const string PORT_NAVLINK_ENTITY = "NavlinkEntity";
6
7 // Outputs
8 protected static const string PORT_DOOR_USER_AGENT = "DoorUserAgent";
9 protected static const string PORT_DOOR_USER_ENTITY = "DoorUserEntity";
10 protected static const string PORT_USE_TELEKINESIS = "UseTelekinesis";
11
12 //------------------------------------------------------------------------
13 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
14 {
15 AIGroup group = AIGroup.Cast(owner);
16
17 if (!group)
18 group = owner.GetParentGroup();
19
20 if (!group)
21 return ENodeResult.FAIL;
22
23 array<AIAgent> agents = {};
24 int nAgents = group.GetAgents(agents);
25
26 IEntity vehicleEntity;
27 GetVariableIn(PORT_VEHICLE_ENTITY, vehicleEntity);
28
29 IEntity navlinkEntity;
30 GetVariableIn(PORT_NAVLINK_ENTITY, navlinkEntity);
31 if (!navlinkEntity)
32 return ENodeResult.FAIL;
33 vector navlinkPos = navlinkEntity.GetOrigin();
34
35 AIAgent bestAgent = null;
36 float bestScore = -float.MAX;
37
38 for (int i = 0; i < nAgents; i++)
39 {
40 AIAgent agent = agents[i];
41
42 IEntity agentControlledEntity = agent.GetControlledEntity();
43 if (!agentControlledEntity)
44 continue;
45
46 BaseCompartmentSlot agentCompartment;
47 IEntity agentVehicleEntity = SCR_AICompartmentHandling.GetAgentVehicleAndCompartment(agent, agentCompartment);
48
49 float distanceToNavlink = vector.Distance(agentControlledEntity.GetOrigin(), navlinkPos);
50
51 float score = 200.0 - distanceToNavlink;
52
53 if (!agentVehicleEntity)
54 {
55 // Not in vehicle, best
56 score += 1600.0;
57 }
58 else
59 {
60 // In vehicle
61
62 // Check compartment type
63 ECompartmentType compType = agentCompartment.GetType();
64 switch (compType)
65 {
66 case ECompartmentType.CARGO: score += 400.0; break; // Best
67 case ECompartmentType.PILOT: score += 200.0; break; // Worse
68 //case ECompartmentType.TURRET: score += 0; break; // Worst - gunner should be last to leave
69 }
70
71 // Is in same vehicle?
72 if (agentVehicleEntity == vehicleEntity)
73 {
74 // In same vehicle, better
75 score += 800.0;
76 }
77 }
78
79 if (score > bestScore)
80 {
81 bestAgent = agent;
82 bestScore = score;
83 }
84 }
85
86 bool telekinesisUse = false;
87 IEntity bestAgentEntity;
88 if (bestAgent)
89 {
90 bestAgentEntity = bestAgent.GetControlledEntity();
91 if (bestAgent.GetLOD() == bestAgent.GetMaxLOD())
92 {
93 telekinesisUse = true;
94 }
95 }
96
97 SetVariableOut(PORT_USE_TELEKINESIS, telekinesisUse);
99 SetVariableOut(PORT_DOOR_USER_ENTITY, bestAgentEntity);
100
101 if (bestAgent && bestAgentEntity)
102 return ENodeResult.SUCCESS;
103 else
104 return ENodeResult.FAIL;
105 }
106
107 //------------------------------------------------------------------------
108 static override bool VisibleInPalette() { return true; }
109
110 //------------------------------------------------------------------------
111 static override string GetOnHoverDescription() { return "Selects an absolutely best possible group member to open a gate when driving a vehicle";};
112
113 //------------------------------------------------------------------------
116
117 //------------------------------------------------------------------------
119 override TStringArray GetVariablesIn() { return s_aVarsIn; }
120}
ECompartmentType
proto external vector GetOrigin()
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
ENodeResult
Definition ENodeResult.c:13
array< string > TStringArray
Definition Types.c:385