DayZ 1.24
Loading...
Searching...
No Matches
MeleeTargeting.c
Go to the documentation of this file.
2{
6
8 {
9 Obj = o;
10 HitPos = p;
12 }
13}
14
16{
23
26
31 float MaxDist;
32
35
62}
63
71
73{
75
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
103
105
106 // Calculate box center
108 vector offset = xzDir * coneLength * 0.5;
110
111 // Gather all targets
113 params.SetParams(boxCenter, xzDir.VectorToAngles(), boxSize, ObjIntersect.Fire, ObjIntersect.Fire, true);
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))
125#endif
126
127 // Find the most suitable target
129 {
130 Object obj = bResult.obj;
131
132 // Check for targetable objects
133 if (!obj.IsAnyInherited(targetableObjects) || !obj.IsAlive())
134 continue;
135
136 // Ready the defaults for the object
137 vector targetPos = obj.GetPosition();
140 int hitComponent = -1;
141
142 float csSum = float.MAX;
143
144 // Find the most suitable component
147 {
148 targetPos = result.ComponentPos;
149 targetAngle = result.ComponentAngle;
150 targetDistance2 = result.ComponentDistance2;
151 hitComponent = result.ComponentIdx;
152 }
153
154 // ProxyInfo
155 if (bResult.proxyInfo)
156 {
157 foreach (BoxCollidingResult pInfo : bResult.proxyInfo)
158 {
160 {
161 targetPos = result.ComponentPos;
162 targetAngle = result.ComponentAngle;
163 targetDistance2 = result.ComponentDistance2;
164 hitComponent = result.ComponentIdx;
165 }
166 }
167 }
168
169 // No suitable component found
170 if (hitComponent == -1 || csSum == float.MAX)
171 continue;
172
173 // Check if it is a better fit than what has been found previously
174 float sum = targetDistance2;
175 if (sum < retVal)
176 {
178 retVal = sum;
179 }
180
181 allTargets.Insert(obj);
182 }
183 }
184
185 return ret;
186 }
187
192
193
195 {
196 foreach (ComponentInfo cInfo : bResult.componentInfo)
197 {
199
201 continue;
202
203 // Smallest number is a winner
204 float cSum = cResult.ComponentDistance2;
205 if (cSum < sum)
206 {
207 sum = cSum;
208 result = cResult;
209 }
210 }
211
212 return result != null;
213 }
214
219
221 {
223 foreach (string zoneName: blacklistedDamageZones)
224 {
225 if (obj.GetDamageZoneNameByComponentIndex(cInfo.component) == zoneName)
226 return false;
227 }
228
229 vector componentPos = cInfo.componentCenter;
230
231 // Too far away! (fast reject)
232 float componentMaxDist2 = Math.SqrFloat(settings.MaxDist + cInfo.componentRadius * obj.GetScale());
236 return false;
237
238 // Here some more accurate check could be placed that would adjust the componentPos
239
240 // Outside of the cone angle!
242 if (componentAngle > settings.ConeHalfAngle)
243 return false;
244
245 // Obstructed!
247 return false;
248
249 // We found something, fill it in!
250 result.ComponentPos = componentPos;
251 result.ComponentAngle = componentAngle;
252 result.ComponentDistance2 = componentDistance2;
253 result.ComponentIdx = cInfo.component;
254
255 return true;
256 }
257
262
264 {
265 if (rayStart == rayEnd)
266 {
267 return true; // Not possible to trace when this happens (zero length raycast)
268 }
269
272 float hitFraction;
273
275 }
276}
PhxInteractionLayers
Definition DayZPhysics.c:2
DiagMenuIDs
Definition EDiagMenuIDs.c:2
const int MAX
Definition EnConvert.c:27
float ConeHalfAngleRad
vector ConeLeftPoint
ref array< typename > TargetableObjects void MeleeTargetSettings(vector coneOrigin, float coneLength, float coneHalfAngle, float coneMinHeight, float coneMaxHeight, vector rayStart, vector dir, float maxDist, EntityAI pToIgnore, array< typename > targetableObjects)
float ConeMinHeight
float ConeLength
vector ConeRightPoint
vector XZDir
bool FindMostSuitableComponent(Object obj, BoxCollidingResult bResult, MeleeTargetSettings settings, out float sum, out ref ComponentResult result)
bool EvaluateComponent(Object obj, ComponentInfo cInfo, MeleeTargetSettings settings, out ref ComponentResult result)
float MaxDist
bool EvaluateComponentEx(Object obj, ComponentInfo cInfo, MeleeTargetSettings settings, out ref ComponentResult result, array< string > blacklistedDamageZones)
EntityAI Attacker
MeleeTargetData GetMeleeTarget(MeleeTargetSettings settings, out array< Object > allTargets=null)
float ConeMaxHeight
bool IsMeleeTargetObstructed(vector rayStart, vector rayEnd)
vector Dir
bool FindMostSuitableComponentEx(Object obj, BoxCollidingResult bResult, MeleeTargetSettings settings, out float sum, out ref ComponentResult result, array< string > blacklistedDamageZones)
class MeleeTargetData ConeOrigin
float ConeHalfAngle
class ComponentResult MELEE_TARGET_OBSTRUCTION_LAYERS
MeleeTargetData GetMeleeTargetEx(MeleeTargetSettings settings, out array< Object > allTargets=null, array< string > blacklistedDamageZones=null)
vector RayStart
vector RayEnd
Class that holds parameters to feed into CGame.IsBoxCollidingGeometryProxy.
static proto bool RayCastBullet(vector begPos, vector endPos, PhxInteractionLayers layerMask, Object ignoreObj, out Object hitObject, out vector hitPosition, out vector hitNormal, out float hitFraction)
Definition Debug.c:14
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Definition Debug.c:489
Definition EnMath.c:7
void MeleeTargetData(Object o, vector p, int c)
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto float Normalize()
Normalizes vector. Returns length.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()
const int COLOR_GREEN
Definition constants.c:65
ShapeFlags
Definition 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 void ConePoints(vector origin, float length, float halfAngle, float angleOffset, out vector leftPoint, out vector rightPoint)
Calculates the points of a right 2D cone in 3D space.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float SqrFloat(float f)
Returns squared value.
static proto float Tan(float angle)
Returns tangent of angle in radians.
static proto float Atan2(float y, float x)
Returns angle in radians from tangent.
static const float RAD2DEG
Definition EnMath.c:16
static const float DEG2RAD
Definition EnMath.c:17
static proto float AbsFloat(float f)
Returns absolute value.