Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetEmptyCompartment.c
Go to the documentation of this file.
1 class SCR_AIGetEmptyCompartment : AITaskScripted
2 {
3  static const string PORT_POSITION = "Position";
4  static const string PORT_AGENT = "Agent";
5  static const string PORT_VEHICLE = "Vehicle";
6 
7  [Attribute("0", UIWidgets.CheckBox, "Occupy driver compartment with Group Leader Agent?" )]
8  protected bool m_bAllowLeaderAsDriver;
9 
10  private IEntity m_VehicleEntity;
11 
12  //------------------------------------------------------------------------------------------------
13  override void OnEnter(AIAgent owner)
14  {
15  GetVariableIn(PORT_VEHICLE, m_VehicleEntity);
16  }
17 
18  //------------------------------------------------------------------------------------------------
19  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
20  {
21  if (!m_VehicleEntity)
22  {
23  ClearVariable(PORT_POSITION);
24  return ENodeResult.FAIL;
25  }
26 
27  BaseCompartmentManagerComponent compartmentMan = BaseCompartmentManagerComponent.Cast(m_VehicleEntity.FindComponent(BaseCompartmentManagerComponent));
28  if (!compartmentMan)
29  {
30  return NodeError(this, owner, "Missing compartment manager on IEntity" + m_VehicleEntity.ToString());
31  }
32 
33  ref array<BaseCompartmentSlot> compartments = {}, pilotComp = {}, turretComp = {}, cargoComp = {};
34  int numOfComp = compartmentMan.GetCompartments(compartments);
35  SCR_AIGroup group = SCR_AIGroup.Cast(owner);
36  if (!group)
37  {
38  return NodeError(this, owner, "GetEmptyCompartment not run on SCR_AIGroup agent!");
39  }
40  AIAgent groupMember;
41  BaseCompartmentSlot compartmentToAlocate;
42  bool foundEmptyCompartment;
43 
44  GetVariableIn(PORT_AGENT, groupMember);
45  if (group.GetAgentsCount() == 1)
46  m_bAllowLeaderAsDriver = true;
47 
48  foreach (BaseCompartmentSlot comp : compartments)
49  {
50  if (!comp.AttachedOccupant() && comp.IsCompartmentAccessible())
51  {
52  if (PilotCompartmentSlot.Cast(comp))
53  pilotComp.Insert(comp);
54  else if (TurretCompartmentSlot.Cast(comp))
55  turretComp.Insert(comp);
56  else
57  cargoComp.Insert(comp);
58  foundEmptyCompartment = true;
59  }
60  }
61 
62  if (!foundEmptyCompartment)
63  {
64  ClearVariable(PORT_POSITION);
65  return ENodeResult.FAIL;
66  }
67 
68  if (groupMember != group.GetLeaderAgent()) // this is not leader -> he has priority driver > turret > cargo
69  {
70  if (!pilotComp.IsEmpty())
71  compartmentToAlocate = pilotComp[0];
72  else if (!turretComp.IsEmpty())
73  compartmentToAlocate = turretComp[0];
74  else if (!cargoComp.IsEmpty())
75  compartmentToAlocate = cargoComp[0];
76  }
77  else // this is leader -> he has priority driver if m_bAllowLeaderAsDriver is true > cargo > turret >
78  {
79  if (m_bAllowLeaderAsDriver && !pilotComp.IsEmpty())
80  compartmentToAlocate = pilotComp[0];
81  else if (!cargoComp.IsEmpty())
82  compartmentToAlocate = cargoComp[0];
83  else if (!turretComp.IsEmpty())
84  compartmentToAlocate = turretComp[0];
85  }
86 
87  if (compartmentToAlocate)
88  {
89  group.AllocateCompartment(compartmentToAlocate);
90  PrintFormat("Here %1 for %2", compartmentToAlocate, owner);
91  SetVariableOut(PORT_POSITION, SCR_AICompartmentHandling.CompartmentClassToType(compartmentToAlocate.Type()));
92  return ENodeResult.SUCCESS;
93  }
94 
95  ClearVariable(PORT_POSITION);
96  return ENodeResult.FAIL;
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  protected static ref TStringArray s_aVarsIn = {
101  PORT_VEHICLE,
102  PORT_AGENT
103  };
104  override TStringArray GetVariablesIn()
105  {
106  return s_aVarsIn;
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  protected static ref TStringArray s_aVarsOut = {
111  PORT_POSITION
112  };
113  override TStringArray GetVariablesOut()
114  {
115  return s_aVarsOut;
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  override bool VisibleInPalette()
120  {
121  return true;
122  }
123 
124  //------------------------------------------------------------------------------------------------
125  override string GetOnHoverDescription()
126  {
127  return "Returns type of next usable compartment. Compartments are allocated in GetIn activity. The compartments are selected with priority pilot>turret>cargo unless AIAgent is leader";
128  }
129 };
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
PilotCompartmentSlot
Definition: PilotCompartmentSlot.c:12
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition: NodeError.c:3
Attribute
typedef Attribute
Post-process effect of scripted camera.
TurretCompartmentSlot
Definition: TurretCompartmentSlot.c:12
SCR_AIGetEmptyCompartment
Definition: SCR_AIGetEmptyCompartment.c:1
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_AICompartmentHandling
Definition: SCR_AIUtils.c:76