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.

278 lines
6.4 KiB

9 years ago
/***
*
* 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.
*
****/
9 years ago
#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
9 years ago
enum handgrenade_e
{
9 years ago
HANDGRENADE_IDLE = 0,
HANDGRENADE_FIDGET,
HANDGRENADE_PINPULL,
HANDGRENADE_THROW1, // toss
HANDGRENADE_THROW2, // medium
HANDGRENADE_THROW3, // hard
HANDGRENADE_HOLSTER,
HANDGRENADE_DRAW
};
LINK_ENTITY_TO_CLASS( weapon_handgrenade, CHandGrenade )
9 years ago
9 years ago
void CHandGrenade::Spawn()
9 years ago
{
9 years ago
Precache();
9 years ago
m_iId = WEAPON_HANDGRENADE;
9 years ago
SET_MODEL( ENT( pev ), "models/w_grenade.mdl" );
9 years ago
#ifndef CLIENT_DLL
pev->dmg = gSkillData.plrDmgHandGrenade;
#endif
m_iDefaultAmmo = HANDGRENADE_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
void CHandGrenade::Precache( void )
{
9 years ago
PRECACHE_MODEL( "models/w_grenade.mdl" );
PRECACHE_MODEL( "models/v_grenade.mdl" );
PRECACHE_MODEL( "models/p_grenade.mdl" );
9 years ago
}
9 years ago
int CHandGrenade::GetItemInfo( ItemInfo *p )
9 years ago
{
9 years ago
p->pszName = STRING( pev->classname );
#if defined( CLIENT_DLL )
9 years ago
p->pszAmmo1 = "Hand Grenade";
p->iMaxAmmo1 = HANDGRENADE_MAX_CARRY;
#else
if( HasInfiniteAmmo() )
{
p->pszAmmo1 = NULL;
p->iMaxAmmo1 = -1;
}
else
{
p->pszAmmo1 = "Hand Grenade";
p->iMaxAmmo1 = HANDGRENADE_MAX_CARRY;
}
#endif// defined(CLIENT_DLL)
9 years ago
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 4;
p->iPosition = 0;
p->iId = m_iId = WEAPON_HANDGRENADE;
p->iWeight = HANDGRENADE_WEIGHT;
p->iFlags = ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE;
#if !defined(CLIENT_DLL)
if( HasInfiniteAmmo() )
p->iFlags |= ITEM_FLAG_NOAUTORELOAD;
#endif
9 years ago
return 1;
}
9 years ago
BOOL CHandGrenade::Deploy()
9 years ago
{
m_flReleaseThrow = -1;
return DefaultDeploy( "models/v_grenade.mdl", "models/p_grenade.mdl", HANDGRENADE_DRAW, "crowbar" );
}
BOOL CHandGrenade::CanHolster( void )
{
// can only holster hand grenades when not primed!
return ( m_flStartThrow == 0 );
}
void CHandGrenade::Holster( int skiplocal /* = 0 */ )
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
#if defined(CLIENT_DLL)
9 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
#else
if( IsUseable() )
#endif // defined( CLIENT_DLL )
9 years ago
{
SendWeaponAnim( HANDGRENADE_HOLSTER );
}
else
{
// no more grenades!
9 years ago
m_pPlayer->pev->weapons &= ~( 1 << WEAPON_HANDGRENADE );
DestroyItem();
9 years ago
}
if( m_flStartThrow )
{
m_flStartThrow = 0;
m_flReleaseThrow = 0;
}
9 years ago
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM );
9 years ago
}
void CHandGrenade::PrimaryAttack()
{
#if defined(CLIENT_DLL)
9 years ago
if( !m_flStartThrow && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0 )
#else
if( !m_flStartThrow && IsUseable() )
#endif // defined(CLIENT_DLL)
9 years ago
{
m_flStartThrow = gpGlobals->time;
m_flReleaseThrow = 0;
SendWeaponAnim( HANDGRENADE_PINPULL );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
}
}
void CHandGrenade::WeaponIdle( void )
{
9 years ago
if( m_flReleaseThrow == 0 && m_flStartThrow )
9 years ago
m_flReleaseThrow = gpGlobals->time;
9 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
9 years ago
if( m_flStartThrow )
9 years ago
{
Vector angThrow = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle;
9 years ago
if( angThrow.x < 0 )
9 years ago
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;
9 years ago
if( flVel > 500 )
9 years ago
flVel = 500;
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 + 3.0;
9 years ago
if( time < 0 )
9 years ago
time = 0;
CGrenade::ShootTimed( m_pPlayer->pev, vecSrc, vecThrow, time );
9 years ago
if( flVel < 500 )
9 years ago
{
SendWeaponAnim( HANDGRENADE_THROW1 );
}
9 years ago
else if( flVel < 1000 )
9 years ago
{
SendWeaponAnim( HANDGRENADE_THROW2 );
}
else
{
SendWeaponAnim( HANDGRENADE_THROW3 );
}
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_flReleaseThrow = 0;
m_flStartThrow = 0;
m_flNextPrimaryAttack = GetNextAttackDelay( 0.5 );
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
#if defined(CLIENT_DLL)
9 years ago
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
9 years ago
9 years ago
if( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
#else
if( !HasInfiniteAmmo() )
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
if( !IsUseable() )
#endif // defined(CLIENT_DLL)
9 years ago
{
// 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 = GetNextAttackDelay( 0.5 );// ensure that the animation can finish playing
9 years ago
}
return;
}
9 years ago
else if( m_flReleaseThrow > 0 )
9 years ago
{
// we've finished the throw, restart.
m_flStartThrow = 0;
#if defined(CLIENT_DLL)
9 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
#else
if( IsUseable() )
#endif // defined(CLIENT_DLL)
9 years ago
{
SendWeaponAnim( HANDGRENADE_DRAW );
}
else
{
RetireWeapon();
return;
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
m_flReleaseThrow = -1;
return;
}
#if defined(CLIENT_DLL)
9 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
#else
if( IsUseable() )
#endif // defined(CLIENT_DLL)
9 years ago
{
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
9 years ago
if( flRand <= 0.75 )
9 years ago
{
iAnim = HANDGRENADE_IDLE;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );// how long till we do this again.
}
9 years ago
else
9 years ago
{
iAnim = HANDGRENADE_FIDGET;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 75.0 / 30.0;
}
SendWeaponAnim( iAnim );
}
}
BOOL CHandGrenade::HasInfiniteAmmo()
{
return IsCurrentMap( "witch" );
}
BOOL CHandGrenade::IsUseable()
{
return HasInfiniteAmmo() || m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0;
}