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.

310 lines
7.2 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"
8 years ago
enum glock_e
{
9 years ago
GLOCK_IDLE1 = 0,
GLOCK_IDLE2,
GLOCK_IDLE3,
GLOCK_SHOOT,
GLOCK_SHOOT_EMPTY,
GLOCK_RELOAD,
GLOCK_RELOAD_NOT_EMPTY,
GLOCK_DRAW,
GLOCK_HOLSTER,
GLOCK_ADD_SILENCER
};
LINK_ENTITY_TO_CLASS( weapon_glock, CGlock )
LINK_ENTITY_TO_CLASS( weapon_9mmhandgun, CGlock )
9 years ago
8 years ago
void CGlock::Spawn()
9 years ago
{
8 years ago
pev->classname = MAKE_STRING( "weapon_9mmhandgun" ); // hack to allow for old names
Precache();
9 years ago
m_iId = WEAPON_GLOCK;
8 years ago
SET_MODEL( ENT( pev ), "models/w_9mmhandgun.mdl" );
9 years ago
m_iDefaultAmmo = GLOCK_MAX_CLIP;
9 years ago
FallInit();// get ready to fall down.
}
void CGlock::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/v_9mmhandgun.mdl" );
PRECACHE_MODEL( "models/w_9mmhandgun.mdl" );
PRECACHE_MODEL( "models/p_9mmhandgun.mdl" );
9 years ago
m_iShell = PRECACHE_MODEL( "models/shell.mdl" );// brass shell
m_iClipModel = PRECACHE_MODEL( "models/w_9mmclip.mdl" );
9 years ago
8 years ago
PRECACHE_SOUND( "items/9mmclip1.wav" );
PRECACHE_SOUND( "items/9mmclip2.wav" );
9 years ago
8 years ago
PRECACHE_SOUND( "weapons/pl_gun1.wav" );//silenced handgun
PRECACHE_SOUND( "weapons/pl_gun2.wav" );//silenced handgun
PRECACHE_SOUND( "weapons/pl_gun3.wav" );//handgun
9 years ago
m_usFireGlock1 = PRECACHE_EVENT( 1, "events/glock1.sc" );
m_usFireGlock2 = PRECACHE_EVENT( 1, "events/glock2.sc" );
}
8 years ago
int CGlock::GetItemInfo( ItemInfo *p )
9 years ago
{
8 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = "9mm";
p->iMaxAmmo1 = _9MM_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = GLOCK_MAX_CLIP;
p->iSlot = 0;
p->iPosition = 3;
9 years ago
p->iFlags = 0;
p->iId = m_iId = WEAPON_GLOCK;
p->iWeight = GLOCK_WEIGHT;
return 1;
}
int CGlock::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 CGlock::Deploy()
9 years ago
{
BOOL bResult = DefaultDeploy( "models/v_9mmhandgun.mdl", "models/p_9mmhandgun.mdl", GLOCK_DRAW, "onehanded", /*UseDecrement() ? 1 : 0*/ 0 );
if( bResult )
{
m_fInAttack = 0;
}
return bResult;
}
void CGlock::Holster( int skiplocal /*= 0*/ )
{
m_fInReload = FALSE;// cancel any reload in progress.
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
SendWeaponAnim( GLOCK_HOLSTER );
m_fInAttack = 0;
9 years ago
}
void CGlock::SecondaryAttack( void )
{
}
void CGlock::PrimaryAttack( void )
{
GlockFire( 0.01, 0.2, TRUE );
9 years ago
}
8 years ago
void CGlock::GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim )
9 years ago
{
// Do not allow attack unless primary attack key was released.
if( m_fInAttack )
return;
8 years ago
if( m_iClip <= 0 )
9 years ago
{
if( !m_fFireOnEmpty )
Reload();
else
9 years ago
{
PlayEmptySound();
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.2f;
9 years ago
}
return;
}
// Prevent from continuously refire.
m_fInAttack = 1;
9 years ago
m_iClip--;
8 years ago
m_pPlayer->pev->effects = (int)( m_pPlayer->pev->effects ) | EF_MUZZLEFLASH;
9 years ago
int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
// silenced
8 years ago
if( pev->body == 1 )
9 years ago
{
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
}
else
{
// non-silenced
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
}
8 years ago
Vector vecSrc = m_pPlayer->GetGunPosition();
9 years ago
Vector vecAiming;
8 years ago
if( fUseAutoAim )
9 years ago
{
vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
}
else
{
vecAiming = gpGlobals->v_forward;
}
Vector vecDir;
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, Vector( flSpread, flSpread, flSpread ), 8192, BULLET_PLAYER_9MM, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), fUseAutoAim ? m_usFireGlock1 : m_usFireGlock2, 0.0, g_vecZero, g_vecZero, vecDir.x, vecDir.y, 0, 0, ( m_iClip == 0 ) ? 1 : 0, 0 );
9 years ago
m_flNextPrimaryAttack = m_flNextSecondaryAttack = GetNextAttackDelay( flCycleTime );
9 years ago
8 years ago
if( !m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
9 years ago
// HEV suit - indicate out of ammo condition
8 years ago
m_pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
void CGlock::Reload( void )
{
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == GLOCK_MAX_CLIP )
return;
9 years ago
int iResult;
if( m_iClip != GLOCK_MAX_CLIP && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0 )
9 years ago
{
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
Vector vecShellVelocity = m_pPlayer->pev->velocity
+ gpGlobals->v_right * RANDOM_FLOAT( -10, 10 )
+ gpGlobals->v_forward * 23;
EjectClip( pev->origin + m_pPlayer->pev->view_ofs
+ gpGlobals->v_up * -22
+ gpGlobals->v_forward * 10
+ gpGlobals->v_right * 2, vecShellVelocity, pev->angles.y, m_iClipModel, TE_BOUNCE_SHELL );
if( m_iClip == 0 )
iResult = DefaultReload( GLOCK_MAX_CLIP, GLOCK_RELOAD, 1.5f );
else
iResult = DefaultReload( GLOCK_MAX_CLIP, GLOCK_RELOAD_NOT_EMPTY, 1.5f );
if( iResult )
{
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
// Unblock primary attack.
m_fInAttack = 0;
}
9 years ago
}
}
void CGlock::WeaponIdle( void )
{
8 years ago
ResetEmptySound();
9 years ago
m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
//
// Unblock primary attack.
// This will only occur if players released primary attack key.
//
m_fInAttack = 0;
8 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
// only idle if the slid isn't back
8 years ago
if( m_iClip != 0 )
9 years ago
{
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.0, 1.0 );
if( flRand <= 0.3f + 0 * 0.75f )
9 years ago
{
iAnim = GLOCK_IDLE3;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 49.0f / 16.0f;
9 years ago
}
else if( flRand <= 0.6f + 0 * 0.875f )
9 years ago
{
iAnim = GLOCK_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 60.0f / 16.0f;
9 years ago
}
else
{
iAnim = GLOCK_IDLE2;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 40.0f / 16.0f;
9 years ago
}
SendWeaponAnim( iAnim, 1 );
}
}
class CGlockAmmo : public CBasePlayerAmmo
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_9mmclip.mdl" );
CBasePlayerAmmo::Spawn();
9 years ago
}
8 years ago
9 years ago
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_9mmclip.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
9 years ago
}
8 years ago
BOOL AddAmmo( CBaseEntity *pOther )
{
if( pOther->GiveAmmo( AMMO_GLOCKCLIP_GIVE, "9mm", _9MM_MAX_CARRY ) != -1 )
9 years ago
{
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
9 years ago
return TRUE;
}
return FALSE;
}
};
8 years ago
LINK_ENTITY_TO_CLASS( ammo_glockclip, CGlockAmmo )
LINK_ENTITY_TO_CLASS( ammo_9mmclip, CGlockAmmo )