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.
248 lines
5.9 KiB
248 lines
5.9 KiB
8 years ago
|
#include "extdll.h"
|
||
|
#include "util.h"
|
||
|
#include "cbase.h"
|
||
|
#include "monsters.h"
|
||
|
#include "weapons.h"
|
||
|
#include "nodes.h"
|
||
|
#include "player.h"
|
||
8 years ago
|
#include "gamerules.h"
|
||
8 years ago
|
|
||
8 years ago
|
#define WEAPON_PEPSIGUN 21
|
||
8 years ago
|
|
||
8 years ago
|
class CPepsigun : public CBasePlayerWeapon
|
||
|
{
|
||
|
public:
|
||
|
void Spawn( void );
|
||
|
void Precache( void );
|
||
8 years ago
|
int iItemSlot( ) { return 3; }
|
||
8 years ago
|
int GetItemInfo(ItemInfo *p);
|
||
8 years ago
|
int AddToPlayer( CBasePlayer *pPlayer );
|
||
8 years ago
|
|
||
|
void PrimaryAttack( void );
|
||
8 years ago
|
BOOL Deploy( );
|
||
8 years ago
|
void Reload( void );
|
||
|
void WeaponIdle( void );
|
||
|
int m_fInReload;
|
||
|
float m_flNextReload;
|
||
|
virtual BOOL UseDecrement( void )
|
||
8 years ago
|
{
|
||
|
#if defined( CLIENT_WEAPONS )
|
||
|
return TRUE;
|
||
|
#else
|
||
8 years ago
|
return FALSE;
|
||
8 years ago
|
#endif
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
private:
|
||
|
};
|
||
|
|
||
|
enum shotgun_e
|
||
|
{
|
||
|
SHOTGUN_IDLE = 0,
|
||
|
SHOTGUN_FIRE,
|
||
|
SHOTGUN_OPEN,
|
||
|
SHOTGUN_INSERT,
|
||
|
SHOTGUN_CLOSE,
|
||
|
SHOTGUN_DRAW
|
||
8 years ago
|
};
|
||
|
|
||
8 years ago
|
LINK_ENTITY_TO_CLASS( weapon_pepsigun, CPepsigun )
|
||
|
|
||
|
void CPepsigun::Spawn()
|
||
|
{
|
||
|
Precache();
|
||
|
m_iId = WEAPON_PEPSIGUN;
|
||
|
SET_MODEL( ENT( pev ), "models/w_pepsigun.mdl" );
|
||
|
|
||
8 years ago
|
m_iDefaultAmmo = HANDGRENADE_DEFAULT_GIVE;
|
||
8 years ago
|
|
||
8 years ago
|
FallInit();// get ready to fall
|
||
8 years ago
|
}
|
||
|
|
||
|
void CPepsigun::Precache( void )
|
||
|
{
|
||
|
PRECACHE_MODEL( "models/v_pepsigun.mdl" );
|
||
8 years ago
|
PRECACHE_MODEL( "models/w_pepsigun.mdl" );
|
||
8 years ago
|
PRECACHE_MODEL( "models/p_pepsigun.mdl" );
|
||
8 years ago
|
|
||
|
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;
|
||
8 years ago
|
}
|
||
|
|
||
|
int CPepsigun::GetItemInfo( ItemInfo *p )
|
||
|
{
|
||
|
p->pszName = STRING( pev->classname );
|
||
8 years ago
|
p->pszAmmo1 = "Hand Grenade";
|
||
|
p->iMaxAmmo1 = HANDGRENADE_MAX_CARRY;
|
||
8 years ago
|
p->pszAmmo2 = NULL;
|
||
|
p->iMaxAmmo2 = -1;
|
||
8 years ago
|
p->iMaxClip = 8;
|
||
8 years ago
|
p->iSlot = 2;
|
||
|
p->iPosition = 4;
|
||
8 years ago
|
p->iFlags = 0;
|
||
8 years ago
|
p->iId = m_iId = WEAPON_PEPSIGUN;
|
||
8 years ago
|
p->iWeight = SHOTGUN_WEIGHT;
|
||
8 years ago
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
BOOL CPepsigun::Deploy()
|
||
|
{
|
||
8 years ago
|
return DefaultDeploy( "models/v_pepsigun.mdl", "models/p_pepsigun.mdl", SHOTGUN_DRAW, "shotgun" );
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
void CPepsigun::PrimaryAttack()
|
||
8 years ago
|
{
|
||
8 years ago
|
m_iClip--;
|
||
|
Vector angThrow = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle;
|
||
8 years ago
|
|
||
8 years ago
|
if( angThrow.x < 0 )
|
||
|
angThrow.x = -10 + angThrow.x * ( ( 90 - 10 ) / 90.0 );
|
||
|
else
|
||
|
angThrow.x = -10 + angThrow.x * ( ( 90 + 10 ) / 90.0 );
|
||
8 years ago
|
|
||
8 years ago
|
float flVel = ( 90 - angThrow.x ) * 4;
|
||
|
if( flVel > 500 )
|
||
|
flVel = 500;
|
||
8 years ago
|
|
||
8 years ago
|
UTIL_MakeVectors( angThrow );
|
||
8 years ago
|
|
||
8 years ago
|
Vector vecSrc = m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_forward * 16;
|
||
8 years ago
|
|
||
8 years ago
|
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;
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
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
|
||
8 years ago
|
if( m_flNextPrimaryAttack > UTIL_WeaponTimeBase() )
|
||
8 years ago
|
return;
|
||
|
|
||
|
// check to see if we're ready to reload
|
||
|
if( m_fInSpecialReload == 0 )
|
||
|
{
|
||
8 years ago
|
SendWeaponAnim( SHOTGUN_OPEN );
|
||
8 years ago
|
m_fInSpecialReload = 1;
|
||
8 years ago
|
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;
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
else if( m_fInSpecialReload == 1 )
|
||
|
{
|
||
8 years ago
|
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
|
||
8 years ago
|
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 ) );
|
||
|
|
||
8 years ago
|
SendWeaponAnim( SHOTGUN_INSERT );
|
||
8 years ago
|
|
||
8 years ago
|
m_flNextReload = UTIL_WeaponTimeBase() + 0.5;
|
||
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
|
||
8 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
// Add them to the clip
|
||
|
m_iClip += 1;
|
||
|
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 1;
|
||
|
m_fInSpecialReload = 1;
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
void CPepsigun::WeaponIdle( void )
|
||
|
{
|
||
8 years ago
|
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() )
|
||
|
{
|
||
8 years ago
|
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
|
||
8 years ago
|
SendWeaponAnim( SHOTGUN_CLOSE );
|
||
|
|
||
8 years ago
|
m_fInSpecialReload = 0;
|
||
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.5;
|
||
|
}
|
||
|
}
|
||
8 years ago
|
else
|
||
|
{
|
||
8 years ago
|
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 );
|
||
8 years ago
|
}
|
||
|
}
|
||
8 years ago
|
}
|