Make Knife back stab multiplier customizable (#834)

- Add Backstab multiplier CKnife member with default value
- Adding REGAMEDLL_API macros correctly to extended members of CKnife
- Added inline functions for specific values, considering original and new behaviour
This commit is contained in:
Francisco Muñoz 2023-06-30 22:52:11 -04:00 committed by GitHub
parent e08cf1e72a
commit 12560c2b87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 51 deletions

View File

@ -1160,6 +1160,7 @@ 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
{
@ -1220,19 +1221,41 @@ public:
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;

View File

@ -12,6 +12,7 @@ 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;
@ -19,6 +20,9 @@ void CKnife::Spawn()
m_flStabDistance = KNIFE_STAB_DISTANCE;
m_flSwingDistance = KNIFE_SWING_DISTANCE;
m_flBackStabMultiplier = KNIFE_BACKSTAB_MULTIPLIER;
#endif
// Get ready to fall down
FallInit();
@ -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)
@ -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()
@ -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);
@ -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);
@ -368,10 +374,11 @@ 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);
@ -379,11 +386,11 @@ BOOL CKnife::Swing(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
)
{
// play thwack or smack sound
switch (RANDOM_LONG(0, 3))
@ -398,9 +405,8 @@ BOOL CKnife::Swing(BOOL fFirst)
if (!pEntity->IsAlive())
return TRUE;
else
flVol = 0.1f;
flVol = 0.1f;
fHitWorld = FALSE;
}
}
@ -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);
@ -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);
@ -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())
{
@ -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();
}
}
@ -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;