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.

308 lines
7.8 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"
#include "gamerules.h"
// special deathmatch shotgun spreads
9 years ago
#define VECTOR_CONE_DM_SHOTGUN Vector( 0.08716, 0.04362, 0.00 )// 10 degrees by 5 degrees
9 years ago
#define VECTOR_CONE_DM_DOUBLESHOTGUN Vector( 0.17365, 0.04362, 0.00 ) // 20 degrees by 5 degrees
9 years ago
enum shotgun_e
{
9 years ago
SHOTGUN_IDLE = 0,
SHOTGUN_FIRE,
SHOTGUN_RELOAD,
SHOTGUN_PUMP,
SHOTGUN_START_RELOAD,
SHOTGUN_DRAW,
SHOTGUN_HOLSTER,
SHOTGUN_IDLE_DEEP
};
LINK_ENTITY_TO_CLASS( weapon_shotgun, CShotgun )
9 years ago
9 years ago
void CShotgun::Spawn()
9 years ago
{
9 years ago
Precache();
9 years ago
m_iId = WEAPON_SHOTGUN;
9 years ago
SET_MODEL( ENT( pev ), "models/w_shotgun.mdl" );
9 years ago
m_iDefaultAmmo = SHOTGUN_DEFAULT_GIVE;
FallInit();// get ready to fall
}
void CShotgun::Precache( void )
{
9 years ago
PRECACHE_MODEL( "models/v_shotgun.mdl" );
PRECACHE_MODEL( "models/w_shotgun.mdl" );
PRECACHE_MODEL( "models/p_shotgun.mdl" );
9 years ago
9 years ago
m_iShell = PRECACHE_MODEL( "models/shotgunshell.mdl" );// shotgun shell
9 years ago
PRECACHE_MODEL( "sprites/wallsmoke.spr" );
9 years ago
PRECACHE_SOUND( "items/9mmclip1.wav" );
9 years ago
9 years ago
PRECACHE_SOUND( "weapons/dbarrel1.wav" );//shotgun
PRECACHE_SOUND( "weapons/sbarrel1.wav" );//shotgun
9 years ago
9 years ago
PRECACHE_SOUND( "weapons/reload1.wav" ); // shotgun reload
PRECACHE_SOUND( "weapons/reload3.wav" ); // shotgun reload
9 years ago
9 years ago
//PRECACHE_SOUND( "weapons/sshell1.wav" ); // shotgun reload - played on client
//PRECACHE_SOUND( "weapons/sshell3.wav" ); // shotgun reload - played on client
9 years ago
9 years ago
PRECACHE_SOUND( "weapons/357_cock1.wav" ); // gun empty sound
PRECACHE_SOUND( "weapons/scock1.wav" ); // cock gun
9 years ago
m_usSingleFire = PRECACHE_EVENT( 1, "events/shotgun1.sc" );
}
int CShotgun::AddToPlayer( CBasePlayer *pPlayer )
{
9 years ago
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
9 years ago
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
9 years ago
int CShotgun::GetItemInfo( ItemInfo *p )
9 years ago
{
9 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = "buckshot";
p->iMaxAmmo1 = BUCKSHOT_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = SHOTGUN_MAX_CLIP;
p->iSlot = 2;
p->iPosition = 0;
9 years ago
p->iFlags = 0;
p->iId = m_iId = WEAPON_SHOTGUN;
p->iWeight = SHOTGUN_WEIGHT;
return 1;
}
9 years ago
BOOL CShotgun::Deploy()
9 years ago
{
return DefaultDeploy( "models/v_shotgun.mdl", "models/p_shotgun.mdl", SHOTGUN_DRAW, "shotgun" );
}
void CShotgun::PrimaryAttack()
{
// don't fire underwater
9 years ago
if( m_pPlayer->pev->waterlevel == 3 )
9 years ago
{
9 years ago
PlayEmptySound();
6 years ago
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15;
9 years ago
return;
}
if( m_iClip <= 1 )
9 years ago
{
9 years ago
Reload();
PlayEmptySound();
9 years ago
return;
}
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
m_iClip -= 2;
9 years ago
int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
9 years ago
m_pPlayer->pev->effects = (int)( m_pPlayer->pev->effects ) | EF_MUZZLEFLASH;
9 years ago
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
9 years ago
Vector vecSrc = m_pPlayer->GetGunPosition();
9 years ago
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
Vector vecDir;
vecDir = m_pPlayer->FireBulletsPlayer( 12, vecSrc, vecAiming, VECTOR_CONE_15DEGREES, 2048, BULLET_PLAYER_BUCKSHOT, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
9 years ago
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usSingleFire, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.2;
9 years ago
if( m_iClip != 0 )
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 6.0;
9 years ago
else
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.2;
9 years ago
m_fInSpecialReload = 0;
9 years ago
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
9 years ago
Vector oldVelocity = m_pPlayer->pev->velocity;
9 years ago
// Send player impulse.
m_pPlayer->pev->velocity = m_pPlayer->pev->velocity - gpGlobals->v_forward * 200;
m_pPlayer->pev->velocity = m_pPlayer->pev->velocity - ( m_pPlayer->pev->velocity - oldVelocity ) * 0.5f;
}
9 years ago
void CShotgun::SecondaryAttack( void )
{
9 years ago
}
void CShotgun::Reload( void )
{
9 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == SHOTGUN_MAX_CLIP )
9 years ago
return;
// don't reload until recoil is done
9 years ago
if( m_flNextPrimaryAttack > UTIL_WeaponTimeBase() )
9 years ago
return;
// check to see if we're ready to reload
9 years ago
if( m_fInSpecialReload == 0 )
9 years ago
{
SendWeaponAnim( SHOTGUN_START_RELOAD );
m_fInSpecialReload = 1;
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.4;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.4;
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.8;
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.8;
9 years ago
return;
}
9 years ago
else if( m_fInSpecialReload == 1 )
9 years ago
{
9 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
// was waiting for gun to move to side
m_fInSpecialReload = 2;
9 years ago
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 ) );
9 years ago
else
9 years ago
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/reload3.wav", 1, ATTN_NORM, 0, 85 + RANDOM_LONG( 0, 0x1f ) );
9 years ago
SendWeaponAnim( SHOTGUN_RELOAD );
m_flNextReload = UTIL_WeaponTimeBase() + 0.3;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.3;
9 years ago
}
else
{
// Add them to the clip
m_iClip += 1;
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 1;
m_fInSpecialReload = 1;
}
}
void CShotgun::WeaponTick()
9 years ago
{
9 years ago
if( m_flPumpTime && m_flPumpTime < gpGlobals->time )
9 years ago
{
// play pumping sound
9 years ago
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/scock1.wav", 1, ATTN_NORM, 0, 95 + RANDOM_LONG( 0, 0x1f ) );
9 years ago
m_flPumpTime = 0;
}
}
9 years ago
void CShotgun::WeaponIdle( void )
{
9 years ago
ResetEmptySound();
9 years ago
m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
9 years ago
if( m_flTimeWeaponIdle < UTIL_WeaponTimeBase() )
9 years ago
{
9 years ago
if( m_iClip == 0 && m_fInSpecialReload == 0 && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
9 years ago
{
9 years ago
Reload();
9 years ago
}
9 years ago
else if( m_fInSpecialReload != 0 )
9 years ago
{
if( m_iClip != SHOTGUN_MAX_CLIP && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
9 years ago
{
9 years ago
Reload();
9 years ago
}
else
{
// reload debounce has timed out
SendWeaponAnim( SHOTGUN_PUMP );
// play cocking sound
9 years ago
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/scock1.wav", 1, ATTN_NORM, 0, 95 + RANDOM_LONG( 0, 0x1f ) );
9 years ago
m_fInSpecialReload = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.5;
}
}
else
{
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
9 years ago
if( flRand <= 0.8 )
9 years ago
{
iAnim = SHOTGUN_IDLE_DEEP;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 51.0 / 12.0 );// * RANDOM_LONG( 2, 5 );
9 years ago
}
else
{
iAnim = SHOTGUN_IDLE;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 51.0 / 9.0 );
9 years ago
}
SendWeaponAnim( iAnim );
}
}
}
class CShotgunAmmo : public CBasePlayerAmmo
{
void Spawn( void )
{
9 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_shotbox.mdl" );
CBasePlayerAmmo::Spawn();
9 years ago
}
void Precache( void )
{
9 years ago
PRECACHE_MODEL( "models/w_shotbox.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
9 years ago
}
BOOL AddAmmo( CBaseEntity *pOther )
{
9 years ago
if( pOther->GiveAmmo( AMMO_BUCKSHOTBOX_GIVE, "buckshot", BUCKSHOT_MAX_CARRY ) != -1 )
9 years ago
{
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
9 years ago
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( ammo_buckshot, CShotgunAmmo )