|
|
|
#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 WEAPON_PEPSIGUN 21
|
|
|
|
|
|
|
|
class CPepsigun : public CBasePlayerWeapon
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
int iItemSlot( ) { return 3; }
|
|
|
|
int GetItemInfo(ItemInfo *p);
|
|
|
|
int AddToPlayer( CBasePlayer *pPlayer );
|
|
|
|
|
|
|
|
void PrimaryAttack( void );
|
|
|
|
BOOL Deploy( );
|
|
|
|
void Reload( void );
|
|
|
|
void WeaponIdle( void );
|
|
|
|
int m_fInReload;
|
|
|
|
float m_flNextReload;
|
|
|
|
virtual BOOL UseDecrement( void )
|
|
|
|
{
|
|
|
|
#if defined( CLIENT_WEAPONS )
|
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
|
|
|
enum shotgun_e
|
|
|
|
{
|
|
|
|
SHOTGUN_IDLE = 0,
|
|
|
|
SHOTGUN_FIRE,
|
|
|
|
SHOTGUN_OPEN,
|
|
|
|
SHOTGUN_INSERT,
|
|
|
|
SHOTGUN_CLOSE,
|
|
|
|
SHOTGUN_DRAW
|
|
|
|
};
|
|
|
|
|
|
|
|
LINK_ENTITY_TO_CLASS( weapon_pepsigun, CPepsigun )
|
|
|
|
|
|
|
|
void CPepsigun::Spawn()
|
|
|
|
{
|
|
|
|
Precache();
|
|
|
|
m_iId = WEAPON_PEPSIGUN;
|
|
|
|
SET_MODEL( ENT( pev ), "models/w_pepsigun.mdl" );
|
|
|
|
|
|
|
|
m_iDefaultAmmo = HANDGRENADE_DEFAULT_GIVE;
|
|
|
|
|
|
|
|
FallInit();// get ready to fall
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPepsigun::Precache( void )
|
|
|
|
{
|
|
|
|
PRECACHE_MODEL( "models/v_pepsigun.mdl" );
|
|
|
|
PRECACHE_MODEL( "models/w_pepsigun.mdl" );
|
|
|
|
PRECACHE_MODEL( "models/p_pepsigun.mdl" );
|
|
|
|
|
|
|
|
PRECACHE_SOUND( "items/9mmclip1.wav" );
|
|
|
|
|
|
|
|
PRECACHE_SOUND( "weapons/dbarrel1.wav" );//shotgun
|
|
|
|
PRECACHE_SOUND( "weapons/pepsigun_shoot.wav" );//shotgun
|
|
|
|
|
|
|
|
PRECACHE_SOUND( "weapons/reload1.wav" ); // shotgun reload
|
|
|
|
PRECACHE_SOUND( "weapons/reload3.wav" ); // shotgun reload
|
|
|
|
|
|
|
|
//PRECACHE_SOUND( "weapons/sshell1.wav" ); // shotgun reload - played on client
|
|
|
|
//PRECACHE_SOUND( "weapons/sshell3.wav" ); // shotgun reload - played on client
|
|
|
|
|
|
|
|
PRECACHE_SOUND( "weapons/357_cock1.wav" ); // gun empty sound
|
|
|
|
PRECACHE_SOUND( "weapons/scock1.wav" ); // cock gun
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPepsigun::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPepsigun::GetItemInfo( ItemInfo *p )
|
|
|
|
{
|
|
|
|
p->pszName = STRING( pev->classname );
|
|
|
|
p->pszAmmo1 = "Hand Grenade";
|
|
|
|
p->iMaxAmmo1 = HANDGRENADE_MAX_CARRY;
|
|
|
|
p->pszAmmo2 = NULL;
|
|
|
|
p->iMaxAmmo2 = -1;
|
|
|
|
p->iMaxClip = 8;
|
|
|
|
p->iSlot = 2;
|
|
|
|
p->iPosition = 4;
|
|
|
|
p->iFlags = 0;
|
|
|
|
p->iId = m_iId = WEAPON_PEPSIGUN;
|
|
|
|
p->iWeight = SHOTGUN_WEIGHT;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CPepsigun::Deploy()
|
|
|
|
{
|
|
|
|
return DefaultDeploy( "models/v_pepsigun.mdl", "models/p_pepsigun.mdl", SHOTGUN_DRAW, "shotgun" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPepsigun::PrimaryAttack()
|
|
|
|
{
|
|
|
|
m_iClip--;
|
|
|
|
Vector angThrow = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle;
|
|
|
|
|
|
|
|
if( angThrow.x < 0 )
|
|
|
|
angThrow.x = -10 + angThrow.x * ( ( 90 - 10 ) / 90.0 );
|
|
|
|
else
|
|
|
|
angThrow.x = -10 + angThrow.x * ( ( 90 + 10 ) / 90.0 );
|
|
|
|
|
|
|
|
float flVel = ( 90 - angThrow.x ) * 4;
|
|
|
|
if( flVel > 500 )
|
|
|
|
flVel = 500;
|
|
|
|
|
|
|
|
UTIL_MakeVectors( angThrow );
|
|
|
|
|
|
|
|
Vector vecSrc = m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_forward * 16;
|
|
|
|
|
|
|
|
Vector vecThrow = gpGlobals->v_forward * flVel + m_pPlayer->pev->velocity;
|
|
|
|
CGrenade::ShootTimed( m_pPlayer->pev, vecSrc, vecThrow*2, 3 );
|
|
|
|
|
|
|
|
SendWeaponAnim( SHOTGUN_FIRE );
|
|
|
|
|
|
|
|
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/pepsigun_shoot.wav", 1, ATTN_NORM, 0, 85 + RANDOM_LONG( 0, 0x1f ) );
|
|
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.75;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.75;
|
|
|
|
m_fInSpecialReload = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPepsigun::Reload( void )
|
|
|
|
{
|
|
|
|
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == SHOTGUN_MAX_CLIP )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// don't reload until recoil is done
|
|
|
|
if( m_flNextPrimaryAttack > UTIL_WeaponTimeBase() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// check to see if we're ready to reload
|
|
|
|
if( m_fInSpecialReload == 0 )
|
|
|
|
{
|
|
|
|
SendWeaponAnim( SHOTGUN_OPEN );
|
|
|
|
m_fInSpecialReload = 1;
|
|
|
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.6;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.6;
|
|
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.0;
|
|
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( m_fInSpecialReload == 1 )
|
|
|
|
{
|
|
|
|
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
|
|
|
|
return;
|
|
|
|
// was waiting for gun to move to side
|
|
|
|
m_fInSpecialReload = 2;
|
|
|
|
|
|
|
|
if( RANDOM_LONG( 0, 1 ) )
|
|
|
|
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/reload1.wav", 1, ATTN_NORM, 0, 85 + RANDOM_LONG( 0, 0x1f ) );
|
|
|
|
else
|
|
|
|
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/reload3.wav", 1, ATTN_NORM, 0, 85 + RANDOM_LONG( 0, 0x1f ) );
|
|
|
|
|
|
|
|
SendWeaponAnim( SHOTGUN_INSERT );
|
|
|
|
|
|
|
|
m_flNextReload = UTIL_WeaponTimeBase() + 0.5;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add them to the clip
|
|
|
|
m_iClip += 1;
|
|
|
|
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 1;
|
|
|
|
m_fInSpecialReload = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPepsigun::WeaponIdle( void )
|
|
|
|
{
|
|
|
|
ResetEmptySound();
|
|
|
|
|
|
|
|
m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
|
|
|
|
|
|
|
|
if( m_flPumpTime && m_flPumpTime < gpGlobals->time )
|
|
|
|
{
|
|
|
|
// play pumping sound
|
|
|
|
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/scock1.wav", 1, ATTN_NORM, 0, 95 + RANDOM_LONG( 0, 0x1f ) );
|
|
|
|
m_flPumpTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_flTimeWeaponIdle < UTIL_WeaponTimeBase() )
|
|
|
|
{
|
|
|
|
if( m_iClip == 0 && m_fInSpecialReload == 0 && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
|
|
|
|
{
|
|
|
|
Reload();
|
|
|
|
}
|
|
|
|
else if( m_fInSpecialReload != 0 )
|
|
|
|
{
|
|
|
|
if( m_iClip != 8 && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
|
|
|
|
{
|
|
|
|
Reload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// reload debounce has timed out
|
|
|
|
SendWeaponAnim( SHOTGUN_CLOSE );
|
|
|
|
|
|
|
|
m_fInSpecialReload = 0;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int iAnim;
|
|
|
|
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
|
|
|
|
if( flRand <= 0.8 )
|
|
|
|
{
|
|
|
|
iAnim = SHOTGUN_IDLE;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 60.0 / 12.0 );// * RANDOM_LONG( 2, 5 );
|
|
|
|
}
|
|
|
|
else if( flRand <= 0.95 )
|
|
|
|
{
|
|
|
|
iAnim = SHOTGUN_IDLE;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 20.0 / 9.0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iAnim = SHOTGUN_IDLE;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 20.0 / 9.0 );
|
|
|
|
}
|
|
|
|
SendWeaponAnim( iAnim );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|