2016-06-04 15:24:23 +02:00
|
|
|
/***
|
|
|
|
*
|
|
|
|
* 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 mp5_e
|
|
|
|
{
|
|
|
|
MP5_LONGIDLE = 0,
|
|
|
|
MP5_IDLE1,
|
|
|
|
MP5_LAUNCH,
|
|
|
|
MP5_RELOAD,
|
|
|
|
MP5_DEPLOY,
|
|
|
|
MP5_FIRE1,
|
|
|
|
MP5_FIRE2,
|
2016-06-25 18:33:39 +02:00
|
|
|
MP5_FIRE3
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( weapon_mp5, CMP5 )
|
|
|
|
LINK_ENTITY_TO_CLASS( weapon_9mmAR, CMP5 )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
//=========================================================
|
|
|
|
int CMP5::SecondaryAmmoIndex( void )
|
|
|
|
{
|
|
|
|
return m_iSecondaryAmmoType;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
void CMP5::Spawn()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
pev->classname = MAKE_STRING( "weapon_9mmAR" ); // hack to allow for old names
|
|
|
|
Precache();
|
|
|
|
SET_MODEL( ENT( pev ), "models/w_9mmAR.mdl" );
|
2016-06-04 15:24:23 +02:00
|
|
|
m_iId = WEAPON_MP5;
|
|
|
|
|
|
|
|
m_iDefaultAmmo = MP5_DEFAULT_GIVE;
|
|
|
|
|
|
|
|
FallInit();// get ready to fall down.
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMP5::Precache( void )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_MODEL( "models/v_9mmAR.mdl" );
|
|
|
|
PRECACHE_MODEL( "models/w_9mmAR.mdl" );
|
|
|
|
PRECACHE_MODEL( "models/p_9mmAR.mdl" );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
m_iShell = PRECACHE_MODEL( "models/shell.mdl" );// brass shellTE_MODEL
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_MODEL( "models/grenade.mdl" ); // grenade
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_MODEL( "models/w_9mmARclip.mdl" );
|
|
|
|
PRECACHE_SOUND( "items/9mmclip1.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_SOUND( "items/clipinsert1.wav" );
|
|
|
|
PRECACHE_SOUND( "items/cliprelease1.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_SOUND( "weapons/hks1.wav" );// H to the K
|
|
|
|
PRECACHE_SOUND( "weapons/hks2.wav" );// H to the K
|
|
|
|
PRECACHE_SOUND( "weapons/hks3.wav" );// H to the K
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
PRECACHE_SOUND( "weapons/glauncher.wav" );
|
|
|
|
PRECACHE_SOUND( "weapons/glauncher2.wav" );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_SOUND( "weapons/357_cock1.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_usMP5 = PRECACHE_EVENT( 1, "events/mp5.sc" );
|
|
|
|
m_usMP52 = PRECACHE_EVENT( 1, "events/mp52.sc" );
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
int CMP5::GetItemInfo( ItemInfo *p )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
p->pszName = STRING( pev->classname );
|
2016-06-04 15:24:23 +02:00
|
|
|
p->pszAmmo1 = "9mm";
|
|
|
|
p->iMaxAmmo1 = _9MM_MAX_CARRY;
|
|
|
|
p->pszAmmo2 = "ARgrenades";
|
|
|
|
p->iMaxAmmo2 = M203_GRENADE_MAX_CARRY;
|
|
|
|
p->iMaxClip = MP5_MAX_CLIP;
|
|
|
|
p->iSlot = 2;
|
|
|
|
p->iPosition = 0;
|
|
|
|
p->iFlags = 0;
|
|
|
|
p->iId = m_iId = WEAPON_MP5;
|
|
|
|
p->iWeight = MP5_WEIGHT;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CMP5::AddToPlayer( CBasePlayer *pPlayer )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
|
|
|
|
WRITE_BYTE( m_iId );
|
|
|
|
MESSAGE_END();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
BOOL CMP5::Deploy()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return DefaultDeploy( "models/v_9mmAR.mdl", "models/p_9mmAR.mdl", MP5_DEPLOY, "mp5" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMP5::PrimaryAttack()
|
|
|
|
{
|
|
|
|
// don't fire underwater
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pPlayer->pev->waterlevel == 3 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
PlayEmptySound();
|
2016-06-04 15:24:23 +02:00
|
|
|
m_flNextPrimaryAttack = 0.15;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_iClip <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PlayEmptySound();
|
|
|
|
m_flNextPrimaryAttack = 0.15;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
|
|
|
|
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
|
|
|
|
|
|
|
|
m_iClip--;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
m_pPlayer->pev->effects = (int)( m_pPlayer->pev->effects ) | EF_MUZZLEFLASH;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// player "shoot" animation
|
|
|
|
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
Vector vecSrc = m_pPlayer->GetGunPosition();
|
2016-06-04 15:24:23 +02:00
|
|
|
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
|
|
|
|
Vector vecDir;
|
|
|
|
#ifdef CLIENT_DLL
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !bIsMultiplayer() )
|
2016-06-04 15:24:23 +02:00
|
|
|
#else
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !g_pGameRules->IsMultiplayer() )
|
2016-06-04 15:24:23 +02:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// optimized multiplayer. Widened to make it easier to hit a moving player
|
|
|
|
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_6DEGREES, 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 );
|
|
|
|
}
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
int flags;
|
2016-06-04 15:24:23 +02:00
|
|
|
#if defined( CLIENT_WEAPONS )
|
|
|
|
flags = FEV_NOTHOST;
|
|
|
|
#else
|
|
|
|
flags = 0;
|
|
|
|
#endif
|
|
|
|
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usMP5, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
// HEV suit - indicate out of ammo condition
|
2016-08-01 13:13:13 +02:00
|
|
|
m_pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2017-06-26 02:47:19 +02:00
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay( 0.1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_flNextPrimaryAttack < UTIL_WeaponTimeBase() )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.1;
|
|
|
|
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMP5::SecondaryAttack( void )
|
|
|
|
{
|
|
|
|
// don't fire underwater
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pPlayer->pev->waterlevel == 3 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PlayEmptySound( );
|
|
|
|
m_flNextPrimaryAttack = 0.15;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
PlayEmptySound();
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
|
|
|
|
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
|
|
|
|
|
|
|
|
m_pPlayer->m_iExtraSoundTypes = bits_SOUND_DANGER;
|
|
|
|
m_pPlayer->m_flStopExtraSoundTime = UTIL_WeaponTimeBase() + 0.2;
|
2016-08-01 13:13:13 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType]--;
|
|
|
|
|
|
|
|
// player "shoot" animation
|
|
|
|
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
|
|
|
|
|
|
|
|
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
|
|
|
|
|
|
|
|
// we don't add in player velocity anymore.
|
2016-08-01 13:13:13 +02:00
|
|
|
CGrenade::ShootContact( m_pPlayer->pev,
|
|
|
|
m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_forward * 16,
|
|
|
|
gpGlobals->v_forward * 800 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
int flags;
|
|
|
|
#if defined( CLIENT_WEAPONS )
|
|
|
|
flags = FEV_NOTHOST;
|
|
|
|
#else
|
|
|
|
flags = 0;
|
|
|
|
#endif
|
|
|
|
PLAYBACK_EVENT( flags, m_pPlayer->edict(), m_usMP52 );
|
2016-08-01 13:13:13 +02:00
|
|
|
|
2017-06-26 02:47:19 +02:00
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay( 1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 5;// idle pretty soon after shooting.
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] )
|
2016-06-04 15:24:23 +02:00
|
|
|
// HEV suit - indicate out of ammo condition
|
2016-08-01 13:13:13 +02:00
|
|
|
m_pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMP5::Reload( void )
|
|
|
|
{
|
2017-07-05 21:20:29 +02:00
|
|
|
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == MP5_MAX_CLIP )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
DefaultReload( MP5_MAX_CLIP, MP5_RELOAD, 1.5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMP5::WeaponIdle( void )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
ResetEmptySound();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
int iAnim;
|
2016-08-01 13:13:13 +02:00
|
|
|
switch( RANDOM_LONG( 0, 1 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
iAnim = MP5_LONGIDLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
iAnim = MP5_IDLE1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendWeaponAnim( iAnim );
|
|
|
|
|
|
|
|
m_flTimeWeaponIdle = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); // how long till we do this again.
|
|
|
|
}
|
|
|
|
|
2017-07-05 16:17:59 +02:00
|
|
|
BOOL CMP5::IsUseable()
|
|
|
|
{
|
|
|
|
//Can be used if the player has AR grenades. - Solokiller
|
|
|
|
return CBasePlayerWeapon::IsUseable() || m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] > 0;
|
|
|
|
}
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
class CMP5AmmoClip : public CBasePlayerAmmo
|
|
|
|
{
|
|
|
|
void Spawn( void )
|
2016-08-01 13:13:13 +02:00
|
|
|
{
|
|
|
|
Precache();
|
|
|
|
SET_MODEL( ENT( pev ), "models/w_9mmARclip.mdl" );
|
|
|
|
CBasePlayerAmmo::Spawn();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
void Precache( void )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_MODEL( "models/w_9mmARclip.mdl" );
|
|
|
|
PRECACHE_SOUND( "items/9mmclip1.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
BOOL AddAmmo( CBaseEntity *pOther )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int bResult = ( pOther->GiveAmmo( AMMO_MP5CLIP_GIVE, "9mm", _9MM_MAX_CARRY ) != -1 );
|
|
|
|
if( bResult )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( ammo_mp5clip, CMP5AmmoClip )
|
|
|
|
LINK_ENTITY_TO_CLASS( ammo_9mmAR, CMP5AmmoClip )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
class CMP5Chainammo : public CBasePlayerAmmo
|
|
|
|
{
|
|
|
|
void Spawn( void )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
Precache();
|
|
|
|
SET_MODEL( ENT( pev ), "models/w_chainammo.mdl" );
|
|
|
|
CBasePlayerAmmo::Spawn();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
void Precache( void )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_MODEL( "models/w_chainammo.mdl" );
|
|
|
|
PRECACHE_SOUND( "items/9mmclip1.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
BOOL AddAmmo( CBaseEntity *pOther )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int bResult = ( pOther->GiveAmmo( AMMO_CHAINBOX_GIVE, "9mm", _9MM_MAX_CARRY ) != -1 );
|
|
|
|
if( bResult )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( ammo_9mmbox, CMP5Chainammo )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
class CMP5AmmoGrenade : public CBasePlayerAmmo
|
|
|
|
{
|
|
|
|
void Spawn( void )
|
2016-08-01 13:13:13 +02:00
|
|
|
{
|
|
|
|
Precache();
|
|
|
|
SET_MODEL( ENT( pev ), "models/w_ARgrenade.mdl" );
|
|
|
|
CBasePlayerAmmo::Spawn();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
void Precache( void )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
PRECACHE_MODEL( "models/w_ARgrenade.mdl" );
|
|
|
|
PRECACHE_SOUND( "items/9mmclip1.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
BOOL AddAmmo( CBaseEntity *pOther )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int bResult = ( pOther->GiveAmmo( AMMO_M203BOX_GIVE, "ARgrenades", M203_GRENADE_MAX_CARRY ) != -1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( bResult )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( ammo_mp5grenades, CMP5AmmoGrenade )
|
|
|
|
LINK_ENTITY_TO_CLASS( ammo_ARgrenades, CMP5AmmoGrenade )
|