Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIDecoIsEnemyWithinRadius.c
Go to the documentation of this file.
2{
3 static const string WAYPOINT_PORT = "WaypointIn";
4 static const string LOCATION_PORT = "LocationOut";
5
6 //---------------------------------------------------------------------------------------------------
7 protected static ref TStringArray s_aVarsOut = {
8 LOCATION_PORT
9 };
11 {
12 return s_aVarsOut;
13 }
14
15 //---------------------------------------------------------------------------------------------------
16 protected static ref TStringArray s_aVarsIn = {
17 WAYPOINT_PORT
18 };
20 {
21 return s_aVarsIn;
22 }
23
24 //---------------------------------------------------------------------------------------------------
25 // Checks if at least one enemy known to group is within the completion radius
26 bool TestLocationOfKnownEnemies(SCR_AIGroupUtilityComponent groupUtility, AIWaypoint waypoint)
27 {
28 float waypointRadiusSq = waypoint.GetCompletionRadius() * waypoint.GetCompletionRadius();
29
30 vector wpOrigin = waypoint.GetOrigin();
31
32 foreach (SCR_AITargetInfo tgtInfo : groupUtility.m_Perception.m_aTargets)
33 {
34 if (tgtInfo.m_eCategory == EAITargetInfoCategory.DESTROYED)
35 continue;
36
37 if (vector.DistanceSq(tgtInfo.m_vWorldPos, wpOrigin) < waypointRadiusSq)
38 {
39 SetVariableOut(LOCATION_PORT, tgtInfo.m_vWorldPos);
40 return true;
41 }
42 }
43 return false;
44 }
45
46 //---------------------------------------------------------------------------------------------------
47 protected override bool TestFunction(AIAgent owner)
48 {
49 AIWaypoint waypoint;
51
52 AIGroup group = AIGroup.Cast(owner);
53 if (!group)
54 return false;
55
56 if ( !GetVariableIn(WAYPOINT_PORT,waypoint) )
57 waypoint = group.GetCurrentWaypoint();
58 if (! waypoint )
59 {
60 Print("Node IsEnemyWithinRadius executed without valid waypoint!");
61 return false;
62 };
63 guc = SCR_AIGroupUtilityComponent.Cast(owner.FindComponent(SCR_AIGroupUtilityComponent));
64 if ( !guc )
65 {
66 Print("Node IsEnemyWithinRadius executed on owner without group utility component!");
67 return false;
68 }
69 return TestLocationOfKnownEnemies(guc, waypoint);
70 }
71
72 //---------------------------------------------------------------------------------------------------
73 protected static override bool VisibleInPalette()
74 {
75 return true;
76 }
77
78 protected static override string GetOnHoverDescription()
79 {
80 return "Decorator that test that at least one detected enemy is within completion radius of waypoint, current waypoint is used if none is provided";
81 }
82};
EAITargetInfoCategory
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
override bool TestFunction(AIAgent owner)
bool TestLocationOfKnownEnemies(SCR_AIGroupUtilityComponent groupUtility, AIWaypoint waypoint)
ref array< ref SCR_AITargetInfo > m_aTargets
ref SCR_AIGroupPerception m_Perception
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
array< string > TStringArray
Definition Types.c:385