From e62bf7baece38953b2a72118c6063e0651820887 Mon Sep 17 00:00:00 2001 From: Roy Shapiro <70241434+RoyShapiro@users.noreply.github.com> Date: Fri, 8 Jul 2022 19:36:06 +0300 Subject: [PATCH] HL:Invasion, attempt to more-or-less restore the upstream crowbar code --- dlls/crowbar.cpp | 773 ++++++++++++++++++++++++++--------------------- dlls/weapons.h | 22 +- 2 files changed, 443 insertions(+), 352 deletions(-) diff --git a/dlls/crowbar.cpp b/dlls/crowbar.cpp index 1eaeb66b..7340d472 100644 --- a/dlls/crowbar.cpp +++ b/dlls/crowbar.cpp @@ -1,347 +1,426 @@ -/*** -* -* Copyright (c) 1999, 2000 Valve LLC. All rights reserved. -* -* This product contains software technology licensed from Id -* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. -* All Rights Reserved. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ - -#include "extdll.h" -#include "util.h" -#include "cbase.h" -#include "monsters.h" -#include "weapons.h" -#include "nodes.h" -#include "player.h" -#include "gamerules.h" - -extern void ClientDecal ( TraceResult *pTrace, Vector vecSrc, Vector vecEnd, int crowbar = 0 ); - - -#define CROWBAR_BODYHIT_VOLUME 128 -#define CROWBAR_WALLHIT_VOLUME 512 - -LINK_ENTITY_TO_CLASS( weapon_crowbar, CCrowbar ); - -enum gauss_e { -/* CROWBAR_IDLE = 0, - CROWBAR_DRAW, - CROWBAR_HOLSTER, - CROWBAR_ATTACK1HIT, - CROWBAR_ATTACK1MISS, - CROWBAR_ATTACK2MISS, - CROWBAR_ATTACK2HIT, - CROWBAR_ATTACK3MISS, - CROWBAR_ATTACK3HIT - */ //modif de Julien : nouveau crowbar - CROWBAR_IDLE = 0, - CROWBAR_DRAW, - CROWBAR_ATTACK1HIT, - CROWBAR_ATTACK1MISS, - CROWBAR_ATTACK2HIT, - CROWBAR_ATTACK2MISS, - -}; - - -void CCrowbar::Spawn( ) -{ - Precache( ); - m_iId = WEAPON_CROWBAR; - SET_MODEL(ENT(pev), "models/w_crowbar.mdl"); - m_iClip = -1; - - FallInit();// get ready to fall down. -} - - -void CCrowbar::Precache( void ) -{ - PRECACHE_MODEL("models/v_crowbar.mdl"); - PRECACHE_MODEL("models/w_crowbar.mdl"); - PRECACHE_MODEL("models/p_crowbar.mdl"); - PRECACHE_SOUND("weapons/cbar_hit1.wav"); - PRECACHE_SOUND("weapons/cbar_hit2.wav"); - PRECACHE_SOUND("weapons/cbar_hitbod1.wav"); - PRECACHE_SOUND("weapons/cbar_hitbod2.wav"); - PRECACHE_SOUND("weapons/cbar_hitbod3.wav"); - PRECACHE_SOUND("weapons/cbar_miss1.wav"); -} - -int CCrowbar::GetItemInfo(ItemInfo *p) -{ - p->pszName = STRING(pev->classname); - p->pszAmmo1 = NULL; - p->iMaxAmmo1 = -1; - p->pszAmmo2 = NULL; - p->iMaxAmmo2 = -1; - p->iMaxClip = WEAPON_NOCLIP; - p->iSlot = 0; - p->iPosition = 0; - p->iId = WEAPON_CROWBAR; - p->iWeight = CROWBAR_WEIGHT; - return 1; -} - - - -// modif de julien -int CCrowbar::AddToPlayer( CBasePlayer *pPlayer ) -{ - if ( CBasePlayerWeapon::AddToPlayer( pPlayer ) ) - { - MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev ); - WRITE_BYTE( m_iId ); - MESSAGE_END(); - - m_pPlayer->TextAmmo( TA_CROWBAR ); - - return TRUE; - } - return FALSE; -} - - -BOOL CCrowbar::Deploy( ) -{ - return DefaultDeploy( "models/v_crowbar.mdl", "models/p_crowbar.mdl", CROWBAR_DRAW, "crowbar" ); -} - -void CCrowbar::Holster( int skiplocal /* = 0 */ ) -{ - m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5; -// SendWeaponAnim( CROWBAR_HOLSTER ); -} - - -void FindHullIntersection( const Vector &vecSrc, TraceResult &tr, float *mins, float *maxs, edict_t *pEntity ) -{ - int i, j, k; - float distance; - float *minmaxs[2] = {mins, maxs}; - TraceResult tmpTrace; - Vector vecHullEnd = tr.vecEndPos; - Vector vecEnd; - - distance = 1e6f; - - vecHullEnd = vecSrc + ((vecHullEnd - vecSrc)*2); - UTIL_TraceLine( vecSrc, vecHullEnd, dont_ignore_monsters, pEntity, &tmpTrace ); - if ( tmpTrace.flFraction < 1.0 ) - { - tr = tmpTrace; - return; - } - - for ( i = 0; i < 2; i++ ) - { - for ( j = 0; j < 2; j++ ) - { - for ( k = 0; k < 2; k++ ) - { - vecEnd.x = vecHullEnd.x + minmaxs[i][0]; - vecEnd.y = vecHullEnd.y + minmaxs[j][1]; - vecEnd.z = vecHullEnd.z + minmaxs[k][2]; - - UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, pEntity, &tmpTrace ); - if ( tmpTrace.flFraction < 1.0 ) - { - float thisDistance = (tmpTrace.vecEndPos - vecSrc).Length(); - if ( thisDistance < distance ) - { - tr = tmpTrace; - distance = thisDistance; - } - } - } - } - } -} - - -void CCrowbar::PrimaryAttack() -{ - if (! Swing( 1 )) - { - SetThink( &CCrowbar::SwingAgain ); - pev->nextthink = gpGlobals->time + 0.1; - } -} - - -void CCrowbar::Smack( ) -{ - //modif de Julien - d - //DecalGunshot( &m_trHit, BULLET_PLAYER_CROWBAR ); - ClientDecal ( &m_trHit, m_vecDecalSrc, m_vecDecalEnd, 1+ (m_iSwing+1) % 2 ); - -} - - -void CCrowbar::SwingAgain( void ) -{ - Swing( 0 ); -} - - -int CCrowbar::Swing( int fFirst ) -{ - int fDidHit = FALSE; - - TraceResult tr; - - UTIL_MakeVectors (m_pPlayer->pev->v_angle); - Vector vecSrc = m_pPlayer->GetGunPosition( ); - Vector vecEnd = vecSrc + gpGlobals->v_forward * 32; - - UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, ENT( m_pPlayer->pev ), &tr ); - - if ( tr.flFraction >= 1.0 ) - { - UTIL_TraceHull( vecSrc, vecEnd, dont_ignore_monsters, head_hull, ENT( m_pPlayer->pev ), &tr ); - if ( tr.flFraction < 1.0 ) - { - // Calculate the point of intersection of the line (or hull) and the object we hit - // This is and approximation of the "best" intersection - CBaseEntity *pHit = CBaseEntity::Instance( tr.pHit ); - if ( !pHit || pHit->IsBSPModel() ) - FindHullIntersection( vecSrc, tr, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, m_pPlayer->edict() ); - vecEnd = tr.vecEndPos; // This is the point on the actual surface (the hull could have hit space) - } - } - - if ( tr.flFraction >= 1.0 ) - { - if (fFirst) - { - // miss - switch( (m_iSwing++) % 2/*3*/ ) - { - case 0: - SendWeaponAnim( CROWBAR_ATTACK1MISS ); break; - case 1: - SendWeaponAnim( CROWBAR_ATTACK2MISS ); break; -/* case 2: - SendWeaponAnim( CROWBAR_ATTACK3MISS ); break; -*/ } - m_flNextPrimaryAttack = gpGlobals->time + 0.5; - // play wiff or swish sound - EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/cbar_miss1.wav", 1, ATTN_NORM, 0, 94 + RANDOM_LONG(0,0xF)); - - // player "shoot" animation - m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); - } - } - else - { - // hit - fDidHit = TRUE; - - CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit); - - switch( ((m_iSwing++) % 2) /*+ 1*/ ) - { - case 0: - SendWeaponAnim( CROWBAR_ATTACK1HIT ); break; - case 1: - SendWeaponAnim( CROWBAR_ATTACK2HIT ); break; -/* case 2: - SendWeaponAnim( CROWBAR_ATTACK3HIT ); break; -*/ } - - // player "shoot" animation - m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); - - ClearMultiDamage( ); - if ( (m_flNextPrimaryAttack + 1 < gpGlobals->time) || g_pGameRules->IsMultiplayer() ) - { - // first swing does full damage - pEntity->TraceAttack(m_pPlayer->pev, gSkillData.plrDmgCrowbar, gpGlobals->v_forward, &tr, DMG_CLUB ); - } - else - { - // subsequent swings do half - pEntity->TraceAttack(m_pPlayer->pev, gSkillData.plrDmgCrowbar / 2, gpGlobals->v_forward, &tr, DMG_CLUB ); - } - ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev ); - - m_flNextPrimaryAttack = gpGlobals->time + 0.25; - - // play thwack, smack, or dong sound - float flVol = 1.0; - int fHitWorld = TRUE; - - if (pEntity) - { - if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE) - { - // play thwack or smack sound - switch( RANDOM_LONG(0,2) ) - { - case 0: - EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/cbar_hitbod1.wav", 1, ATTN_NORM); break; - case 1: - EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/cbar_hitbod2.wav", 1, ATTN_NORM); break; - case 2: - EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/cbar_hitbod3.wav", 1, ATTN_NORM); break; - } - m_pPlayer->m_iWeaponVolume = CROWBAR_BODYHIT_VOLUME; - if (!pEntity->IsAlive() ) - return TRUE; - else - flVol = 0.1; - - fHitWorld = FALSE; - } - } - - // play texture hit sound - // UNDONE: Calculate the correct point of intersection when we hit with the hull instead of the line - - if (fHitWorld) - { - float fvolbar = TEXTURETYPE_PlaySound(&tr, vecSrc, vecSrc + (vecEnd-vecSrc)*2, BULLET_PLAYER_CROWBAR); - - if ( g_pGameRules->IsMultiplayer() ) - { - // override the volume here, cause we don't play texture sounds in multiplayer, - // and fvolbar is going to be 0 from the above call. - - fvolbar = 1; - } - - // also play crowbar strike - switch( RANDOM_LONG(0,1) ) - { - case 0: - //UTIL_EmitAmbientSound(ENT(0), ptr->vecEndPos, "weapons/cbar_hit1.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG(0,3)); - EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/cbar_hit1.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG(0,3)); - break; - case 1: - //UTIL_EmitAmbientSound(ENT(0), ptr->vecEndPos, "weapons/cbar_hit2.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG(0,3)); - EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/cbar_hit2.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG(0,3)); - break; - } - } - - // delay the decal a bit - m_trHit = tr; - m_vecDecalSrc = vecSrc; - m_vecDecalEnd = vecEnd; - SetThink( &CCrowbar::Smack ); - pev->nextthink = gpGlobals->time + 0.2; - - m_pPlayer->m_iWeaponVolume = flVol * CROWBAR_WALLHIT_VOLUME; - } - return fDidHit; -} - - - +/*** +* +* Copyright (c) 1996-2002, Valve LLC. All rights reserved. +* +* This product contains software technology licensed from Id +* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. +* All Rights Reserved. +* +* Use, distribution, and modification of this source code and/or resulting +* object code is restricted to non-commercial enhancements to products from +* Valve LLC. All other use, distribution, or modification is prohibited +* without written permission from Valve LLC. +* +****/ + +#include "extdll.h" +#include "util.h" +#include "cbase.h" +#include "monsters.h" +#include "weapons.h" +#include "nodes.h" +#include "player.h" +#include "gamerules.h" + +extern void ClientDecal ( TraceResult *pTrace, Vector vecSrc, Vector vecEnd, int crowbar = 0 ); + +#define CROWBAR_BODYHIT_VOLUME 128 +#define CROWBAR_WALLHIT_VOLUME 512 + +LINK_ENTITY_TO_CLASS( weapon_crowbar, CCrowbar ) + +enum crowbar_e +{ +/* CROWBAR_IDLE = 0, + CROWBAR_DRAW, + CROWBAR_HOLSTER, + CROWBAR_ATTACK1HIT, + CROWBAR_ATTACK1MISS, + CROWBAR_ATTACK2MISS, + CROWBAR_ATTACK2HIT, + CROWBAR_ATTACK3MISS, +#if !CROWBAR_IDLE_ANIM + CROWBAR_ATTACK3HIT +#else + CROWBAR_ATTACK3HIT, + CROWBAR_IDLE2, + CROWBAR_IDLE3 +#endif +*/ + CROWBAR_IDLE = 0, //modif de Julien : nouveau crowbar + CROWBAR_DRAW, + CROWBAR_ATTACK1HIT, + CROWBAR_ATTACK1MISS, + CROWBAR_ATTACK2HIT, + CROWBAR_ATTACK2MISS, +}; + +void CCrowbar::Spawn() +{ + Precache(); + m_iId = WEAPON_CROWBAR; + SET_MODEL( ENT( pev ), "models/w_crowbar.mdl" ); + m_iClip = -1; + + FallInit();// get ready to fall down. +} + +void CCrowbar::Precache( void ) +{ + PRECACHE_MODEL( "models/v_crowbar.mdl" ); + PRECACHE_MODEL( "models/w_crowbar.mdl" ); + PRECACHE_MODEL( "models/p_crowbar.mdl" ); + PRECACHE_SOUND( "weapons/cbar_hit1.wav" ); + PRECACHE_SOUND( "weapons/cbar_hit2.wav" ); + PRECACHE_SOUND( "weapons/cbar_hitbod1.wav" ); + PRECACHE_SOUND( "weapons/cbar_hitbod2.wav" ); + PRECACHE_SOUND( "weapons/cbar_hitbod3.wav" ); + PRECACHE_SOUND( "weapons/cbar_miss1.wav" ); + + //m_usCrowbar = PRECACHE_EVENT( 1, "events/crowbar.sc" ); +} + +int CCrowbar::GetItemInfo( ItemInfo *p ) +{ + p->pszName = STRING( pev->classname ); + p->pszAmmo1 = NULL; + p->iMaxAmmo1 = -1; + p->pszAmmo2 = NULL; + p->iMaxAmmo2 = -1; + p->iMaxClip = WEAPON_NOCLIP; + p->iSlot = 0; + p->iPosition = 0; + p->iId = WEAPON_CROWBAR; + p->iWeight = CROWBAR_WEIGHT; + return 1; +} + +// modif de julien +int CCrowbar::AddToPlayer( CBasePlayer *pPlayer ) +{ + if ( CBasePlayerWeapon::AddToPlayer( pPlayer ) ) + { + MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev ); + WRITE_BYTE( m_iId ); + MESSAGE_END(); + + m_pPlayer->TextAmmo( TA_CROWBAR ); + + return TRUE; + } + return FALSE; +} + +BOOL CCrowbar::Deploy() +{ + return DefaultDeploy( "models/v_crowbar.mdl", "models/p_crowbar.mdl", CROWBAR_DRAW, "crowbar" ); +} + +void CCrowbar::Holster( int skiplocal /* = 0 */ ) +{ + m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f; + //SendWeaponAnim( CROWBAR_HOLSTER ); //modif de Roy +} + +void FindHullIntersection( const Vector &vecSrc, TraceResult &tr, float *mins, float *maxs, edict_t *pEntity ) +{ + int i, j, k; + float distance; + float *minmaxs[2] = {mins, maxs}; + TraceResult tmpTrace; + Vector vecHullEnd = tr.vecEndPos; + Vector vecEnd; + + distance = 1e6f; + + vecHullEnd = vecSrc + ( ( vecHullEnd - vecSrc ) * 2.0f ); + UTIL_TraceLine( vecSrc, vecHullEnd, dont_ignore_monsters, pEntity, &tmpTrace ); + if( tmpTrace.flFraction < 1.0f ) + { + tr = tmpTrace; + return; + } + + for( i = 0; i < 2; i++ ) + { + for( j = 0; j < 2; j++ ) + { + for( k = 0; k < 2; k++ ) + { + vecEnd.x = vecHullEnd.x + minmaxs[i][0]; + vecEnd.y = vecHullEnd.y + minmaxs[j][1]; + vecEnd.z = vecHullEnd.z + minmaxs[k][2]; + + UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, pEntity, &tmpTrace ); + if( tmpTrace.flFraction < 1.0f ) + { + float thisDistance = ( tmpTrace.vecEndPos - vecSrc ).Length(); + if( thisDistance < distance ) + { + tr = tmpTrace; + distance = thisDistance; + } + } + } + } + } +} + +void CCrowbar::PrimaryAttack() +{ + if( !Swing( 1 ) ) + { +#if !CLIENT_DLL + SetThink( &CCrowbar::SwingAgain ); + pev->nextthink = gpGlobals->time + 0.1f; +#endif + } +} + +void CCrowbar::Smack() +{ + //DecalGunshot( &m_trHit, BULLET_PLAYER_CROWBAR ); //modif de Roy, add Julien's decal model + ClientDecal ( &m_trHit, m_vecDecalSrc, m_vecDecalEnd, 1+ (m_iSwing+1) % 2 ); +} + +void CCrowbar::SwingAgain( void ) +{ + Swing( 0 ); +} + +void CCrowbar::SendWeaponAnim( int iAnim, int skiplocal, int body ) //Fix??? +{ + skiplocal = 0; + + m_pPlayer->pev->weaponanim = iAnim; + +#if CLIENT_WEAPONS + if( skiplocal && ENGINE_CANSKIP( m_pPlayer->edict() ) ) + return; +#endif + MESSAGE_BEGIN( MSG_ONE, SVC_WEAPONANIM, NULL, m_pPlayer->pev ); + WRITE_BYTE( iAnim ); // sequence number + WRITE_BYTE( pev->body ); // weaponmodel bodygroup. + MESSAGE_END(); +} + +int CCrowbar::Swing( int fFirst ) +{ + int fDidHit = FALSE; + + TraceResult tr; + + UTIL_MakeVectors( m_pPlayer->pev->v_angle ); + Vector vecSrc = m_pPlayer->GetGunPosition(); + Vector vecEnd = vecSrc + gpGlobals->v_forward * 32.0f; + + UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, ENT( m_pPlayer->pev ), &tr ); + +#if !CLIENT_DLL + if( tr.flFraction >= 1.0f ) + { + UTIL_TraceHull( vecSrc, vecEnd, dont_ignore_monsters, head_hull, ENT( m_pPlayer->pev ), &tr ); + if( tr.flFraction < 1.0f ) + { + // Calculate the point of intersection of the line (or hull) and the object we hit + // This is and approximation of the "best" intersection + CBaseEntity *pHit = CBaseEntity::Instance( tr.pHit ); + if( !pHit || pHit->IsBSPModel() ) + FindHullIntersection( vecSrc, tr, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, m_pPlayer->edict() ); + vecEnd = tr.vecEndPos; // This is the point on the actual surface (the hull could have hit space) + } + } +#endif + if( fFirst ) + { + /*PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_usCrowbar, + 0.0f, g_vecZero, g_vecZero, 0, 0, 0, + 0, 0, 0 );*/ //Removed as suggested by nekonomicon, edit de Roy + } + + if( tr.flFraction >= 1.0f ) + { + if( fFirst ) + { + // miss + switch( (m_iSwing++) % 2/*3*/ ) + { + case 0: + SendWeaponAnim( CROWBAR_ATTACK1MISS ); break; + case 1: + SendWeaponAnim( CROWBAR_ATTACK2MISS ); break; +/* case 2: + SendWeaponAnim( CROWBAR_ATTACK3MISS ); break; +*/ } + // miss + m_flNextPrimaryAttack = GetNextAttackDelay( 0.5 ); + // play wiff or swish sound + EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/cbar_miss1.wav", 1, ATTN_NORM, 0, 94 + RANDOM_LONG(0,0xF)); +#if CROWBAR_IDLE_ANIM + m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); +#endif + // player "shoot" animation + m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); + } + } + else + { + switch( ( ( m_iSwing++ ) % 2 ) /*+ 1*/ ) //modif de Roy a-la Julien, we don't have Attack3hit here. + { + case 0: + SendWeaponAnim( CROWBAR_ATTACK1HIT ); + break; + case 1: + SendWeaponAnim( CROWBAR_ATTACK2HIT ); + break; + /*case 2: + SendWeaponAnim( CROWBAR_ATTACK3HIT ); + break;*/ + } + + // player "shoot" animation + m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); + +#if !CLIENT_DLL + // hit + fDidHit = TRUE; + CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit ); + + // play thwack, smack, or dong sound + float flVol = 1.0f; + int fHitWorld = TRUE; + + if( pEntity ) + { + ClearMultiDamage(); + // If building with the clientside weapon prediction system, + // UTIL_WeaponTimeBase() is always 0 and m_flNextPrimaryAttack is >= -1.0f, thus making + // m_flNextPrimaryAttack + 1 < UTIL_WeaponTimeBase() always evaluate to false. +#if CLIENT_WEAPONS + if( ( m_flNextPrimaryAttack + 1.0f == UTIL_WeaponTimeBase() ) || g_pGameRules->IsMultiplayer() ) +#else + if( ( m_flNextPrimaryAttack + 1.0f < UTIL_WeaponTimeBase() ) || g_pGameRules->IsMultiplayer() ) +#endif + { + // first swing does full damage + pEntity->TraceAttack( m_pPlayer->pev, gSkillData.plrDmgCrowbar, gpGlobals->v_forward, &tr, DMG_CLUB ); + } + else + { + // subsequent swings do half + pEntity->TraceAttack( m_pPlayer->pev, gSkillData.plrDmgCrowbar * 0.5f, gpGlobals->v_forward, &tr, DMG_CLUB ); + } + ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev ); + + if( pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE ) + { + // play thwack or smack sound + switch( RANDOM_LONG( 0, 2 ) ) + { + case 0: + EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hitbod1.wav", 1.0f, ATTN_NORM ); + break; + case 1: + EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hitbod2.wav", 1.0f, ATTN_NORM ); + break; + case 2: + EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hitbod3.wav", 1.0f, ATTN_NORM ); + break; + } + + m_pPlayer->m_iWeaponVolume = CROWBAR_BODYHIT_VOLUME; + + if( !pEntity->IsAlive() ) + { +#if CROWBAR_FIX_RAPID_CROWBAR + m_flNextPrimaryAttack = GetNextAttackDelay(0.25); +#endif + return TRUE; + } + else + flVol = 0.1f; + + fHitWorld = FALSE; + } + } + + // play texture hit sound + // UNDONE: Calculate the correct point of intersection when we hit with the hull instead of the line + + if( fHitWorld ) + { + float fvolbar = TEXTURETYPE_PlaySound( &tr, vecSrc, vecSrc + ( vecEnd - vecSrc ) * 2.0f, BULLET_PLAYER_CROWBAR ); + + if( g_pGameRules->IsMultiplayer() ) + { + // override the volume here, cause we don't play texture sounds in multiplayer, + // and fvolbar is going to be 0 from the above call. + + fvolbar = 1.0f; + } + + // also play crowbar strike + switch( RANDOM_LONG( 0, 1 ) ) + { + case 0: + EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hit1.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG( 0, 3 ) ); + break; + case 1: + EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hit2.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG( 0, 3 ) ); + break; + } + + // delay the decal a bit + m_trHit = tr; + } + + m_pPlayer->m_iWeaponVolume = (int)( flVol * CROWBAR_WALLHIT_VOLUME ); + + // delay the decal a bit, modif de Roy + m_trHit = tr; + m_vecDecalSrc = vecSrc; + m_vecDecalEnd = vecEnd; + SetThink( &CCrowbar::Smack ); + pev->nextthink = gpGlobals->time + 0.2f; +#endif +#if CROWBAR_DELAY_FIX + m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.25f; +#else + m_flNextPrimaryAttack = GetNextAttackDelay( 0.25f ); +#endif + } +#if CROWBAR_IDLE_ANIM + m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); +#endif + return fDidHit; +} + +#if CROWBAR_IDLE_ANIM +void CCrowbar::WeaponIdle( void ) +{ + if( m_flTimeWeaponIdle < UTIL_WeaponTimeBase() ) + { + int iAnim; + float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 ); + if( flRand > 0.9f ) + { + iAnim = CROWBAR_IDLE2; + m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 160.0f / 30.0f; + } + else + { + if( flRand > 0.5f ) + { + iAnim = CROWBAR_IDLE; + m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 70.0f / 30.0f; + } + else + { + iAnim = CROWBAR_IDLE3; + m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 160.0f / 30.0f; + } + } + SendWeaponAnim( iAnim ); + } +} +#endif diff --git a/dlls/weapons.h b/dlls/weapons.h index 5427f35b..8ea663a5 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -571,21 +571,33 @@ public: int iItemSlot( void ) { return 1; } void EXPORT SwingAgain( void ); void EXPORT Smack( void ); - int GetItemInfo(ItemInfo *p); + int GetItemInfo( ItemInfo *p ); + int AddToPlayer( CBasePlayer *pPlayer ); + void SendWeaponAnim( int iAnim, int skiplocal = 1, int body = 0 ); // skiplocal is 1 if client is predicting weapon animations void PrimaryAttack( void ); int Swing( int fFirst ); BOOL Deploy( void ); void Holster( int skiplocal = 0 ); +#if CROWBAR_IDLE_ANIM + void WeaponIdle(); +#endif int m_iSwing; TraceResult m_trHit; - Vector m_vecDecalSrc; + Vector m_vecDecalSrc; //modif de Roy Vector m_vecDecalEnd; - // modif de julien - int AddToPlayer( CBasePlayer *pPlayer ); - + virtual BOOL UseDecrement( void ) + { +#if CLIENT_WEAPONS + return TRUE; +#else + return FALSE; +#endif + } +private: + unsigned short m_usCrowbar; }; class CPython : public CBasePlayerWeapon