Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIFindTurrets.c
Go to the documentation of this file.
1 class SCR_AIFindTurrets: AITaskScripted
2 {
3  static const string PORT_CENTER_OF_SEARCH = "OriginIn";
4  static const string PORT_RADIUS = "RadiusIn";
5  static const string PORT_TURRET_NUMBER = "TurretNumber";
6  static const string PORT_TURRET_FOUND = "TurretsFound";
7 
8  private BaseWorld m_world;
9  private int m_turretCount;
10  private int m_agentsCount;
11  private bool m_turretsFound;
12  private SCR_AIGroup m_groupOwner;
13 
14  //------------------------------------------------------------------------------------------------
15  override bool VisibleInPalette() {return true;}
16 
17  //------------------------------------------------------------------------------------------------
18  override void OnInit(AIAgent owner)
19  {
20  if (!m_world && GetGame())
21  m_world = GetGame().GetWorld();
22  m_groupOwner = SCR_AIGroup.Cast(owner);
23  if (!m_groupOwner)
24  {
25  m_groupOwner = SCR_AIGroup.Cast(owner.GetParentGroup());
26  if (!m_groupOwner)
27  NodeError(this, owner, "Node is not run on SCR_AIGroup agent or owner is not member of SCR_AIGroup!");
28  }
29  }
30 
31  //------------------------------------------------------------------------------------------------
32  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
33  {
34  if (!m_world)
35  {
36  ClearVariable(PORT_TURRET_NUMBER);
37  ClearVariable(PORT_TURRET_FOUND);
38  return ENodeResult.FAIL;
39  }
40  vector center;
41  float radius;
42  m_agentsCount = m_groupOwner.GetAgentsCount();
43 
44  GetVariableIn(PORT_CENTER_OF_SEARCH, center);
45  GetVariableIn(PORT_RADIUS, radius);
46 
47  m_world.QueryEntitiesBySphere(center, radius, GetFirstEntity, FilterEntities, EQueryEntitiesFlags.DYNAMIC | EQueryEntitiesFlags.WITH_OBJECT);
48  if (m_turretsFound)
49  SetVariableOut(PORT_TURRET_NUMBER, m_turretCount);
50  else
51  ClearVariable(PORT_TURRET_NUMBER);
52  SetVariableOut(PORT_TURRET_FOUND, m_turretsFound);
53  return ENodeResult.SUCCESS;
54  }
55 
56  bool GetFirstEntity(IEntity ent)
57  {
58  BaseCompartmentManagerComponent compComp = BaseCompartmentManagerComponent.Cast(ent.FindComponent(BaseCompartmentManagerComponent));
59  if (!compComp)
60  return true;
61 
62  array<BaseCompartmentSlot> compartmentSlots = {};
63  compComp.GetCompartments(compartmentSlots);
64  foreach (BaseCompartmentSlot slot : compartmentSlots)
65  {
66  TurretCompartmentSlot turretComp = TurretCompartmentSlot.Cast(slot);
67  if (turretComp)
68  {
69  if (!turretComp.AttachedOccupant() && turretComp.IsCompartmentAccessible() && !turretComp.IsReserved())
70  {
71  //turretComp.GetCompartmentSlotID();
72  m_turretCount += 1;
73  m_turretsFound = true;
74  if (m_turretCount <= m_agentsCount) // do not occupy more turrets that you have agents
75  m_groupOwner.AllocateCompartment(turretComp);
76  break;
77  }
78  }
79  }
80  return true; //continue search to next turret
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  bool FilterEntities(IEntity ent)
85  {
86  return Turret.Cast(ent) != null;
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  protected static ref TStringArray s_aVarsOut = {
91  PORT_TURRET_NUMBER,
92  PORT_TURRET_FOUND
93  };
94  override TStringArray GetVariablesOut()
95  {
96  return s_aVarsOut;
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  protected static ref TStringArray s_aVarsIn = {
101  PORT_CENTER_OF_SEARCH,
102  PORT_RADIUS
103  };
104  override TStringArray GetVariablesIn()
105  {
106  return s_aVarsIn;
107  }
108 };
Turret
@ Turret
Definition: SCR_AIVehicleBehavior.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
SCR_AIFindTurrets
Definition: SCR_AIFindTurrets.c:1
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition: NodeError.c:3
TurretCompartmentSlot
Definition: TurretCompartmentSlot.c:12
SCR_AIGroup
Definition: SCR_AIGroup.c:68