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.
 
 
 
 
 
 

298 lines
7.6 KiB

/***
*
* 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 shotgun_e
{
SHOTGUN_IDLE = 0,
SHOTGUN_IDLE2,
SHOTGUN_FIRE,
SHOTGUN_RELOAD_START,
SHOTGUN_RELOAD_INS,
SHOTGUN_RELOAD_END,
SHOTGUN_DRAW
};
LINK_ENTITY_TO_CLASS( weapon_shotgun, CShotgun );
void CShotgun::Spawn( )
{
Precache( );
m_iId = WEAPON_SHOTGUN;
SET_MODEL(ENT(pev), "models/w_shotgun.mdl");
m_iDefaultAmmo = SHOTGUN_DEFAULT_GIVE;
FallInit();// get ready to fall
}
void CShotgun::Precache( void )
{
PRECACHE_MODEL("models/v_shotgun.mdl");
PRECACHE_MODEL("models/w_shotgun.mdl");
PRECACHE_MODEL("models/p_shotgun.mdl");
m_iShell = PRECACHE_MODEL ("models/shotgunshell.mdl");// shotgun shell
PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND ("weapons/dbarrel1.wav");//shotgun
PRECACHE_SOUND ("weapons/sbarrel1.wav");//shotgun
PRECACHE_SOUND ("weapons/shotgun_fire_safe.wav");
PRECACHE_SOUND ("weapons/shotgun_fire.wav");
PRECACHE_SOUND ("weapons/shotgun_insert.wav");
PRECACHE_SOUND ("weapons/shotgun_pump.wav");
//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/shotgun.sc" );
}
int CShotgun::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 CShotgun::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "buckshot";
p->iMaxAmmo1 = BUCKSHOT_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = SHOTGUN_MAX_CLIP;
p->iSlot = 2;
p->iPosition = 2;
p->iFlags = 0;
p->iId = m_iId = WEAPON_SHOTGUN;
p->iWeight = SHOTGUN_WEIGHT;
return 1;
}
BOOL CShotgun::Deploy( )
{
return DefaultDeploy( "models/v_shotgun.mdl", "models/p_shotgun.mdl", SHOTGUN_DRAW, "Shotgun" );
}
void CShotgun::PrimaryAttack()
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3 && m_pPlayer->pev->watertype > CONTENT_FLYFIELD)
{
PlayEmptySound( );
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15;
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;
#ifndef CLIENT_DLL
SetThink( &CShotgun::LolShell );
pev->nextthink = gpGlobals->time + 0.6;
#endif
m_iClip--;
int flags;
#if defined( 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 );
// regular old, untouched spread.
Vector vecDir = m_pPlayer->FireBulletsPlayer( 8, vecSrc, vecAiming, VECTOR_CONE_10DEGREES, 2048, BULLET_PLAYER_BUCKSHOT, 0, gSkillData.plrDmgBuckshot, m_pPlayer->pev, m_pPlayer->random_seed );
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 );
if (m_iClip != 0)
m_flPumpTime = gpGlobals->time + 0.5;
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.3;
if (m_iClip != 0)
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 5.0;
else
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.3;
m_fInSpecialReload = 0;
}
void CShotgun::LolShell( void )
{
#ifndef CLIENT_DLL
Vector vecShellVelocity = m_pPlayer->pev->velocity
+ gpGlobals->v_right * 60
+ gpGlobals->v_up * 200
+ gpGlobals->v_forward * 40;
EjectBrass( m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_up * -12 + gpGlobals->v_forward * 45 + gpGlobals->v_right * 30, vecShellVelocity, pev->angles.y, m_iShell, TE_BOUNCE_SHOTSHELL );
#endif
}
void CShotgun::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_RELOAD_START );
m_fInSpecialReload = 1;
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.6;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.6;
m_flNextPrimaryAttack = 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;
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/shotgun_insert.wav", 1, ATTN_NORM, 0, 85 + RANDOM_LONG(0,0x1f));
SendWeaponAnim( SHOTGUN_RELOAD_INS );
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 CShotgun::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/shotgun_pump.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 != SHOTGUN_MAX_CLIP && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
{
Reload( );
}
else
{
// reload debounce has timed out
SendWeaponAnim( SHOTGUN_RELOAD_END );
// play cocking sound
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/shotgun_pump.wav", 1, ATTN_NORM, 0, 95 + RANDOM_LONG(0,0x1f));
m_fInSpecialReload = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.5;
}
}
else
{
SendWeaponAnim( SHOTGUN_IDLE );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + (20.0/9.0);
}
}
}
class CShotgunAmmo : public CBasePlayerAmmo
{
void Spawn( void )
{
Precache( );
SET_MODEL(ENT(pev), "models/w_shotbox.mdl");
CBasePlayerAmmo::Spawn( );
}
void Precache( void )
{
PRECACHE_MODEL ("models/w_shotbox.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
}
BOOL AddAmmo( CBaseEntity *pOther )
{
if (pOther->GiveAmmo( AMMO_BUCKSHOTBOX_GIVE, "buckshot", BUCKSHOT_MAX_CARRY ) != -1)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( ammo_buckshot, CShotgunAmmo );