Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

363 lines
9.0 KiB

9 years ago
/***
*
* 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"
#define CROWBAR_BODYHIT_VOLUME 128
#define CROWBAR_WALLHIT_VOLUME 512
LINK_ENTITY_TO_CLASS( weapon_crowbar, CCrowbar )
9 years ago
enum crowbar_e
8 years ago
{
9 years ago
CROWBAR_IDLE = 0,
CROWBAR_DRAW,
CROWBAR_HOLSTER,
CROWBAR_AIM,
CROWBAR_HOLD,
CROWBAR_RELEASEHIT,
CROWBAR_RELEASEMISS
9 years ago
};
void CCrowbar::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
m_iId = WEAPON_CROWBAR;
8 years ago
SET_MODEL( ENT( pev ), "models/w_crowbar.mdl" );
9 years ago
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" );
8 years ago
m_usCrowbar = PRECACHE_EVENT( 1, "events/crowbar.sc" );
9 years ago
}
8 years ago
int CCrowbar::GetItemInfo( ItemInfo *p )
9 years ago
{
8 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = NULL;
p->iMaxAmmo1 = -1;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 0;
p->iPosition = 2;
9 years ago
p->iId = WEAPON_CROWBAR;
p->iWeight = CROWBAR_WEIGHT;
return 1;
}
int CCrowbar::AddToPlayer( CBasePlayer *pPlayer )
{
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
8 years ago
BOOL CCrowbar::Deploy()
9 years ago
{
m_flReleaseThrow = -1;
9 years ago
return DefaultDeploy( "models/v_crowbar.mdl", "models/p_crowbar.mdl", CROWBAR_DRAW, "crowbar" );
}
BOOL CCrowbar::CanHolster( void )
{
// can only holster crowbar when not primed!
return ( m_flStartThrow == 0 );
}
9 years ago
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 )
{
8 years ago
int i, j, k;
9 years ago
float distance;
float *minmaxs[2] = {mins, maxs};
8 years ago
TraceResult tmpTrace;
9 years ago
Vector vecHullEnd = tr.vecEndPos;
Vector vecEnd;
distance = 1e6f;
8 years ago
vecHullEnd = vecSrc + ( ( vecHullEnd - vecSrc ) * 2 );
9 years ago
UTIL_TraceLine( vecSrc, vecHullEnd, dont_ignore_monsters, pEntity, &tmpTrace );
8 years ago
if( tmpTrace.flFraction < 1.0 )
9 years ago
{
tr = tmpTrace;
return;
}
8 years ago
for( i = 0; i < 2; i++ )
9 years ago
{
8 years ago
for( j = 0; j < 2; j++ )
9 years ago
{
8 years ago
for( k = 0; k < 2; k++ )
9 years ago
{
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 );
8 years ago
if( tmpTrace.flFraction < 1.0 )
9 years ago
{
8 years ago
float thisDistance = ( tmpTrace.vecEndPos - vecSrc ).Length();
if( thisDistance < distance )
9 years ago
{
tr = tmpTrace;
distance = thisDistance;
}
}
}
}
}
}
void CCrowbar::PrimaryAttack()
{
if( !m_flStartThrow )
9 years ago
{
m_flStartThrow = gpGlobals->time;
m_flReleaseThrow = 0;
SendWeaponAnim( CROWBAR_AIM );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.45;
}
else if( m_flTimeWeaponIdle <= UTIL_WeaponTimeBase() )
{
SendWeaponAnim( CROWBAR_HOLD );
9 years ago
}
}
8 years ago
void CCrowbar::Smack()
9 years ago
{
DecalGunshot( &m_trHit, BULLET_PLAYER_CROWBAR );
}
void CCrowbar::SwingAgain( void )
{
Swing( 0 );
}
int CCrowbar::Swing( int fFirst )
{
int fDidHit = FALSE;
TraceResult tr;
8 years ago
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
Vector vecSrc = m_pPlayer->GetGunPosition();
Vector vecEnd = vecSrc + gpGlobals->v_forward * 32;
9 years ago
UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, ENT( m_pPlayer->pev ), &tr );
#ifndef CLIENT_DLL
8 years ago
if( tr.flFraction >= 1.0 )
9 years ago
{
UTIL_TraceHull( vecSrc, vecEnd, dont_ignore_monsters, head_hull, ENT( m_pPlayer->pev ), &tr );
8 years ago
if( tr.flFraction < 1.0 )
9 years ago
{
// 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 );
8 years ago
if( !pHit || pHit->IsBSPModel() )
9 years ago
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.0, (float *)&g_vecZero, (float *)&g_vecZero, 0, 0, 0,
0, 0, 0 );
}
9 years ago
8 years ago
if( tr.flFraction >= 1.0 )
9 years ago
{
8 years ago
if( fFirst )
9 years ago
{
// miss
m_flNextPrimaryAttack = GetNextAttackDelay( 0.5 );
9 years ago
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
}
}
else
{
SendWeaponAnim( CROWBAR_RELEASEHIT );
9 years ago
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
8 years ago
#ifndef CLIENT_DLL
9 years ago
// hit
fDidHit = TRUE;
8 years ago
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
9 years ago
// play thwack, smack, or dong sound
float flVol = 1.0;
int fHitWorld = TRUE;
9 years ago
8 years ago
if( pEntity )
9 years ago
{
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.
#ifdef CLIENT_WEAPONS
if( ( m_flNextPrimaryAttack + 1 == UTIL_WeaponTimeBase() ) || g_pGameRules->IsMultiplayer() )
#else
if( ( m_flNextPrimaryAttack + 1 < 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 / 2, gpGlobals->v_forward, &tr, DMG_CLUB );
}
ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev );
8 years ago
if( pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE )
9 years ago
{
// play thwack or smack sound
8 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
case 0:
8 years ago
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hitbod1.wav", 1, ATTN_NORM );
break;
9 years ago
case 1:
8 years ago
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hitbod2.wav", 1, ATTN_NORM );
break;
9 years ago
case 2:
8 years ago
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hitbod3.wav", 1, ATTN_NORM );
break;
9 years ago
}
m_pPlayer->m_iWeaponVolume = CROWBAR_BODYHIT_VOLUME;
8 years ago
if( !pEntity->IsAlive() )
return TRUE;
9 years ago
else
8 years ago
flVol = 0.1;
9 years ago
fHitWorld = FALSE;
}
}
// play texture hit sound
// UNDONE: Calculate the correct point of intersection when we hit with the hull instead of the line
8 years ago
if( fHitWorld )
9 years ago
{
8 years ago
float fvolbar = TEXTURETYPE_PlaySound( &tr, vecSrc, vecSrc + ( vecEnd - vecSrc ) * 2, BULLET_PLAYER_CROWBAR );
9 years ago
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
// 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
8 years ago
switch( RANDOM_LONG( 0, 1 ) )
9 years ago
{
case 0:
8 years ago
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hit1.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG( 0, 3 ) );
9 years ago
break;
case 1:
8 years ago
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/cbar_hit2.wav", fvolbar, ATTN_NORM, 0, 98 + RANDOM_LONG( 0, 3 ) );
9 years ago
break;
}
// delay the decal a bit
m_trHit = tr;
}
m_pPlayer->m_iWeaponVolume = (int)( flVol * CROWBAR_WALLHIT_VOLUME );
8 years ago
9 years ago
SetThink( &CCrowbar::Smack );
pev->nextthink = UTIL_WeaponTimeBase() + 0.2;
#endif
m_flNextPrimaryAttack = GetNextAttackDelay( 0.5 );
9 years ago
}
return fDidHit;
}
void CCrowbar::WeaponIdle( void )
{
if( m_flReleaseThrow == 0 && m_flStartThrow )
m_flReleaseThrow = gpGlobals->time;
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
return;
if( m_flStartThrow )
{
if( !Swing( 1 ) )
{
SetThink( &CCrowbar::SwingAgain );
pev->nextthink = gpGlobals->time + 0.1;
}
m_flReleaseThrow = 0;
m_flStartThrow = 0;
m_flNextPrimaryAttack = GetNextAttackDelay( 0.5 );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
return;
}
else if( m_flReleaseThrow > 0 )
{
// we've finished the throw, restart.
m_flStartThrow = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
m_flReleaseThrow = -1;
return;
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 35.0 / 13.0;
SendWeaponAnim( CROWBAR_IDLE );
}