Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shield hit punchangle change logic grouped #999

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines +1493 to +1495
Copy link
Contributor

@fl0werD fl0werD Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In original code another logic

}
#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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's useless check because clamp

#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
Loading