mirror of https://github.com/FWGS/hlsdk-xash3d
348 lines
8.1 KiB
C++
Executable File
348 lines
8.1 KiB
C++
Executable File
/***
|
|
*
|
|
* Copyright (c) 1999, 2000 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_IDLE1 = 0,
|
|
SHOTGUN_IDLE2,
|
|
SHOTGUN_IDLE3,
|
|
SHOTGUN_HOLSTER,
|
|
SHOTGUN_DRAW,
|
|
SHOTGUN_FIRE,
|
|
SHOTGUN_FIRE2,
|
|
SHOTGUN_RELOAD
|
|
};
|
|
|
|
class CShotgun : public CBasePlayerWeapon
|
|
{
|
|
public:
|
|
void Spawn( void );
|
|
void Precache( void );
|
|
int iItemSlot( ) { return 1; }
|
|
int GetItemInfo(ItemInfo *p);
|
|
int AddToPlayer( CBasePlayer *pPlayer );
|
|
|
|
void PrimaryAttack( void );
|
|
void SecondaryAttack( void );
|
|
BOOL Deploy( );
|
|
void Holster( int skiplocal = 0 );
|
|
void Reload( void );
|
|
void WeaponIdle( void );
|
|
int m_iShell;
|
|
|
|
virtual BOOL UseDecrement( void )
|
|
{
|
|
#if defined( CLIENT_WEAPONS )
|
|
return TRUE;
|
|
#else
|
|
return FALSE;
|
|
#endif
|
|
}
|
|
|
|
private:
|
|
unsigned short m_usDoubleFire;
|
|
unsigned short m_usSingleFire;
|
|
};
|
|
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/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/shotgun1.sc" );
|
|
m_usDoubleFire = PRECACHE_EVENT( 1, "events/shotgun2.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 = "shotgun";
|
|
p->iMaxAmmo1 = SHOTGUN_MAX_CARRY;
|
|
p->pszAmmo2 = NULL;
|
|
p->iMaxAmmo2 = -1;
|
|
p->iMaxClip = SHOTGUN_MAX_CLIP;
|
|
p->iSlot = 1;
|
|
p->iPosition = 1;
|
|
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::Holster( int skiplocal /* = 0 */ )
|
|
{
|
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
|
|
SendWeaponAnim( SHOTGUN_HOLSTER );
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
PLAYBACK_EVENT( 0, m_pPlayer->edict(), m_usSingleFire );
|
|
|
|
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
|
|
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
|
|
|
|
m_iClip--;
|
|
|
|
// player "shoot" animation
|
|
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
|
|
|
|
Vector vecSrc = m_pPlayer->GetGunPosition( );
|
|
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
|
|
|
|
if ( g_pGameRules->IsDeathmatch() )
|
|
{
|
|
// altered deathmatch spread
|
|
m_pPlayer->FireBullets( 4, vecSrc, vecAiming, VECTOR_CONE_DM_SHOTGUN, 2048, BULLET_PLAYER_SHOTGUN, 0 );
|
|
}
|
|
else
|
|
{
|
|
// regular old, untouched spread.
|
|
m_pPlayer->FireBullets( 6, vecSrc, vecAiming, VECTOR_CONE_10DEGREES, 2048, BULLET_PLAYER_SHOTGUN, 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);
|
|
|
|
double dSingleShotAnim = 0.95;
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + dSingleShotAnim;
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + dSingleShotAnim;
|
|
|
|
if (m_iClip != 0)
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + dSingleShotAnim + 3.6;
|
|
else
|
|
m_flTimeWeaponIdle = dSingleShotAnim;
|
|
}
|
|
|
|
|
|
void CShotgun::SecondaryAttack( void )
|
|
{
|
|
// 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 <= 1)
|
|
{
|
|
PlayEmptySound( );
|
|
Reload( );
|
|
return;
|
|
}
|
|
|
|
PLAYBACK_EVENT( 0, m_pPlayer->edict(), m_usDoubleFire );
|
|
|
|
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
|
|
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
|
|
|
|
m_iClip -= 2;
|
|
|
|
// player "shoot" animation
|
|
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
|
|
|
|
Vector vecSrc = m_pPlayer->GetGunPosition( );
|
|
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
|
|
|
|
if ( g_pGameRules->IsDeathmatch() )
|
|
{
|
|
// tuned for deathmatch
|
|
m_pPlayer->FireBullets( 8, vecSrc, vecAiming, VECTOR_CONE_DM_DOUBLESHOTGUN, 2048, BULLET_PLAYER_SHOTGUN, 0 );
|
|
}
|
|
else
|
|
{
|
|
// untouched default single player
|
|
m_pPlayer->FireBullets( 12, vecSrc, vecAiming, VECTOR_CONE_10DEGREES, 2048, BULLET_PLAYER_SHOTGUN, 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);
|
|
|
|
double dDoubleShotAnim = 1.1;
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + dDoubleShotAnim;
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + dDoubleShotAnim;
|
|
|
|
if (m_iClip != 0)
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + dDoubleShotAnim + 3.6;
|
|
else
|
|
m_flTimeWeaponIdle = dDoubleShotAnim;
|
|
}
|
|
|
|
|
|
void CShotgun::Reload( void )
|
|
{
|
|
int iResult;
|
|
|
|
iResult = DefaultReload( SHOTGUN_MAX_CLIP, SHOTGUN_RELOAD, 111.0/36.0 );
|
|
|
|
if (iResult)
|
|
{
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
|
|
}
|
|
}
|
|
|
|
|
|
void CShotgun::WeaponIdle( void )
|
|
{
|
|
ResetEmptySound( );
|
|
|
|
m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
|
|
|
|
if (m_flTimeWeaponIdle < gpGlobals->time)
|
|
{
|
|
if (m_iClip == 0 && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
|
{
|
|
Reload( );
|
|
}
|
|
else
|
|
{
|
|
int iAnim;
|
|
float flRand = RANDOM_FLOAT(0, 1);
|
|
if (flRand <= 0.8)
|
|
{
|
|
iAnim = SHOTGUN_IDLE1;
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + (89.0/30.0);// * RANDOM_LONG(2, 5);
|
|
}
|
|
else if (flRand <= 0.95)
|
|
{
|
|
iAnim = SHOTGUN_IDLE2;
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + (149.0/40.0);
|
|
}
|
|
else
|
|
{
|
|
iAnim = SHOTGUN_IDLE3;
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + (149.0/40.0);
|
|
}
|
|
SendWeaponAnim( iAnim );
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class CShotgunAmmo : public CBasePlayerAmmo
|
|
{
|
|
void Spawn( void )
|
|
{
|
|
Precache( );
|
|
//SET_MODEL(ENT(pev), "models/w_shotbox.mdl");
|
|
SET_MODEL(ENT(pev), "models/w_shotgunammo.mdl");
|
|
CBasePlayerAmmo::Spawn( );
|
|
}
|
|
void Precache( void )
|
|
{
|
|
//PRECACHE_MODEL ("models/w_shotbox.mdl");
|
|
PRECACHE_MODEL ("models/w_shotgunammo.mdl");
|
|
PRECACHE_SOUND("items/9mmclip1.wav");
|
|
}
|
|
BOOL AddAmmo( CBaseEntity *pOther )
|
|
{
|
|
if (pOther->GiveAmmo( AMMO_SHOTGUN_GIVE, "shotgun", SHOTGUN_MAX_CARRY ) != -1)
|
|
{
|
|
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
};
|
|
LINK_ENTITY_TO_CLASS( ammo_shotgun, CShotgunAmmo );
|
|
|
|
|