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.
309 lines
7.0 KiB
309 lines
7.0 KiB
8 years ago
|
//fixed (maybe)
|
||
8 years ago
|
#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
|
||
|
|
||
|
#include "extdll.h"
|
||
|
#include "util.h"
|
||
|
#include "cbase.h"
|
||
|
#include "weapons.h"
|
||
|
#include "monsters.h"
|
||
|
#include "player.h"
|
||
|
#include "gamerules.h"
|
||
|
#include "shake.h"
|
||
|
|
||
|
#include "nodes.h"
|
||
|
#include "soundent.h"
|
||
8 years ago
|
#define WEAPON_SNIPARS 18
|
||
8 years ago
|
|
||
8 years ago
|
class CSnipars : public CBasePlayerWeapon
|
||
|
{
|
||
|
public:
|
||
8 years ago
|
#ifndef CLIENT_DLL
|
||
|
int Save( CSave &save );
|
||
|
int Restore( CRestore &restore );
|
||
|
static TYPEDESCRIPTION m_SaveData[];
|
||
|
#endif
|
||
8 years ago
|
void Spawn( void );
|
||
|
void Precache( void );
|
||
|
int iItemSlot( void ) { return 2; }
|
||
|
int GetItemInfo(ItemInfo *p);
|
||
|
int AddToPlayer( CBasePlayer *pPlayer );
|
||
|
void PrimaryAttack( void );
|
||
|
void SecondaryAttack( void );
|
||
|
BOOL Deploy( void );
|
||
|
void Holster( int skiplocal = 0 );
|
||
|
void Reload( void );
|
||
|
void WeaponIdle( void );
|
||
|
void Shoot( float flSpread, float flCycleTime, BOOL fUseAutoAim );
|
||
|
float m_flSoundDelay;
|
||
|
|
||
|
BOOL m_fInZoom;// don't save this.
|
||
|
|
||
|
virtual BOOL UseDecrement( void )
|
||
|
{
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
//unsigned short m_usFireSniper;
|
||
|
};
|
||
|
|
||
8 years ago
|
TYPEDESCRIPTION CSnipars::m_SaveData[] =
|
||
|
{
|
||
|
DEFINE_FIELD( CSnipars, m_flSoundDelay, FIELD_FLOAT ),
|
||
|
DEFINE_FIELD( CSnipars, m_fInZoom, FIELD_INTEGER ),
|
||
|
};
|
||
|
|
||
|
IMPLEMENT_SAVERESTORE( CSnipars, CBasePlayerWeapon )
|
||
|
|
||
8 years ago
|
enum sniper_e
|
||
|
{
|
||
|
SNIPARS_IDLE = 0,
|
||
|
SNIPARS_DRAW,
|
||
|
SNIPARS_FIRE,
|
||
|
SNIPARS_RELOAD
|
||
8 years ago
|
};
|
||
|
|
||
|
LINK_ENTITY_TO_CLASS( weapon_snipars, CSnipars );
|
||
|
|
||
|
int CSnipars::GetItemInfo(ItemInfo *p)
|
||
|
{
|
||
8 years ago
|
p->pszName = STRING(pev->classname);
|
||
|
p->pszAmmo1 = "snipars";
|
||
8 years ago
|
p->iMaxAmmo1 = 50;
|
||
8 years ago
|
p->pszAmmo2 = NULL;
|
||
|
p->iMaxAmmo2 = -1;
|
||
8 years ago
|
p->iMaxClip = 10;
|
||
8 years ago
|
p->iFlags = 0;
|
||
|
p->iSlot = 3;
|
||
|
p->iPosition = 4;
|
||
|
p->iId = m_iId = WEAPON_SNIPARS;
|
||
8 years ago
|
p->iWeight = 10;
|
||
8 years ago
|
|
||
|
return 1;
|
||
|
}
|
||
8 years ago
|
|
||
|
int CSnipars::AddToPlayer( CBasePlayer *pPlayer )
|
||
|
{
|
||
8 years ago
|
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
|
}
|
||
|
|
||
|
void CSnipars::Spawn( )
|
||
|
{
|
||
8 years ago
|
pev->classname = MAKE_STRING("weapon_snipars");
|
||
|
Precache( );
|
||
|
m_iId = WEAPON_SNIPARS;
|
||
|
SET_MODEL(ENT(pev), "models/w_sniper.mdl");
|
||
8 years ago
|
|
||
8 years ago
|
m_iDefaultAmmo = 10;
|
||
8 years ago
|
|
||
8 years ago
|
FallInit();
|
||
8 years ago
|
}
|
||
|
|
||
|
void CSnipars::Precache( void )
|
||
|
{
|
||
8 years ago
|
PRECACHE_MODEL("models/v_sniper.mdl");
|
||
|
PRECACHE_MODEL("models/w_sniper.mdl");
|
||
|
PRECACHE_MODEL("models/p_sniper.mdl");
|
||
8 years ago
|
|
||
8 years ago
|
PRECACHE_MODEL("models/w_357ammo.mdl");
|
||
|
PRECACHE_SOUND("items/9mmclip1.wav");
|
||
8 years ago
|
|
||
8 years ago
|
PRECACHE_SOUND ("weapons/sniper_shoot1.wav");
|
||
|
PRECACHE_SOUND ("weapons/sniper_shoot2.wav");
|
||
|
PRECACHE_SOUND ("weapons/sniper_shoot3.wav");
|
||
|
PRECACHE_SOUND ("weapons/sniper_shoot4.wav");
|
||
|
PRECACHE_SOUND ("weapons/sniper_shoot5.wav");
|
||
8 years ago
|
|
||
8 years ago
|
//m_usFireSniper = PRECACHE_EVENT( 1, "events/glock1.sc" );
|
||
8 years ago
|
}
|
||
|
|
||
|
BOOL CSnipars::Deploy( )
|
||
|
{
|
||
8 years ago
|
return DefaultDeploy( "models/v_sniper.mdl", "models/p_sniper.mdl", SNIPARS_DRAW, "snipars", UseDecrement() );
|
||
8 years ago
|
}
|
||
|
|
||
|
void CSnipars::Holster( int skiplocal /* = 0 */ )
|
||
|
{
|
||
8 years ago
|
m_fInReload = FALSE;
|
||
|
|
||
|
if ( m_fInZoom )
|
||
|
{
|
||
|
SecondaryAttack();
|
||
|
}
|
||
|
m_pPlayer->m_flNextAttack = gpGlobals->time + 1.0;
|
||
|
m_flTimeWeaponIdle = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
|
||
8 years ago
|
}
|
||
|
|
||
|
void CSnipars::SecondaryAttack( void )
|
||
|
{
|
||
8 years ago
|
if ( m_pPlayer->pev->fov != 0 )
|
||
|
{
|
||
|
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0;
|
||
|
m_fInZoom = 0;
|
||
|
UTIL_ScreenFade( m_pPlayer, Vector(0,0,0), 0.5, 0.25, 255, FFADE_IN );
|
||
|
|
||
|
}
|
||
|
else if ( m_pPlayer->pev->fov != 15 )
|
||
|
{
|
||
|
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 15;
|
||
|
m_fInZoom = 1;
|
||
|
UTIL_ScreenFade( m_pPlayer, Vector(0,0,0), 0.5, 0.25, 255, FFADE_IN );
|
||
|
}
|
||
|
pev->nextthink = gpGlobals->time + 0.1;
|
||
|
m_flNextSecondaryAttack = gpGlobals->time + 1.0;
|
||
8 years ago
|
}
|
||
|
|
||
|
void CSnipars::PrimaryAttack( void )
|
||
8 years ago
|
{
|
||
8 years ago
|
if(m_iClip > 0)
|
||
|
{
|
||
|
Shoot( 0.0001, 1.5, TRUE );
|
||
8 years ago
|
switch( RANDOM_LONG( 0, 3 ) )
|
||
|
{
|
||
|
case 0:
|
||
|
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/sniper_shoot1.wav", 1, ATTN_NORM );
|
||
|
break;
|
||
|
case 1:
|
||
|
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/sniper_shoot2.wav", 1, ATTN_NORM );
|
||
|
break;
|
||
|
case 2:
|
||
|
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/sniper_shoot3.wav", 1, ATTN_NORM );
|
||
|
break;
|
||
|
case 3:
|
||
|
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/sniper_shoot4.wav", 1, ATTN_NORM );
|
||
|
break;
|
||
|
case 4:
|
||
|
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/sniper_shoot5.wav", 1, ATTN_NORM );
|
||
|
break;
|
||
|
};
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
void CSnipars::Shoot( float flSpread , float flCycleTime, BOOL fUseAutoAim )
|
||
|
{
|
||
|
|
||
8 years ago
|
if (m_pPlayer->pev->waterlevel == 3)
|
||
|
{
|
||
|
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/sniper_cock1.wav", 0.8, ATTN_NORM);
|
||
|
m_flNextPrimaryAttack = 0.15; return;
|
||
|
}
|
||
|
if (m_iClip <= 0)
|
||
|
{
|
||
|
if (m_fFireOnEmpty)
|
||
|
{
|
||
|
m_flNextPrimaryAttack = gpGlobals->time + 0.2;
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
SendWeaponAnim( SNIPARS_FIRE );
|
||
|
m_iClip--;
|
||
|
|
||
|
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
|
||
|
|
||
|
int flags;
|
||
|
|
||
|
// player "shoot" animation
|
||
|
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
|
||
|
|
||
|
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
|
||
|
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
|
||
|
|
||
|
Vector vecSrc = m_pPlayer->GetGunPosition( );
|
||
|
Vector vecAiming;
|
||
|
|
||
|
if ( fUseAutoAim )
|
||
|
{
|
||
|
vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
vecAiming = gpGlobals->v_forward;
|
||
|
}
|
||
|
|
||
8 years ago
|
Vector vecDir = m_pPlayer->FireBulletsPlayer( 3, vecSrc, vecAiming, Vector( flSpread, flSpread, flSpread ), 8192, BULLET_PLAYER_9MM, 0, 50, m_pPlayer->pev, m_pPlayer->random_seed );
|
||
8 years ago
|
|
||
|
//PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usFireSniper, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, ( m_iClip == 0 ) ? 1 : 0, 0 );
|
||
|
pev->effects |= EF_MUZZLEFLASH;
|
||
|
m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->time + flCycleTime;
|
||
|
|
||
|
if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
||
|
m_flTimeWeaponIdle = RANDOM_FLOAT( 10, 15 );
|
||
8 years ago
|
}
|
||
|
|
||
|
void CSnipars::Reload( void )
|
||
|
{
|
||
8 years ago
|
if ( m_fInZoom )
|
||
|
{
|
||
|
SecondaryAttack();
|
||
|
}
|
||
|
if ( m_pPlayer->ammo_snipars <= 0 )
|
||
|
return;
|
||
|
|
||
|
if ( m_pPlayer->pev->fov != 0 )
|
||
|
{
|
||
|
m_fInZoom = FALSE;
|
||
|
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
|
||
|
}
|
||
|
//if (m_iClip == 0)
|
||
|
//DefaultReload( 5, SNIPARS_RELOAD, 1.5 );
|
||
|
//else
|
||
|
DefaultReload( 5, SNIPARS_RELOAD, 1.5 );
|
||
8 years ago
|
}
|
||
|
|
||
|
void CSnipars::WeaponIdle( void )
|
||
|
{
|
||
8 years ago
|
m_pPlayer->GetAutoaimVector( AUTOAIM_2DEGREES );
|
||
|
|
||
|
if ( m_flTimeWeaponIdle < gpGlobals->time )
|
||
|
{
|
||
|
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
|
||
|
if (flRand <= 0.75)
|
||
|
{
|
||
|
if (m_iClip)
|
||
|
{
|
||
|
SendWeaponAnim( SNIPARS_IDLE );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
SendWeaponAnim( SNIPARS_IDLE );
|
||
|
}
|
||
|
m_flTimeWeaponIdle = gpGlobals->time + 60.0 / 12.0;
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
class CSniparsAmmo : public CBasePlayerAmmo
|
||
|
{
|
||
8 years ago
|
void Spawn( void )
|
||
|
{
|
||
|
Precache( );
|
||
8 years ago
|
SET_MODEL(ENT(pev), "models/w_357ammo.mdl");
|
||
8 years ago
|
CBasePlayerAmmo::Spawn( );
|
||
|
}
|
||
|
void Precache( void )
|
||
|
{
|
||
|
PRECACHE_MODEL ("models/w_357ammo.mdl");
|
||
|
PRECACHE_SOUND("items/9mmclip1.wav");
|
||
|
}
|
||
|
BOOL AddAmmo( CBaseEntity *pOther )
|
||
|
{
|
||
8 years ago
|
if (pOther->GiveAmmo( 10, "snipars", 50 ) != -1)
|
||
8 years ago
|
{
|
||
|
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
|
||
|
return TRUE;
|
||
|
}
|
||
|
return FALSE;
|
||
|
}
|
||
8 years ago
|
};
|
||
8 years ago
|
LINK_ENTITY_TO_CLASS( ammo_snipars, CSniparsAmmo );
|
||
8 years ago
|
|
||
|
#endif
|