Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIGroupTargetCluster.c
Go to the documentation of this file.
2{
3 // Limits angle within -PI..PI range
4 static float WrapAngleDiff(float angle)
5 {
6 while (angle < -Math.PI)
7 angle += Math.PI2;
8 while (angle > Math.PI)
9 angle -= Math.PI2;
10 return angle;
11 }
12
13 // Limits angle within 0..2PI range
14 static float WrapAngle(float angle)
15 {
16 while (angle < 0)
17 angle += Math.PI2;
18 while (angle > Math.PI2)
19 angle -= Math.PI2;
20 return angle;
21 }
22
23 // Converts a direction vector to angle
24 static float DirToAngle(vector dir)
25 {
26 float a = Math.Atan2(dir[0], dir[2]);
27 return WrapAngle(a);
28 }
29}
30
31class SCR_AITargetInfoPolar : Managed
32{
33 SCR_AITargetInfo m_Target;
34
35 [SortAttribute()] // Sorting is used for clustering
36 float m_fAngle;
37
39}
40
42{
43 ref array<SCR_AITargetInfo> m_aTargets = {}; // Those arrays are parallel
44 ref array<float> m_aAngles = {}; // Angle to that target
45 ref array<float> m_aDistances = {}; // Distance to that target
46 ref array<IEntity> m_aEntities = {}; // Entities of the target
47
48 ref SCR_AITargetClusterState m_State;
49
50 float m_fAngleMin;
51 float m_fAngleMax;
52
53 //---------------------------------------------------------------------------
54 void AddTarget(SCR_AITargetInfo target, float angle, float dist)
55 {
56 m_aTargets.Insert(target);
57 m_aAngles.Insert(angle);
58 m_aDistances.Insert(dist);
59 m_aEntities.Insert(target.m_Entity);
60 }
61
62 //---------------------------------------------------------------------------
63 // Adds targets from other cluster to this cluster. Adjusts min/max angles limits.
64 // ! Doesn't modify orders
65 void AddCluster(SCR_AIGroupTargetCluster other)
66 {
67 // Add other points and angles
68 foreach (float angle : other.m_aAngles)
69 m_aAngles.Insert(angle);
70 foreach (float distance : other.m_aDistances)
71 m_aDistances.Insert(distance);
72 foreach (SCR_AITargetInfo target : other.m_aTargets)
73 m_aTargets.Insert(target);
74 foreach (IEntity entity : other.m_aEntities)
75 m_aEntities.Insert(entity);
76
77 // Resolve the new min-max angle values
78 float span0 = SCR_AIPolar.WrapAngleDiff(other.m_fAngleMax - m_fAngleMin);
79 float span1 = SCR_AIPolar.WrapAngleDiff(other.m_fAngleMin - m_fAngleMax);
80
81 if (span0 == span1)
82 if (span0 > 0)
83 m_fAngleMax = other.m_fAngleMax;
84 else
85 m_fAngleMin = other.m_fAngleMin;
86 else if (Math.AbsFloat(span0) > Math.AbsFloat(span1))
87 m_fAngleMax = other.m_fAngleMax;
88 else
89 m_fAngleMin = other.m_fAngleMin;
90 }
91
92 //---------------------------------------------------------------------------
93 // Moves state from other cluster to this one
94 // The other cluster's state is reset
95 void MoveStateFrom(SCR_AIGroupTargetCluster other)
96 {
97 m_State = other.m_State;
98 m_State.m_Cluster = this;
99 other.m_State = null;
100 }
101
102 //---------------------------------------------------------------------------
103 // Returns distance to closest target
104 float GetMinDistance()
105 {
106 if (m_aDistances.IsEmpty())
107 return -1;
108
109 float minDist = float.MAX;
110 foreach (float dist : m_aDistances)
111 {
112 if (dist < minDist)
113 minDist = dist;
114 }
115
116 return minDist;
117 }
118}
float m_fDistance
float m_fAngle
class SCR_AIPolar m_Target
void SCR_AITargetClusterState(SCR_AIGroupTargetCluster cluster)
float distance
Definition Math.c:13