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.
259 lines
5.6 KiB
259 lines
5.6 KiB
#include "extdll.h" |
|
#include "util.h" |
|
#include "cbase.h" |
|
#include "monsters.h" |
|
#include "weapons.h" |
|
#include "nodes.h" |
|
#include "player.h" |
|
|
|
enum glock_e |
|
{ |
|
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 |
|
}; |
|
|
|
class CGlock2 : public CBasePlayerWeapon |
|
{ |
|
public: |
|
void Spawn( void ); |
|
void Precache( void ); |
|
int iItemSlot( void ) { return 2; } |
|
int GetItemInfo(ItemInfo *p); |
|
|
|
void PrimaryAttack( void ); |
|
void SecondaryAttack( void ); |
|
void GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim ); |
|
BOOL Deploy( void ); |
|
void Reload( void ); |
|
void WeaponIdle( void ); |
|
|
|
virtual BOOL UseDecrement( void ) |
|
{ |
|
return FALSE; |
|
} |
|
|
|
private: |
|
int m_iShell; |
|
|
|
unsigned short m_usFireGlock1; |
|
unsigned short m_usFireGlock2; |
|
}; |
|
|
|
LINK_ENTITY_TO_CLASS( weapon_glock2, CGlock2 ) |
|
|
|
void CGlock2::Spawn() |
|
{ |
|
pev->classname = MAKE_STRING( "weapon_glock2" ); // hack to allow for old names |
|
Precache(); |
|
m_iId = WEAPON_GLOCK2; |
|
SET_MODEL( ENT( pev ), "models/w_9mmhandgun.mdl" ); |
|
|
|
m_iDefaultAmmo = GLOCK_DEFAULT_GIVE; |
|
|
|
FallInit();// get ready to fall down. |
|
} |
|
|
|
void CGlock2::Precache( void ) |
|
{ |
|
PRECACHE_MODEL( "models/v_9mmhandgun.mdl" ); |
|
PRECACHE_MODEL( "models/w_9mmhandgun.mdl" ); |
|
PRECACHE_MODEL( "models/p_9mmhandgun.mdl" ); |
|
|
|
m_iShell = PRECACHE_MODEL( "models/shell.mdl" );// brass shell |
|
|
|
PRECACHE_SOUND( "items/9mmclip1.wav" ); |
|
PRECACHE_SOUND( "items/9mmclip2.wav" ); |
|
|
|
PRECACHE_SOUND( "weapons/pl_gun1.wav" );//silenced handgun |
|
PRECACHE_SOUND( "weapons/pl_gun2.wav" );//silenced handgun |
|
PRECACHE_SOUND( "weapons/pl_gun3.wav" );//handgun |
|
|
|
m_usFireGlock1 = PRECACHE_EVENT( 1, "events/glock1.sc" ); |
|
m_usFireGlock2 = PRECACHE_EVENT( 1, "events/glock2.sc" ); |
|
} |
|
|
|
int CGlock2::GetItemInfo( ItemInfo *p ) |
|
{ |
|
p->pszName = STRING( pev->classname ); |
|
p->pszAmmo1 = "snipars"; |
|
p->iMaxAmmo1 = _9MM_MAX_CARRY; |
|
p->pszAmmo2 = NULL; |
|
p->iMaxAmmo2 = -1; |
|
p->iMaxClip = GLOCK_MAX_CLIP; |
|
p->iSlot = 1; |
|
p->iPosition = 2; |
|
p->iFlags = 0; |
|
p->iId = m_iId = WEAPON_GLOCK2; |
|
p->iWeight = GLOCK_WEIGHT; |
|
|
|
return 1; |
|
} |
|
|
|
BOOL CGlock2::Deploy() |
|
{ |
|
// pev->body = 1; |
|
return DefaultDeploy( "models/v_9mmhandgun.mdl", "models/p_9mmhandgun.mdl", GLOCK_DRAW, "onehanded", /*UseDecrement() ? 1 : 0*/ 0 ); |
|
} |
|
|
|
void CGlock2::SecondaryAttack( void ) |
|
{ |
|
GlockFire( 0.1, 0.2, FALSE ); |
|
} |
|
|
|
void CGlock2::PrimaryAttack( void ) |
|
{ |
|
GlockFire( 0.01, 0.3, TRUE ); |
|
} |
|
|
|
void CGlock2::GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim ) |
|
{ |
|
if( m_iClip <= 0 ) |
|
{ |
|
if( m_fFireOnEmpty ) |
|
{ |
|
PlayEmptySound(); |
|
m_flNextPrimaryAttack = gpGlobals->time + 0.2; |
|
} |
|
|
|
return; |
|
} |
|
|
|
m_iClip--; |
|
|
|
m_pPlayer->pev->effects = (int)( m_pPlayer->pev->effects ) | EF_MUZZLEFLASH; |
|
|
|
int flags; |
|
#if defined( CLIENT_WEAPONS ) |
|
flags = FEV_NOTHOST; |
|
#else |
|
flags = 0; |
|
#endif |
|
// player "shoot" animation |
|
m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); |
|
|
|
// silenced |
|
if( pev->body == 1 ) |
|
{ |
|
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; |
|
} |
|
|
|
Vector vecSrc = m_pPlayer->GetGunPosition(); |
|
Vector vecAiming; |
|
|
|
if( fUseAutoAim ) |
|
{ |
|
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, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, ( m_iClip == 0 ) ? 1 : 0, 0 ); |
|
|
|
m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->time + flCycleTime; |
|
|
|
if( !m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 ) |
|
// HEV suit - indicate out of ammo condition |
|
m_pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 ); |
|
|
|
m_flTimeWeaponIdle = gpGlobals->time + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); |
|
} |
|
|
|
void CGlock2::Reload( void ) |
|
{ |
|
if( m_pPlayer->ammo_snipars <= 0 ) |
|
return; |
|
|
|
int iResult; |
|
|
|
if( m_iClip == 0 ) |
|
iResult = DefaultReload( 17, GLOCK_RELOAD, 1.5 ); |
|
else |
|
iResult = DefaultReload( 17, GLOCK_RELOAD_NOT_EMPTY, 1.5 ); |
|
|
|
if( iResult ) |
|
{ |
|
m_flTimeWeaponIdle = gpGlobals->time + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); |
|
} |
|
} |
|
|
|
void CGlock2::WeaponIdle( void ) |
|
{ |
|
ResetEmptySound(); |
|
|
|
m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); |
|
|
|
if( m_flTimeWeaponIdle > gpGlobals->time ) |
|
return; |
|
|
|
// only idle if the slid isn't back |
|
if( m_iClip != 0 ) |
|
{ |
|
int iAnim; |
|
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.0, 1.0 ); |
|
|
|
if( flRand <= 0.3 + 0 * 0.75 ) |
|
{ |
|
iAnim = GLOCK_IDLE3; |
|
m_flTimeWeaponIdle = gpGlobals->time + 49.0 / 16; |
|
} |
|
else if( flRand <= 0.6 + 0 * 0.875 ) |
|
{ |
|
iAnim = GLOCK_IDLE1; |
|
m_flTimeWeaponIdle = gpGlobals->time + 60.0 / 16.0; |
|
} |
|
else |
|
{ |
|
iAnim = GLOCK_IDLE2; |
|
m_flTimeWeaponIdle = gpGlobals->time + 40.0 / 16.0; |
|
} |
|
SendWeaponAnim( iAnim, 1 ); |
|
} |
|
} |
|
|
|
class CGlock2Ammo : public CBasePlayerAmmo |
|
{ |
|
void Spawn( void ) |
|
{ |
|
Precache(); |
|
SET_MODEL( ENT( pev ), "models/w_9mmclip.mdl" ); |
|
CBasePlayerAmmo::Spawn(); |
|
} |
|
|
|
void Precache( void ) |
|
{ |
|
PRECACHE_MODEL( "models/w_9mmclip.mdl" ); |
|
PRECACHE_SOUND( "items/9mmclip1.wav" ); |
|
} |
|
|
|
BOOL AddAmmo( CBaseEntity *pOther ) |
|
{ |
|
if( pOther->GiveAmmo( AMMO_GLOCKCLIP_GIVE, "9mm", _9MM_MAX_CARRY ) != -1 ) |
|
{ |
|
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM ); |
|
return TRUE; |
|
} |
|
return FALSE; |
|
} |
|
}; |
|
|
|
LINK_ENTITY_TO_CLASS( ammo_snipars, CGlock2Ammo )
|
|
|