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

Make Knife back stab multiplier customizable #834

Merged
merged 6 commits into from
Jul 1, 2023
Merged
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
43 changes: 33 additions & 10 deletions regamedll/dlls/weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -1151,15 +1151,16 @@ class CHEGrenade: public CBasePlayerWeapon
};


const float KNIFE_BODYHIT_VOLUME = 128.0f;
const float KNIFE_WALLHIT_VOLUME = 512.0f;
const float KNIFE_MAX_SPEED = 250.0f;
const float KNIFE_MAX_SPEED_SHIELD = 180.0f;
const float KNIFE_STAB_DAMAGE = 65.0f;
const float KNIFE_SWING_DAMAGE = 15.0f;
const float KNIFE_SWING_DAMAGE_FAST = 20.0f;
const float KNIFE_STAB_DISTANCE = 32.0f;
const float KNIFE_SWING_DISTANCE = 48.0f;
const float KNIFE_BODYHIT_VOLUME = 128.0f;
const float KNIFE_WALLHIT_VOLUME = 512.0f;
const float KNIFE_MAX_SPEED = 250.0f;
const float KNIFE_MAX_SPEED_SHIELD = 180.0f;
const float KNIFE_STAB_DAMAGE = 65.0f;
const float KNIFE_SWING_DAMAGE = 15.0f;
const float KNIFE_SWING_DAMAGE_FAST = 20.0f;
const float KNIFE_STAB_DISTANCE = 32.0f;
const float KNIFE_SWING_DISTANCE = 48.0f;
const float KNIFE_BACKSTAB_MULTIPLIER = 3.0f;

enum knife_e
{
Expand Down Expand Up @@ -1220,19 +1221,41 @@ class CKnife: public CBasePlayerWeapon
void SetPlayerShieldAnim();
void ResetPlayerShieldAnim();

float KnifeStabDamage() const;
float KnifeSwingDamage(bool fast) const;
float KnifeStabDistance() const;
float KnifeSwingDistance() const;
float KnifeBackStabMultiplier() const;

private:
TraceResult m_trHit;
unsigned short m_usKnife;

// Extra RegameDLL features
#ifdef REGAMEDLL_API
float m_flStabBaseDamage;
float m_flSwingBaseDamage;
float m_flSwingBaseDamage_Fast;

float m_flStabDistance;
float m_flSwingDistance;

float m_flBackStabMultiplier;
#endif
};

#ifdef REGAMEDLL_API
inline float CKnife::KnifeStabDamage() const { return m_flStabBaseDamage; }
inline float CKnife::KnifeSwingDamage(bool fast) const { return fast ? m_flSwingBaseDamage_Fast : m_flSwingBaseDamage; }
inline float CKnife::KnifeStabDistance() const { return m_flStabDistance; }
inline float CKnife::KnifeSwingDistance() const { return m_flSwingDistance; }
inline float CKnife::KnifeBackStabMultiplier() const { return m_flBackStabMultiplier; }
#else
inline float CKnife::KnifeStabDamage() const { return KNIFE_STAB_DAMAGE; }
inline float CKnife::KnifeSwingDamage(bool fast) const { return fast ? KNIFE_SWING_DAMAGE_FAST : KNIFE_SWING_DAMAGE; }
inline float CKnife::KnifeStabDistance() const { return KNIFE_STAB_DISTANCE; }
inline float CKnife::KnifeSwingDistance() const { return KNIFE_SWING_DISTANCE; }
inline float CKnife::KnifeBackStabMultiplier() const { return KNIFE_BACKSTAB_MULTIPLIER; }
#endif // REGAMEDLL_API

const float M249_MAX_SPEED = 220.0f;
const float M249_DAMAGE = 32.0f;
Expand Down
93 changes: 52 additions & 41 deletions regamedll/dlls/wpn_shared/wpn_knife.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ void CKnife::Spawn()
m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN;
m_iClip = WEAPON_NOCLIP;

#ifdef REGAMEDLL_API
m_flStabBaseDamage = KNIFE_STAB_DAMAGE;
m_flSwingBaseDamage = KNIFE_SWING_DAMAGE;
m_flSwingBaseDamage_Fast = KNIFE_SWING_DAMAGE_FAST;

m_flStabDistance = KNIFE_STAB_DISTANCE;
m_flSwingDistance = KNIFE_SWING_DISTANCE;

m_flBackStabMultiplier = KNIFE_BACKSTAB_MULTIPLIER;
#endif

// Get ready to fall down
FallInit();

Expand All @@ -44,12 +48,16 @@ void CKnife::Precache()

m_usKnife = PRECACHE_EVENT(1, "events/knife.sc");

#ifdef REGAMEDLL_API
m_flStabBaseDamage = KNIFE_STAB_DAMAGE;
m_flSwingBaseDamage = KNIFE_SWING_DAMAGE;
m_flSwingBaseDamage_Fast = KNIFE_SWING_DAMAGE_FAST;

m_flStabDistance = KNIFE_STAB_DISTANCE;
m_flSwingDistance = KNIFE_SWING_DISTANCE;

m_flBackStabMultiplier = KNIFE_BACKSTAB_MULTIPLIER;
#endif
}

int CKnife::GetItemInfo(ItemInfo *p)
Expand Down Expand Up @@ -166,14 +174,7 @@ void CKnife::SetPlayerShieldAnim()
if (!m_pPlayer->HasShield())
return;

if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
{
Q_strcpy(m_pPlayer->m_szAnimExtention, "shield");
}
else
{
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldknife");
}
Q_strcpy(m_pPlayer->m_szAnimExtention, (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) != 0 ? "shield" : "shieldknife");
}

void CKnife::ResetPlayerShieldAnim()
Expand Down Expand Up @@ -271,7 +272,7 @@ BOOL CKnife::Swing(BOOL fFirst)
UTIL_MakeVectors(m_pPlayer->pev->v_angle);

vecSrc = m_pPlayer->GetGunPosition();
vecEnd = vecSrc + gpGlobals->v_forward * m_flSwingDistance;
vecEnd = vecSrc + gpGlobals->v_forward * KnifeSwingDistance();

UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer->edict(), &tr);

Expand Down Expand Up @@ -303,8 +304,8 @@ BOOL CKnife::Swing(BOOL fFirst)
{
switch ((m_iSwing++) % 2)
{
case 0: SendWeaponAnim(KNIFE_MIDATTACK1HIT, UseDecrement() != FALSE); break;
case 1: SendWeaponAnim(KNIFE_MIDATTACK2HIT, UseDecrement() != FALSE); break;
case 0: SendWeaponAnim(KNIFE_MIDATTACK1HIT, UseDecrement() != FALSE); break;
case 1: SendWeaponAnim(KNIFE_MIDATTACK2HIT, UseDecrement() != FALSE); break;
}

// miss
Expand All @@ -322,10 +323,15 @@ BOOL CKnife::Swing(BOOL fFirst)
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;

// play wiff or swish sound
if (RANDOM_LONG(0, 1))
EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_slash1.wav", VOL_NORM, ATTN_NORM, 0, 94);
else
EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_slash2.wav", VOL_NORM, ATTN_NORM, 0, 94);
EMIT_SOUND_DYN(m_pPlayer->edict(),
CHAN_WEAPON,
RANDOM_LONG(0, 1) ?
"weapons/knife_slash1.wav" :
"weapons/knife_slash2.wav",
VOL_NORM,
ATTN_NORM,
0,
94);

// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
Expand All @@ -340,8 +346,8 @@ BOOL CKnife::Swing(BOOL fFirst)
{
switch ((m_iSwing++) % 2)
{
case 0: SendWeaponAnim(KNIFE_MIDATTACK1HIT, UseDecrement() != FALSE); break;
case 1: SendWeaponAnim(KNIFE_MIDATTACK2HIT, UseDecrement() != FALSE); break;
case 0: SendWeaponAnim(KNIFE_MIDATTACK1HIT, UseDecrement() != FALSE); break;
case 1: SendWeaponAnim(KNIFE_MIDATTACK2HIT, UseDecrement() != FALSE); break;
}

m_flNextPrimaryAttack = GetNextAttackDelay(0.4);
Expand All @@ -368,39 +374,39 @@ BOOL CKnife::Swing(BOOL fFirst)
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
ClearMultiDamage();

if (m_flNextPrimaryAttack + 0.4f < UTIL_WeaponTimeBase())
pEntity->TraceAttack(m_pPlayer->pev, m_flSwingBaseDamage_Fast, gpGlobals->v_forward, &tr, (DMG_NEVERGIB | DMG_BULLET));
else
pEntity->TraceAttack(m_pPlayer->pev, m_flSwingBaseDamage, gpGlobals->v_forward, &tr, (DMG_NEVERGIB | DMG_BULLET));
pEntity->TraceAttack(m_pPlayer->pev,
KnifeSwingDamage(m_flNextPrimaryAttack + 0.4f < UTIL_WeaponTimeBase()),
gpGlobals->v_forward,
&tr,
(DMG_NEVERGIB | DMG_BULLET));

ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);

#ifndef REGAMEDLL_FIXES
if (pEntity) // -V595
#endif
{
if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE
#ifdef REGAMEDLL_FIXES
if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE && pEntity->Classify() != CLASS_VEHICLE)
#else
if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE)
&& pEntity->Classify() != CLASS_VEHICLE
#endif
)
{
// play thwack or smack sound
switch (RANDOM_LONG(0, 3))
{
case 0: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit1.wav", VOL_NORM, ATTN_NORM); break;
case 1: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit2.wav", VOL_NORM, ATTN_NORM); break;
case 2: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit3.wav", VOL_NORM, ATTN_NORM); break;
case 3: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit4.wav", VOL_NORM, ATTN_NORM); break;
case 0: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit1.wav", VOL_NORM, ATTN_NORM); break;
case 1: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit2.wav", VOL_NORM, ATTN_NORM); break;
case 2: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit3.wav", VOL_NORM, ATTN_NORM); break;
case 3: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit4.wav", VOL_NORM, ATTN_NORM); break;
}

m_pPlayer->m_iWeaponVolume = KNIFE_BODYHIT_VOLUME;

if (!pEntity->IsAlive())
return TRUE;
else
flVol = 0.1f;

flVol = 0.1f;
fHitWorld = FALSE;
}
}
Expand Down Expand Up @@ -449,7 +455,7 @@ BOOL CKnife::Stab(BOOL fFirst)
UTIL_MakeVectors(m_pPlayer->pev->v_angle);

vecSrc = m_pPlayer->GetGunPosition();
vecEnd = vecSrc + gpGlobals->v_forward * m_flStabDistance;
vecEnd = vecSrc + gpGlobals->v_forward * KnifeStabDistance();

UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer->edict(), &tr);

Expand Down Expand Up @@ -486,10 +492,15 @@ BOOL CKnife::Stab(BOOL fFirst)
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f;

// play wiff or swish sound
if (RANDOM_LONG(0, 1))
EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_slash1.wav", VOL_NORM, ATTN_NORM, 0, 94);
else
EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_slash2.wav", VOL_NORM, ATTN_NORM, 0, 94);
EMIT_SOUND_DYN(m_pPlayer->edict(),
CHAN_WEAPON,
RANDOM_LONG(0, 1) ?
"weapons/knife_slash1.wav" :
"weapons/knife_slash2.wav",
VOL_NORM,
ATTN_NORM,
0,
94);

// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
Expand Down Expand Up @@ -517,7 +528,7 @@ BOOL CKnife::Stab(BOOL fFirst)
// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);

float flDamage = m_flStabBaseDamage;
float flDamage = KnifeStabDamage();

if (pEntity && pEntity->IsPlayer())
{
Expand All @@ -532,10 +543,10 @@ BOOL CKnife::Stab(BOOL fFirst)

flDot = DotProduct(vec2LOS, gpGlobals->v_forward.Make2D());

//Triple the damage if we are stabbing them in the back.
// Multiply the damage if we are stabbing them in the back.
if (flDot > 0.80f)
{
flDamage *= 3.0f;
flDamage *= KnifeBackStabMultiplier();
}
}

Expand All @@ -549,11 +560,11 @@ BOOL CKnife::Stab(BOOL fFirst)
if (pEntity) // -V595
#endif
{
if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE
#ifdef REGAMEDLL_FIXES
if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE && pEntity->Classify() != CLASS_VEHICLE)
#else
if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE)
&& pEntity->Classify() != CLASS_VEHICLE
#endif
)
{
EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_stab.wav", VOL_NORM, ATTN_NORM);
m_pPlayer->m_iWeaponVolume = KNIFE_BODYHIT_VOLUME;
Expand Down