Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetAllocatedCompartment.c
Go to the documentation of this file.
1 class SCR_AIGetAllocatedCompartment: AITaskScripted
2 {
3  static const string PORT_COMPARTMENT = "CompartmentOut";
4  static const string PORT_VEHICLE = "VehicleOut";
5  static const string ERROR_LOG = "Node is not run on SCR_AIGroup agent or owner is not member of SCR_AIGroup!";
6 
7  protected SCR_AIGroup m_groupOwner;
8  protected int m_indexOfLastCompartment = -1;
9  protected bool m_searchStarted = false;
10 
11  [Attribute("-1",uiwidget: UIWidgets.ComboBox, "Restrict to specific compartment?", "", ParamEnumArray.FromEnum(EAICompartmentType))]
12  EAICompartmentType m_eCompartmentType;
13 
14  //------------------------------------------------------------------------------------------------
15  override bool VisibleInPalette() {return true;}
16 
17  //------------------------------------------------------------------------------------------------
18  override void OnInit(AIAgent owner)
19  {
20  m_groupOwner = SCR_AIGroup.Cast(owner);
21  if (!m_groupOwner)
22  {
23  m_groupOwner = SCR_AIGroup.Cast(owner.GetParentGroup());
24  if (!m_groupOwner)
25  NodeError(this, owner, ERROR_LOG);
26  }
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
31  {
32  if (!m_groupOwner)
33  return NodeError(this, owner, ERROR_LOG);
34  ref array<BaseCompartmentSlot> compartments = {};
35  m_groupOwner.GetAllocatedCompartments(compartments);
36  BaseCompartmentSlot compartmentOut;
37  IEntity vehicleOut;
38 
39  if (!m_searchStarted)
40  {
41  m_indexOfLastCompartment = compartments.Count() - 1;
42  m_searchStarted = true;
43  }
44 
45  for (int index = m_indexOfLastCompartment; index >= 0; index--)
46  {
47  if (compartments[index] && IsCompartmentOfSameType(compartments[index].Type(), m_eCompartmentType))
48  {
49  compartmentOut = compartments[index];
50  vehicleOut = compartments[index].GetVehicle();
51  m_indexOfLastCompartment = index - 1 ; // remember last index of compartment to search from
52  break;
53  }
54  }
55 
56  if (compartmentOut)
57  {
58  SetVariableOut(PORT_COMPARTMENT, compartmentOut);
59  SetVariableOut(PORT_VEHICLE, vehicleOut);
60  return ENodeResult.SUCCESS;
61  }
62  return ENodeResult.FAIL;
63  }
64  //------------------------------------------------------------------------------------------------
65  override void OnAbort(AIAgent owner, Node nodeCausingAbort)
66  {
67  m_searchStarted = false;
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  bool IsCompartmentOfSameType(typename compartmentType, EAICompartmentType AICompartmentType)
72  {
73  switch (AICompartmentType)
74  {
75  case EAICompartmentType.Turret :
76  {
77  return compartmentType.IsInherited(TurretCompartmentSlot);
78  };
79  case EAICompartmentType.Cargo :
80  {
81  return compartmentType.IsInherited(CargoCompartmentSlot);
82  };
83  case EAICompartmentType.Pilot :
84  {
85  return compartmentType.IsInherited(PilotCompartmentSlot);
86  };
87  default: //unspecified means type is "ANY"
88  {
89  return true;
90  };
91  }
92  return false;
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  protected static ref TStringArray s_aVarsOut = {
97  PORT_COMPARTMENT,
98  PORT_VEHICLE
99  };
100  override TStringArray GetVariablesOut()
101  {
102  return s_aVarsOut;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  override string GetOnHoverDescription() { return "Gets allocated compartments of group to distribute (and eventually occupy) along group members. \nOne can restrict which compartment types to allocate None means any"; };
107 };
SCR_AIGetAllocatedCompartment
Definition: SCR_AIGetAllocatedCompartment.c:1
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
EAICompartmentType
EAICompartmentType
Definition: SCR_AIVehicleBehavior.c:1
CargoCompartmentSlot
Definition: CargoCompartmentSlot.c:12
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_AIGroup
Definition: SCR_AIGroup.c:68