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.

1301 lines
31 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.
*
* This source code contains proprietary and confidential information of
* Valve LLC and its suppliers. Access to this code is restricted to
* persons who have executed a written SDK license with Valve. Any access,
* use or distribution of this code by or to any unlicensed person is illegal.
*
****/
/*
===== turret.cpp ========================================================
*/
//
// TODO:
// Take advantage of new monster fields like m_hEnemy and get rid of that OFFSET() stuff
// Revisit enemy validation stuff, maybe it's not necessary with the newest monster code
//
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "effects.h"
extern Vector VecBModelOrigin( entvars_t* pevBModel );
#define TURRET_SHOTS 2
#define TURRET_RANGE (100 * 12)
#define TURRET_SPREAD Vector( 0, 0, 0 )
#define TURRET_TURNRATE 30 //angles per 0.1 second
#define TURRET_MAXWAIT 15 // seconds turret will stay active w/o a target
#define TURRET_MAXSPIN 5 // seconds turret barrel will spin w/o a target
#define TURRET_MACHINE_VOLUME 0.5
typedef enum
{
TURRET_ANIM_NONE = 0,
TURRET_ANIM_FIRE,
TURRET_ANIM_SPIN,
TURRET_ANIM_DEPLOY,
TURRET_ANIM_RETIRE,
TURRET_ANIM_DIE
9 years ago
} TURRET_ANIM;
class CBaseTurret : public CBaseMonster
{
public:
9 years ago
void Spawn( void );
virtual void Precache( void );
void UpdateOnRemove();
9 years ago
void KeyValue( KeyValueData *pkvd );
void EXPORT TurretUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
9 years ago
virtual void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );
virtual int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
virtual int Classify( void );
9 years ago
int BloodColor( void ) { return DONT_BLEED; }
void GibMonster( void ) {} // UNDONE: Throw turret gibs?
// Think functions
void EXPORT ActiveThink(void);
void EXPORT SearchThink(void);
void EXPORT AutoSearchThink(void);
void EXPORT TurretDeath(void);
virtual void EXPORT SpinDownCall(void) { m_iSpin = 0; }
virtual void EXPORT SpinUpCall(void) { m_iSpin = 1; }
9 years ago
// void SpinDown( void );
9 years ago
// float EXPORT SpinDownCall( void ) { return SpinDown(); }
9 years ago
// virtual float SpinDown( void ) { return 0;}
// virtual float Retire( void ) { return 0;}
9 years ago
9 years ago
void EXPORT Deploy( void );
void EXPORT Retire( void );
9 years ago
void EXPORT Initialize( void );
9 years ago
9 years ago
virtual void Ping( void );
virtual void EyeOn( void );
virtual void EyeOff( void );
9 years ago
9 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
9 years ago
static TYPEDESCRIPTION m_SaveData[];
9 years ago
// other functions
9 years ago
void SetTurretAnim( TURRET_ANIM anim );
int MoveTurret( void );
virtual void Shoot( Vector &vecSrc, Vector &vecDirToEnemy ) { };
9 years ago
float m_flMaxSpin; // Max time to spin the barrel w/o a target
int m_iSpin;
CSprite *m_pEyeGlow;
9 years ago
int m_eyeBrightness;
9 years ago
9 years ago
int m_iDeployHeight;
int m_iRetractHeight;
9 years ago
int m_iMinPitch;
int m_iBaseTurnRate; // angles per second
float m_fTurnRate; // actual turn rate
int m_iOrientation; // 0 = floor, 1 = Ceiling
9 years ago
int m_iOn;
9 years ago
int m_fBeserk; // Sometimes this bitch will just freak out
int m_iAutoStart; // true if the turret auto deploys when a target
9 years ago
// enters its range
9 years ago
Vector m_vecLastSight;
float m_flLastSight; // Last time we saw a target
float m_flMaxWait; // Max time to seach w/o a target
int m_iSearchSpeed; // Not Used!
// movement
9 years ago
float m_flStartYaw;
Vector m_vecCurAngles;
Vector m_vecGoalAngles;
9 years ago
9 years ago
float m_flPingTime; // Time until the next ping, used when searching
float m_flSpinUpTime; // Amount of time until the barrel should spin down when searching
9 years ago
};
TYPEDESCRIPTION CBaseTurret::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CBaseTurret, m_flMaxSpin, FIELD_FLOAT ),
DEFINE_FIELD( CBaseTurret, m_iSpin, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_pEyeGlow, FIELD_CLASSPTR ),
DEFINE_FIELD( CBaseTurret, m_eyeBrightness, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_iDeployHeight, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_iRetractHeight, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_iMinPitch, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_iBaseTurnRate, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_fTurnRate, FIELD_FLOAT ),
DEFINE_FIELD( CBaseTurret, m_iOrientation, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_iOn, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_fBeserk, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_iAutoStart, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_vecLastSight, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CBaseTurret, m_flLastSight, FIELD_TIME ),
DEFINE_FIELD( CBaseTurret, m_flMaxWait, FIELD_FLOAT ),
DEFINE_FIELD( CBaseTurret, m_iSearchSpeed, FIELD_INTEGER ),
DEFINE_FIELD( CBaseTurret, m_flStartYaw, FIELD_FLOAT ),
DEFINE_FIELD( CBaseTurret, m_vecCurAngles, FIELD_VECTOR ),
DEFINE_FIELD( CBaseTurret, m_vecGoalAngles, FIELD_VECTOR ),
DEFINE_FIELD( CBaseTurret, m_flPingTime, FIELD_TIME ),
DEFINE_FIELD( CBaseTurret, m_flSpinUpTime, FIELD_TIME ),
};
IMPLEMENT_SAVERESTORE( CBaseTurret, CBaseMonster )
9 years ago
class CTurret : public CBaseTurret
{
public:
9 years ago
void Spawn( void );
void Precache( void );
9 years ago
// Think functions
9 years ago
void SpinUpCall( void );
void SpinDownCall( void );
9 years ago
9 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
9 years ago
9 years ago
static TYPEDESCRIPTION m_SaveData[];
9 years ago
// other functions
9 years ago
void Shoot( Vector &vecSrc, Vector &vecDirToEnemy );
9 years ago
private:
int m_iStartSpin;
};
TYPEDESCRIPTION CTurret::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CTurret, m_iStartSpin, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CTurret, CBaseTurret )
9 years ago
class CMiniTurret : public CBaseTurret
{
public:
9 years ago
void Spawn();
void Precache( void );
9 years ago
// other functions
9 years ago
void Shoot( Vector &vecSrc, Vector &vecDirToEnemy );
9 years ago
};
LINK_ENTITY_TO_CLASS( monster_turret, CTurret )
LINK_ENTITY_TO_CLASS( monster_miniturret, CMiniTurret )
9 years ago
void CBaseTurret::KeyValue( KeyValueData *pkvd )
{
9 years ago
if( FStrEq( pkvd->szKeyName, "maxsleep" ) )
9 years ago
{
9 years ago
m_flMaxWait = atof( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
9 years ago
else if( FStrEq( pkvd->szKeyName, "orientation" ) )
9 years ago
{
9 years ago
m_iOrientation = atoi( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
9 years ago
else if( FStrEq( pkvd->szKeyName, "searchspeed" ) )
9 years ago
{
9 years ago
m_iSearchSpeed = atoi( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
9 years ago
else if( FStrEq( pkvd->szKeyName, "turnrate" ) )
9 years ago
{
9 years ago
m_iBaseTurnRate = atoi( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
9 years ago
else if( FStrEq( pkvd->szKeyName, "style" ) ||
FStrEq( pkvd->szKeyName, "height" ) ||
FStrEq( pkvd->szKeyName, "value1" ) ||
FStrEq( pkvd->szKeyName, "value2" ) ||
FStrEq( pkvd->szKeyName, "value3" ) )
9 years ago
pkvd->fHandled = TRUE;
else
CBaseMonster::KeyValue( pkvd );
}
void CBaseTurret::Spawn()
{
9 years ago
Precache();
9 years ago
pev->nextthink = gpGlobals->time + 1;
pev->movetype = MOVETYPE_FLY;
pev->sequence = 0;
9 years ago
pev->frame = 0;
pev->solid = SOLID_SLIDEBOX;
9 years ago
pev->takedamage = DAMAGE_AIM;
9 years ago
SetBits( pev->flags, FL_MONSTER );
9 years ago
SetUse( &CBaseTurret::TurretUse );
9 years ago
if( ( pev->spawnflags & SF_MONSTER_TURRET_AUTOACTIVATE )
&& !( pev->spawnflags & SF_MONSTER_TURRET_STARTINACTIVE ) )
9 years ago
{
m_iAutoStart = TRUE;
}
9 years ago
ResetSequenceInfo();
9 years ago
SetBoneController( 0, 0 );
SetBoneController( 1, 0 );
m_flFieldOfView = VIEW_FIELD_FULL;
// m_flSightRange = TURRET_RANGE;
}
9 years ago
void CBaseTurret::Precache()
9 years ago
{
9 years ago
PRECACHE_SOUND( "turret/tu_fire1.wav" );
PRECACHE_SOUND( "turret/tu_ping.wav" );
PRECACHE_SOUND( "turret/tu_active2.wav" );
PRECACHE_SOUND( "turret/tu_die.wav" );
PRECACHE_SOUND( "turret/tu_die2.wav" );
PRECACHE_SOUND( "turret/tu_die3.wav" );
// PRECACHE_SOUND( "turret/tu_retract.wav" ); // just use deploy sound to save memory
PRECACHE_SOUND( "turret/tu_deploy.wav" );
PRECACHE_SOUND( "turret/tu_spinup.wav" );
PRECACHE_SOUND( "turret/tu_spindown.wav" );
PRECACHE_SOUND( "turret/tu_search.wav" );
PRECACHE_SOUND( "turret/tu_alert.wav" );
9 years ago
}
void CBaseTurret::UpdateOnRemove()
{
CBaseEntity::UpdateOnRemove();
if( m_pEyeGlow )
{
UTIL_Remove( m_pEyeGlow );
m_pEyeGlow = 0;
}
}
9 years ago
#define TURRET_GLOW_SPRITE "sprites/flare3.spr"
void CTurret::Spawn()
9 years ago
{
Precache();
SET_MODEL( ENT( pev ), "models/turret.mdl" );
pev->health = gSkillData.turretHealth;
9 years ago
m_HackedGunPos = Vector( 0, 0, 12.75 );
9 years ago
m_flMaxSpin = TURRET_MAXSPIN;
pev->view_ofs.z = 12.75;
9 years ago
9 years ago
CBaseTurret::Spawn();
9 years ago
m_iRetractHeight = 16;
m_iDeployHeight = 32;
9 years ago
m_iMinPitch = -15;
UTIL_SetSize( pev, Vector( -32, -32, -m_iRetractHeight ), Vector( 32, 32, m_iRetractHeight ) );
9 years ago
SetThink( &CBaseTurret::Initialize );
9 years ago
m_pEyeGlow = CSprite::SpriteCreate( TURRET_GLOW_SPRITE, pev->origin, FALSE );
m_pEyeGlow->SetTransparency( kRenderGlow, 255, 0, 0, 0, kRenderFxNoDissipation );
m_pEyeGlow->SetAttachment( edict(), 2 );
m_eyeBrightness = 0;
pev->nextthink = gpGlobals->time + 0.3f;
9 years ago
}
void CTurret::Precache()
{
9 years ago
CBaseTurret::Precache();
PRECACHE_MODEL( "models/turret.mdl" );
PRECACHE_MODEL( TURRET_GLOW_SPRITE );
9 years ago
}
void CMiniTurret::Spawn()
{
9 years ago
Precache();
SET_MODEL( ENT( pev ), "models/miniturret.mdl" );
pev->health = gSkillData.miniturretHealth;
m_HackedGunPos = Vector( 0.0f, 0.0f, 12.75f );
9 years ago
m_flMaxSpin = 0;
pev->view_ofs.z = 12.75f;
9 years ago
9 years ago
CBaseTurret::Spawn();
9 years ago
m_iRetractHeight = 16;
m_iDeployHeight = 32;
9 years ago
m_iMinPitch = -15;
UTIL_SetSize( pev, Vector( -16, -16, -m_iRetractHeight ), Vector( 16, 16, m_iRetractHeight ) );
9 years ago
9 years ago
SetThink( &CBaseTurret::Initialize );
pev->nextthink = gpGlobals->time + 0.3f;
9 years ago
}
void CMiniTurret::Precache()
{
9 years ago
CBaseTurret::Precache();
PRECACHE_MODEL( "models/miniturret.mdl" );
PRECACHE_SOUND( "weapons/hks1.wav" );
PRECACHE_SOUND( "weapons/hks2.wav" );
PRECACHE_SOUND( "weapons/hks3.wav" );
9 years ago
}
9 years ago
void CBaseTurret::Initialize( void )
9 years ago
{
m_iOn = 0;
m_fBeserk = 0;
m_iSpin = 0;
SetBoneController( 0, 0 );
SetBoneController( 1, 0 );
9 years ago
if( m_iBaseTurnRate == 0 )
m_iBaseTurnRate = TURRET_TURNRATE;
if( m_flMaxWait == 0 )
m_flMaxWait = TURRET_MAXWAIT;
9 years ago
m_flStartYaw = pev->angles.y;
9 years ago
if( m_iOrientation == 1 )
9 years ago
{
pev->idealpitch = 180;
pev->angles.x = 180;
pev->view_ofs.z = -pev->view_ofs.z;
pev->effects |= EF_INVLIGHT;
pev->angles.y = pev->angles.y + 180;
9 years ago
if( pev->angles.y > 360 )
9 years ago
pev->angles.y = pev->angles.y - 360;
}
m_vecGoalAngles.x = 0;
9 years ago
if( m_iAutoStart )
9 years ago
{
m_flLastSight = gpGlobals->time + m_flMaxWait;
9 years ago
SetThink( &CBaseTurret::AutoSearchThink );
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
}
else
9 years ago
SetThink( &CBaseEntity::SUB_DoNothing );
9 years ago
}
void CBaseTurret::TurretUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
9 years ago
if( !ShouldToggle( useType, m_iOn ) )
9 years ago
return;
9 years ago
if( m_iOn )
9 years ago
{
m_hEnemy = NULL;
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
m_iAutoStart = FALSE;// switching off a turret disables autostart
9 years ago
//!!!! this should spin down first!!BUGBUG
9 years ago
SetThink( &CBaseTurret::Retire );
9 years ago
}
else
{
pev->nextthink = gpGlobals->time + 0.1f; // turn on delay
9 years ago
// if the turret is flagged as an autoactivate turret, re-enable it's ability open self.
9 years ago
if( pev->spawnflags & SF_MONSTER_TURRET_AUTOACTIVATE )
9 years ago
{
m_iAutoStart = TRUE;
}
9 years ago
SetThink( &CBaseTurret::Deploy );
9 years ago
}
}
void CBaseTurret::Ping( void )
{
// make the pinging noise every second while searching
9 years ago
if( m_flPingTime == 0 )
9 years ago
m_flPingTime = gpGlobals->time + 1;
9 years ago
else if( m_flPingTime <= gpGlobals->time )
9 years ago
{
m_flPingTime = gpGlobals->time + 1;
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "turret/tu_ping.wav", 1, ATTN_NORM );
EyeOn();
9 years ago
}
9 years ago
else if( m_eyeBrightness > 0 )
9 years ago
{
9 years ago
EyeOff();
9 years ago
}
}
9 years ago
void CBaseTurret::EyeOn()
9 years ago
{
9 years ago
if( m_pEyeGlow )
9 years ago
{
9 years ago
if( m_eyeBrightness != 255 )
9 years ago
{
m_eyeBrightness = 255;
}
m_pEyeGlow->SetBrightness( m_eyeBrightness );
}
}
9 years ago
void CBaseTurret::EyeOff()
9 years ago
{
9 years ago
if( m_pEyeGlow )
9 years ago
{
9 years ago
if( m_eyeBrightness > 0 )
9 years ago
{
m_eyeBrightness = Q_max( 0, m_eyeBrightness - 30 );
9 years ago
m_pEyeGlow->SetBrightness( m_eyeBrightness );
}
}
}
9 years ago
void CBaseTurret::ActiveThink( void )
9 years ago
{
int fAttack = 0;
Vector vecDirToEnemy;
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
StudioFrameAdvance();
9 years ago
if( ( !m_iOn ) || ( m_hEnemy == 0 ) )
9 years ago
{
m_hEnemy = NULL;
m_flLastSight = gpGlobals->time + m_flMaxWait;
9 years ago
SetThink( &CBaseTurret::SearchThink );
9 years ago
return;
}
9 years ago
// if it's dead, look for something new
9 years ago
if( !m_hEnemy->IsAlive() )
9 years ago
{
9 years ago
if( !m_flLastSight )
9 years ago
{
m_flLastSight = gpGlobals->time + 0.5f; // continue-shooting timeout
9 years ago
}
else
{
9 years ago
if( gpGlobals->time > m_flLastSight )
{
9 years ago
m_hEnemy = NULL;
m_flLastSight = gpGlobals->time + m_flMaxWait;
9 years ago
SetThink( &CBaseTurret::SearchThink );
9 years ago
return;
}
}
}
Vector vecMid = pev->origin + pev->view_ofs;
Vector vecMidEnemy = m_hEnemy->BodyTarget( vecMid );
// Look for our current enemy
9 years ago
int fEnemyVisible = FBoxVisible( pev, m_hEnemy->pev, vecMidEnemy );
9 years ago
vecDirToEnemy = vecMidEnemy - vecMid; // calculate dir and dist to enemy
float flDistToEnemy = vecDirToEnemy.Length();
9 years ago
Vector vec = UTIL_VecToAngles( vecMidEnemy - vecMid );
9 years ago
// Current enmey is not visible.
9 years ago
if( !fEnemyVisible || ( flDistToEnemy > TURRET_RANGE ) )
9 years ago
{
9 years ago
if( !m_flLastSight )
m_flLastSight = gpGlobals->time + 0.5f;
9 years ago
else
{
// Should we look for a new target?
9 years ago
if( gpGlobals->time > m_flLastSight )
9 years ago
{
m_hEnemy = NULL;
m_flLastSight = gpGlobals->time + m_flMaxWait;
9 years ago
SetThink( &CBaseTurret::SearchThink );
9 years ago
return;
}
}
fEnemyVisible = 0;
}
else
{
m_vecLastSight = vecMidEnemy;
}
UTIL_MakeAimVectors( m_vecCurAngles );
9 years ago
/*
ALERT( at_console, "%.0f %.0f : %.2f %.2f %.2f\n",
m_vecCurAngles.x, m_vecCurAngles.y,
gpGlobals->v_forward.x, gpGlobals->v_forward.y, gpGlobals->v_forward.z );
*/
Vector vecLOS = vecDirToEnemy; //vecMid - m_vecLastSight;
vecLOS = vecLOS.Normalize();
// Is the Gun looking at the target
if( DotProduct( vecLOS, gpGlobals->v_forward ) <= 0.866f ) // 30 degree slop
9 years ago
fAttack = FALSE;
else
fAttack = TRUE;
// fire the gun
9 years ago
if( m_iSpin && ( ( fAttack ) || ( m_fBeserk ) ) )
9 years ago
{
Vector vecSrc, vecAng;
GetAttachment( 0, vecSrc, vecAng );
9 years ago
SetTurretAnim( TURRET_ANIM_FIRE );
Shoot( vecSrc, gpGlobals->v_forward );
9 years ago
}
else
{
9 years ago
SetTurretAnim( TURRET_ANIM_SPIN );
9 years ago
}
//move the gun
9 years ago
if( m_fBeserk )
9 years ago
{
9 years ago
if( RANDOM_LONG( 0, 9 ) == 0 )
9 years ago
{
9 years ago
m_vecGoalAngles.y = RANDOM_FLOAT( 0, 360 );
m_vecGoalAngles.x = RANDOM_FLOAT( 0, 90 ) - 90 * m_iOrientation;
TakeDamage( pev, pev, 1, DMG_GENERIC ); // don't beserk forever
9 years ago
return;
}
}
9 years ago
else if( fEnemyVisible )
9 years ago
{
9 years ago
if( vec.y > 360 )
9 years ago
vec.y -= 360;
9 years ago
if( vec.y < 0 )
9 years ago
vec.y += 360;
9 years ago
//ALERT( at_console, "[%.2f]", vec.x );
9 years ago
if( vec.x < -180 )
9 years ago
vec.x += 360;
9 years ago
if( vec.x > 180 )
9 years ago
vec.x -= 360;
// now all numbers should be in [1...360]
// pin to turret limitations to [-90...15]
9 years ago
if( m_iOrientation == 0 )
9 years ago
{
9 years ago
if( vec.x > 90 )
9 years ago
vec.x = 90;
9 years ago
else if( vec.x < m_iMinPitch )
9 years ago
vec.x = m_iMinPitch;
}
else
{
9 years ago
if( vec.x < -90 )
9 years ago
vec.x = -90;
9 years ago
else if( vec.x > -m_iMinPitch )
9 years ago
vec.x = -m_iMinPitch;
}
9 years ago
// ALERT( at_console, "->[%.2f]\n", vec.x );
9 years ago
m_vecGoalAngles.y = vec.y;
m_vecGoalAngles.x = vec.x;
}
SpinUpCall();
MoveTurret();
}
9 years ago
void CTurret::Shoot( Vector &vecSrc, Vector &vecDirToEnemy )
9 years ago
{
FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_12MM, 1 );
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "turret/tu_fire1.wav", 1, 0.6 );
9 years ago
pev->effects = pev->effects | EF_MUZZLEFLASH;
}
9 years ago
void CMiniTurret::Shoot( Vector &vecSrc, Vector &vecDirToEnemy )
9 years ago
{
FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_9MM, 1 );
9 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/hks1.wav", 1, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/hks2.wav", 1, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/hks3.wav", 1, ATTN_NORM );
break;
9 years ago
}
pev->effects = pev->effects | EF_MUZZLEFLASH;
}
9 years ago
void CBaseTurret::Deploy( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
StudioFrameAdvance();
9 years ago
9 years ago
if( pev->sequence != TURRET_ANIM_DEPLOY )
9 years ago
{
m_iOn = 1;
9 years ago
SetTurretAnim( TURRET_ANIM_DEPLOY );
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_deploy.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
9 years ago
SUB_UseTargets( this, USE_ON, 0 );
}
9 years ago
if( m_fSequenceFinished )
9 years ago
{
pev->maxs.z = m_iDeployHeight;
pev->mins.z = -m_iDeployHeight;
9 years ago
UTIL_SetSize( pev, pev->mins, pev->maxs );
9 years ago
m_vecCurAngles.x = 0;
9 years ago
if( m_iOrientation == 1 )
9 years ago
{
m_vecCurAngles.y = UTIL_AngleMod( pev->angles.y + 180 );
}
else
{
m_vecCurAngles.y = UTIL_AngleMod( pev->angles.y );
}
9 years ago
SetTurretAnim( TURRET_ANIM_SPIN );
9 years ago
pev->framerate = 0;
9 years ago
SetThink( &CBaseTurret::SearchThink );
9 years ago
}
m_flLastSight = gpGlobals->time + m_flMaxWait;
}
9 years ago
void CBaseTurret::Retire( void )
9 years ago
{
// make the turret level
m_vecGoalAngles.x = 0;
m_vecGoalAngles.y = m_flStartYaw;
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
9 years ago
StudioFrameAdvance();
9 years ago
9 years ago
EyeOff();
9 years ago
9 years ago
if( !MoveTurret() )
9 years ago
{
9 years ago
if( m_iSpin )
9 years ago
{
SpinDownCall();
}
9 years ago
else if( pev->sequence != TURRET_ANIM_RETIRE )
9 years ago
{
9 years ago
SetTurretAnim( TURRET_ANIM_RETIRE );
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "turret/tu_deploy.wav", TURRET_MACHINE_VOLUME, ATTN_NORM, 0, 120 );
9 years ago
SUB_UseTargets( this, USE_OFF, 0 );
}
9 years ago
else if( m_fSequenceFinished )
{
9 years ago
m_iOn = 0;
m_flLastSight = 0;
9 years ago
SetTurretAnim( TURRET_ANIM_NONE );
9 years ago
pev->maxs.z = m_iRetractHeight;
pev->mins.z = -m_iRetractHeight;
9 years ago
UTIL_SetSize( pev, pev->mins, pev->maxs );
if( m_iAutoStart )
9 years ago
{
9 years ago
SetThink( &CBaseTurret::AutoSearchThink );
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
}
else
9 years ago
SetThink( &CBaseEntity::SUB_DoNothing );
9 years ago
}
}
else
{
9 years ago
SetTurretAnim( TURRET_ANIM_SPIN );
9 years ago
}
}
9 years ago
void CTurret::SpinUpCall( void )
9 years ago
{
9 years ago
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
// Are we already spun up? If not start the two stage process.
9 years ago
if( !m_iSpin )
9 years ago
{
SetTurretAnim( TURRET_ANIM_SPIN );
9 years ago
// for the first pass, spin up the the barrel
9 years ago
if( !m_iStartSpin )
9 years ago
{
pev->nextthink = gpGlobals->time + 1.0f; // spinup delay
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_spinup.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
9 years ago
m_iStartSpin = 1;
pev->framerate = 0.1f;
9 years ago
}
// after the barrel is spun up, turn on the hum
else if( pev->framerate >= 1.0f )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1f; // retarget delay
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_STATIC, "turret/tu_active2.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
SetThink( &CBaseTurret::ActiveThink );
9 years ago
m_iStartSpin = 0;
m_iSpin = 1;
}
else
{
pev->framerate += 0.075f;
9 years ago
}
}
9 years ago
if( m_iSpin )
9 years ago
{
9 years ago
SetThink( &CBaseTurret::ActiveThink );
9 years ago
}
}
9 years ago
void CTurret::SpinDownCall( void )
9 years ago
{
9 years ago
if( m_iSpin )
9 years ago
{
SetTurretAnim( TURRET_ANIM_SPIN );
if( pev->framerate == 1.0f )
9 years ago
{
9 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "turret/tu_active2.wav", 0, 0, SND_STOP, 100 );
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "turret/tu_spindown.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
9 years ago
}
pev->framerate -= 0.02f;
9 years ago
if( pev->framerate <= 0 )
9 years ago
{
pev->framerate = 0;
m_iSpin = 0;
}
}
}
9 years ago
void CBaseTurret::SetTurretAnim( TURRET_ANIM anim )
9 years ago
{
9 years ago
if( pev->sequence != anim )
9 years ago
{
9 years ago
switch( anim )
9 years ago
{
case TURRET_ANIM_FIRE:
case TURRET_ANIM_SPIN:
9 years ago
if( pev->sequence != TURRET_ANIM_FIRE && pev->sequence != TURRET_ANIM_SPIN )
9 years ago
{
pev->frame = 0;
}
break;
default:
pev->frame = 0;
break;
}
pev->sequence = anim;
9 years ago
ResetSequenceInfo();
9 years ago
9 years ago
switch( anim )
9 years ago
{
case TURRET_ANIM_RETIRE:
9 years ago
pev->frame = 255;
pev->framerate = -1.0;
9 years ago
break;
case TURRET_ANIM_DIE:
9 years ago
pev->framerate = 1.0;
9 years ago
break;
default:
break;
9 years ago
}
9 years ago
//ALERT( at_console, "Turret anim #%d\n", anim );
9 years ago
}
}
//
// This search function will sit with the turret deployed and look for a new target.
// After a set amount of time, the barrel will spin down. After m_flMaxWait, the turret will
// retact.
//
9 years ago
void CBaseTurret::SearchThink( void )
9 years ago
{
// ensure rethink
9 years ago
SetTurretAnim( TURRET_ANIM_SPIN );
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
9 years ago
if( m_flSpinUpTime == 0 && m_flMaxSpin )
9 years ago
m_flSpinUpTime = gpGlobals->time + m_flMaxSpin;
9 years ago
Ping();
9 years ago
// If we have a target and we're still healthy
if( m_hEnemy != 0 )
9 years ago
{
9 years ago
if( !m_hEnemy->IsAlive() )
9 years ago
m_hEnemy = NULL;// Dead enemy forces a search for new one
}
// Acquire Target
if( m_hEnemy == 0 )
9 years ago
{
9 years ago
Look( TURRET_RANGE );
9 years ago
m_hEnemy = BestVisibleEnemy();
}
// If we've found a target, spin up the barrel and start to attack
if( m_hEnemy != 0 )
9 years ago
{
m_flLastSight = 0;
m_flSpinUpTime = 0;
9 years ago
SetThink( &CBaseTurret::ActiveThink );
9 years ago
}
else
{
// Are we out of time, do we need to retract?
9 years ago
if( gpGlobals->time > m_flLastSight )
9 years ago
{
//Before we retrace, make sure that we are spun down.
m_flLastSight = 0;
m_flSpinUpTime = 0;
9 years ago
SetThink( &CBaseTurret::Retire );
9 years ago
}
// should we stop the spin?
9 years ago
else if( ( m_flSpinUpTime ) && ( gpGlobals->time > m_flSpinUpTime ) )
9 years ago
{
SpinDownCall();
}
// generic hunt for new victims
m_vecGoalAngles.y = ( m_vecGoalAngles.y + 0.1f * m_fTurnRate );
9 years ago
if( m_vecGoalAngles.y >= 360 )
9 years ago
m_vecGoalAngles.y -= 360;
MoveTurret();
}
}
//
9 years ago
// This think function will deploy the turret when something comes into range. This is for
// automatically activated turrets.
//
9 years ago
void CBaseTurret::AutoSearchThink( void )
9 years ago
{
// ensure rethink
9 years ago
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.3f;
9 years ago
// If we have a target and we're still healthy
if( m_hEnemy != 0 )
9 years ago
{
9 years ago
if( !m_hEnemy->IsAlive() )
9 years ago
m_hEnemy = NULL;// Dead enemy forces a search for new one
}
// Acquire Target
if( m_hEnemy == 0 )
9 years ago
{
Look( TURRET_RANGE );
m_hEnemy = BestVisibleEnemy();
}
if( m_hEnemy != 0 )
9 years ago
{
9 years ago
SetThink( &CBaseTurret::Deploy );
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_alert.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
9 years ago
}
}
9 years ago
void CBaseTurret::TurretDeath( void )
9 years ago
{
//BOOL iActive = FALSE;
9 years ago
9 years ago
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
9 years ago
if( pev->deadflag != DEAD_DEAD )
9 years ago
{
pev->deadflag = DEAD_DEAD;
9 years ago
float flRndSound = RANDOM_FLOAT( 0, 1 );
9 years ago
if( flRndSound <= 0.33f )
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die.wav", 1.0, ATTN_NORM );
else if( flRndSound <= 0.66f )
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die2.wav", 1.0, ATTN_NORM );
9 years ago
else
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die3.wav", 1.0, ATTN_NORM );
9 years ago
9 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "turret/tu_active2.wav", 0, 0, SND_STOP, 100 );
9 years ago
9 years ago
if( m_iOrientation == 0 )
9 years ago
m_vecGoalAngles.x = -15;
else
m_vecGoalAngles.x = -90;
9 years ago
SetTurretAnim( TURRET_ANIM_DIE );
9 years ago
9 years ago
EyeOn();
9 years ago
}
9 years ago
EyeOff();
9 years ago
9 years ago
if( pev->dmgtime + RANDOM_FLOAT( 0, 2 ) > gpGlobals->time )
9 years ago
{
// lots of smoke
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( RANDOM_FLOAT( pev->absmin.x, pev->absmax.x ) );
WRITE_COORD( RANDOM_FLOAT( pev->absmin.y, pev->absmax.y ) );
WRITE_COORD( pev->origin.z - m_iOrientation * 64 );
WRITE_SHORT( g_sModelIndexSmoke );
WRITE_BYTE( 25 ); // scale * 10
9 years ago
WRITE_BYTE( 10 - m_iOrientation * 5 ); // framerate
9 years ago
MESSAGE_END();
}
9 years ago
if( pev->dmgtime + RANDOM_FLOAT( 0, 5 ) > gpGlobals->time )
9 years ago
{
Vector vecSrc = Vector( RANDOM_FLOAT( pev->absmin.x, pev->absmax.x ), RANDOM_FLOAT( pev->absmin.y, pev->absmax.y ), 0 );
9 years ago
if( m_iOrientation == 0 )
9 years ago
vecSrc = vecSrc + Vector( 0, 0, RANDOM_FLOAT( pev->origin.z, pev->absmax.z ) );
else
vecSrc = vecSrc + Vector( 0, 0, RANDOM_FLOAT( pev->absmin.z, pev->origin.z ) );
UTIL_Sparks( vecSrc );
}
9 years ago
if( m_fSequenceFinished && !MoveTurret() && pev->dmgtime + 5 < gpGlobals->time )
9 years ago
{
pev->framerate = 0;
SetThink( NULL );
}
}
9 years ago
void CBaseTurret::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
9 years ago
{
9 years ago
if( ptr->iHitgroup == 10 )
9 years ago
{
// hit armor
9 years ago
if( pev->dmgtime != gpGlobals->time || (RANDOM_LONG( 0, 10 ) < 1 ) )
9 years ago
{
9 years ago
UTIL_Ricochet( ptr->vecEndPos, RANDOM_FLOAT( 1, 2 ) );
9 years ago
pev->dmgtime = gpGlobals->time;
}
flDamage = 0.1;// don't hurt the monster much, but allow bits_COND_LIGHT_DAMAGE to be generated
}
9 years ago
if( !pev->takedamage )
9 years ago
return;
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
}
// take damage. bitsDamageType indicates type of damage sustained, ie: DMG_BULLET
9 years ago
int CBaseTurret::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
9 years ago
if( !pev->takedamage )
9 years ago
return 0;
9 years ago
if( !m_iOn )
flDamage *= 0.1f;
9 years ago
pev->health -= flDamage;
9 years ago
if( pev->health <= 0 )
9 years ago
{
pev->health = 0;
pev->takedamage = DAMAGE_NO;
pev->dmgtime = gpGlobals->time;
9 years ago
ClearBits( pev->flags, FL_MONSTER ); // why are they set in the first place???
9 years ago
SetUse( NULL );
9 years ago
SetThink( &CBaseTurret::TurretDeath );
9 years ago
SUB_UseTargets( this, USE_ON, 0 ); // wake up others
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
return 0;
}
9 years ago
if( pev->health <= 10 )
9 years ago
{
9 years ago
if( m_iOn && ( 1 || RANDOM_LONG( 0, 0x7FFF ) > 800 ) )
9 years ago
{
m_fBeserk = 1;
9 years ago
SetThink( &CBaseTurret::SearchThink );
9 years ago
}
}
return 1;
}
9 years ago
int CBaseTurret::MoveTurret( void )
9 years ago
{
int state = 0;
// any x movement?
9 years ago
if( m_vecCurAngles.x != m_vecGoalAngles.x )
9 years ago
{
float flDir = m_vecGoalAngles.x > m_vecCurAngles.x ? 1 : -1 ;
m_vecCurAngles.x += 0.1f * m_fTurnRate * flDir;
9 years ago
// if we started below the goal, and now we're past, peg to goal
9 years ago
if( flDir == 1 )
9 years ago
{
9 years ago
if( m_vecCurAngles.x > m_vecGoalAngles.x )
9 years ago
m_vecCurAngles.x = m_vecGoalAngles.x;
}
else
{
9 years ago
if( m_vecCurAngles.x < m_vecGoalAngles.x )
9 years ago
m_vecCurAngles.x = m_vecGoalAngles.x;
}
9 years ago
if( m_iOrientation == 0 )
SetBoneController( 1, -m_vecCurAngles.x );
9 years ago
else
9 years ago
SetBoneController( 1, m_vecCurAngles.x );
9 years ago
state = 1;
}
9 years ago
if( m_vecCurAngles.y != m_vecGoalAngles.y )
9 years ago
{
float flDir = m_vecGoalAngles.y > m_vecCurAngles.y ? 1 : -1 ;
9 years ago
float flDist = fabs( m_vecGoalAngles.y - m_vecCurAngles.y );
if( flDist > 180 )
9 years ago
{
flDist = 360 - flDist;
flDir = -flDir;
}
9 years ago
if( flDist > 30 )
9 years ago
{
9 years ago
if( m_fTurnRate < m_iBaseTurnRate * 10 )
9 years ago
{
m_fTurnRate += m_iBaseTurnRate;
}
}
9 years ago
else if( m_fTurnRate > 45 )
9 years ago
{
m_fTurnRate -= m_iBaseTurnRate;
}
else
{
m_fTurnRate += m_iBaseTurnRate;
}
m_vecCurAngles.y += 0.1f * m_fTurnRate * flDir;
9 years ago
9 years ago
if( m_vecCurAngles.y < 0 )
9 years ago
m_vecCurAngles.y += 360;
9 years ago
else if( m_vecCurAngles.y >= 360 )
9 years ago
m_vecCurAngles.y -= 360;
if( flDist < ( 0.05f * m_iBaseTurnRate ) )
9 years ago
m_vecCurAngles.y = m_vecGoalAngles.y;
9 years ago
//ALERT( at_console, "%.2f -> %.2f\n", m_vecCurAngles.y, y );
if( m_iOrientation == 0 )
SetBoneController( 0, m_vecCurAngles.y - pev->angles.y );
9 years ago
else
9 years ago
SetBoneController( 0, pev->angles.y - 180 - m_vecCurAngles.y );
9 years ago
state = 1;
}
9 years ago
if( !state )
9 years ago
m_fTurnRate = m_iBaseTurnRate;
9 years ago
//ALERT( at_console, "(%.2f, %.2f)->(%.2f, %.2f)\n", m_vecCurAngles.x,
// m_vecCurAngles.y, m_vecGoalAngles.x, m_vecGoalAngles.y );
9 years ago
return state;
}
//
// ID as a machine
//
9 years ago
int CBaseTurret::Classify( void )
9 years ago
{
9 years ago
if( m_iOn || m_iAutoStart )
9 years ago
return CLASS_MACHINE;
return CLASS_NONE;
}
//=========================================================
// Sentry gun - smallest turret, placed near grunt entrenchments
//=========================================================
class CSentry : public CBaseTurret
{
public:
9 years ago
void Spawn();
void Precache( void );
9 years ago
// other functions
9 years ago
void Shoot( Vector &vecSrc, Vector &vecDirToEnemy );
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
9 years ago
void EXPORT SentryTouch( CBaseEntity *pOther );
void EXPORT SentryDeath( void );
};
LINK_ENTITY_TO_CLASS( monster_sentry, CSentry )
9 years ago
void CSentry::Precache()
{
9 years ago
CBaseTurret::Precache();
PRECACHE_MODEL( "models/sentry.mdl" );
PRECACHE_SOUND( "weapons/hks1.wav" );
PRECACHE_SOUND( "weapons/hks2.wav" );
PRECACHE_SOUND( "weapons/hks3.wav" );
9 years ago
}
void CSentry::Spawn()
{
9 years ago
Precache();
SET_MODEL( ENT( pev ), "models/sentry.mdl" );
pev->health = gSkillData.sentryHealth;
m_HackedGunPos = Vector( 0, 0, 48 );
pev->view_ofs.z = 48;
9 years ago
m_flMaxWait = 1E6;
9 years ago
m_flMaxSpin = 1E6;
9 years ago
CBaseTurret::Spawn();
m_iRetractHeight = 64;
m_iDeployHeight = 64;
9 years ago
m_iMinPitch = -60;
UTIL_SetSize( pev, Vector( -16, -16, -m_iRetractHeight ), Vector( 16, 16, m_iRetractHeight ) );
9 years ago
9 years ago
SetTouch( &CSentry::SentryTouch );
SetThink( &CBaseTurret::Initialize );
pev->nextthink = gpGlobals->time + 0.3f;
9 years ago
}
9 years ago
void CSentry::Shoot( Vector &vecSrc, Vector &vecDirToEnemy )
9 years ago
{
FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_MP5, 1 );
9 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/hks1.wav", 1, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/hks2.wav", 1, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/hks3.wav", 1, ATTN_NORM );
break;
9 years ago
}
pev->effects = pev->effects | EF_MUZZLEFLASH;
}
9 years ago
int CSentry::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
9 years ago
if( !pev->takedamage )
9 years ago
return 0;
9 years ago
if( !m_iOn )
9 years ago
{
SetThink( &CBaseTurret::Deploy );
SetUse( NULL );
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
}
pev->health -= flDamage;
9 years ago
if( pev->health <= 0 )
9 years ago
{
pev->health = 0;
pev->takedamage = DAMAGE_NO;
pev->dmgtime = gpGlobals->time;
9 years ago
ClearBits( pev->flags, FL_MONSTER ); // why are they set in the first place???
9 years ago
SetUse( NULL );
9 years ago
SetThink( &CSentry::SentryDeath );
9 years ago
SUB_UseTargets( this, USE_ON, 0 ); // wake up others
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
return 0;
}
return 1;
}
void CSentry::SentryTouch( CBaseEntity *pOther )
{
9 years ago
if( pOther && ( pOther->IsPlayer() || ( pOther->pev->flags & FL_MONSTER ) ) )
9 years ago
{
9 years ago
TakeDamage( pOther->pev, pOther->pev, 0, 0 );
9 years ago
}
}
9 years ago
void CSentry::SentryDeath( void )
9 years ago
{
//BOOL iActive = FALSE;
9 years ago
9 years ago
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
9 years ago
if( pev->deadflag != DEAD_DEAD )
9 years ago
{
pev->deadflag = DEAD_DEAD;
9 years ago
float flRndSound = RANDOM_FLOAT( 0, 1 );
9 years ago
if( flRndSound <= 0.33f )
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die.wav", 1.0, ATTN_NORM );
else if( flRndSound <= 0.66f )
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die2.wav", 1.0, ATTN_NORM );
9 years ago
else
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die3.wav", 1.0, ATTN_NORM );
9 years ago
9 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "turret/tu_active2.wav", 0, 0, SND_STOP, 100 );
9 years ago
SetBoneController( 0, 0 );
SetBoneController( 1, 0 );
9 years ago
SetTurretAnim( TURRET_ANIM_DIE );
9 years ago
pev->solid = SOLID_NOT;
pev->angles.y = UTIL_AngleMod( pev->angles.y + RANDOM_LONG( 0, 2 ) * 120 );
9 years ago
EyeOn();
9 years ago
}
9 years ago
EyeOff();
9 years ago
Vector vecSrc, vecAng;
GetAttachment( 1, vecSrc, vecAng );
9 years ago
if( pev->dmgtime + RANDOM_FLOAT( 0, 2 ) > gpGlobals->time )
9 years ago
{
// lots of smoke
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( vecSrc.x + RANDOM_FLOAT( -16, 16 ) );
WRITE_COORD( vecSrc.y + RANDOM_FLOAT( -16, 16 ) );
WRITE_COORD( vecSrc.z - 32 );
WRITE_SHORT( g_sModelIndexSmoke );
WRITE_BYTE( 15 ); // scale * 10
WRITE_BYTE( 8 ); // framerate
MESSAGE_END();
}
9 years ago
if( pev->dmgtime + RANDOM_FLOAT( 0, 8 ) > gpGlobals->time )
9 years ago
{
UTIL_Sparks( vecSrc );
}
9 years ago
if( m_fSequenceFinished && pev->dmgtime + 5 < gpGlobals->time )
9 years ago
{
pev->framerate = 0;
SetThink( NULL );
}
}