|
|
|
/***
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
// special deathmatch shotgun spreads
|
|
|
|
#define VECTOR_CONE_DM_SHOTGUN Vector( 0.08716, 0.04362, 0.00 )// 10 degrees by 5 degrees
|
|
|
|
#define VECTOR_CONE_DM_DOUBLESHOTGUN Vector( 0.17365, 0.04362, 0.00 ) // 20 degrees by 5 degrees
|
|
|
|
|
|
|
|
enum shotguna_e
|
|
|
|
{
|
|
|
|
SHOTGUNA_IDLE = 0,
|
|
|
|
SHOTGUNA_IDLE2,
|
|
|
|
SHOTGUNA_IDLE3,
|
|
|
|
SHOTGUNA_SHOOT,
|
|
|
|
SHOTGUNA_RELOAD,
|
|
|
|
SHOTGUNA_START_RELOAD,
|
|
|
|
SHOTGUNA_END_RELOAD,
|
|
|
|
SHOTGUNA_DRAW,
|
|
|
|
SHOTGUNA_HOLSTER
|
|
|
|
};
|
|
|
|
|
|
|
|
LINK_ENTITY_TO_CLASS( weapon_autoshotgun, CShotgunA );
|
|
|
|
|
|
|
|
void CShotgunA::Spawn( )
|
|
|
|
{
|
|
|
|
Precache( );
|
|
|
|
m_iId = WEAPON_SHOTGUNA;
|
|
|
|
SET_MODEL(ENT(pev), "models/w_autoshotgun.mdl");
|
|
|
|
|
|
|
|
m_iDefaultAmmo = SHOTGUNA_DEFAULT_GIVE;
|
|
|
|
|
|
|
|
FallInit();// get ready to fall
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CShotgunA::Precache( void )
|
|
|
|
{
|
|
|
|
PRECACHE_MODEL("models/v_autoshotgun.mdl");
|
|
|
|
PRECACHE_MODEL("models/w_autoshotgun.mdl");
|
|
|
|
PRECACHE_MODEL("models/p_autoshotgun.mdl");
|
|
|
|
|
|
|
|
m_iShell = PRECACHE_MODEL ("models/autoshotgunshell.mdl");// shotgun shell
|
|
|
|
|
|
|
|
PRECACHE_SOUND("items/9mmclip1.wav");
|
|
|
|
|
|
|
|
PRECACHE_SOUND ("weapons/dbarrel1.wav");//shotgun
|
|
|
|
PRECACHE_SOUND ("weapons/sbarrel1.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
|
|
|
|
|
|
|
|
m_usSingleFire = PRECACHE_EVENT( 1, "events/autoshotgun1.sc" );
|
|
|
|
m_usDoubleFire = PRECACHE_EVENT( 1, "events/autoshotgun2.sc" );
|
|
|
|
}
|
|
|
|
|
|
|
|
int CShotgunA::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 CShotgunA::GetItemInfo(ItemInfo *p)
|
|
|
|
{
|
|
|
|
p->pszName = STRING(pev->classname);
|
|
|
|
p->pszAmmo1 = "buckshot";
|
|
|
|
p->iMaxAmmo1 = BUCKSHOT_MAX_CARRY;
|
|
|
|
p->pszAmmo2 = NULL;
|
|
|
|
p->iMaxAmmo2 = -1;
|
|
|
|
p->iMaxClip = SHOTGUNA_MAX_CLIP;
|
|
|
|
p->iSlot = 2;
|
|
|
|
p->iPosition = 3;
|
|
|
|
p->iFlags = 0;
|
|
|
|
p->iId = m_iId = WEAPON_SHOTGUNA;
|
|
|
|
p->iWeight = SHOTGUNA_WEIGHT;
|
|
|
|
p->weaponName = "Full Automatic Shotgun";
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CShotgunA::Deploy( )
|
|
|
|
{
|
|
|
|
return DefaultDeploy( "models/v_autoshotgun.mdl", "models/p_autoshotgun.mdl", SHOTGUNA_DRAW, "autoshotgun" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CShotgunA::Holster( int skiplocal /* = 0 */ )
|
|
|
|
{
|
|
|
|
m_fInReload = FALSE;// cancel any reload in progress.
|
|
|
|
|
|
|
|
if ( m_fInZoom )
|
|
|
|
{
|
|
|
|
SecondaryAttack();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f;
|
|
|
|
m_flTimeWeaponIdle = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
|
|
|
|
SendWeaponAnim( SHOTGUNA_HOLSTER );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CShotgunA::PrimaryAttack()
|
|
|
|
{
|
|
|
|
// don't fire underwater
|
|
|
|
if (m_pPlayer->pev->waterlevel == 3 && m_pPlayer->pev->watertype > CONTENT_FLYFIELD)
|
|
|
|
{
|
|
|
|
PlayEmptySound( );
|
|
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.05f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_iClip <= 0)
|
|
|
|
{
|
|
|
|
Reload( );
|
|
|
|
if (m_iClip == 0)
|
|
|
|
PlayEmptySound( );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
|
|
|
|
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
|
|
|
|
|
|
|
|
m_iClip--;
|
|
|
|
|
|
|
|
int flags;
|
|
|
|
#if CLIENT_WEAPONS
|
|
|
|
flags = FEV_NOTHOST;
|
|
|
|
#else
|
|
|
|
flags = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
|
|
|
|
|
|
|
|
Vector vecSrc = m_pPlayer->GetGunPosition( );
|
|
|
|
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
|
|
|
|
|
|
|
|
Vector vecDir;
|
|
|
|
|
|
|
|
#if CLIENT_DLL
|
|
|
|
if ( bIsMultiplayer() )
|
|
|
|
#else
|
|
|
|
if ( g_pGameRules->IsMultiplayer() )
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
vecDir = m_pPlayer->FireBulletsPlayer( 4, vecSrc, vecAiming, VECTOR_CONE_DM_SHOTGUN, 2048, BULLET_PLAYER_BUCKSHOT, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// regular old, untouched spread.
|
|
|
|
vecDir = m_pPlayer->FireBulletsPlayer( 8, vecSrc, vecAiming, VECTOR_CONE_10DEGREES, 2048, BULLET_PLAYER_BUCKSHOT, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usSingleFire, 0.0, g_vecZero, g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
|
|
|
// HEV suit - indicate out of ammo condition
|
|
|
|
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
|
|
|
|
|
|
|
|
if (m_iClip != 0)
|
|
|
|
m_flPumpTime = gpGlobals->time + 0.5f;
|
|
|
|
|
|
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.35f;
|
|
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.65f;
|
|
|
|
if (m_iClip != 0)
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 5.0f;
|
|
|
|
else
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.75f;
|
|
|
|
m_fInSpecialReload = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CShotgunA::SecondaryAttack( void )
|
|
|
|
{
|
|
|
|
if ( m_pPlayer->pev->fov != 0 )
|
|
|
|
{
|
|
|
|
m_fInZoom = FALSE;
|
|
|
|
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
|
|
|
|
}
|
|
|
|
else if ( m_pPlayer->pev->fov != 40 )
|
|
|
|
{
|
|
|
|
m_fInZoom = TRUE;
|
|
|
|
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CShotgunA::Reload( void )
|
|
|
|
{
|
|
|
|
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == SHOTGUNA_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( SHOTGUNA_START_RELOAD );
|
|
|
|
m_fInZoom = FALSE;
|
|
|
|
m_fInSpecialReload = 1;
|
|
|
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.6f;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.6f;
|
|
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.0f;
|
|
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f;
|
|
|
|
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( SHOTGUNA_RELOAD );
|
|
|
|
|
|
|
|
m_flNextReload = UTIL_WeaponTimeBase() + 0.5f;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add them to the clip
|
|
|
|
m_iClip += 1;
|
|
|
|
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 1;
|
|
|
|
m_fInSpecialReload = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CShotgunA::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
|
|
|
|
{
|
|
|
|
// play cocking sound
|
|
|
|
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/scock1.wav", 1, ATTN_NORM, 0, 95 + RANDOM_LONG(0,0x1f));
|
|
|
|
m_fInSpecialReload = 0;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.5f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int iAnim;
|
|
|
|
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
|
|
|
|
if (flRand <= 0.8f)
|
|
|
|
{
|
|
|
|
iAnim = SHOTGUNA_IDLE;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + (60.0f/12.0f);// * RANDOM_LONG(2, 5);
|
|
|
|
}
|
|
|
|
else if (flRand <= 0.95f)
|
|
|
|
{
|
|
|
|
iAnim = SHOTGUNA_IDLE2;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + (20.0f/9.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iAnim = SHOTGUNA_IDLE3;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + (20.0f/9.0f);
|
|
|
|
}
|
|
|
|
SendWeaponAnim( iAnim );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|