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.
212 lines
4.6 KiB
212 lines
4.6 KiB
8 years ago
|
/*
|
||
|
Здесь был rainbow
|
||
|
*/
|
||
|
|
||
|
#include "extdll.h"
|
||
|
#include "util.h"
|
||
|
#include "cbase.h"
|
||
|
#include "monsters.h"
|
||
|
#include "weapons.h"
|
||
|
#include "nodes.h"
|
||
|
#include "player.h"
|
||
|
|
||
|
#define HANDGRENADE_PRIMARY_VOLUME 450
|
||
|
|
||
|
enum handgrenade_e
|
||
|
{
|
||
|
HANDGRENADE_IDLE = 0,
|
||
|
HANDGRENADE_THROW2,
|
||
|
HANDGRENADE_DRAW,
|
||
|
HANDGRENADE_FIDGET
|
||
|
|
||
|
|
||
|
};
|
||
|
|
||
|
LINK_ENTITY_TO_CLASS( weapon_rock, CRock )
|
||
|
|
||
|
void CRock::Spawn()
|
||
|
{
|
||
|
Precache();
|
||
|
m_iId = WEAPON_ROCK;
|
||
|
SET_MODEL( ENT( pev ), "models/w_rock.mdl" );
|
||
|
|
||
|
#ifndef CLIENT_DLL
|
||
|
pev->dmg = 40;
|
||
|
#endif
|
||
|
m_iDefaultAmmo = 10000000;
|
||
|
|
||
|
FallInit();// get ready to fall down.
|
||
|
}
|
||
|
|
||
|
void CRock::Precache( void )
|
||
|
{
|
||
|
PRECACHE_MODEL( "models/w_rock.mdl" );
|
||
|
PRECACHE_MODEL( "models/v_rock.mdl" );
|
||
|
PRECACHE_MODEL( "models/p_rock.mdl" );
|
||
|
}
|
||
|
|
||
|
int CRock::GetItemInfo( ItemInfo *p )
|
||
|
{
|
||
|
p->pszName = STRING( pev->classname );
|
||
|
p->pszAmmo1 = "Hand Grenade";
|
||
|
p->iMaxAmmo1 = 10000000000000;
|
||
|
p->pszAmmo2 = NULL;
|
||
|
p->iMaxAmmo2 = -1;
|
||
|
p->iMaxClip = WEAPON_NOCLIP;
|
||
|
p->iSlot = 4;
|
||
|
p->iPosition = 4;
|
||
|
p->iId = m_iId = WEAPON_ROCK;
|
||
|
p->iWeight = HANDGRENADE_WEIGHT;
|
||
|
p->iFlags = ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE;
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
BOOL CRock::Deploy()
|
||
|
{
|
||
|
m_flReleaseThrow = -1;
|
||
|
return DefaultDeploy( "models/v_rock.mdl", "models/p_rock.mdl", HANDGRENADE_DRAW, "crowbar" );
|
||
|
}
|
||
|
|
||
|
BOOL CRock::CanHolster( void )
|
||
|
{
|
||
|
// can only holster hand grenades when not primed!
|
||
|
return ( m_flStartThrow == 0 );
|
||
|
}
|
||
|
|
||
|
void CRock::Holster( int skiplocal /* = 0 */ )
|
||
|
{
|
||
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
|
||
|
|
||
|
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
|
||
|
{
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// no more grenades!
|
||
|
m_pPlayer->pev->weapons &= ~( 1 << WEAPON_HANDGRENADE );
|
||
|
SetThink( &CBasePlayerItem::DestroyItem );
|
||
|
pev->nextthink = gpGlobals->time + 0.1;
|
||
|
}
|
||
|
|
||
|
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM );
|
||
|
}
|
||
|
|
||
|
void CRock::PrimaryAttack()
|
||
|
{
|
||
|
if( !m_flStartThrow && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0 )
|
||
|
{
|
||
|
m_flStartThrow = gpGlobals->time;
|
||
|
m_flReleaseThrow = 0;
|
||
|
|
||
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void CRock::WeaponIdle( void )
|
||
|
{
|
||
|
if( m_flReleaseThrow == 0 && m_flStartThrow )
|
||
|
m_flReleaseThrow = gpGlobals->time;
|
||
|
|
||
|
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
|
||
|
return;
|
||
|
|
||
|
if( m_flStartThrow )
|
||
|
{
|
||
|
Vector angThrow = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle;
|
||
|
|
||
|
if( angThrow.x < 0 )
|
||
|
angThrow.x = -10 + angThrow.x * ( ( 90 - 10 ) / 90.0 );
|
||
|
else
|
||
|
angThrow.x = -10 + angThrow.x * ( ( 90 + 10 ) / 90.0 );
|
||
|
|
||
|
float flVel = ( 90 - angThrow.x ) * 4;
|
||
|
if( flVel > 500 )
|
||
|
flVel = 1300;
|
||
|
|
||
|
UTIL_MakeVectors( angThrow );
|
||
|
|
||
|
Vector vecSrc = m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_forward * 16;
|
||
|
|
||
|
Vector vecThrow = gpGlobals->v_forward * flVel + m_pPlayer->pev->velocity;
|
||
|
|
||
|
// alway explode 3 seconds after the pin was pulled
|
||
|
float time = m_flStartThrow - gpGlobals->time + 3000000000;
|
||
|
if( time < 0 )
|
||
|
time = 0;
|
||
|
|
||
|
|
||
|
CGrenadeRock::ShootTimed( m_pPlayer->pev, vecSrc, vecThrow, time );
|
||
|
|
||
|
|
||
|
if( flVel < 500 )
|
||
|
{
|
||
|
SendWeaponAnim( HANDGRENADE_THROW2 );
|
||
|
}
|
||
|
else if( flVel < 1000 )
|
||
|
{
|
||
|
SendWeaponAnim( HANDGRENADE_THROW2 );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
SendWeaponAnim( HANDGRENADE_THROW2 );
|
||
|
}
|
||
|
|
||
|
// player "shoot" animation
|
||
|
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
|
||
|
|
||
|
m_flReleaseThrow = 0;
|
||
|
m_flStartThrow = 0;
|
||
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5;
|
||
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
|
||
|
|
||
|
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
|
||
|
|
||
|
if( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
|
||
|
{
|
||
|
// just threw last grenade
|
||
|
// set attack times in the future, and weapon idle in the future so we can see the whole throw
|
||
|
// animation, weapon idle will automatically retire the weapon for us.
|
||
|
m_flTimeWeaponIdle = m_flNextSecondaryAttack = m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5;// ensure that the animation can finish playing
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
else if( m_flReleaseThrow > 0 )
|
||
|
{
|
||
|
// we've finished the throw, restart.
|
||
|
m_flStartThrow = 0;
|
||
|
|
||
|
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
|
||
|
{
|
||
|
SendWeaponAnim( HANDGRENADE_DRAW );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
RetireWeapon();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
|
||
|
m_flReleaseThrow = -1;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
|
||
|
{
|
||
|
int iAnim;
|
||
|
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 20 );
|
||
|
if( flRand <= 0.75 )
|
||
|
{
|
||
|
iAnim = HANDGRENADE_IDLE;
|
||
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );// how long till we do this again.
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
iAnim = HANDGRENADE_FIDGET;
|
||
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 75.0 / 30.0;
|
||
|
}
|
||
|
|
||
|
SendWeaponAnim( iAnim );
|
||
|
}
|
||
|
}
|