DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ GetMeleeTarget()

static Object GetMeleeTarget ( vector pos,
vector dir,
float angle,
float dist,
float minHeight,
float maxHeight,
EntityAI pToIgnore,
array< typename > targetableObjects,
out array< Object > allTargets = NULL )
static

returns fight target

См. определение в файле DayZPlayerUtils.c строка 94

95 {
96 // Print("In: GetFightTarget");
98
99 GetEntitiesInCone(pos, dir, angle, dist, minHeight, maxHeight, m_CachedEntList);
100
101 Object ret = NULL;
102 Object obj = NULL;
103
104 float retVal = dist * 2; // max value
105 float tgAngle = Math.Tan(Math.DEG2RAD * angle);
106
107 // DrawStartFrame();
108
109 foreach(auto ent: m_CachedEntList)
110 {
111 if (ent == pToIgnore)
112 {
113 continue;
114 }
115
116 Class.CastTo(obj, ent);
117 if(obj)
118 {
119 // check for targetable objects
120 if( !obj.IsAnyInherited(targetableObjects) )
121 { continue; }
122
123 if( !obj.IsAlive() )
124 { continue; }
125 }
126
127 vector entpos = ent.GetPosition();
128
129 vector diff = entpos - pos;
130 float cDistSq = diff.LengthSq();
131 if (cDistSq > dist*dist) // out of distance
132 {
133 //Print("out of distance");
134 continue;
135 }
136
137 float frontDist = diff[0]*dir[0] + diff[2]*dir[2];
138 if (frontDist < 0.1) // behind the pos/dist half plane or further than dist
139 {
140 //Print("behind the pos/dist half plane or further than dist");
141 continue;
142 }
143
144 vector project = pos + dir * frontDist;
145 vector posdiff = Vector(project[0] - entpos[0], 0, project[2] - entpos[2]);
146 float sideDist = posdiff.LengthSq();
147
148 if (sideDist > tgAngle) // out of cone
149 {
150 //Print("out of cone");
151 continue;
152 }
153
154 float sum = frontDist + sideDist;
155 if (sum < retVal)
156 {
157 ret = ent;
158 retVal = sum;
159 }
160 else
161 {
162 //Print("sum !< retVal");
163 }
164
165 // string txt = project.ToString() + ": " + sum.ToString();
166 // DrawDebugBox(project,0.01,0xffff0000);
167 // DrawDebugBox(entpos,0.01,0xffff0000);
168 // DrawDebugText(txt, project, 1.0);
169 allTargets.Insert(ent);
170 }
171
172 return ret;
173 }
static ref array< Object > m_CachedEntList
Определения DayZPlayerUtils.c:461
static proto native void GetEntitiesInCone(vector pos, vector dir, float angle, float dist, float minHeigh, float maxHeight, out array< Object > entList)
static void InitCachedEntList()
Определения DayZPlayerUtils.c:468
Super root of all classes in Enforce script.
Определения EnScript.c:11
Определения EnMath.c:7
Определения ObjectTyped.c:2
proto native float LengthSq()
Returns squared length (magnitudeSqr)
Определения EnConvert.c:106
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Tan(float angle)
Returns tangent of angle in radians.
static const float DEG2RAD
Определения EnMath.c:17

Перекрестные ссылки Class::CastTo(), Math::DEG2RAD, GetEntitiesInCone(), InitCachedEntList(), vector::LengthSq(), m_CachedEntList, Math::Tan() и Vector().