DayZ 1.26
DayZ Explorer by KGB
Загрузка...
Поиск...
Не найдено
Файл MeleeTargeting.c

См. исходные тексты.

Структуры данных

class  MeleeTargetData
 
class  ComponentResult
 

Функции

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)
 

Переменные

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
 

Функции

◆ EvaluateComponent()

bool EvaluateComponent ( Object obj,
ComponentInfo cInfo,
MeleeTargetSettings settings,
out ref ComponentResult result )
273 {
274 return EvaluateComponentEx(obj, cInfo, settings, result, {});
275 }
bool EvaluateComponentEx(Object obj, ComponentInfo cInfo, MeleeTargetSettings settings, out ref ComponentResult result, array< string > blacklistedDamageZones)
Definition MeleeTargeting.c:226
Definition EntityAI.c:95

Перекрестные ссылки 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

227 {
229 foreach (string zoneName: blacklistedDamageZones)
230 {
231 if (obj.GetDamageZoneNameByComponentIndex(cInfo.component) == zoneName)
232 {
233 return false;
234 }
235 }
236
237 vector componentPos = cInfo.componentCenter;
238
239 // Too far away! (fast reject)
240 float componentMaxDist2 = Math.SqrFloat(settings.MaxDist + cInfo.componentRadius * obj.GetScale());
244 {
245 return false;
246 }
247
248 // Here some more accurate check could be placed that would adjust the componentPos
249
250 // Outside of the cone angle!
252 if (componentAngle > settings.ConeHalfAngle)
253 {
254 return false;
255 }
256
257 // Obstructed!
259 {
260 return false;
261 }
262
263 // We found something, fill it in!
264 result.ComponentPos = componentPos;
265 result.ComponentAngle = componentAngle;
266 result.ComponentDistance2 = componentDistance2;
267 result.ComponentIdx = cInfo.component;
268
269 return true;
270 }
bool IsMeleeTargetObstructed(vector rayStart, vector rayEnd)
Definition MeleeTargeting.c:277
Definition EnMath3D.c:28
Definition EnMath.c:7
Definition EnConvert.c:106
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
static proto vector NearestPoint(vector beg, vector end, vector pos)
Point on line beg .. end nearest to pos.
static proto float AngleFromPosition(vector origin, vector originDir, vector target)
Angle that a target is from the direction of an origin.
static proto float SqrFloat(float f)
Returns squared value.
static proto float AbsFloat(float f)
Returns absolute value.
static const float RAD2DEG
Definition EnMath.c:16

Перекрестные ссылки Math::AbsFloat(), Math3D::AngleFromPosition(), vector::DistanceSq(), IsMeleeTargetObstructed(), Math3D::NearestPoint(), Math::RAD2DEG и Math::SqrFloat().

Используется в EvaluateComponent() и FindMostSuitableComponentEx().

◆ FindMostSuitableComponent()

bool FindMostSuitableComponent ( Object obj,
BoxCollidingResult bResult,
MeleeTargetSettings settings,
out float sum,
out ref ComponentResult result )
222 {
224 }
bool FindMostSuitableComponentEx(Object obj, BoxCollidingResult bResult, MeleeTargetSettings settings, out float sum, out ref ComponentResult result, array< string > blacklistedDamageZones)
Definition MeleeTargeting.c:198

Перекрестные ссылки FindMostSuitableComponentEx().

◆ FindMostSuitableComponentEx()

bool FindMostSuitableComponentEx ( Object obj,
BoxCollidingResult bResult,
MeleeTargetSettings settings,
out float sum,
out ref ComponentResult result,
array< string > blacklistedDamageZones )
199 {
200 foreach (ComponentInfo cInfo : bResult.componentInfo)
201 {
203
205 {
206 continue;
207 }
208
209 // Smallest number is a winner
210 float cSum = cResult.ComponentDistance2;
211 if (cSum < sum)
212 {
213 sum = cSum;
214 result = cResult;
215 }
216 }
217
218 return result != null;
219 }
Definition MeleeTargeting.c:65

Перекрестные ссылки EvaluateComponentEx().

Используется в FindMostSuitableComponent() и GetMeleeTargetEx().

◆ GetMeleeTarget()

MeleeTargetData GetMeleeTarget ( MeleeTargetSettings settings,
out array< Object > allTargets = null )
193 {
195 }
MeleeTargetData GetMeleeTargetEx(MeleeTargetSettings settings, out array< Object > allTargets=null, array< string > blacklistedDamageZones=null)
Definition MeleeTargeting.c:76

Перекрестные ссылки GetMeleeTargetEx().

◆ GetMeleeTargetEx()

MeleeTargetData GetMeleeTargetEx ( MeleeTargetSettings settings,
out array< Object > allTargets = null,
array< string > blacklistedDamageZones = null )
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 {
135 continue;
136 }
137
138 // Ready the defaults for the object
139 vector targetPos = obj.GetPosition();
142 int hitComponent = -1;
143
144 float csSum = float.MAX;
145
146 // Find the most suitable component
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 {
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 {
182 retVal = sum;
183 }
184
185 allTargets.Insert(obj);
186 }
187 }
188
189 return ret;
190 }
DiagMenuIDs
Definition EDiagMenuIDs.c:2
const int MAX
Definition EnConvert.c:27
Class that holds parameters to feed into CGame.IsBoxCollidingGeometryProxy.
Definition IsBoxCollidingGeometryProxyClasses.c:3
Definition Debug.c:14
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Definition Debug.c:388
Definition EnDebug.c:233
Definition Building.c:6
Definition MeleeTargeting.c:2
Definition ObjectTyped.c:2
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 Tan(float angle)
Returns tangent of angle in radians.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.

Перекрестные ссылки 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() и Vector().

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

◆ IsMeleeTargetObstructed()

bool IsMeleeTargetObstructed ( vector rayStart,
vector rayEnd )
278 {
279 if (rayStart == rayEnd)
280 {
281 return true; // Not possible to trace when this happens (zero length raycast)
282 }
283
286 float hitFraction;
287
289 }
class ComponentResult MELEE_TARGET_OBSTRUCTION_LAYERS
Definition DayZPhysics.c:124
static proto bool RayCastBullet(vector begPos, vector endPos, PhxInteractionLayers layerMask, Object ignoreObj, out Object hitObject, out vector hitPosition, out vector hitNormal, out float hitFraction)

Перекрестные ссылки MELEE_TARGET_OBSTRUCTION_LAYERS и DayZPhysics::RayCastBullet().

Используется в 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 )
37 {
44
47
48 Dir = dir;
49
50 XZDir = dir;
51 XZDir[1] = 0;
53
55
58
59 // Calculate cone points
61 }
float ConeHalfAngleRad
Definition MeleeTargeting.c:20
vector ConeLeftPoint
Definition MeleeTargeting.c:24
float ConeMinHeight
Definition MeleeTargeting.c:21
float ConeLength
Definition MeleeTargeting.c:18
vector ConeRightPoint
Definition MeleeTargeting.c:25
vector XZDir
Definition MeleeTargeting.c:30
float MaxDist
Definition MeleeTargeting.c:31
EntityAI Attacker
Definition MeleeTargeting.c:33
float ConeMaxHeight
Definition MeleeTargeting.c:22
vector Dir
Definition MeleeTargeting.c:29
class MeleeTargetData ConeOrigin
float ConeHalfAngle
Definition MeleeTargeting.c:19
vector RayStart
Definition MeleeTargeting.c:27
vector RayEnd
Definition MeleeTargeting.c:28
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

Перекрестные ссылки Math::Atan2(), Attacker, ConeHalfAngle, ConeHalfAngleRad, ConeLeftPoint, ConeLength, ConeMaxHeight, ConeMinHeight, ConeOrigin, Math3D::ConePoints(), ConeRightPoint, Math::DEG2RAD, Dir, MaxDist, vector::Normalize(), RayEnd, RayStart, Math::SqrFloat() и XZDir.

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

Переменные

◆ Attacker

EntityAI Attacker

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

◆ ConeHalfAngle

float ConeHalfAngle

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

◆ ConeHalfAngleRad

float ConeHalfAngleRad

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

◆ ConeLeftPoint

vector ConeLeftPoint

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

◆ ConeLength

float ConeLength

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

◆ ConeMaxHeight

float ConeMaxHeight

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

◆ ConeMinHeight

float ConeMinHeight

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

◆ ConeOrigin

class MeleeTargetData ConeOrigin

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

◆ ConeRightPoint

vector ConeRightPoint

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

◆ Dir

vector Dir

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

◆ MaxDist

float MaxDist

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

◆ MELEE_TARGET_OBSTRUCTION_LAYERS

◆ RayEnd

vector RayEnd

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

◆ RayStart

vector RayStart

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

◆ XZDir

vector XZDir

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