Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIFindTurrets.c
Go to the documentation of this file.
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
10
11 //------------------------------------------------------------------------------------------------
12 static override bool VisibleInPalette() {return true;}
13
14 //------------------------------------------------------------------------------------------------
15 override void OnInit(AIAgent owner)
16 {
17 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
18 m_tagSystem = TagSystem.Cast(world.FindSystem(TagSystem));
19 if (!m_tagSystem)
20 {
21 NodeError(this, owner, "SCR_AIFindTurret: TagManager is not present in the world, cannot find static turrets.");
22 }
23 m_groupOwner = SCR_AIGroup.Cast(owner);
24 if (!m_groupOwner)
25 {
26 m_groupOwner = SCR_AIGroup.Cast(owner.GetParentGroup());
27 if (!m_groupOwner)
28 NodeError(this, owner, "Node is not run on SCR_AIGroup agent or owner is not member of SCR_AIGroup!");
29 }
30 }
31
32 //------------------------------------------------------------------------------------------------
33 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
34 {
35 if (!m_tagSystem)
36 {
37 ClearVariable(PORT_TURRET_NUMBER);
38 ClearVariable(PORT_TURRET_FOUND);
39 return ENodeResult.FAIL;
40 }
41 vector center;
42 float radius;
43 int agentsCount = m_groupOwner.GetAgentsCount();
44 int turretCount;
45 bool turretsFound;
46
47 GetVariableIn(PORT_CENTER_OF_SEARCH, center);
48 GetVariableIn(PORT_RADIUS, radius);
49
50 array<IEntity> entities = {};
51 m_tagSystem.GetTagsInRange(entities, center, radius, ETagCategory.StaticTurret);
52
53 foreach (IEntity ent : entities)
54 {
56 if (!compComp)
57 continue;
58
60 if (!vehicleUsageComp)
61 continue;
62
63 // Ignore mortars, we can't use them autonomously
64 if (vehicleUsageComp.GetVehicleType() != EAIVehicleType.STATIC_WEAPON)
65 continue;
66
67 array<BaseCompartmentSlot> compartmentSlots = {};
68 compComp.GetCompartments(compartmentSlots);
69 foreach (BaseCompartmentSlot slot : compartmentSlots)
70 {
71 TurretCompartmentSlot turretComp = TurretCompartmentSlot.Cast(slot);
72 if (turretComp)
73 {
74 if (!turretComp.AttachedOccupant() && turretComp.IsCompartmentAccessible() && !turretComp.IsReserved())
75 {
76 turretCount += 1;
77 turretsFound = true;
78 if (turretCount <= agentsCount) // do not occupy more turrets that you have agents
79 m_groupOwner.AllocateCompartment(turretComp);
80 break;
81 }
82 }
83 }
84 }
85 if (turretsFound)
86 SetVariableOut(PORT_TURRET_NUMBER, turretCount);
87 else
88 ClearVariable(PORT_TURRET_NUMBER);
89 SetVariableOut(PORT_TURRET_FOUND, turretsFound);
90 return ENodeResult.SUCCESS;
91 }
92
93 //------------------------------------------------------------------------------------------------
94 protected static ref TStringArray s_aVarsOut = {
95 PORT_TURRET_NUMBER,
96 PORT_TURRET_FOUND
97 };
99 {
100 return s_aVarsOut;
101 }
102
103 //------------------------------------------------------------------------------------------------
104 protected static ref TStringArray s_aVarsIn = {
105 PORT_CENTER_OF_SEARCH,
106 PORT_RADIUS
107 };
109 {
110 return s_aVarsIn;
111 }
112
113 //------------------------------------------------------------------------------------------------
114 static override string GetOnHoverDescription()
115 {
116 return "SCR_AIFindTurrets: finds all static turrets within center and radius. All results are allocated (reserved) for this group.";
117 }
118};
ETagCategory
Definition ETagCategory.c:2
ArmaReforgerScripted GetGame()
Definition game.c:1398
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition NodeError.c:3
EAIVehicleType
Vehicle type from point view of AI usage.
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
proto void ClearVariable(string name)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
override TStringArray GetVariablesIn()
static override string GetOnHoverDescription()
static ref TStringArray s_aVarsOut
SCR_AIGroup m_groupOwner
override TStringArray GetVariablesOut()
static ref TStringArray s_aVarsIn
static override bool VisibleInPalette()
override void OnInit(AIAgent owner)
ENodeResult
Definition ENodeResult.c:13
array< string > TStringArray
Definition Types.c:385