diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index bd22989e..739d1538 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -1151,15 +1151,16 @@ public: }; -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 { @@ -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; diff --git a/regamedll/dlls/wpn_shared/wpn_knife.cpp b/regamedll/dlls/wpn_shared/wpn_knife.cpp index 18275c04..aa7e177c 100644 --- a/regamedll/dlls/wpn_shared/wpn_knife.cpp +++ b/regamedll/dlls/wpn_shared/wpn_knife.cpp @@ -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); @@ -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 @@ -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); @@ -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); @@ -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,28 +386,27 @@ 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)) { - 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; } } @@ -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;