Skip to content

Commit

Permalink
Shield hit punchangle change logic grouped
Browse files Browse the repository at this point in the history
  • Loading branch information
dystopm committed Aug 13, 2024
1 parent f9969ac commit 5779d61
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
54 changes: 30 additions & 24 deletions regamedll/dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,30 +1443,7 @@ VectorRef CBaseEntity::__API_HOOK(FireBullets3)(VectorRef vecSrc, VectorRef vecD

if (tr.iHitgroup == HITGROUP_SHIELD)
{
EMIT_SOUND(pEntity->edict(), CHAN_VOICE, (RANDOM_LONG(0, 1) == 1) ? "weapons/ric_metal-1.wav" : "weapons/ric_metal-2.wav", VOL_NORM, ATTN_NORM);
UTIL_Sparks(tr.vecEndPos);

pEntity->pev->punchangle.x = iCurrentDamage * RANDOM_FLOAT(-0.15, 0.15);
pEntity->pev->punchangle.z = iCurrentDamage * RANDOM_FLOAT(-0.15, 0.15);

#ifndef REGAMEDLL_FIXES
if (pEntity->pev->punchangle.x < 4)
#else
if (pEntity->pev->punchangle.x < -4)
#endif
{
pEntity->pev->punchangle.x = -4;
}

if (pEntity->pev->punchangle.z < -5)
{
pEntity->pev->punchangle.z = -5;
}
else if (pEntity->pev->punchangle.z > 5)
{
pEntity->pev->punchangle.z = 5;
}

pEntity->HitShield(iCurrentDamage, &tr);
break;
}

Expand Down Expand Up @@ -1503,6 +1480,35 @@ VectorRef CBaseEntity::__API_HOOK(FireBullets3)(VectorRef vecSrc, VectorRef vecD
return vecRet;
}

void CBaseEntity::HitShield(float flDamage, TraceResult *ptr)
{
if (RANDOM_LONG(0, 1))
EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/ric_metal-1.wav", VOL_NORM, ATTN_NORM);
else
EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/ric_metal-2.wav", VOL_NORM, ATTN_NORM);

UTIL_Sparks(ptr->vecEndPos);

#ifdef REGAMEDLL_FIXES
if (Q_fabs(pev->punchangle.x) < 4.0)
{
pev->punchangle.x = clamp(flDamage * RANDOM_FLOAT(-0.15, 0.15), -4.0f, 4.0f);
}
#else
pev->punchangle.x = flDamage * RANDOM_FLOAT(-0.15, 0.15);

if (pev->punchangle.x < 4)
pev->punchangle.x = -4;
#endif

#ifdef REGAMEDLL_FIXES
if (Q_fabs(pev->punchangle.z) < 5.0)
#endif
{
pev->punchangle.z = clamp(flDamage * RANDOM_FLOAT(-0.15, 0.15), -5.0f, 5.0f);
}
}

void CBaseEntity::TraceBleed(float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType)
{
if (BloodColor() == DONT_BLEED)
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class CBaseEntity {
bool Intersects(const Vector &mins, const Vector &maxs);
bool CanTakeHealth(float flHealth = 0.0f) const;
void MakeDormant();
void HitShield(float flDamage, TraceResult* ptr);

// This entity's classname.
const char *GetClassname() const { return pev->classname.str(); }
Expand Down
25 changes: 7 additions & 18 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,27 +640,16 @@ void EXT_FUNC CBasePlayer::__API_HOOK(TraceAttack)(entvars_t *pevAttacker, float

if (bHitShield)
{
#ifndef REGAMEDLL_FIXES
flDamage = 0;
bShouldBleed = false;

if (RANDOM_LONG(0, 1))
EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/ric_metal-1.wav", VOL_NORM, ATTN_NORM);
else
EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/ric_metal-2.wav", VOL_NORM, ATTN_NORM);

UTIL_Sparks(ptr->vecEndPos);

pev->punchangle.x = flDamage * RANDOM_FLOAT(-0.15, 0.15);
pev->punchangle.z = flDamage * RANDOM_FLOAT(-0.15, 0.15);

if (pev->punchangle.x < 4)
pev->punchangle.x = -4;
#endif

if (pev->punchangle.z < -5)
pev->punchangle.z = -5;
bShouldBleed = false;
HitShield(flDamage, ptr);

else if (pev->punchangle.z > 5)
pev->punchangle.z = 5;
#ifdef REGAMEDLL_FIXES
flDamage = 0;
#endif
}
else
{
Expand Down

0 comments on commit 5779d61

Please sign in to comment.