DayZ 1.24
Loading...
Searching...
No Matches
MeleeTargeting.c File Reference

Go to the source code of this file.

Classes

class  MeleeTargetData
 
class  ComponentResult
 

Functions

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)
 
MeleeTargetData GetMeleeTargetEx (MeleeTargetSettings settings, out array< Object > allTargets=null, array< string > blacklistedDamageZones=null)
 
MeleeTargetData GetMeleeTarget (MeleeTargetSettings settings, out array< Object > allTargets=null)
 
bool FindMostSuitableComponentEx (Object obj, BoxCollidingResult bResult, MeleeTargetSettings settings, out float sum, out ref ComponentResult result, array< string > blacklistedDamageZones)
 
bool FindMostSuitableComponent (Object obj, BoxCollidingResult bResult, MeleeTargetSettings settings, out float sum, out ref ComponentResult result)
 
bool EvaluateComponentEx (Object obj, ComponentInfo cInfo, MeleeTargetSettings settings, out ref ComponentResult result, array< string > blacklistedDamageZones)
 
bool EvaluateComponent (Object obj, ComponentInfo cInfo, MeleeTargetSettings settings, out ref ComponentResult result)
 
bool IsMeleeTargetObstructed (vector rayStart, vector rayEnd)
 

Variables

class MeleeTargetData ConeOrigin
 
float ConeLength
 
float ConeHalfAngle
 
float ConeHalfAngleRad
 
float ConeMinHeight
 
float ConeMaxHeight
 
vector ConeLeftPoint
 
vector ConeRightPoint
 
vector RayStart
 
vector RayEnd
 
vector Dir
 
vector XZDir
 
float MaxDist
 
EntityAI Attacker
 
class ComponentResult MELEE_TARGET_OBSTRUCTION_LAYERS = PhxInteractionLayers.BUILDING | PhxInteractionLayers.DOOR | PhxInteractionLayers.VEHICLE | PhxInteractionLayers.ROADWAY | PhxInteractionLayers.TERRAIN | PhxInteractionLayers.ITEM_SMALL | PhxInteractionLayers.ITEM_LARGE | PhxInteractionLayers.FENCE
 

Function Documentation

◆ EvaluateComponent()

bool EvaluateComponent ( Object obj,
ComponentInfo cInfo,
MeleeTargetSettings settings,
out ref ComponentResult result )

Definition at line 258 of file MeleeTargeting.c.

259 {
260 return EvaluateComponentEx(obj, cInfo, settings, result, {});
261 }
bool EvaluateComponentEx(Object obj, ComponentInfo cInfo, MeleeTargetSettings settings, out ref ComponentResult result, array< string > blacklistedDamageZones)

References EvaluateComponentEx().

◆ EvaluateComponentEx()

bool EvaluateComponentEx ( Object obj,
ComponentInfo cInfo,
MeleeTargetSettings settings,
out ref ComponentResult result,
array< string > blacklistedDamageZones )

check if the component is on blacklist, if so, continue in lookup

Definition at line 220 of file MeleeTargeting.c.

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 }
bool IsMeleeTargetObstructed(vector rayStart, vector rayEnd)
Definition EnMath.c:7
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
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 SqrFloat(float f)
Returns squared value.
static const float RAD2DEG
Definition EnMath.c:16
static proto float AbsFloat(float f)
Returns absolute value.

References Math::AbsFloat(), Math3D::AngleFromPosition(), vector::DistanceSq(), IsMeleeTargetObstructed(), Math3D::NearestPoint(), Math::RAD2DEG, and Math::SqrFloat().

Referenced by EvaluateComponent(), and FindMostSuitableComponentEx().

◆ FindMostSuitableComponent()

bool FindMostSuitableComponent ( Object obj,
BoxCollidingResult bResult,
MeleeTargetSettings settings,
out float sum,
out ref ComponentResult result )

Definition at line 215 of file MeleeTargeting.c.

216 {
218 }
bool FindMostSuitableComponentEx(Object obj, BoxCollidingResult bResult, MeleeTargetSettings settings, out float sum, out ref ComponentResult result, array< string > blacklistedDamageZones)

References FindMostSuitableComponentEx().

◆ FindMostSuitableComponentEx()

bool FindMostSuitableComponentEx ( Object obj,
BoxCollidingResult bResult,
MeleeTargetSettings settings,
out float sum,
out ref ComponentResult result,
array< string > blacklistedDamageZones )

Definition at line 194 of file MeleeTargeting.c.

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 }

References EvaluateComponentEx().

Referenced by FindMostSuitableComponent(), and GetMeleeTargetEx().

◆ GetMeleeTarget()

MeleeTargetData GetMeleeTarget ( MeleeTargetSettings settings,
out array< Object > allTargets = null )

Definition at line 188 of file MeleeTargeting.c.

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

References GetMeleeTargetEx().

◆ GetMeleeTargetEx()

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

Definition at line 76 of file MeleeTargeting.c.

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 }
DiagMenuIDs
Definition EDiagMenuIDs.c:2
const int MAX
Definition EnConvert.c:27
Class that holds parameters to feed into CGame.IsBoxCollidingGeometryProxy.
Definition Debug.c:14
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Definition Debug.c:489
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 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.

References Math::AbsFloat(), Math3D::AngleFromPosition(), COLOR_GREEN, vector::Distance(), vector::DistanceSq(), Debug::DrawLine(), FindMostSuitableComponentEx(), DiagMenu::GetBool(), GetGame(), Math::Lerp(), MAX, Math3D::NearestPoint(), Math::RAD2DEG, Math::Tan(), and Vector().

Referenced by GetMeleeTarget().

◆ IsMeleeTargetObstructed()

bool IsMeleeTargetObstructed ( vector rayStart,
vector rayEnd )

Definition at line 263 of file MeleeTargeting.c.

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 }
class ComponentResult MELEE_TARGET_OBSTRUCTION_LAYERS
static proto bool RayCastBullet(vector begPos, vector endPos, PhxInteractionLayers layerMask, Object ignoreObj, out Object hitObject, out vector hitPosition, out vector hitNormal, out float hitFraction)

References MELEE_TARGET_OBSTRUCTION_LAYERS, and DayZPhysics::RayCastBullet().

Referenced by EvaluateComponentEx().

◆ MeleeTargetSettings()

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 )

Definition at line 36 of file MeleeTargeting.c.

37 {
44
47
48 Dir = dir;
49
50 XZDir = dir;
51 XZDir[1] = 0;
53
55
58
59 // Calculate cone points
61 }
float ConeHalfAngleRad
vector ConeLeftPoint
float ConeMinHeight
float ConeLength
vector ConeRightPoint
vector XZDir
float MaxDist
EntityAI Attacker
float ConeMaxHeight
vector Dir
class MeleeTargetData ConeOrigin
float ConeHalfAngle
vector RayStart
vector RayEnd
proto float Normalize()
Normalizes vector. Returns length.
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 Atan2(float y, float x)
Returns angle in radians from tangent.
static const float DEG2RAD
Definition EnMath.c:17

References Math::Atan2(), Attacker, ConeHalfAngle, ConeHalfAngleRad, ConeLeftPoint, ConeLength, ConeMaxHeight, ConeMinHeight, ConeOrigin, Math3D::ConePoints(), ConeRightPoint, Math::DEG2RAD, Dir, MaxDist, vector::Normalize(), RayEnd, RayStart, Math::SqrFloat(), and XZDir.

Referenced by TargetSelection().

Variable Documentation

◆ Attacker

EntityAI Attacker

Definition at line 33 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ ConeHalfAngle

float ConeHalfAngle

Definition at line 19 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ ConeHalfAngleRad

float ConeHalfAngleRad

Definition at line 20 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ ConeLeftPoint

vector ConeLeftPoint

Definition at line 24 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ ConeLength

float ConeLength

Definition at line 18 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ ConeMaxHeight

float ConeMaxHeight

Definition at line 22 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ ConeMinHeight

float ConeMinHeight

Definition at line 21 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ ConeOrigin

class MeleeTargetData ConeOrigin

Referenced by MeleeTargetSettings().

◆ ConeRightPoint

vector ConeRightPoint

Definition at line 25 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ Dir

vector Dir

Definition at line 29 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ MaxDist

float MaxDist

Definition at line 31 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ MELEE_TARGET_OBSTRUCTION_LAYERS

◆ RayEnd

vector RayEnd

Definition at line 28 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ RayStart

vector RayStart

Definition at line 27 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().

◆ XZDir

vector XZDir

Definition at line 30 of file MeleeTargeting.c.

Referenced by MeleeTargetSettings().