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.

481 lines
12 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.
*
****/
#if !OEM_BUILD && !HLDEMO_BUILD
9 years ago
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "gamerules.h"
enum satchel_state
{
SATCHEL_IDLE = 0,
SATCHEL_READY,
SATCHEL_RELOAD
};
9 years ago
enum satchel_e
{
9 years ago
SATCHEL_IDLE1 = 0,
SATCHEL_FIDGET1,
SATCHEL_DRAW,
SATCHEL_DROP
};
9 years ago
enum satchel_radio_e
{
9 years ago
SATCHEL_RADIO_IDLE1 = 0,
SATCHEL_RADIO_FIDGET1,
SATCHEL_RADIO_DRAW,
SATCHEL_RADIO_FIRE,
SATCHEL_RADIO_HOLSTER
};
class CSatchelCharge : public CGrenade
{
Vector m_lastBounceOrigin; // Used to fix a bug in engine: when object isn't moving, but its speed isn't 0 and on ground isn't set
9 years ago
void Spawn( void );
void Precache( void );
void BounceSound( void );
void EXPORT SatchelSlide( CBaseEntity *pOther );
void EXPORT SatchelThink( void );
public:
void Deactivate( void );
};
LINK_ENTITY_TO_CLASS( monster_satchel, CSatchelCharge )
9 years ago
//=========================================================
// Deactivate - do whatever it is we do to an orphaned
// satchel when we don't want it in the world anymore.
//=========================================================
void CSatchelCharge::Deactivate( void )
{
pev->solid = SOLID_NOT;
UTIL_Remove( this );
}
9 years ago
void CSatchelCharge::Spawn( void )
9 years ago
{
9 years ago
Precache();
9 years ago
// motor
pev->movetype = MOVETYPE_BOUNCE;
pev->solid = SOLID_BBOX;
9 years ago
SET_MODEL( ENT( pev ), "models/w_satchel.mdl" );
//UTIL_SetSize( pev, Vector( -16, -16, -4 ), Vector( 16, 16, 32 ) ); // Old box -- size of headcrab monsters/players get blocked by this
UTIL_SetSize( pev, Vector( -4, -4, -4 ), Vector( 4, 4, 4 ) ); // Uses point-sized, and can be stepped over
9 years ago
UTIL_SetOrigin( pev, pev->origin );
SetTouch( &CSatchelCharge::SatchelSlide );
SetUse( &CGrenade::DetonateUse );
SetThink( &CSatchelCharge::SatchelThink );
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
pev->gravity = 0.5f;
pev->friction = 0.8f;
9 years ago
pev->dmg = gSkillData.plrDmgSatchel;
9 years ago
// ResetSequenceInfo();
9 years ago
pev->sequence = 1;
}
void CSatchelCharge::SatchelSlide( CBaseEntity *pOther )
{
//entvars_t *pevOther = pOther->pev;
9 years ago
// don't hit the guy that launched this grenade
9 years ago
if( pOther->edict() == pev->owner )
9 years ago
return;
9 years ago
// pev->avelocity = Vector( 300, 300, 300 );
9 years ago
pev->gravity = 1;// normal gravity now
// HACKHACK - On ground isn't always set, so look for ground underneath
TraceResult tr;
9 years ago
UTIL_TraceLine( pev->origin, pev->origin - Vector( 0, 0, 10 ), ignore_monsters, edict(), &tr );
9 years ago
if( tr.flFraction < 1.0f )
9 years ago
{
// add a bit of static friction
pev->velocity = pev->velocity * 0.95;
pev->avelocity = pev->avelocity * 0.9;
// play sliding sound, volume based on velocity
}
if( !( pev->flags & FL_ONGROUND ) && pev->velocity.Length2D() > 10.0f )
9 years ago
{
// Fix for a bug in engine: when object isn't moving, but its speed isn't 0 and on ground isn't set
if( pev->origin != m_lastBounceOrigin )
BounceSound();
9 years ago
}
m_lastBounceOrigin = pev->origin;
// There is no model animation so commented this out to prevent net traffic
// StudioFrameAdvance();
9 years ago
}
9 years ago
void CSatchelCharge::SatchelThink( void )
9 years ago
{
// There is no model animation so commented this out to prevent net traffic
// StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
9 years ago
if( !IsInWorld() )
9 years ago
{
UTIL_Remove( this );
return;
}
9 years ago
if( pev->waterlevel == 3 )
9 years ago
{
pev->movetype = MOVETYPE_FLY;
pev->velocity = pev->velocity * 0.8f;
pev->avelocity = pev->avelocity * 0.9f;
9 years ago
pev->velocity.z += 8;
}
9 years ago
else if( pev->waterlevel == 0 )
9 years ago
{
pev->movetype = MOVETYPE_BOUNCE;
}
else
{
pev->velocity.z -= 8.0f;
9 years ago
}
}
9 years ago
void CSatchelCharge::Precache( void )
9 years ago
{
PRECACHE_MODEL( "models/w_satchel.mdl" );
9 years ago
PRECACHE_SOUND( "weapons/g_bounce1.wav" );
PRECACHE_SOUND( "weapons/g_bounce2.wav" );
PRECACHE_SOUND( "weapons/g_bounce3.wav" );
9 years ago
}
9 years ago
void CSatchelCharge::BounceSound( void )
9 years ago
{
9 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "weapons/g_bounce1.wav", 1, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "weapons/g_bounce2.wav", 1, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "weapons/g_bounce3.wav", 1, ATTN_NORM );
break;
9 years ago
}
}
LINK_ENTITY_TO_CLASS( weapon_satchel, CSatchel )
9 years ago
//=========================================================
// CALLED THROUGH the newly-touched weapon's instance. The existing player weapon is pOriginal
//=========================================================
int CSatchel::AddDuplicate( CBasePlayerItem *pOriginal )
{
CSatchel *pSatchel;
4 years ago
#if CLIENT_DLL
9 years ago
if( bIsMultiplayer() )
9 years ago
#else
9 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
#endif
{
pSatchel = (CSatchel *)pOriginal;
if( pSatchel->m_chargeReady != SATCHEL_IDLE )
9 years ago
{
// player has some satchels deployed. Refuse to add more.
return FALSE;
}
}
9 years ago
return CBasePlayerWeapon::AddDuplicate( pOriginal );
9 years ago
}
//=========================================================
//=========================================================
int CSatchel::AddToPlayer( CBasePlayer *pPlayer )
{
int bResult = CBasePlayerItem::AddToPlayer( pPlayer );
9 years ago
pPlayer->pev->weapons |= ( 1 << m_iId );
m_chargeReady = SATCHEL_IDLE;// this satchel charge weapon now forgets that any satchels are deployed by it.
9 years ago
9 years ago
if( bResult )
9 years ago
{
9 years ago
return AddWeapon();
9 years ago
}
return FALSE;
}
9 years ago
void CSatchel::Spawn()
9 years ago
{
9 years ago
Precache();
9 years ago
m_iId = WEAPON_SATCHEL;
9 years ago
SET_MODEL( ENT( pev ), "models/w_satchel.mdl" );
9 years ago
m_iDefaultAmmo = SATCHEL_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
void CSatchel::Precache( void )
{
9 years ago
PRECACHE_MODEL( "models/v_satchel.mdl" );
PRECACHE_MODEL( "models/v_satchel_radio.mdl" );
PRECACHE_MODEL( "models/w_satchel.mdl" );
PRECACHE_MODEL( "models/p_satchel.mdl" );
PRECACHE_MODEL( "models/p_satchel_radio.mdl" );
9 years ago
UTIL_PrecacheOther( "monster_satchel" );
}
9 years ago
int CSatchel::GetItemInfo( ItemInfo *p )
9 years ago
{
9 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = "Satchel Charge";
p->iMaxAmmo1 = SATCHEL_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 4;
p->iPosition = 1;
p->iFlags = ITEM_FLAG_SELECTONEMPTY | ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE;
p->iId = m_iId = WEAPON_SATCHEL;
p->iWeight = SATCHEL_WEIGHT;
return 1;
}
//=========================================================
//=========================================================
BOOL CSatchel::IsUseable( void )
{
return CanDeploy();
9 years ago
}
BOOL CSatchel::CanDeploy( void )
{
9 years ago
if( m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()] > 0 )
9 years ago
{
// player is carrying some satchels
return TRUE;
}
if( m_chargeReady )
9 years ago
{
// player isn't carrying any satchels, but has some out
return TRUE;
}
return FALSE;
}
9 years ago
BOOL CSatchel::Deploy()
9 years ago
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10.0f, 15.0f );
9 years ago
9 years ago
if( m_chargeReady )
9 years ago
return DefaultDeploy( "models/v_satchel_radio.mdl", "models/p_satchel_radio.mdl", SATCHEL_RADIO_DRAW, "hive" );
else
return DefaultDeploy( "models/v_satchel.mdl", "models/p_satchel.mdl", SATCHEL_DRAW, "trip" );
return TRUE;
}
void CSatchel::Holster( int skiplocal /* = 0 */ )
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
if( m_chargeReady )
9 years ago
{
SendWeaponAnim( SATCHEL_RADIO_HOLSTER );
}
else
{
SendWeaponAnim( SATCHEL_DROP );
}
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "common/null.wav", 1.0f, ATTN_NORM );
9 years ago
if( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] && m_chargeReady != SATCHEL_READY )
9 years ago
{
9 years ago
m_pPlayer->pev->weapons &= ~( 1 << WEAPON_SATCHEL );
DestroyItem();
9 years ago
}
}
void CSatchel::PrimaryAttack()
{
9 years ago
switch( m_chargeReady )
9 years ago
{
case SATCHEL_IDLE:
9 years ago
{
Throw();
9 years ago
}
break;
case SATCHEL_READY:
9 years ago
{
SendWeaponAnim( SATCHEL_RADIO_FIRE );
9 years ago
edict_t *pPlayer = m_pPlayer->edict();
9 years ago
CBaseEntity *pSatchel = NULL;
9 years ago
while( ( pSatchel = UTIL_FindEntityInSphere( pSatchel, m_pPlayer->pev->origin, 4096 ) ) != NULL )
9 years ago
{
if( FClassnameIs( pSatchel->pev, "monster_satchel" ) )
9 years ago
{
if( pSatchel->pev->owner == pPlayer )
{
pSatchel->Use( m_pPlayer, m_pPlayer, USE_ON, 0 );
}
9 years ago
}
}
m_chargeReady = SATCHEL_RELOAD;
m_flNextPrimaryAttack = GetNextAttackDelay( 0.5f );
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5f;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5f;
break;
9 years ago
}
case SATCHEL_RELOAD:
9 years ago
// we're reloading, don't allow fire
break;
}
}
void CSatchel::SecondaryAttack( void )
{
if( m_chargeReady != SATCHEL_RELOAD )
9 years ago
{
9 years ago
Throw();
9 years ago
}
}
void CSatchel::Throw( void )
{
9 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
9 years ago
{
4 years ago
#if !CLIENT_DLL
9 years ago
Vector vecSrc = m_pPlayer->pev->origin;
Vector vecThrow = gpGlobals->v_forward * 274 + m_pPlayer->pev->velocity;
9 years ago
CBaseEntity *pSatchel = Create( "monster_satchel", vecSrc, Vector( 0, 0, 0 ), m_pPlayer->edict() );
9 years ago
pSatchel->pev->velocity = vecThrow;
pSatchel->pev->avelocity.y = 400;
9 years ago
m_pPlayer->pev->viewmodel = MAKE_STRING( "models/v_satchel_radio.mdl" );
m_pPlayer->pev->weaponmodel = MAKE_STRING( "models/p_satchel_radio.mdl" );
9 years ago
#else
9 years ago
LoadVModel( "models/v_satchel_radio.mdl", m_pPlayer );
9 years ago
#endif
SendWeaponAnim( SATCHEL_RADIO_DRAW );
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_chargeReady = SATCHEL_READY;
9 years ago
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_flNextPrimaryAttack = GetNextAttackDelay( 1.0f );
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
}
}
void CSatchel::WeaponIdle( void )
{
9 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
switch( m_chargeReady )
{
case SATCHEL_IDLE:
9 years ago
SendWeaponAnim( SATCHEL_FIDGET1 );
// use tripmine animations
strcpy( m_pPlayer->m_szAnimExtention, "trip" );
break;
case SATCHEL_READY:
9 years ago
SendWeaponAnim( SATCHEL_RADIO_FIDGET1 );
// use hivehand animations
strcpy( m_pPlayer->m_szAnimExtention, "hive" );
break;
case SATCHEL_RELOAD:
9 years ago
if( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
9 years ago
{
m_chargeReady = 0;
RetireWeapon();
return;
}
4 years ago
#if !CLIENT_DLL
9 years ago
m_pPlayer->pev->viewmodel = MAKE_STRING( "models/v_satchel.mdl" );
m_pPlayer->pev->weaponmodel = MAKE_STRING( "models/p_satchel.mdl" );
9 years ago
#else
9 years ago
LoadVModel( "models/v_satchel.mdl", m_pPlayer );
9 years ago
#endif
SendWeaponAnim( SATCHEL_DRAW );
// use tripmine animations
strcpy( m_pPlayer->m_szAnimExtention, "trip" );
m_flNextPrimaryAttack = GetNextAttackDelay( 0.5f );
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5f;
m_chargeReady = SATCHEL_IDLE;
9 years ago
break;
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );// how long till we do this again.
}
//=========================================================
// DeactivateSatchels - removes all satchels owned by
// the provided player. Should only be used upon death.
//
// Made this global on purpose.
//=========================================================
void DeactivateSatchels( CBasePlayer *pOwner )
{
edict_t *pFind;
pFind = FIND_ENTITY_BY_CLASSNAME( NULL, "monster_satchel" );
9 years ago
while( !FNullEnt( pFind ) )
9 years ago
{
CBaseEntity *pEnt = CBaseEntity::Instance( pFind );
CSatchelCharge *pSatchel = (CSatchelCharge *)pEnt;
9 years ago
if( pSatchel )
9 years ago
{
9 years ago
if( pSatchel->pev->owner == pOwner->edict() )
9 years ago
{
pSatchel->Deactivate();
}
}
pFind = FIND_ENTITY_BY_CLASSNAME( pFind, "monster_satchel" );
}
}
#endif