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.

596 lines
15 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 !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
#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"
8 years ago
enum w_squeak_e
{
9 years ago
WSQUEAK_IDLE1 = 0,
WSQUEAK_FIDGET,
WSQUEAK_JUMP,
WSQUEAK_RUN
9 years ago
};
8 years ago
enum squeak_e
{
9 years ago
SQUEAK_IDLE1 = 0,
SQUEAK_FIDGETFIT,
SQUEAK_FIDGETNIP,
SQUEAK_DOWN,
SQUEAK_UP,
SQUEAK_THROW
};
#ifndef CLIENT_DLL
class CSqueakGrenade : public CGrenade
{
void Spawn( void );
void Precache( void );
8 years ago
int Classify( void );
9 years ago
void EXPORT SuperBounceTouch( CBaseEntity *pOther );
void EXPORT HuntThink( void );
8 years ago
int BloodColor( void ) { return BLOOD_COLOR_YELLOW; }
9 years ago
void Killed( entvars_t *pevAttacker, int iGib );
void GibMonster( void );
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
8 years ago
static TYPEDESCRIPTION m_SaveData[];
9 years ago
static float m_flNextBounceSoundTime;
// CBaseEntity *m_pTarget;
float m_flDie;
Vector m_vecTarget;
float m_flNextHunt;
float m_flNextHit;
Vector m_posPrev;
EHANDLE m_hOwner;
8 years ago
int m_iMyClass;
9 years ago
};
float CSqueakGrenade::m_flNextBounceSoundTime = 0;
LINK_ENTITY_TO_CLASS( monster_snark, CSqueakGrenade )
TYPEDESCRIPTION CSqueakGrenade::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CSqueakGrenade, m_flDie, FIELD_TIME ),
DEFINE_FIELD( CSqueakGrenade, m_vecTarget, FIELD_VECTOR ),
DEFINE_FIELD( CSqueakGrenade, m_flNextHunt, FIELD_TIME ),
DEFINE_FIELD( CSqueakGrenade, m_flNextHit, FIELD_TIME ),
DEFINE_FIELD( CSqueakGrenade, m_posPrev, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CSqueakGrenade, m_hOwner, FIELD_EHANDLE ),
};
IMPLEMENT_SAVERESTORE( CSqueakGrenade, CGrenade )
9 years ago
#define SQUEEK_DETONATE_DELAY 15.0
8 years ago
int CSqueakGrenade::Classify( void )
9 years ago
{
8 years ago
if( m_iMyClass != 0 )
9 years ago
return m_iMyClass; // protect against recursion
if( m_hEnemy != 0 )
9 years ago
{
m_iMyClass = CLASS_INSECT; // no one cares about it
8 years ago
switch( m_hEnemy->Classify() )
9 years ago
{
case CLASS_PLAYER:
case CLASS_HUMAN_PASSIVE:
case CLASS_HUMAN_MILITARY:
m_iMyClass = 0;
return CLASS_ALIEN_MILITARY; // barney's get mad, grunts get mad at it
}
m_iMyClass = 0;
}
return CLASS_ALIEN_BIOWEAPON;
}
8 years ago
void CSqueakGrenade::Spawn( void )
9 years ago
{
//++ BulliT
#ifndef CLIENT_DLL
if( SGBOW == AgGametype() )
{
//Spawn crossbow instead.
8 years ago
//CBaseEntity *pNewWeapon = CBaseEntity::Create( "weapon_crossbow", g_pGameRules->VecWeaponRespawnSpot( this ), pev->angles, pev->owner );
return;
}
#endif
//-- Martin Webrant
8 years ago
Precache();
9 years ago
// motor
pev->movetype = MOVETYPE_BOUNCE;
pev->solid = SOLID_BBOX;
8 years ago
SET_MODEL( ENT( pev ), "models/w_squeak.mdl" );
UTIL_SetSize( pev, Vector( -4, -4, 0 ), Vector( 4, 4, 8 ) );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
SetTouch( &CSqueakGrenade::SuperBounceTouch );
SetThink( &CSqueakGrenade::HuntThink );
pev->nextthink = gpGlobals->time + 0.1;
m_flNextHunt = gpGlobals->time + 1E6;
pev->flags |= FL_MONSTER;
8 years ago
pev->takedamage = DAMAGE_AIM;
pev->health = gSkillData.snarkHealth;
pev->gravity = 0.5;
pev->friction = 0.5;
9 years ago
pev->dmg = gSkillData.snarkDmgPop;
m_flDie = gpGlobals->time + SQUEEK_DETONATE_DELAY;
m_flFieldOfView = 0; // 180 degrees
8 years ago
if( pev->owner )
9 years ago
m_hOwner = Instance( pev->owner );
m_flNextBounceSoundTime = gpGlobals->time;// reset each time a snark is spawned.
pev->sequence = WSQUEAK_RUN;
8 years ago
ResetSequenceInfo();
9 years ago
}
void CSqueakGrenade::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_squeak.mdl" );
PRECACHE_SOUND( "squeek/sqk_blast1.wav" );
PRECACHE_SOUND( "common/bodysplat.wav" );
PRECACHE_SOUND( "squeek/sqk_die1.wav" );
PRECACHE_SOUND( "squeek/sqk_hunt1.wav" );
PRECACHE_SOUND( "squeek/sqk_hunt2.wav" );
PRECACHE_SOUND( "squeek/sqk_hunt3.wav" );
PRECACHE_SOUND( "squeek/sqk_deploy1.wav" );
9 years ago
}
8 years ago
void CSqueakGrenade::Killed( entvars_t *pevAttacker, int iGib )
9 years ago
{
pev->model = iStringNull;// make invisible
SetThink( &CBaseEntity::SUB_Remove );
SetTouch( NULL );
pev->nextthink = gpGlobals->time + 0.1;
// since squeak grenades never leave a body behind, clear out their takedamage now.
// Squeaks do a bit of radius damage when they pop, and that radius damage will
// continue to call this function unless we acknowledge the Squeak's death now. (sjb)
pev->takedamage = DAMAGE_NO;
// play squeek blast
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_ITEM, "squeek/sqk_blast1.wav", 1, 0.5, 0, PITCH_NORM );
9 years ago
8 years ago
CSoundEnt::InsertSound( bits_SOUND_COMBAT, pev->origin, SMALL_EXPLOSION_VOLUME, 3.0 );
9 years ago
UTIL_BloodDrips( pev->origin, g_vecZero, BloodColor(), 80 );
if( m_hOwner != 0 )
8 years ago
RadiusDamage( pev, m_hOwner->pev, pev->dmg, CLASS_NONE, DMG_BLAST );
9 years ago
else
8 years ago
RadiusDamage( pev, pev, pev->dmg, CLASS_NONE, DMG_BLAST );
9 years ago
// reset owner so death message happens
if( m_hOwner != 0 )
9 years ago
pev->owner = m_hOwner->edict();
8 years ago
CBaseMonster::Killed( pevAttacker, GIB_ALWAYS );
9 years ago
}
8 years ago
void CSqueakGrenade::GibMonster( void )
9 years ago
{
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "common/bodysplat.wav", 0.75, ATTN_NORM, 0, 200 );
9 years ago
}
void CSqueakGrenade::HuntThink( void )
{
// ALERT( at_console, "think\n" );
8 years ago
if( !IsInWorld() )
9 years ago
{
SetTouch( NULL );
UTIL_Remove( this );
return;
}
8 years ago
StudioFrameAdvance();
9 years ago
pev->nextthink = gpGlobals->time + 0.1;
// explode when ready
8 years ago
if( gpGlobals->time >= m_flDie )
9 years ago
{
8 years ago
g_vecAttackDir = pev->velocity.Normalize();
9 years ago
pev->health = -1;
Killed( pev, 0 );
return;
}
// float
8 years ago
if( pev->waterlevel != 0 )
9 years ago
{
8 years ago
if( pev->movetype == MOVETYPE_BOUNCE )
9 years ago
{
pev->movetype = MOVETYPE_FLY;
}
pev->velocity = pev->velocity * 0.9;
pev->velocity.z += 8.0;
}
else if( pev->movetype == MOVETYPE_FLY )
9 years ago
{
pev->movetype = MOVETYPE_BOUNCE;
}
// return if not time to hunt
8 years ago
if( m_flNextHunt > gpGlobals->time )
9 years ago
return;
m_flNextHunt = gpGlobals->time + 2.0;
//CBaseEntity *pOther = NULL;
9 years ago
Vector vecDir;
TraceResult tr;
Vector vecFlat = pev->velocity;
vecFlat.z = 0;
8 years ago
vecFlat = vecFlat.Normalize();
9 years ago
UTIL_MakeVectors( pev->angles );
if( m_hEnemy == 0 || !m_hEnemy->IsAlive() )
9 years ago
{
// find target, bounce a bit towards it.
Look( 512 );
8 years ago
m_hEnemy = BestVisibleEnemy();
9 years ago
}
// squeek if it's about time blow up
8 years ago
if( ( m_flDie - gpGlobals->time <= 0.5 ) && ( m_flDie - gpGlobals->time >= 0.3 ) )
9 years ago
{
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "squeek/sqk_die1.wav", 1, ATTN_NORM, 0, 100 + RANDOM_LONG( 0, 0x3F ) );
CSoundEnt::InsertSound( bits_SOUND_COMBAT, pev->origin, 256, 0.25 );
9 years ago
}
// higher pitch as squeeker gets closer to detonation time
8 years ago
float flpitch = 155.0 - 60.0 * ( ( m_flDie - gpGlobals->time ) / SQUEEK_DETONATE_DELAY );
if( flpitch < 80 )
9 years ago
flpitch = 80;
if( m_hEnemy != 0 )
9 years ago
{
8 years ago
if( FVisible( m_hEnemy ) )
9 years ago
{
vecDir = m_hEnemy->EyePosition() - pev->origin;
8 years ago
m_vecTarget = vecDir.Normalize();
9 years ago
}
float flVel = pev->velocity.Length();
8 years ago
float flAdj = 50.0 / ( flVel + 10.0 );
9 years ago
8 years ago
if( flAdj > 1.2 )
9 years ago
flAdj = 1.2;
// ALERT( at_console, "think : enemy\n");
// ALERT( at_console, "%.0f %.2f %.2f %.2f\n", flVel, m_vecTarget.x, m_vecTarget.y, m_vecTarget.z );
pev->velocity = pev->velocity * flAdj + m_vecTarget * 300;
}
8 years ago
if( pev->flags & FL_ONGROUND )
9 years ago
{
pev->avelocity = Vector( 0, 0, 0 );
}
else
{
8 years ago
if( pev->avelocity == Vector( 0, 0, 0 ) )
9 years ago
{
pev->avelocity.x = RANDOM_FLOAT( -100, 100 );
pev->avelocity.z = RANDOM_FLOAT( -100, 100 );
}
}
8 years ago
if( ( pev->origin - m_posPrev ).Length() < 1.0 )
9 years ago
{
pev->velocity.x = RANDOM_FLOAT( -100, 100 );
pev->velocity.y = RANDOM_FLOAT( -100, 100 );
}
m_posPrev = pev->origin;
pev->angles = UTIL_VecToAngles( pev->velocity );
pev->angles.z = 0;
pev->angles.x = 0;
}
void CSqueakGrenade::SuperBounceTouch( CBaseEntity *pOther )
{
8 years ago
float flpitch;
9 years ago
8 years ago
TraceResult tr = UTIL_GetGlobalTrace();
9 years ago
// don't hit the guy that launched this grenade
8 years ago
if( pev->owner && pOther->edict() == pev->owner )
9 years ago
return;
// at least until we've bounced once
pev->owner = NULL;
pev->angles.x = 0;
pev->angles.z = 0;
// avoid bouncing too much
8 years ago
if( m_flNextHit > gpGlobals->time )
9 years ago
return;
// higher pitch as squeeker gets closer to detonation time
8 years ago
flpitch = 155.0 - 60.0 * ( ( m_flDie - gpGlobals->time ) / SQUEEK_DETONATE_DELAY );
9 years ago
8 years ago
if( pOther->pev->takedamage && m_flNextAttack < gpGlobals->time )
9 years ago
{
// attack!
// make sure it's me who has touched them
8 years ago
if( tr.pHit == pOther->edict() )
9 years ago
{
// and it's not another squeakgrenade
8 years ago
if( tr.pHit->v.modelindex != pev->modelindex )
9 years ago
{
8 years ago
// ALERT( at_console, "hit enemy\n" );
ClearMultiDamage();
8 years ago
pOther->TraceAttack( pev, gSkillData.snarkDmgBite, gpGlobals->v_forward, &tr, DMG_SLASH );
if( m_hOwner != 0 )
9 years ago
ApplyMultiDamage( pev, m_hOwner->pev );
else
ApplyMultiDamage( pev, pev );
pev->dmg += gSkillData.snarkDmgPop; // add more explosion damage
// m_flDie += 2.0; // add more life
// make bite sound
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "squeek/sqk_deploy1.wav", 1.0, ATTN_NORM, 0, (int)flpitch );
9 years ago
m_flNextAttack = gpGlobals->time + 0.5;
}
}
else
{
8 years ago
// ALERT( at_console, "been hit\n" );
9 years ago
}
}
m_flNextHit = gpGlobals->time + 0.1;
m_flNextHunt = gpGlobals->time;
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
// in multiplayer, we limit how often snarks can make their bounce sounds to prevent overflows.
8 years ago
if( gpGlobals->time < m_flNextBounceSoundTime )
9 years ago
{
// too soon!
return;
}
}
8 years ago
if( !( pev->flags & FL_ONGROUND ) )
9 years ago
{
// play bounce sound
8 years ago
float flRndSound = RANDOM_FLOAT( 0, 1 );
if( flRndSound <= 0.33 )
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "squeek/sqk_hunt1.wav", 1, ATTN_NORM, 0, (int)flpitch );
else if( flRndSound <= 0.66 )
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "squeek/sqk_hunt2.wav", 1, ATTN_NORM, 0, (int)flpitch );
else
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "squeek/sqk_hunt3.wav", 1, ATTN_NORM, 0, (int)flpitch );
CSoundEnt::InsertSound( bits_SOUND_COMBAT, pev->origin, 256, 0.25 );
9 years ago
}
else
{
// skittering sound
8 years ago
CSoundEnt::InsertSound( bits_SOUND_COMBAT, pev->origin, 100, 0.1 );
9 years ago
}
m_flNextBounceSoundTime = gpGlobals->time + 0.5;// half second.
}
#endif
LINK_ENTITY_TO_CLASS( weapon_snark, CSqueak )
9 years ago
8 years ago
void CSqueak::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
m_iId = WEAPON_SNARK;
8 years ago
SET_MODEL( ENT( pev ), "models/w_sqknest.mdl" );
9 years ago
FallInit();//get ready to fall down.
m_iDefaultAmmo = SNARK_DEFAULT_GIVE;
8 years ago
9 years ago
pev->sequence = 1;
pev->animtime = gpGlobals->time;
pev->framerate = 1.0;
}
void CSqueak::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_sqknest.mdl" );
PRECACHE_MODEL( "models/v_squeak.mdl" );
PRECACHE_MODEL( "models/p_squeak.mdl" );
PRECACHE_SOUND( "squeek/sqk_hunt2.wav" );
PRECACHE_SOUND( "squeek/sqk_hunt3.wav" );
UTIL_PrecacheOther( "monster_snark" );
m_usSnarkFire = PRECACHE_EVENT( 1, "events/snarkfire.sc" );
9 years ago
}
8 years ago
int CSqueak::GetItemInfo( ItemInfo *p )
9 years ago
{
8 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = "Snarks";
p->iMaxAmmo1 = SNARK_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 4;
p->iPosition = 3;
p->iId = m_iId = WEAPON_SNARK;
p->iWeight = SNARK_WEIGHT;
p->iFlags = ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE;
return 1;
}
8 years ago
BOOL CSqueak::Deploy()
9 years ago
{
// play hunt sound
8 years ago
float flRndSound = RANDOM_FLOAT( 0, 1 );
9 years ago
8 years ago
if( flRndSound <= 0.5 )
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "squeek/sqk_hunt2.wav", 1, ATTN_NORM, 0, 100 );
else
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "squeek/sqk_hunt3.wav", 1, ATTN_NORM, 0, 100 );
9 years ago
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
return DefaultDeploy( "models/v_squeak.mdl", "models/p_squeak.mdl", SQUEAK_UP, "squeak" );
}
void CSqueak::Holster( int skiplocal /* = 0 */ )
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
8 years ago
if( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
9 years ago
{
8 years ago
m_pPlayer->pev->weapons &= ~( 1 << WEAPON_SNARK );
DestroyItem();
9 years ago
return;
}
9 years ago
SendWeaponAnim( SQUEAK_DOWN );
8 years ago
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM );
9 years ago
}
void CSqueak::PrimaryAttack()
{
8 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
9 years ago
{
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
TraceResult tr;
Vector trace_origin;
// HACK HACK: Ugly hacks to handle change in origin based on new physics code for players
// Move origin up if crouched and start trace a bit outside of body ( 20 units instead of 16 )
trace_origin = m_pPlayer->pev->origin;
8 years ago
if( m_pPlayer->pev->flags & FL_DUCKING )
9 years ago
{
trace_origin = trace_origin - ( VEC_HULL_MIN - VEC_DUCK_HULL_MIN );
}
// find place to toss monster
UTIL_TraceLine( trace_origin + gpGlobals->v_forward * 20, trace_origin + gpGlobals->v_forward * 64, dont_ignore_monsters, NULL, &tr );
8 years ago
int flags;
9 years ago
#ifdef CLIENT_WEAPONS
8 years ago
flags = FEV_NOTHOST;
9 years ago
#else
8 years ago
flags = 0;
9 years ago
#endif
8 years ago
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usSnarkFire, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, 0, 0, 0, 0 );
9 years ago
8 years ago
if( tr.fAllSolid == 0 && tr.fStartSolid == 0 && tr.flFraction > 0.25 )
9 years ago
{
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
#ifndef CLIENT_DLL
CBaseEntity *pSqueak = CBaseEntity::Create( "monster_snark", tr.vecEndPos, m_pPlayer->pev->v_angle, m_pPlayer->edict() );
pSqueak->pev->velocity = gpGlobals->v_forward * 200 + m_pPlayer->pev->velocity;
#endif
// play hunt sound
8 years ago
float flRndSound = RANDOM_FLOAT( 0, 1 );
9 years ago
8 years ago
if( flRndSound <= 0.5 )
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "squeek/sqk_hunt2.wav", 1, ATTN_NORM, 0, 105 );
9 years ago
else
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "squeek/sqk_hunt3.wav", 1, ATTN_NORM, 0, 105 );
9 years ago
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_fJustThrown = 1;
m_flNextPrimaryAttack = GetNextAttackDelay( 0.3 );
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0;
}
}
}
void CSqueak::SecondaryAttack( void )
{
}
void CSqueak::WeaponIdle( void )
{
8 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
8 years ago
if( m_fJustThrown )
9 years ago
{
m_fJustThrown = 0;
8 years ago
if( !m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()] )
9 years ago
{
RetireWeapon();
return;
}
SendWeaponAnim( SQUEAK_UP );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
return;
}
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
8 years ago
if( flRand <= 0.75 )
9 years ago
{
iAnim = SQUEAK_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 30.0 / 16 * (2);
}
8 years ago
else if( flRand <= 0.875 )
9 years ago
{
iAnim = SQUEAK_FIDGETFIT;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 70.0 / 16.0;
}
else
{
iAnim = SQUEAK_FIDGETNIP;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 80.0 / 16.0;
}
SendWeaponAnim( iAnim );
}
#endif