Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIGetRandomPointWithExclude.c
Go to the documentation of this file.
2{
3 static const string ENTITY_PORT = "Entity";
4 static const string ORIGIN_PORT = "SearchCenter";
5 static const string RADIUS_PORT = "SearchRadius";
6 static const string EXCLUSION_ORIGIN_PORT = "ExclusionCenter";
7 static const string EXCLUSION_RADIUS_PORT = "ExclusionRadius";
8 static const string PORT_RESULT_VECTOR = "Position";
9
10 [Attribute("", UIWidgets.Coords, "Search Position Center", "", )]
12
13 [Attribute("10", UIWidgets.EditBox, "Search Position Radius", "", )]
14 protected float m_fSearchRadius;
15
16 [Attribute("", UIWidgets.Coords, "Exclusion position center", "", )]
18
19 [Attribute("2", UIWidgets.EditBox, "Radius of exclusion area", "", )]
20 protected float m_fExcludeRadius;
21
22 [Attribute("10", UIWidgets.EditBox, "How many attempts of finding new position should be made", "", )]
23 protected int m_iIterationCount;
24
25 //------------------------------------------------------------------------------------------------
26 static override bool VisibleInPalette()
27 {
28 return true;
29 }
30
31 //------------------------------------------------------------------------------------------------
32 protected static ref TStringArray s_aVarsIn = {
33 ENTITY_PORT,
34 ORIGIN_PORT,
35 RADIUS_PORT,
36 EXCLUSION_ORIGIN_PORT,
37 EXCLUSION_RADIUS_PORT
38 };
39 override array<string> GetVariablesIn()
40 {
41 return s_aVarsIn;
42 }
43
44 //------------------------------------------------------------------------------------------------
45 protected static ref TStringArray s_aVarsOut = {
46 PORT_RESULT_VECTOR
47 };
48 override array<string> GetVariablesOut()
49 {
50 return s_aVarsOut;
51 }
52
53 //------------------------------------------------------------------------------------------------
54 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
55 {
56 vector exclusionPos, searchPos, result;
57 IEntity entitySearch;
58 float searchRadius, exclusionRadius;
59
60 if (GetVariableIn(ENTITY_PORT,entitySearch))
61 {
62 searchPos = entitySearch.GetOrigin();
63 }
64 else if(!GetVariableIn(ORIGIN_PORT,searchPos))
65 {
66 IEntity ent = owner.GetControlledEntity();
67 if (!ent)
68 {
69 searchPos = m_vSearchCenter;
70 }
71 searchPos = ent.GetOrigin();
72 }
73
74 if (!GetVariableIn(EXCLUSION_ORIGIN_PORT,exclusionPos))
75 exclusionPos = searchPos;
76 if (!GetVariableIn(RADIUS_PORT,searchRadius))
77 searchRadius = m_fSearchRadius;
78 if (!GetVariableIn(EXCLUSION_RADIUS_PORT,exclusionRadius))
79 exclusionRadius = m_fExcludeRadius;
80
81 if (!FindPosition2D(result, searchPos, searchRadius, exclusionPos, exclusionRadius, m_iIterationCount))
82 return ENodeResult.FAIL;
83
84 SetVariableOut(PORT_RESULT_VECTOR,result);
85 return ENodeResult.SUCCESS;
86 }
87
88 // returns position inside a circle that is not inside an exlusion circle, iterative
89 //------------------------------------------------------------------------------------------------------------------------------------------------------------
90 protected bool FindPosition2D(out vector randomPos, vector randomSphereOrigin, float randomSphereRadius, vector excludeSphereOrigin = vector.Zero, float excludeRadius = 0, int iterationCount = 50)
91 {
92 if (randomSphereOrigin == excludeSphereOrigin || excludeRadius < 1.0e-8)
93 {
94 randomPos = s_AIRandomGenerator.GenerateRandomPointInRadius(excludeRadius, randomSphereRadius, randomSphereOrigin, true);
95 randomPos[1] = randomSphereOrigin[1];
96 return true;
97 }
98 else
99 {
100 float excludeRadiusSq = excludeRadius * excludeRadius;
101 float randomRadiusSq = randomSphereRadius * randomSphereRadius;
102 for (int i = iterationCount; i > 0; i--)
103 {
104 randomPos = s_AIRandomGenerator.GenerateRandomPointInRadius(0, randomSphereRadius, randomSphereOrigin, true);
105
106 // Repeat if position is inside exclusion zone
107 if (excludeRadius > 0 && vector.DistanceSqXZ(randomPos, excludeSphereOrigin) < excludeRadiusSq)
108 continue;
109
110 randomPos[1] = randomSphereOrigin[1];
111 return true;
112 }
113 }
114 return false;
115 }
116
117 //------------------------------------------------------------------------------------------------
118 static override protected string GetOnHoverDescription()
119 {
120 return "Returns random position in circle that does not lie inside an exclusion circle. Center is taken from Entity variable or from SearchCenter variable";
121 }
122};
class SCR_AINodePortsHelpers s_AIRandomGenerator
proto external vector GetOrigin()
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
bool FindPosition2D(out vector randomPos, vector randomSphereOrigin, float randomSphereRadius, vector excludeSphereOrigin=vector.Zero, float excludeRadius=0, int iterationCount=50)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385