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

Go to the source code of this file.

Enumerations

enum  EMeleeHitType {
  NONE = -1 , LIGHT , HEAVY , SPRINT ,
  KICK , FINISHER_LIVERSTAB , FINISHER_NECKSTAB , FINISHER_GENERIC ,
  WPN_HIT , WPN_HIT_BUTTSTOCK , WPN_STAB , WPN_STAB_FINISHER
}
 

Functions

void DayZPlayerImplementMeleeCombat (DayZPlayerImplement player)
 
void Init (DayZPlayerImplement player)
 
void ~DayZPlayerImplementMeleeCombat ()
 
EMeleeHitType GetHitType ()
 
void SetHitZoneIdx (int pHitZone)
 
EntityAI GetTargetEntity ()
 
void SetTargetObject (Object pTarget)
 
int GetHitZoneIdx ()
 component idx
 
vector GetHitPos ()
 
void SetHitPos (vector pHitPos)
 
int GetFinisherType ()
 
void SetFinisherType (int pFinisherType)
 
int GetWeaponMode ()
 
void Reset (InventoryItem weapon, EMeleeHitType hitMask, bool wasHitEvent=false)
 
void ResetTarget ()
 
void Update (InventoryItem weapon, EMeleeHitType hitMask, bool wasHitEvent=false)
 
void CheckMeleeItem ()
 
int SelectWeaponMode (InventoryItem weapon)
 
float GetWeaponRange (InventoryItem weapon, int weaponMode)
 
float GetRange ()
 
float GetAngle ()
 
void TargetSelection ()
 
int TrySelectFinisherType (InventoryItem weapon, EntityAI target)
 General condition for finisher attacks.
 
int DetermineSpecificFinisherType (ItemBase weapon)
 
void InternalResetTarget ()
 
void SetTarget (Object obj, vector hitPos, int hitZone)
 
bool CanObjectBeTargeted (Object obj, bool checkNonAligneAble=false)
 
bool HitZoneSelectionRaycastHelper (out vector hitPos, out int hitZone, out Object target)
 
bool HitZoneSelectionRaycast (out vector hitPos, out int hitZone, out Object target, bool useCamera)
 
void HitZoneSelection ()
 DEPRECATED.
 
bool IsObstructed (Object object)
 DEPRECATED - New function in MeleeTargeting.
 
bool IsEntityBehindEntityInAngle (EntityAI source, EntityAI target, float angle)
 

Variables

enum EMeleeHitType TARGETING_ANGLE_NORMAL = 30.0
 Target selection settings.
 
const float TARGETING_ANGLE_SPRINT = 15.0
 Second Pass: Half angle of cone during sprint.
 
const float TARGETING_MIN_HEIGHT = -2.0
 Second Pass: How deep the cone goes in meters from player position.
 
const float TARGETING_MAX_HEIGHT = 2.0
 Second Pass: How high the cone goes in meters from player position.
 
const float TARGETING_RAY_RADIUS_EX = 0.5
 Second Pass: Max distance from ray projected from player looking direction.
 
const float TARGETING_RAY_RADIUS = 0.25
 DEPRECATED: "HitZoneSelection".
 
const float TARGETING_RAY_DIST = 5.0
 DEPRECATED: "HitZoneSelection".
 
const float TARGETING_RAY_DIST_SHORT = 2.0
 DEPRECATED: "HitZoneSelection".
 
const float RANGE_EXTENDER_NORMAL = 0.65
 General range extension.
 
const float RANGE_EXTENDER_SPRINT = 1.35
 General range extension while in sprint.
 
const string DEFAULT_HIT_ZONE = "Torso"
 DEPRECATED: "HitZoneSelection".
 
ref MeleeTargeting m_MeleeTargeting
 Target selecting "component".
 
Object m_TargetObject
 Targets - types.
 
EMeleeTargetType m_TargetType
 DEPRECATED: Was added but never used..?
 
ref array< Objectm_AllTargetObjects
 All potential targets found during most recent TargetSelection.
 
ref array< typenamem_TargetableObjects
 Typenames of all directly/preferred targetable objects (1st Pass + 2nd Pass)
 
ref array< typenamem_NonAlignableObjects
 Typenames of objects that can be targeted, but are not a priority (3rd Pass)
 
ref array< stringm_BlacklistedDamageZones
 List of blacklisted damage zone names (cannot use indices due to the possible changes when p3d components are recalculated)
 
DayZPlayerImplement m_DZPlayer
 Parent.
 
InventoryItem m_Weapon
 Weapons - cache.
 
int m_WeaponMode
 WeaponMode used during most recent Update.
 
float m_WeaponRange
 WeaponRange used during most recent Update.
 
bool m_ForceUntargetable
 Misc - cache.
 
bool m_SprintAttack
 If most recent attack was a sprint attack.
 
bool m_WasHit
 If most recent attack was.
 
vector m_RayStart
 Start position of most recent HitZoneSelectionRaycast.
 
vector m_RayEnd
 End position of most recent HitZoneSelectionRaycast.
 
vector m_RayEndShort
 DEPRECATED: "HitZoneSelection".
 
EMeleeHitType m_HitType
 Hit type of the most recent attack.
 
int m_HitZoneIdx
 Hit result - cache.
 
int m_FinisherType
 
string m_HitZoneName
 Most recent target HitZone name.
 
vector m_HitPositionWS
 Most recent target position.
 
int m_DebugForcedFinisherType
 

Enumeration Type Documentation

◆ EMeleeHitType

Enumerator
NONE 
LIGHT 
HEAVY 
SPRINT 
KICK 
FINISHER_LIVERSTAB 
FINISHER_NECKSTAB 
FINISHER_GENERIC 
WPN_HIT 
WPN_HIT_BUTTSTOCK 
WPN_STAB 
WPN_STAB_FINISHER 

Definition at line 1 of file DayZPlayerImplementMeleeCombat.c.

Function Documentation

◆ CanObjectBeTargeted()

bool CanObjectBeTargeted ( Object obj,
bool checkNonAligneAble = false )
protected

Definition at line 508 of file DayZPlayerImplementMeleeCombat.c.

509 {
510 return obj && obj.IsAlive() && (obj.IsAnyInherited(m_TargetableObjects) || (checkNonAligneAble && obj.IsAnyInherited(m_NonAlignableObjects)));
511 }
ref array< typename > m_NonAlignableObjects
Typenames of objects that can be targeted, but are not a priority (3rd Pass)
ref array< typename > m_TargetableObjects
Typenames of all directly/preferred targetable objects (1st Pass + 2nd Pass)

References m_NonAlignableObjects, and m_TargetableObjects.

Referenced by TargetSelection().

◆ CheckMeleeItem()

void CheckMeleeItem ( )
private

Definition at line 248 of file DayZPlayerImplementMeleeCombat.c.

249 {
250 if (m_Weapon)
251 {
252 ItemBase item = ItemBase.Cast(m_Weapon.ProcessMeleeItemDamage(GetWeaponMode()));
253
254 if (item && item.GetHierarchyRootPlayer())
255 PlayerBase.Cast(item.GetHierarchyRootPlayer()).SetCheckMeleeItem(item);
256 else if (m_Weapon && m_Weapon.GetHierarchyRootPlayer())
257 PlayerBase.Cast(m_Weapon.GetHierarchyRootPlayer()).SetCheckMeleeItem(ItemBase.Cast(m_Weapon));
258 }
259 }
InventoryItem m_Weapon
Weapons - cache.

References GetWeaponMode(), and m_Weapon.

◆ DayZPlayerImplementMeleeCombat()

void DayZPlayerImplementMeleeCombat ( DayZPlayerImplement player)
private

Definition at line 90 of file DayZPlayerImplementMeleeCombat.c.

91 {
92 Init(player);
93 }
override Widget Init()
Definition DayZGame.c:120

References Init().

Referenced by DayZPlayer::DayZPlayerImplement().

◆ DetermineSpecificFinisherType()

int DetermineSpecificFinisherType ( ItemBase weapon)
protected

Definition at line 468 of file DayZPlayerImplementMeleeCombat.c.

469 {
471 {
473 EMeleeHitType.FINISHER_LIVERSTAB,
474 EMeleeHitType.FINISHER_NECKSTAB
475 };
476
478 }
479
480 if (!weapon || !weapon.GetValidFinishers() || weapon.GetValidFinishers().Count() == 0)
481 return EMeleeHitType.FINISHER_LIVERSTAB;
482
484 int idx = Math.Round(Math.Lerp(0, weapon.GetValidFinishers().Count() - 1, player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSGeneric)));
485 return weapon.GetValidFinishers()[idx];
486 }
DayZPlayerImplement m_DZPlayer
Parent.
int m_DebugForcedFinisherType
Definition EnMath.c:7
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float Round(float f)
Returns mathematical round of value.

References Math::Lerp(), m_DebugForcedFinisherType, m_DZPlayer, and Math::Round().

Referenced by TrySelectFinisherType().

◆ GetAngle()

float GetAngle ( )
protected

Definition at line 322 of file DayZPlayerImplementMeleeCombat.c.

323 {
324 if (m_SprintAttack)
326 else
328 }
bool m_SprintAttack
If most recent attack was a sprint attack.
const float TARGETING_ANGLE_SPRINT
Second Pass: Half angle of cone during sprint.
enum EMeleeHitType TARGETING_ANGLE_NORMAL
Target selection settings.

References m_SprintAttack, TARGETING_ANGLE_NORMAL, and TARGETING_ANGLE_SPRINT.

Referenced by TargetSelection().

◆ GetFinisherType()

int GetFinisherType ( )
private

Definition at line 177 of file DayZPlayerImplementMeleeCombat.c.

178 {
179 return m_FinisherType;
180 }

References m_FinisherType.

Referenced by TargetSelection().

◆ GetHitPos()

vector GetHitPos ( )
private

Definition at line 167 of file DayZPlayerImplementMeleeCombat.c.

168 {
169 return m_HitPositionWS;
170 }
vector m_HitPositionWS
Most recent target position.

References m_HitPositionWS.

◆ GetHitType()

EMeleeHitType GetHitType ( )
private

Definition at line 141 of file DayZPlayerImplementMeleeCombat.c.

142 {
143 return m_HitType;
144 }
EMeleeHitType m_HitType
Hit type of the most recent attack.

References m_HitType.

◆ GetHitZoneIdx()

int GetHitZoneIdx ( )
private

component idx

Definition at line 162 of file DayZPlayerImplementMeleeCombat.c.

163 {
164 return m_HitZoneIdx;
165 }
int m_HitZoneIdx
Hit result - cache.

References m_HitZoneIdx.

◆ GetRange()

float GetRange ( )
protected

Definition at line 317 of file DayZPlayerImplementMeleeCombat.c.

318 {
320 }
float m_WeaponRange
WeaponRange used during most recent Update.
const float RANGE_EXTENDER_NORMAL
General range extension.

References m_WeaponRange, and RANGE_EXTENDER_NORMAL.

Referenced by HitZoneSelectionRaycast(), and TargetSelection().

◆ GetTargetEntity()

EntityAI GetTargetEntity ( )
private

Definition at line 151 of file DayZPlayerImplementMeleeCombat.c.

152 {
153 return EntityAI.Cast(m_TargetObject);
154 }
Object m_TargetObject
Targets - types.

References m_TargetObject.

Referenced by Update().

◆ GetWeaponMode()

int GetWeaponMode ( )
private

Definition at line 187 of file DayZPlayerImplementMeleeCombat.c.

188 {
189 return m_WeaponMode;
190 }
int m_WeaponMode
WeaponMode used during most recent Update.

References m_WeaponMode.

Referenced by CheckMeleeItem(), and HitZoneSelection().

◆ GetWeaponRange()

float GetWeaponRange ( InventoryItem weapon,
int weaponMode )
protected

Definition at line 309 of file DayZPlayerImplementMeleeCombat.c.

310 {
311 if (weapon)
312 return weapon.GetMeleeCombatData().GetModeRange(weaponMode);
313 else
314 return m_DZPlayer.GetMeleeCombatData().GetModeRange(weaponMode);
315 }

References m_DZPlayer.

Referenced by HitZoneSelection(), and Reset().

◆ HitZoneSelection()

void HitZoneSelection ( )
protected

DEPRECATED.

make sure we are in range of the current weapon;

2d only

just for building and transports (big objects)

if no object in cone, set this object from raycast for these special cases

Definition at line 580 of file DayZPlayerImplementMeleeCombat.c.

581 {
584
585 // ray properties
586 vector pos;
587 vector cameraDirection = GetGame().GetCurrentCameraDirection();
588
589 MiscGameplayFunctions.GetHeadBonePos(player, pos);
590 m_RayStart = pos;
593
594 // raycast
597 float hitFraction;
600
602 {
603 m_HitZoneIdx = -1;
604 //Print("HitZoneSelection failed");
605 }
606 else if (hitObjects.Count() > 0)
607 {
608 cursorTarget = hitObjects.Get(0);
609
611 vector playerPos = m_DZPlayer.GetPosition();
614 playerPos[1] = 0;
615 hitPos[1] = 0;
616
619 {
621 if (m_TargetObject == null)
623 }
624
626 {
627 m_HitZoneName = cursorTarget.GetDamageZoneNameByComponentIndex(m_HitZoneIdx);
628 //Print("hit object: " + m_TargetObject + " | component idx: " + m_HitZoneIdx + " | hitzone name: " + m_HitZoneName);
629 }
630 else
631 {
633 m_HitZoneName = DEFAULT_HIT_ZONE; //Default to torso if no zone is targeted
634 }
635 }
636 else
637 {
638 m_HitZoneIdx = -1;
639 //Print("HitZoneSelection failed");
640 }
641 }
PhxInteractionLayers
Definition DayZPhysics.c:2
float GetWeaponRange(InventoryItem weapon, int weaponMode)
vector m_RayEndShort
DEPRECATED: "HitZoneSelection".
const float TARGETING_RAY_DIST_SHORT
DEPRECATED: "HitZoneSelection".
const float TARGETING_RAY_DIST
DEPRECATED: "HitZoneSelection".
vector m_RayStart
Start position of most recent HitZoneSelectionRaycast.
const string DEFAULT_HIT_ZONE
DEPRECATED: "HitZoneSelection".
string m_HitZoneName
Most recent target HitZone name.
vector m_RayEnd
End position of most recent HitZoneSelectionRaycast.
const float TARGETING_RAY_RADIUS
DEPRECATED: "HitZoneSelection".
static proto bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, set< Object > results=NULL, Object with=NULL, Object ignore=NULL, bool sorted=false, bool ground_only=false, int iType=ObjIntersectView, float radius=0.0, CollisionFlags flags=CollisionFlags.NEARESTCONTACT)
Raycasts world by given parameters.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()

References DEFAULT_HIT_ZONE, vector::Distance(), GetGame(), GetWeaponMode(), GetWeaponRange(), m_DZPlayer, m_HitPositionWS, m_HitZoneIdx, m_HitZoneName, m_NonAlignableObjects, m_RayEnd, m_RayEndShort, m_RayStart, m_TargetObject, m_Weapon, DayZPhysics::RaycastRV(), TARGETING_RAY_DIST, TARGETING_RAY_DIST_SHORT, and TARGETING_RAY_RADIUS.

◆ HitZoneSelectionRaycast()

bool HitZoneSelectionRaycast ( out vector hitPos,
out int hitZone,
out Object target,
bool useCamera )
protected

Prevents targeting of objects behind player

Opponent is inside car - targeting range is shorter in that case

Definition at line 522 of file DayZPlayerImplementMeleeCombat.c.

523 {
525
526 vector pos;
527 vector dir;
529 if (useCamera)
530 {
531 // What the player camera is looking at (crosshair)
533 player.GetCurrentCameraTransform(pos, dir, cameraRotation);
534 playerDir = dir;
535 }
536 else
537 {
538 // What the player himself is looking at
539 playerDir = MiscGameplayFunctions.GetHeadingVector(player);
540 dir = GetGame().GetCurrentCameraDirection();
541 MiscGameplayFunctions.GetHeadBonePos(player, pos);
542 }
543
545 if (vector.Dot(dir, playerDir) < 0.5)
546 return false;
547
548 m_RayStart = pos;
549 m_RayEnd = m_RayStart + GetRange() * dir;
550
551 // raycast
554
556 {
557 target = hitObjects[0];
558 m_ForceUntargetable = false;
559
562 if (playerTarget && playerTarget.IsInVehicle())
563 {
564 if (vector.DistanceSq(pos, hitPos) > Math.SqrFloat(GetRange() * 0.5))
565 {
566 m_ForceUntargetable = true;
567 target = null;
569 hitZone = -1;
570 }
571 }
572
573 return true;
574 }
575
576 return false;
577 }
bool m_ForceUntargetable
Misc - cache.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Definition EnConvert.c:271
static const vector Zero
Definition EnConvert.c:110
static proto float SqrFloat(float f)
Returns squared value.

References vector::DistanceSq(), vector::Dot(), GetGame(), GetRange(), m_DZPlayer, m_ForceUntargetable, m_RayEnd, m_RayStart, DayZPhysics::RaycastRV(), Math::SqrFloat(), and vector::Zero.

Referenced by HitZoneSelectionRaycastHelper().

◆ HitZoneSelectionRaycastHelper()

bool HitZoneSelectionRaycastHelper ( out vector hitPos,
out int hitZone,
out Object target )
protected

Definition at line 513 of file DayZPlayerImplementMeleeCombat.c.

514 {
516 // Not sure if desired, as it can give some results that feel a little odd
517 // But it will depend entirely on the player and situation..
518 // I guess the crosshair is hidden while melee anyways though
519 // || ( m_DZPlayer.IsInThirdPerson() && HitZoneSelectionRaycast(hitPos, hitZone, target, true);
520 }
bool HitZoneSelectionRaycast(out vector hitPos, out int hitZone, out Object target, bool useCamera)

References HitZoneSelectionRaycast().

Referenced by TargetSelection().

◆ Init()

void Init ( DayZPlayerImplement player)
private

Definition at line 95 of file DayZPlayerImplementMeleeCombat.c.

96 {
98
100
101 m_HitZoneName = "";
102 m_HitZoneIdx = -1;
103 m_FinisherType = -1;
105
106 m_SprintAttack = false;
107 m_WasHit = false;
108
110 m_TargetType = EMeleeTargetType.ALIGNABLE;
112#ifdef DIAG_DEVELOPER
114#endif
115
117
118 m_TargetableObjects = new array<typename>; //checks against CONFIG hierarchy
122
124 m_NonAlignableObjects.Insert(Building);
130
132 m_BlacklistedDamageZones.Insert("Brain");
133 }
bool m_WasHit
If most recent attack was.
ref array< string > m_BlacklistedDamageZones
List of blacklisted damage zone names (cannot use indices due to the possible changes when p3d compon...
ref MeleeTargeting m_MeleeTargeting
Target selecting "component".
ref array< Object > m_AllTargetObjects
All potential targets found during most recent TargetSelection.
EMeleeTargetType m_TargetType
DEPRECATED: Was added but never used..?
EMeleeTargetType

References m_AllTargetObjects, m_BlacklistedDamageZones, m_DebugForcedFinisherType, m_DZPlayer, m_FinisherType, m_HitPositionWS, m_HitZoneIdx, m_HitZoneName, m_MeleeTargeting, m_NonAlignableObjects, m_SprintAttack, m_TargetableObjects, m_TargetObject, m_TargetType, m_WasHit, and vector::Zero.

◆ InternalResetTarget()

void InternalResetTarget ( )
protected

Definition at line 488 of file DayZPlayerImplementMeleeCombat.c.

489 {
492 m_HitZoneIdx = -1;
493 m_HitZoneName = "";
494 SetFinisherType(-1);
495 }
void SetFinisherType(int pFinisherType)

References m_HitPositionWS, m_HitZoneIdx, m_HitZoneName, m_TargetObject, SetFinisherType(), and vector::Zero.

Referenced by ResetTarget(), and TargetSelection().

◆ IsEntityBehindEntityInAngle()

bool IsEntityBehindEntityInAngle ( EntityAI source,
EntityAI target,
float angle )
private

Definition at line 668 of file DayZPlayerImplementMeleeCombat.c.

669 {
670 vector targetDirection = target.GetDirection();
673 {
674 targetDirection = Vector(targetZombie.GetOrientationSynced(), 0, 0);
675 targetDirection = targetDirection.AnglesToVector();
676 }
677 vector toSourceDirection = (source.GetPosition() - target.GetPosition());
678
679 targetDirection[1] = 0;
680 toSourceDirection[1] = 0;
681
682 targetDirection.Normalize();
683 toSourceDirection.Normalize();
684
687
688 int hitDir = Math.Acos(cosFi) * Math.RAD2DEG;
689
690 if (cross[1] < 0)
691 hitDir = -hitDir;
692
693 return hitDir <= (-180 + angle) || hitDir >= (180 - angle);
694 }
Super root of all classes in Enforce script.
Definition EnScript.c:11
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 Acos(float c)
Returns angle in radians from cosinus.
static const float RAD2DEG
Definition EnMath.c:16

References Math::Acos(), Class::CastTo(), vector::Dot(), Math::RAD2DEG, and Vector().

Referenced by TrySelectFinisherType().

◆ IsObstructed()

bool IsObstructed ( Object object)
protected

DEPRECATED - New function in MeleeTargeting.

not possible to trace when this happens (zero length raycast)

Definition at line 644 of file DayZPlayerImplementMeleeCombat.c.

645 {
646 // check direct visibility of object (obstruction check)
649 float hitFraction;
653
654 if (object)
655 {
656 MiscGameplayFunctions.GetHeadBonePos(player, start);
657 end = start + MiscGameplayFunctions.GetHeadingVector(player) * vector.Distance(player.GetPosition(), object.GetPosition());
658
659 if (end == start)
660 return true;
661
663 }
664
665 return false;
666 }
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 vector::Distance(), m_DZPlayer, and DayZPhysics::RayCastBullet().

◆ Reset()

void Reset ( InventoryItem weapon,
EMeleeHitType hitMask,
bool wasHitEvent = false )
private

◆ ResetTarget()

◆ SelectWeaponMode()

int SelectWeaponMode ( InventoryItem weapon)
protected

melee with firearm

melee weapon attacks - gets mode from the item

bare hand melee mode selection

default bare-hand light attack

Definition at line 265 of file DayZPlayerImplementMeleeCombat.c.

266 {
267 if (weapon)
268 {
270 if (weapon.IsInherited(Weapon))
271 {
272 switch (m_HitType)
273 {
274 case EMeleeHitType.WPN_HIT:
275 return 0;
276 case EMeleeHitType.WPN_HIT_BUTTSTOCK:
277 return 1;
278 case EMeleeHitType.WPN_STAB:
279 return 2;
280 }
281 }
282 else
283 {
285 switch (m_HitType)
286 {
287 case EMeleeHitType.LIGHT:
288 return weapon.GetMeleeMode();
289 case EMeleeHitType.HEAVY:
290 return weapon.GetMeleeHeavyMode();
291 case EMeleeHitType.SPRINT:
292 return weapon.GetMeleeSprintMode();
293 }
294 }
295 }
296
298 switch (m_HitType)
299 {
300 case EMeleeHitType.HEAVY:
301 return 1;
302 case EMeleeHitType.SPRINT:
303 return 2;
304 }
305
306 return 0;
307 }
script counterpart to engine's class Weapon

References m_HitType.

Referenced by Reset().

◆ SetFinisherType()

void SetFinisherType ( int pFinisherType)
private

Definition at line 182 of file DayZPlayerImplementMeleeCombat.c.

183 {
185 }

References m_FinisherType.

Referenced by InternalResetTarget(), and Update().

◆ SetHitPos()

void SetHitPos ( vector pHitPos)
private

Definition at line 172 of file DayZPlayerImplementMeleeCombat.c.

173 {
175 }

References m_HitPositionWS.

◆ SetHitZoneIdx()

void SetHitZoneIdx ( int pHitZone)
private

Definition at line 146 of file DayZPlayerImplementMeleeCombat.c.

147 {
149 }

References m_HitZoneIdx.

◆ SetTarget()

void SetTarget ( Object obj,
vector hitPos,
int hitZone )
protected

Definition at line 497 of file DayZPlayerImplementMeleeCombat.c.

498 {
499 if (obj)
500 {
501 m_TargetObject = obj;
504 m_HitZoneName = m_TargetObject.GetDamageZoneNameByComponentIndex(m_HitZoneIdx);
505 }
506 }

References m_HitPositionWS, m_HitZoneIdx, m_HitZoneName, and m_TargetObject.

Referenced by TargetSelection().

◆ SetTargetObject()

void SetTargetObject ( Object pTarget)
private

Definition at line 156 of file DayZPlayerImplementMeleeCombat.c.

157 {
159 }

References m_TargetObject.

◆ TargetSelection()

void TargetSelection ( )
protected

Definition at line 330 of file DayZPlayerImplementMeleeCombat.c.

331 {
332 // Prepare common variables
334 vector pos = m_DZPlayer.GetPosition();
335 vector rayStart = m_DZPlayer.GetBonePositionWS(m_DZPlayer.GetBoneIndexByName("Head"));
336
338 m_DZPlayer.GetCurrentCameraTransform(cameraPos, cameraDir, cameraRot);
339 vector dir = MiscGameplayFunctions.GetHeadingVector(player);
340 dir[1] = cameraDir[1];
341
342 // Calculate max distances
343 float dist = GetRange();
344 float angle = GetAngle();
345 float dist2 = Math.SqrFloat(dist);
346
347 // There's generally 2 TargetSelection calls per animation
348 // First to obtain target to move towards during animation
349 // Second one is to see if that target is still in range before applying damage to it
350 // m_WasHit means the hit event occured, so this is the second call
351
352 if (m_WasHit && GetFinisherType() == -1)
353 {
354 // See if the component is still in range
356 {
358 // This result should still be cached, so no need to fill it in again
359 return;
360 }
361 }
362
363 // Find a new target
365
368 int hitZone;
369
370 // First pass - Prefer what the player is looking at (only aligneable ones, we will try for nonaligneable later)
372 {
374 {
376 return;
377 }
378
380 {
382
384 return;
385 }
386 }
387
388 // Second pass - Try to obtain something aligneable closeby the player watching direction
390
391 if (targetData)
392 {
393 SetTarget(targetData.Obj, targetData.HitPos, targetData.HitComponent);
394 return;
395 }
396
397 // Third pass - We found no aligneable target, check if the target that we are directly looking at is nonalignable (big)
399 {
401
403 return;
404 }
405 }
void SetTarget(Object obj, vector hitPos, int hitZone)
const float TARGETING_MIN_HEIGHT
Second Pass: How deep the cone goes in meters from player position.
const float TARGETING_MAX_HEIGHT
Second Pass: How high the cone goes in meters from player position.
bool HitZoneSelectionRaycastHelper(out vector hitPos, out int hitZone, out Object target)
const float TARGETING_RAY_RADIUS_EX
Second Pass: Max distance from ray projected from player looking direction.
bool CanObjectBeTargeted(Object obj, bool checkNonAligneAble=false)
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)

References CanObjectBeTargeted(), vector::DistanceSq(), GetAngle(), GetFinisherType(), GetRange(), HitZoneSelectionRaycastHelper(), InternalResetTarget(), m_AllTargetObjects, m_BlacklistedDamageZones, m_DZPlayer, m_ForceUntargetable, m_HitZoneName, m_MeleeTargeting, m_TargetableObjects, m_TargetObject, m_WasHit, MeleeTargetSettings(), SetTarget(), Math::SqrFloat(), TARGETING_MAX_HEIGHT, TARGETING_MIN_HEIGHT, and TARGETING_RAY_RADIUS_EX.

Referenced by Update().

◆ TrySelectFinisherType()

int TrySelectFinisherType ( InventoryItem weapon,
EntityAI target )
protected

General condition for finisher attacks.

Parameters
weaponWeapon used in the attack
targetTarget entity
Returns
int - type of finisher (-1 == no finisher)

perform only for finisher suitable weapons

check if attacker is in right pos and angle against victim

Check if the infected is aware of the player

prone checks

firearm

Definition at line 413 of file DayZPlayerImplementMeleeCombat.c.

414 {
415 if (m_WasHit)
416 return -1;
417
418 if (target)
419 {
420 vector dir = target.GetPosition() - m_DZPlayer.GetPosition();
421
424
425 float moveFraction = m_DZPlayer.CollisionMoveTest(dir, vector.Zero, 1.0, target, hitEntity, hitPos, hitNormal);
426 if (moveFraction < 1.0)
427 return -1;
428 }
429
431 if (target && target.CanBeBackstabbed() && weapon && (weapon.IsMeleeFinisher() || m_HitType == EMeleeHitType.WPN_STAB) && !weapon.IsRuined())
432 {
433 bool playGenericFinisherAnimation = false;
436 {
439 return -1;
440
441 int mindState = targetZombie.GetMindStateSynced();
443 if (mindState >= DayZInfectedConstants.MINDSTATE_DISTURBED)
444 return -1;
445 }
446
449 if (targetZombie)
451 else if (targetPlayer)
453 else
455
457 if (weapon.IsWeapon())
458 return EMeleeHitType.WPN_STAB_FINISHER;
460 return EMeleeHitType.FINISHER_GENERIC;
461 else //specific hit depending on the component hit (gotten from the target)
463 }
464
465 return -1;
466 }
DayZInfectedConstants
Definition DayZInfected.c:2
bool IsEntityBehindEntityInAngle(EntityAI source, EntityAI target, float angle)
int DetermineSpecificFinisherType(ItemBase weapon)

References DetermineSpecificFinisherType(), IsEntityBehindEntityInAngle(), m_DebugForcedFinisherType, m_DZPlayer, m_HitType, m_WasHit, and vector::Zero.

Referenced by Update().

◆ Update()

void Update ( InventoryItem weapon,
EMeleeHitType hitMask,
bool wasHitEvent = false )
private

Store target into input packet

Definition at line 220 of file DayZPlayerImplementMeleeCombat.c.

221 {
223
224#ifndef SERVER
226 {
227 //Error("DayZPlayerImplementMeleeCombat - ScriptInputUserData already posted");
228 return;
229 }
230
233
235 if (GetGame().IsMultiplayer())
236 {
239 ctx.Write(m_TargetObject);
240 ctx.Write(m_HitPositionWS);
241 ctx.Write(m_HitZoneIdx);
242 ctx.Write(m_FinisherType);
243 ctx.Send();
244 }
245#endif
246 }
const int INPUT_UDT_MELEE_TARGET
Definition _constants.c:6
void Reset()
Definition Inventory.c:1018
EntityAI GetTargetEntity()
int TrySelectFinisherType(InventoryItem weapon, EntityAI target)
General condition for finisher attacks.
proto static native bool CanStoreInputUserData()

References ScriptInputUserData::CanStoreInputUserData(), GetGame(), GetTargetEntity(), INPUT_UDT_MELEE_TARGET, m_FinisherType, m_HitPositionWS, m_HitZoneIdx, m_TargetObject, Reset(), SetFinisherType(), TargetSelection(), and TrySelectFinisherType().

◆ ~DayZPlayerImplementMeleeCombat()

Definition at line 135 of file DayZPlayerImplementMeleeCombat.c.

135{}

Variable Documentation

◆ DEFAULT_HIT_ZONE

const string DEFAULT_HIT_ZONE = "Torso"
protected

DEPRECATED: "HitZoneSelection".

Definition at line 34 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelection().

◆ m_AllTargetObjects

ref array<Object> m_AllTargetObjects
protected

All potential targets found during most recent TargetSelection.

Definition at line 42 of file DayZPlayerImplementMeleeCombat.c.

Referenced by DayZInfected::ChaseAttackLogic(), DayZInfected::FightAttackLogic(), DayZInfected::Init(), Init(), Reset(), and TargetSelection().

◆ m_BlacklistedDamageZones

ref array<string> m_BlacklistedDamageZones
protected

List of blacklisted damage zone names (cannot use indices due to the possible changes when p3d components are recalculated)

Definition at line 51 of file DayZPlayerImplementMeleeCombat.c.

Referenced by Init(), and TargetSelection().

◆ m_DebugForcedFinisherType

int m_DebugForcedFinisherType
private

◆ m_DZPlayer

◆ m_FinisherType

int m_FinisherType
protected

Definition at line 74 of file DayZPlayerImplementMeleeCombat.c.

Referenced by GetFinisherType(), Init(), SetFinisherType(), and Update().

◆ m_ForceUntargetable

bool m_ForceUntargetable
protected

Misc - cache.

Forcing current target as untargetable

Definition at line 62 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelectionRaycast(), and TargetSelection().

◆ m_HitPositionWS

vector m_HitPositionWS
protected

Most recent target position.

Definition at line 76 of file DayZPlayerImplementMeleeCombat.c.

Referenced by GetHitPos(), HitZoneSelection(), Init(), InternalResetTarget(), ResetTarget(), SetHitPos(), SetTarget(), and Update().

◆ m_HitType

◆ m_HitZoneIdx

int m_HitZoneIdx
protected

Hit result - cache.

Most recent target HitZone index

Definition at line 73 of file DayZPlayerImplementMeleeCombat.c.

Referenced by GetHitZoneIdx(), HitZoneSelection(), Init(), InternalResetTarget(), ResetTarget(), SetHitZoneIdx(), SetTarget(), and Update().

◆ m_HitZoneName

string m_HitZoneName
protected

Most recent target HitZone name.

Definition at line 75 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelection(), Init(), InternalResetTarget(), ResetTarget(), SetTarget(), and TargetSelection().

◆ m_MeleeTargeting

ref MeleeTargeting m_MeleeTargeting
protected

Target selecting "component".

Contains logic for Second Pass

Definition at line 37 of file DayZPlayerImplementMeleeCombat.c.

Referenced by Init(), and TargetSelection().

◆ m_NonAlignableObjects

ref array<typename> m_NonAlignableObjects
protected

Typenames of objects that can be targeted, but are not a priority (3rd Pass)

Definition at line 50 of file DayZPlayerImplementMeleeCombat.c.

Referenced by CanObjectBeTargeted(), HitZoneSelection(), and Init().

◆ m_RayEnd

vector m_RayEnd
protected

End position of most recent HitZoneSelectionRaycast.

Definition at line 67 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelection(), and HitZoneSelectionRaycast().

◆ m_RayEndShort

vector m_RayEndShort
protected

DEPRECATED: "HitZoneSelection".

Definition at line 68 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelection().

◆ m_RayStart

vector m_RayStart
protected

Start position of most recent HitZoneSelectionRaycast.

Definition at line 66 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelection(), and HitZoneSelectionRaycast().

◆ m_SprintAttack

bool m_SprintAttack
protected

If most recent attack was a sprint attack.

Definition at line 63 of file DayZPlayerImplementMeleeCombat.c.

Referenced by GetAngle(), Init(), and Reset().

◆ m_TargetableObjects

ref array<typename> m_TargetableObjects
protected

Typenames of all directly/preferred targetable objects (1st Pass + 2nd Pass)

Definition at line 49 of file DayZPlayerImplementMeleeCombat.c.

Referenced by CanObjectBeTargeted(), DayZInfected::ChaseAttackLogic(), DayZInfected::FightAttackLogic(), DayZInfected::Init(), Init(), and TargetSelection().

◆ m_TargetObject

◆ m_TargetType

EMeleeTargetType m_TargetType
protected

DEPRECATED: Was added but never used..?

Definition at line 41 of file DayZPlayerImplementMeleeCombat.c.

Referenced by Init(), and Reset().

◆ m_WasHit

bool m_WasHit
protected

If most recent attack was.

Definition at line 64 of file DayZPlayerImplementMeleeCombat.c.

Referenced by Init(), Reset(), TargetSelection(), and TrySelectFinisherType().

◆ m_Weapon

InventoryItem m_Weapon
protected

◆ m_WeaponMode

int m_WeaponMode
protected

WeaponMode used during most recent Update.

Definition at line 58 of file DayZPlayerImplementMeleeCombat.c.

Referenced by GetWeaponMode(), and Reset().

◆ m_WeaponRange

float m_WeaponRange
protected

WeaponRange used during most recent Update.

Definition at line 59 of file DayZPlayerImplementMeleeCombat.c.

Referenced by GetRange(), and Reset().

◆ RANGE_EXTENDER_NORMAL

const float RANGE_EXTENDER_NORMAL = 0.65
protected

General range extension.

Definition at line 31 of file DayZPlayerImplementMeleeCombat.c.

Referenced by GetRange().

◆ RANGE_EXTENDER_SPRINT

const float RANGE_EXTENDER_SPRINT = 1.35
protected

General range extension while in sprint.

Definition at line 32 of file DayZPlayerImplementMeleeCombat.c.

◆ TARGETING_ANGLE_NORMAL

enum EMeleeHitType TARGETING_ANGLE_NORMAL = 30.0

Target selection settings.

Second Pass: Half angle of cone

Referenced by GetAngle().

◆ TARGETING_ANGLE_SPRINT

const float TARGETING_ANGLE_SPRINT = 15.0
protected

Second Pass: Half angle of cone during sprint.

Definition at line 23 of file DayZPlayerImplementMeleeCombat.c.

Referenced by GetAngle().

◆ TARGETING_MAX_HEIGHT

const float TARGETING_MAX_HEIGHT = 2.0
protected

Second Pass: How high the cone goes in meters from player position.

Definition at line 25 of file DayZPlayerImplementMeleeCombat.c.

Referenced by TargetSelection().

◆ TARGETING_MIN_HEIGHT

const float TARGETING_MIN_HEIGHT = -2.0
protected

Second Pass: How deep the cone goes in meters from player position.

Definition at line 24 of file DayZPlayerImplementMeleeCombat.c.

Referenced by TargetSelection().

◆ TARGETING_RAY_DIST

const float TARGETING_RAY_DIST = 5.0
protected

DEPRECATED: "HitZoneSelection".

Definition at line 28 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelection().

◆ TARGETING_RAY_DIST_SHORT

const float TARGETING_RAY_DIST_SHORT = 2.0
protected

DEPRECATED: "HitZoneSelection".

Definition at line 29 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelection().

◆ TARGETING_RAY_RADIUS

const float TARGETING_RAY_RADIUS = 0.25
protected

DEPRECATED: "HitZoneSelection".

Definition at line 27 of file DayZPlayerImplementMeleeCombat.c.

Referenced by HitZoneSelection().

◆ TARGETING_RAY_RADIUS_EX

const float TARGETING_RAY_RADIUS_EX = 0.5
protected

Second Pass: Max distance from ray projected from player looking direction.

Definition at line 26 of file DayZPlayerImplementMeleeCombat.c.

Referenced by TargetSelection().