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

◆ GetMeleeTargetEx()

MeleeTargetData GetMeleeTargetEx ( MeleeTargetSettings settings,
out array< Object > allTargets = null,
array< string > blacklistedDamageZones = null )

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

77 {
79
80 // Easier access to MeleeTargetSettings variables
81 vector coneOrigin = settings.ConeOrigin;
82 float coneLength = settings.ConeLength;
83 float coneHalfAngle = settings.ConeHalfAngle;
84 float radAngle = settings.ConeHalfAngleRad;
85 float coneMinHeight = settings.ConeMinHeight;
86 float coneMaxHeight = settings.ConeMaxHeight;
87
88 vector coneLeft = settings.ConeLeftPoint;
89 vector coneRight = settings.ConeRightPoint;
90
91 vector rayStart = settings.RayStart;
92 vector rayEnd = settings.RayEnd;
93 vector dir = settings.Dir;
94 vector xzDir = settings.XZDir;
95 float maxDist = settings.MaxDist;
96
97 EntityAI pToIgnore = settings.Attacker;
98 array<typename> targetableObjects = settings.TargetableObjects;
99
100 // Calculate box size
101 float boxWidth = vector.Distance(coneLeft, coneRight);
102 float boxHeight = coneMaxHeight - coneMinHeight;
103
104 vector boxSize = Vector(boxWidth, boxHeight, coneLength);
105
106 // Calculate box center
107 vector centerHeight = Vector(0, Math.Lerp(coneMinHeight, coneMaxHeight, 0.5), 0);
108 vector offset = xzDir * coneLength * 0.5;
109 vector boxCenter = coneOrigin + offset + centerHeight;
110
111 // Gather all targets
113 params.SetParams(boxCenter, xzDir.VectorToAngles(), boxSize, ObjIntersect.Fire, ObjIntersect.Fire, true);
115 array<Object> toIgnore = { pToIgnore };
116 if (GetGame().IsBoxCollidingGeometryProxy(params, toIgnore, results))
117 {
118 //
119 float retVal = float.MAX;
120 float tgAngle = Math.Tan(radAngle);
121
122 #ifdef DIAG_DEVELOPER
123 if (DiagMenu.GetBool(DiagMenuIDs.MELEE_DRAW_RANGE) && DiagMenu.GetBool(DiagMenuIDs.MELEE_DEBUG))
124 Debug.DrawLine(rayStart, rayEnd, COLOR_GREEN, ShapeFlags.ONCE);
125 #endif
126
127 // Find the most suitable target
128 foreach (BoxCollidingResult bResult : results)
129 {
130 Object obj = bResult.obj;
131
132 // Check for targetable objects
133 if (!obj.IsAnyInherited(targetableObjects) || !obj.IsAlive())
134 {
135 continue;
136 }
137
138 // Ready the defaults for the object
139 vector targetPos = obj.GetPosition();
140 float targetAngle = Math.RAD2DEG * Math.AbsFloat(Math3D.AngleFromPosition(coneOrigin, dir, targetPos));
141 float targetDistance2 = vector.DistanceSq(targetPos, Math3D.NearestPoint(rayStart, rayEnd, targetPos));
142 int hitComponent = -1;
143
144 float csSum = float.MAX;
145
146 // Find the most suitable component
147 ComponentResult result;
148 if (FindMostSuitableComponentEx(obj, bResult, settings, csSum, result, blacklistedDamageZones))
149 {
150 targetPos = result.ComponentPos;
151 targetAngle = result.ComponentAngle;
152 targetDistance2 = result.ComponentDistance2;
153 hitComponent = result.ComponentIdx;
154 }
155
156 // ProxyInfo
157 if (bResult.proxyInfo)
158 {
159 foreach (BoxCollidingResult pInfo : bResult.proxyInfo)
160 {
161 if (FindMostSuitableComponentEx(obj, pInfo, settings, csSum, result, blacklistedDamageZones))
162 {
163 targetPos = result.ComponentPos;
164 targetAngle = result.ComponentAngle;
165 targetDistance2 = result.ComponentDistance2;
166 hitComponent = result.ComponentIdx;
167 }
168 }
169 }
170
171 // No suitable component found
172 if (hitComponent == -1 || csSum == float.MAX)
173 {
174 continue;
175 }
176
177 // Check if it is a better fit than what has been found previously
178 float sum = targetDistance2;
179 if (sum < retVal)
180 {
181 ret = new MeleeTargetData(obj, targetPos, hitComponent);
182 retVal = sum;
183 }
184
185 allTargets.Insert(obj);
186 }
187 }
188
189 return ret;
190 }
DiagMenuIDs
Определения EDiagMenuIDs.c:2
const int MAX
Определения EnConvert.c:27
bool FindMostSuitableComponentEx(Object obj, BoxCollidingResult bResult, MeleeTargetSettings settings, out float sum, out ComponentResult result, array< string > blacklistedDamageZones)
Определения MeleeTargeting.c:198
proto native void SetParams(vector center, vector orientation, vector edgeLength, ObjIntersect primaryType, ObjIntersect secondaryType, bool fullComponentInfo)
Set the parameters.
Class that holds parameters to feed into CGame.IsBoxCollidingGeometryProxy.
float ComponentAngle
Определения MeleeTargeting.c:67
vector ComponentPos
Определения MeleeTargeting.c:66
float ComponentDistance2
Определения MeleeTargeting.c:68
int ComponentIdx
Определения MeleeTargeting.c:69
Определения MeleeTargeting.c:65
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Определения Debug.c:382
Определения Debug.c:2
Определения EnDebug.c:233
Определения Building.c:6
Определения EnMath3D.c:28
Определения EnMath.c:7
Определения MeleeTargeting.c:2
Определения ObjectTyped.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
const float MAX
Определения EnConvert.c:99
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
Определения EnConvert.c:106
proto native CGame GetGame()
const int COLOR_GREEN
Определения constants.c:65
ShapeFlags
Определения EnDebug.c:126
static proto bool GetBool(int id, bool reverse=false)
Get value as bool from the given script id.
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float AngleFromPosition(vector origin, vector originDir, vector target)
Angle that a target is from the direction of an origin.
static proto vector NearestPoint(vector beg, vector end, vector pos)
Point on line beg .. end nearest to pos.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float Tan(float angle)
Returns tangent of angle in radians.
static const float RAD2DEG
Определения EnMath.c:16
static proto float AbsFloat(float f)
Returns absolute value.

Перекрестные ссылки Math::AbsFloat(), Math3D::AngleFromPosition(), COLOR_GREEN, ComponentResult::ComponentAngle, ComponentResult::ComponentDistance2, ComponentResult::ComponentIdx, ComponentResult::ComponentPos, vector::Distance(), vector::DistanceSq(), Debug::DrawLine(), FindMostSuitableComponentEx(), DiagMenu::GetBool(), GetGame(), Math::Lerp(), float::MAX, MAX, MeleeTargetSettings(), Math3D::NearestPoint(), Math::RAD2DEG, BoxCollidingParams::SetParams(), Math::Tan(), Vector() и vector::VectorToAngles().

Используется в GetMeleeTarget().