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.

221 lines
5.0 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 "soundent.h"
#include "gamerules.h"
enum uzi_e
{
UZI_LONGIDLE = 0,
UZI_IDLE1,
UZI_RELOAD,
UZI_DEPLOY,
UZI_FIRE1,
UZI_FIRE2,
UZI_FIRE3
};
LINK_ENTITY_TO_CLASS( weapon_uzi, CUZI )
//=========================================================
//=========================================================
int CUZI::SecondaryAmmoIndex( void )
{
return m_iSecondaryAmmoType;
}
void CUZI::Spawn( )
{
pev->classname = MAKE_STRING("weapon_uzi"); // hack to allow for old names
Precache( );
SET_MODEL(ENT(pev), "models/w_uzi.mdl");
m_iId = WEAPON_UZI;
m_iDefaultAmmo = UZI_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
void CUZI::Precache( void )
{
PRECACHE_MODEL("models/v_uzi.mdl");
PRECACHE_MODEL("models/w_uzi.mdl");
PRECACHE_MODEL("models/p_uzi.mdl");
m_iShell = PRECACHE_MODEL ("models/9mm_shell.mdl");// brass shellTE_MODEL
PRECACHE_MODEL("models/w_uziclip.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND("items/clipinsert1.wav");
PRECACHE_SOUND("items/cliprelease1.wav");
PRECACHE_SOUND ("weapons/uzi1.wav");// H to the K
PRECACHE_SOUND ("weapons/uzi2.wav");// H to the K
PRECACHE_SOUND ("weapons/uzi3.wav");// H to the K
PRECACHE_SOUND ("weapons/357_cock1.wav");
m_usUZI = PRECACHE_EVENT( 1, "events/uzi.sc" );
}
int CUZI::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "9mm";
p->iMaxAmmo1 = _9MM_MAX_CARRY;
p->iMaxClip = UZI_MAX_CLIP;
p->iSlot = 1;
p->iPosition = 3;
p->iFlags = 0;
p->iId = m_iId = WEAPON_UZI;
p->iWeight = UZI_WEIGHT;
p->weaponName = "9mm Uzi";
return 1;
}
int CUZI::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;
}
BOOL CUZI::Deploy( )
{
return DefaultDeploy( "models/v_uzi.mdl", "models/p_uzi.mdl", UZI_DEPLOY, "uzi" );
}
void CUZI::PrimaryAttack()
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3 && m_pPlayer->pev->watertype > CONTENT_FLYFIELD)
{
PlayEmptySound( );
m_flNextPrimaryAttack = 0.15;
return;
}
if (m_iClip <= 0)
{
PlayEmptySound();
m_flNextPrimaryAttack = 0.15;
return;
}
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
m_iClip--;
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
Vector vecSrc = m_pPlayer->GetGunPosition( );
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
Vector vecDir;
4 years ago
#if CLIENT_DLL
if( bIsMultiplayer() )
#else
if( g_pGameRules->IsMultiplayer() )
#endif
{
// optimized multiplayer. Widened to make it easier to hit a moving player
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_3DEGREES, 8192, BULLET_PLAYER_MP5, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed );
}
else
{
// single player spread
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_3DEGREES, 8192, BULLET_PLAYER_MP5, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed );
}
int flags;
4 years ago
#if CLIENT_WEAPONS
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usUZI, 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);
m_flNextPrimaryAttack = GetNextAttackDelay( 0.1f );
if ( m_flNextPrimaryAttack < UTIL_WeaponTimeBase() )
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.01f;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
void CUZI::Reload( void )
{
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == UZI_MAX_CLIP )
return;
DefaultReload( UZI_MAX_CLIP, UZI_RELOAD, 3.0);
}
void CUZI::WeaponIdle( void )
{
ResetEmptySound( );
m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
if ( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
return;
int iAnim;
switch ( RANDOM_LONG( 0, 1 ) )
{
case 0:
iAnim = UZI_LONGIDLE;
break;
default:
case 1:
iAnim = UZI_IDLE1;
break;
}
SendWeaponAnim( iAnim );
m_flTimeWeaponIdle = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); // how long till we do this again.
}