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";
10 [
Attribute(
"", UIWidgets.Coords,
"Search Position Center",
"", )]
11 protected vector m_vSearchCenter;
13 [
Attribute(
"10", UIWidgets.EditBox,
"Search Position Radius",
"", )]
14 protected float m_fSearchRadius;
16 [
Attribute(
"", UIWidgets.Coords,
"Exclusion position center",
"", )]
17 protected vector m_vExcludeCenter;
19 [
Attribute(
"2", UIWidgets.EditBox,
"Radius of exclusion area",
"", )]
20 protected float m_fExcludeRadius;
22 [
Attribute(
"10", UIWidgets.EditBox,
"How many attempts of finding new position should be made",
"", )]
23 protected int m_iIterationCount;
26 override bool VisibleInPalette()
32 protected static ref TStringArray s_aVarsIn = {
36 EXCLUSION_ORIGIN_PORT,
39 override array<string> GetVariablesIn()
45 protected static ref TStringArray s_aVarsOut = {
48 override array<string> GetVariablesOut()
54 override ENodeResult EOnTaskSimulate(AIAgent owner,
float dt)
56 vector exclusionPos, searchPos, result;
58 float searchRadius, exclusionRadius;
60 if (GetVariableIn(ENTITY_PORT,entitySearch))
62 searchPos = entitySearch.GetOrigin();
64 else if(!GetVariableIn(ORIGIN_PORT,searchPos))
66 IEntity ent = owner.GetControlledEntity();
69 searchPos = m_vSearchCenter;
71 searchPos = ent.GetOrigin();
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;
81 if (!FindPosition2D(result, searchPos, searchRadius, exclusionPos, exclusionRadius, m_iIterationCount))
82 return ENodeResult.FAIL;
84 SetVariableOut(PORT_RESULT_VECTOR,result);
85 return ENodeResult.SUCCESS;
90 protected bool FindPosition2D(out vector randomPos, vector randomSphereOrigin,
float randomSphereRadius, vector excludeSphereOrigin = vector.Zero,
float excludeRadius = 0,
int iterationCount = 50)
92 if (randomSphereOrigin == excludeSphereOrigin || excludeRadius < 1.0e-8)
94 randomPos = s_AIRandomGenerator.GenerateRandomPointInRadius(excludeRadius, randomSphereRadius, randomSphereOrigin,
true);
95 randomPos[1] = randomSphereOrigin[1];
100 float excludeRadiusSq = excludeRadius * excludeRadius;
101 float randomRadiusSq = randomSphereRadius * randomSphereRadius;
102 for (
int i = iterationCount; i > 0; i--)
104 randomPos = s_AIRandomGenerator.GenerateRandomPointInRadius(0, randomSphereRadius, randomSphereOrigin,
true);
107 if (excludeRadius > 0 && vector.DistanceSqXZ(randomPos, excludeSphereOrigin) < excludeRadiusSq)
110 randomPos[1] = randomSphereOrigin[1];
118 override protected string GetOnHoverDescription()
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";