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.

1330 lines
31 KiB

7 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
7 years ago
} TURRET_ANIM;
class CBaseTurret : public CBaseMonster
{
public:
8 years ago
void Spawn( void );
virtual void Precache( void );
void UpdateOnRemove();
7 years ago
void KeyValue( KeyValueData *pkvd );
void EXPORT TurretUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
8 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 );
7 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; }
8 years ago
// void SpinDown( void );
7 years ago
// float EXPORT SpinDownCall( void ) { return SpinDown(); }
8 years ago
// virtual float SpinDown( void ) { return 0;}
// virtual float Retire( void ) { return 0;}
7 years ago
8 years ago
void EXPORT Deploy( void );
void EXPORT Retire( void );
7 years ago
8 years ago
void EXPORT Initialize( void );
7 years ago
8 years ago
virtual void Ping( void );
virtual void EyeOn( void );
virtual void EyeOff( void );
9 years ago
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
8 years ago
static TYPEDESCRIPTION m_SaveData[];
7 years ago
// other functions
8 years ago
void SetTurretAnim( TURRET_ANIM anim );
int MoveTurret( void );
virtual void Shoot( Vector &vecSrc, Vector &vecDirToEnemy ) { };
7 years ago
float m_flMaxSpin; // Max time to spin the barrel w/o a target
int m_iSpin;
CSprite *m_pEyeGlow;
8 years ago
int m_eyeBrightness;
7 years ago
8 years ago
int m_iDeployHeight;
int m_iRetractHeight;
7 years ago
int m_iMinPitch;
int m_iBaseTurnRate; // angles per second
float m_fTurnRate; // actual turn rate
int m_iOrientation; // 0 = floor, 1 = Ceiling
8 years ago
int m_iOn;
7 years ago
virtual STATE getState() { if (m_iOn) { return STATE_ON; } else { return STATE_OFF; } }
int m_fBeserk; // Sometimes this bitch will just freak out
int m_iAutoStart; // true if the turret auto deploys when a target
8 years ago
// enters its range
7 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
8 years ago
float m_flStartYaw;
Vector m_vecCurAngles;
Vector m_vecGoalAngles;
7 years ago
8 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
7 years ago
};
TYPEDESCRIPTION CBaseTurret::m_SaveData[] =
7 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 )
7 years ago
class CTurret : public CBaseTurret
{
public:
8 years ago
void Spawn( void );
void Precache( void );
7 years ago
// Think functions
8 years ago
void SpinUpCall( void );
void SpinDownCall( void );
7 years ago
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
7 years ago
8 years ago
static TYPEDESCRIPTION m_SaveData[];
7 years ago
// other functions
8 years ago
void Shoot( Vector &vecSrc, Vector &vecDirToEnemy );
7 years ago
private:
int m_iStartSpin;
};
TYPEDESCRIPTION CTurret::m_SaveData[] =
7 years ago
{
DEFINE_FIELD( CTurret, m_iStartSpin, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CTurret, CBaseTurret )
7 years ago
class CMiniTurret : public CBaseTurret
{
public:
8 years ago
void Spawn();
void Precache( void );
7 years ago
// other functions
8 years ago
void Shoot( Vector &vecSrc, Vector &vecDirToEnemy );
7 years ago
};
LINK_ENTITY_TO_CLASS( monster_turret, CTurret )
LINK_ENTITY_TO_CLASS( monster_miniturret, CMiniTurret )
7 years ago
void CBaseTurret::KeyValue( KeyValueData *pkvd )
{
8 years ago
if( FStrEq( pkvd->szKeyName, "maxsleep" ) )
7 years ago
{
8 years ago
m_flMaxWait = atof( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "orientation" ) )
7 years ago
{
8 years ago
m_iOrientation = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "searchspeed" ) )
7 years ago
{
8 years ago
m_iSearchSpeed = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "turnrate" ) )
7 years ago
{
8 years ago
m_iBaseTurnRate = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "style" ) ||
FStrEq( pkvd->szKeyName, "height" ) ||
FStrEq( pkvd->szKeyName, "value1" ) ||
FStrEq( pkvd->szKeyName, "value2" ) ||
FStrEq( pkvd->szKeyName, "value3" ) )
7 years ago
pkvd->fHandled = TRUE;
else
CBaseMonster::KeyValue( pkvd );
}
void CBaseTurret::Spawn()
{
8 years ago
Precache();
7 years ago
SetNextThink( 1 );
pev->movetype = MOVETYPE_FLY;
pev->sequence = 0;
8 years ago
pev->frame = 0;
pev->solid = SOLID_SLIDEBOX;
7 years ago
pev->takedamage = DAMAGE_AIM;
8 years ago
SetBits( pev->flags, FL_MONSTER );
9 years ago
SetUse( &CBaseTurret::TurretUse );
7 years ago
8 years ago
if( ( pev->spawnflags & SF_MONSTER_TURRET_AUTOACTIVATE )
&& !( pev->spawnflags & SF_MONSTER_TURRET_STARTINACTIVE ) )
7 years ago
{
m_iAutoStart = TRUE;
}
if( m_iOrientation == 1 )
{
pev->idealpitch = 180;
pev->angles.x = 180;
}
8 years ago
ResetSequenceInfo();
7 years ago
SetBoneController( 0, 0 );
SetBoneController( 1, 0 );
m_flFieldOfView = VIEW_FIELD_FULL;
// m_flSightRange = TURRET_RANGE;
}
8 years ago
void CBaseTurret::Precache()
9 years ago
{
8 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
}
7 years ago
void CBaseTurret::UpdateOnRemove()
7 years ago
{
CBaseEntity::UpdateOnRemove();
if( m_pEyeGlow )
{
UTIL_Remove( m_pEyeGlow );
m_pEyeGlow = 0;
}
7 years ago
}
#define TURRET_GLOW_SPRITE "sprites/flare3.spr"
void CTurret::Spawn()
8 years ago
{
Precache();
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/turret.mdl" );
7 years ago
if (!pev->health)
pev->health = gSkillData.turretHealth;
m_HackedGunPos = Vector( 0, 0, 12.75 );
8 years ago
m_flMaxSpin = TURRET_MAXSPIN;
pev->view_ofs.z = 12.75;
7 years ago
8 years ago
CBaseTurret::Spawn();
7 years ago
m_iRetractHeight = 16;
m_iDeployHeight = 32;
8 years ago
m_iMinPitch = -15;
UTIL_SetSize( pev, Vector( -32, -32, -m_iRetractHeight ), Vector( 32, 32, m_iRetractHeight ) );
7 years ago
SetThink(&CTurret::Initialize);
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;
SetNextThink( 0.3f );
7 years ago
}
void CTurret::Precache()
{
8 years ago
CBaseTurret::Precache();
7 years ago
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/turret.mdl" );
8 years ago
PRECACHE_MODEL( TURRET_GLOW_SPRITE );
7 years ago
}
void CMiniTurret::Spawn()
{
8 years ago
Precache();
if( pev->model )
SET_MODEL( ENT( pev ), STRING( pev->model ) ); //LRC
7 years ago
else
SET_MODEL( ENT( pev ), "models/miniturret.mdl" );
if( !pev->health )
pev->health = gSkillData.miniturretHealth;
m_HackedGunPos = Vector( 0.0f, 0.0f, 12.75f );
7 years ago
m_flMaxSpin = 0;
pev->view_ofs.z = 12.75f;
7 years ago
8 years ago
CBaseTurret::Spawn();
7 years ago
m_iRetractHeight = 16;
m_iDeployHeight = 32;
8 years ago
m_iMinPitch = -15;
UTIL_SetSize( pev, Vector( -16, -16, -m_iRetractHeight ), Vector( 16, 16, m_iRetractHeight ) );
7 years ago
SetThink( &CMiniTurret::Initialize );
SetNextThink( 0.3f );
7 years ago
}
void CMiniTurret::Precache()
{
8 years ago
CBaseTurret::Precache();
7 years ago
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/miniturret.mdl" );
8 years ago
PRECACHE_SOUND( "weapons/hks1.wav" );
PRECACHE_SOUND( "weapons/hks2.wav" );
PRECACHE_SOUND( "weapons/hks3.wav" );
7 years ago
}
8 years ago
void CBaseTurret::Initialize( void )
7 years ago
{
m_iOn = 0;
m_fBeserk = 0;
m_iSpin = 0;
SetBoneController( 0, 0 );
SetBoneController( 1, 0 );
8 years ago
if( m_iBaseTurnRate == 0 )
m_iBaseTurnRate = TURRET_TURNRATE;
if( m_flMaxWait == 0 )
m_flMaxWait = TURRET_MAXWAIT;
7 years ago
m_flStartYaw = pev->angles.y;
8 years ago
if( m_iOrientation == 1 )
7 years ago
{
//pev->idealpitch = 180;
//pev->angles.x = 180; //This is moved to CBaseTurret::Spawn for fix old bug in original HL. G-Cont.
7 years ago
pev->view_ofs.z = -pev->view_ofs.z;
pev->effects |= EF_INVLIGHT;
pev->angles.y = pev->angles.y + 180;
8 years ago
if( pev->angles.y > 360 )
7 years ago
pev->angles.y = pev->angles.y - 360;
}
m_vecGoalAngles.x = 0;
8 years ago
if( m_iAutoStart )
7 years ago
{
m_flLastSight = gpGlobals->time + m_flMaxWait;
8 years ago
SetThink( &CBaseTurret::AutoSearchThink );
SetNextThink( 0.1f );
7 years ago
}
else
SetThink(&CBaseTurret::SUB_DoNothing);
}
void CBaseTurret::TurretUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
8 years ago
if( !ShouldToggle( useType, m_iOn ) )
7 years ago
return;
8 years ago
if( m_iOn )
7 years ago
{
m_hEnemy = NULL;
SetNextThink( 0.1f );
7 years ago
m_iAutoStart = FALSE;// switching off a turret disables autostart
7 years ago
//!!!! this should spin down first!!BUGBUG
8 years ago
SetThink( &CBaseTurret::Retire );
7 years ago
}
else
{
SetNextThink( 0.1f ); // turn on delay
7 years ago
// if the turret is flagged as an autoactivate turret, re-enable it's ability open self.
8 years ago
if( pev->spawnflags & SF_MONSTER_TURRET_AUTOACTIVATE )
7 years ago
{
m_iAutoStart = TRUE;
}
8 years ago
SetThink( &CBaseTurret::Deploy );
7 years ago
}
}
void CBaseTurret::Ping( void )
{
// make the pinging noise every second while searching
8 years ago
if( m_flPingTime == 0 )
7 years ago
m_flPingTime = gpGlobals->time + 1;
8 years ago
else if( m_flPingTime <= gpGlobals->time )
7 years ago
{
m_flPingTime = gpGlobals->time + 1;
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "turret/tu_ping.wav", 1, ATTN_NORM );
EyeOn();
7 years ago
}
8 years ago
else if( m_eyeBrightness > 0 )
7 years ago
{
8 years ago
EyeOff();
7 years ago
}
}
8 years ago
void CBaseTurret::EyeOn()
7 years ago
{
8 years ago
if( m_pEyeGlow )
7 years ago
{
8 years ago
if( m_eyeBrightness != 255 )
7 years ago
{
m_eyeBrightness = 255;
}
m_pEyeGlow->SetBrightness( m_eyeBrightness );
}
}
8 years ago
void CBaseTurret::EyeOff()
7 years ago
{
8 years ago
if( m_pEyeGlow )
7 years ago
{
8 years ago
if( m_eyeBrightness > 0 )
7 years ago
{
m_eyeBrightness = Q_max( 0, m_eyeBrightness - 30 );
7 years ago
m_pEyeGlow->SetBrightness( m_eyeBrightness );
}
}
}
8 years ago
void CBaseTurret::ActiveThink( void )
7 years ago
{
int fAttack = 0;
Vector vecDirToEnemy;
SetNextThink( 0.1f );
8 years ago
StudioFrameAdvance();
7 years ago
if( ( !m_iOn ) || ( m_hEnemy == 0 ) )
7 years ago
{
m_hEnemy = NULL;
m_flLastSight = gpGlobals->time + m_flMaxWait;
8 years ago
SetThink( &CBaseTurret::SearchThink );
7 years ago
return;
}
7 years ago
// if it's dead, look for something new
8 years ago
if( !m_hEnemy->IsAlive() )
7 years ago
{
8 years ago
if( !m_flLastSight )
7 years ago
{
m_flLastSight = gpGlobals->time + 0.5f; // continue-shooting timeout
7 years ago
}
else
{
8 years ago
if( gpGlobals->time > m_flLastSight )
{
7 years ago
m_hEnemy = NULL;
m_flLastSight = gpGlobals->time + m_flMaxWait;
8 years ago
SetThink( &CBaseTurret::SearchThink );
7 years ago
return;
}
}
}
Vector vecMid = pev->origin + pev->view_ofs;
Vector vecMidEnemy = m_hEnemy->BodyTarget( vecMid );
// Look for our current enemy
8 years ago
int fEnemyVisible = FBoxVisible( pev, m_hEnemy->pev, vecMidEnemy );
7 years ago
vecDirToEnemy = vecMidEnemy - vecMid; // calculate dir and dist to enemy
float flDistToEnemy = vecDirToEnemy.Length();
8 years ago
Vector vec = UTIL_VecToAngles( vecMidEnemy - vecMid );
7 years ago
// Current enmey is not visible.
8 years ago
if( !fEnemyVisible || ( flDistToEnemy > TURRET_RANGE ) )
7 years ago
{
8 years ago
if( !m_flLastSight )
m_flLastSight = gpGlobals->time + 0.5f;
7 years ago
else
{
// Should we look for a new target?
8 years ago
if( gpGlobals->time > m_flLastSight )
7 years ago
{
m_hEnemy = NULL;
m_flLastSight = gpGlobals->time + m_flMaxWait;
8 years ago
SetThink( &CBaseTurret::SearchThink );
7 years ago
return;
}
}
fEnemyVisible = 0;
}
else
{
m_vecLastSight = vecMidEnemy;
}
UTIL_MakeAimVectors( m_vecCurAngles );
7 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
7 years ago
fAttack = FALSE;
else
fAttack = TRUE;
// fire the gun
8 years ago
if( m_iSpin && ( ( fAttack ) || ( m_fBeserk ) ) )
7 years ago
{
Vector vecSrc, vecAng;
GetAttachment( 0, vecSrc, vecAng );
8 years ago
SetTurretAnim( TURRET_ANIM_FIRE );
Shoot( vecSrc, gpGlobals->v_forward );
7 years ago
}
else
{
8 years ago
SetTurretAnim( TURRET_ANIM_SPIN );
7 years ago
}
//move the gun
8 years ago
if( m_fBeserk )
7 years ago
{
8 years ago
if( RANDOM_LONG( 0, 9 ) == 0 )
7 years ago
{
8 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
7 years ago
return;
}
}
8 years ago
else if( fEnemyVisible )
7 years ago
{
8 years ago
if( vec.y > 360 )
7 years ago
vec.y -= 360;
8 years ago
if( vec.y < 0 )
7 years ago
vec.y += 360;
8 years ago
//ALERT( at_console, "[%.2f]", vec.x );
8 years ago
if( vec.x < -180 )
7 years ago
vec.x += 360;
8 years ago
if( vec.x > 180 )
7 years ago
vec.x -= 360;
// now all numbers should be in [1...360]
// pin to turret limitations to [-90...15]
8 years ago
if( m_iOrientation == 0 )
7 years ago
{
8 years ago
if( vec.x > 90 )
7 years ago
vec.x = 90;
8 years ago
else if( vec.x < m_iMinPitch )
7 years ago
vec.x = m_iMinPitch;
}
else
{
8 years ago
if( vec.x < -90 )
7 years ago
vec.x = -90;
8 years ago
else if( vec.x > -m_iMinPitch )
7 years ago
vec.x = -m_iMinPitch;
}
8 years ago
// ALERT( at_console, "->[%.2f]\n", vec.x );
7 years ago
m_vecGoalAngles.y = vec.y;
m_vecGoalAngles.x = vec.x;
}
SpinUpCall();
MoveTurret();
}
8 years ago
void CTurret::Shoot( Vector &vecSrc, Vector &vecDirToEnemy )
7 years ago
{
FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_12MM, 1 );
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "turret/tu_fire1.wav", 1, 0.6 );
7 years ago
pev->effects = pev->effects | EF_MUZZLEFLASH;
}
8 years ago
void CMiniTurret::Shoot( Vector &vecSrc, Vector &vecDirToEnemy )
7 years ago
{
FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_9MM, 1 );
8 years ago
switch( RANDOM_LONG( 0, 2 ) )
7 years ago
{
8 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;
7 years ago
}
pev->effects = pev->effects | EF_MUZZLEFLASH;
}
8 years ago
void CBaseTurret::Deploy( void )
7 years ago
{
SetNextThink( 0.1f );
8 years ago
StudioFrameAdvance();
7 years ago
8 years ago
if( pev->sequence != TURRET_ANIM_DEPLOY )
7 years ago
{
m_iOn = 1;
8 years ago
SetTurretAnim( TURRET_ANIM_DEPLOY );
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_deploy.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
7 years ago
SUB_UseTargets( this, USE_ON, 0 );
}
8 years ago
if( m_fSequenceFinished )
7 years ago
{
pev->maxs.z = m_iDeployHeight;
pev->mins.z = -m_iDeployHeight;
8 years ago
UTIL_SetSize( pev, pev->mins, pev->maxs );
7 years ago
m_vecCurAngles.x = 0;
8 years ago
if( m_iOrientation == 1 )
7 years ago
{
m_vecCurAngles.y = UTIL_AngleMod( pev->angles.y + 180 );
}
else
{
m_vecCurAngles.y = UTIL_AngleMod( pev->angles.y );
}
8 years ago
SetTurretAnim( TURRET_ANIM_SPIN );
7 years ago
pev->framerate = 0;
8 years ago
SetThink( &CBaseTurret::SearchThink );
7 years ago
}
m_flLastSight = gpGlobals->time + m_flMaxWait;
}
8 years ago
void CBaseTurret::Retire( void )
7 years ago
{
// make the turret level
m_vecGoalAngles.x = 0;
m_vecGoalAngles.y = m_flStartYaw;
SetNextThink( 0.1f );
7 years ago
8 years ago
StudioFrameAdvance();
7 years ago
8 years ago
EyeOff();
7 years ago
8 years ago
if( !MoveTurret() )
7 years ago
{
8 years ago
if( m_iSpin )
7 years ago
{
SpinDownCall();
}
8 years ago
else if( pev->sequence != TURRET_ANIM_RETIRE )
7 years ago
{
8 years ago
SetTurretAnim( TURRET_ANIM_RETIRE );
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "turret/tu_deploy.wav", TURRET_MACHINE_VOLUME, ATTN_NORM, 0, 120 );
7 years ago
SUB_UseTargets( this, USE_OFF, 0 );
}
8 years ago
else if( m_fSequenceFinished )
{
7 years ago
m_iOn = 0;
m_flLastSight = 0;
8 years ago
SetTurretAnim( TURRET_ANIM_NONE );
7 years ago
pev->maxs.z = m_iRetractHeight;
pev->mins.z = -m_iRetractHeight;
8 years ago
UTIL_SetSize( pev, pev->mins, pev->maxs );
if( m_iAutoStart )
7 years ago
{
8 years ago
SetThink( &CBaseTurret::AutoSearchThink );
SetNextThink( 0.1f );
7 years ago
}
else
SetThink(&CBaseTurret::SUB_DoNothing);
}
}
else
{
8 years ago
SetTurretAnim( TURRET_ANIM_SPIN );
7 years ago
}
}
8 years ago
void CTurret::SpinUpCall( void )
7 years ago
{
8 years ago
StudioFrameAdvance();
SetNextThink( 0.1f );
7 years ago
// Are we already spun up? If not start the two stage process.
8 years ago
if( !m_iSpin )
7 years ago
{
SetTurretAnim( TURRET_ANIM_SPIN );
7 years ago
// for the first pass, spin up the the barrel
8 years ago
if( !m_iStartSpin )
7 years ago
{
SetNextThink( 1.0f ); // spinup delay
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_spinup.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
7 years ago
m_iStartSpin = 1;
pev->framerate = 0.1f;
7 years ago
}
// after the barrel is spun up, turn on the hum
else if( pev->framerate >= 1.0f )
7 years ago
{
SetNextThink( 0.1f ); // retarget delay
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_STATIC, "turret/tu_active2.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
7 years ago
SetThink(&CTurret::ActiveThink);
m_iStartSpin = 0;
m_iSpin = 1;
}
else
{
pev->framerate += 0.075f;
7 years ago
}
}
8 years ago
if( m_iSpin )
7 years ago
{
SetThink(&CTurret::ActiveThink);
}
}
8 years ago
void CTurret::SpinDownCall( void )
7 years ago
{
8 years ago
if( m_iSpin )
7 years ago
{
SetTurretAnim( TURRET_ANIM_SPIN );
if( pev->framerate == 1.0f )
7 years ago
{
8 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 );
7 years ago
}
pev->framerate -= 0.02f;
8 years ago
if( pev->framerate <= 0 )
7 years ago
{
pev->framerate = 0;
m_iSpin = 0;
}
}
}
8 years ago
void CBaseTurret::SetTurretAnim( TURRET_ANIM anim )
7 years ago
{
8 years ago
if( pev->sequence != anim )
7 years ago
{
8 years ago
switch( anim )
7 years ago
{
case TURRET_ANIM_FIRE:
case TURRET_ANIM_SPIN:
8 years ago
if( pev->sequence != TURRET_ANIM_FIRE && pev->sequence != TURRET_ANIM_SPIN )
7 years ago
{
pev->frame = 0;
}
break;
default:
pev->frame = 0;
break;
}
pev->sequence = anim;
8 years ago
ResetSequenceInfo();
7 years ago
8 years ago
switch( anim )
7 years ago
{
case TURRET_ANIM_RETIRE:
8 years ago
pev->frame = 255;
pev->framerate = -1.0;
7 years ago
break;
case TURRET_ANIM_DIE:
8 years ago
pev->framerate = 1.0;
7 years ago
break;
default:
break;
}
8 years ago
//ALERT( at_console, "Turret anim #%d\n", anim );
7 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.
//
8 years ago
void CBaseTurret::SearchThink( void )
7 years ago
{
// ensure rethink
8 years ago
SetTurretAnim( TURRET_ANIM_SPIN );
StudioFrameAdvance();
SetNextThink( 0.1f );
7 years ago
8 years ago
if( m_flSpinUpTime == 0 && m_flMaxSpin )
7 years ago
m_flSpinUpTime = gpGlobals->time + m_flMaxSpin;
8 years ago
Ping();
7 years ago
// If we have a target and we're still healthy
if( m_hEnemy != 0 )
7 years ago
{
8 years ago
if( !m_hEnemy->IsAlive() )
7 years ago
m_hEnemy = NULL;// Dead enemy forces a search for new one
}
// Acquire Target
if( m_hEnemy == 0 )
7 years ago
{
8 years ago
Look( TURRET_RANGE );
7 years ago
m_hEnemy = BestVisibleEnemy();
}
// If we've found a target, spin up the barrel and start to attack
if( m_hEnemy != 0 )
7 years ago
{
m_flLastSight = 0;
m_flSpinUpTime = 0;
8 years ago
SetThink( &CBaseTurret::ActiveThink );
7 years ago
}
else
{
// Are we out of time, do we need to retract?
8 years ago
if( gpGlobals->time > m_flLastSight )
7 years ago
{
//Before we retrace, make sure that we are spun down.
m_flLastSight = 0;
m_flSpinUpTime = 0;
8 years ago
SetThink( &CBaseTurret::Retire );
7 years ago
}
// should we stop the spin?
8 years ago
else if( ( m_flSpinUpTime ) && ( gpGlobals->time > m_flSpinUpTime ) )
7 years ago
{
SpinDownCall();
}
// generic hunt for new victims
m_vecGoalAngles.y = ( m_vecGoalAngles.y + 0.1f * m_fTurnRate );
8 years ago
if( m_vecGoalAngles.y >= 360 )
7 years ago
m_vecGoalAngles.y -= 360;
MoveTurret();
}
}
//
7 years ago
// This think function will deploy the turret when something comes into range. This is for
// automatically activated turrets.
//
8 years ago
void CBaseTurret::AutoSearchThink( void )
7 years ago
{
// ensure rethink
8 years ago
StudioFrameAdvance();
SetNextThink( 0.3f );
7 years ago
// If we have a target and we're still healthy
if( m_hEnemy != 0 )
7 years ago
{
8 years ago
if( !m_hEnemy->IsAlive() )
7 years ago
m_hEnemy = NULL;// Dead enemy forces a search for new one
}
// Acquire Target
if( m_hEnemy == 0 )
7 years ago
{
Look( TURRET_RANGE );
m_hEnemy = BestVisibleEnemy();
}
if( m_hEnemy != 0 )
7 years ago
{
8 years ago
SetThink( &CBaseTurret::Deploy );
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_alert.wav", TURRET_MACHINE_VOLUME, ATTN_NORM );
7 years ago
}
}
8 years ago
void CBaseTurret::TurretDeath( void )
7 years ago
{
//BOOL iActive = FALSE;
7 years ago
8 years ago
StudioFrameAdvance();
7 years ago
SetNextThink( 0.1 );
8 years ago
if( pev->deadflag != DEAD_DEAD )
7 years ago
{
pev->deadflag = DEAD_DEAD;
8 years ago
float flRndSound = RANDOM_FLOAT( 0, 1 );
7 years ago
if( flRndSound <= 0.33f )
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die.wav", 1.0, ATTN_NORM );
else if( flRndSound <= 0.66f )
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die2.wav", 1.0, ATTN_NORM );
7 years ago
else
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die3.wav", 1.0, ATTN_NORM );
7 years ago
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "turret/tu_active2.wav", 0, 0, SND_STOP, 100 );
7 years ago
8 years ago
if( m_iOrientation == 0 )
7 years ago
m_vecGoalAngles.x = -15;
else
m_vecGoalAngles.x = -90;
8 years ago
SetTurretAnim( TURRET_ANIM_DIE );
7 years ago
8 years ago
EyeOn();
7 years ago
}
8 years ago
EyeOff();
7 years ago
8 years ago
if( pev->dmgtime + RANDOM_FLOAT( 0, 2 ) > gpGlobals->time )
7 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
8 years ago
WRITE_BYTE( 10 - m_iOrientation * 5 ); // framerate
7 years ago
MESSAGE_END();
}
8 years ago
if( pev->dmgtime + RANDOM_FLOAT( 0, 5 ) > gpGlobals->time )
7 years ago
{
Vector vecSrc = Vector( RANDOM_FLOAT( pev->absmin.x, pev->absmax.x ), RANDOM_FLOAT( pev->absmin.y, pev->absmax.y ), 0 );
8 years ago
if( m_iOrientation == 0 )
7 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 );
}
8 years ago
if( m_fSequenceFinished && !MoveTurret() && pev->dmgtime + 5 < gpGlobals->time )
7 years ago
{
pev->framerate = 0;
SetThink( NULL );
}
}
8 years ago
void CBaseTurret::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
7 years ago
{
8 years ago
if( ptr->iHitgroup == 10 )
7 years ago
{
// hit armor
8 years ago
if( pev->dmgtime != gpGlobals->time || (RANDOM_LONG( 0, 10 ) < 1 ) )
7 years ago
{
8 years ago
UTIL_Ricochet( ptr->vecEndPos, RANDOM_FLOAT( 1, 2 ) );
7 years ago
pev->dmgtime = gpGlobals->time;
}
flDamage = 0.1;// don't hurt the monster much, but allow bits_COND_LIGHT_DAMAGE to be generated
}
8 years ago
if( !pev->takedamage )
7 years ago
return;
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
}
// take damage. bitsDamageType indicates type of damage sustained, ie: DMG_BULLET
8 years ago
int CBaseTurret::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
7 years ago
{
8 years ago
if( !pev->takedamage )
7 years ago
return 0;
8 years ago
if( !m_iOn )
flDamage *= 0.1f;
7 years ago
pev->health -= flDamage;
8 years ago
if( pev->health <= 0 )
7 years ago
{
pev->health = 0;
pev->takedamage = DAMAGE_NO;
pev->dmgtime = gpGlobals->time;
8 years ago
ClearBits( pev->flags, FL_MONSTER ); // why are they set in the first place???
7 years ago
9 years ago
SetUse( NULL );
8 years ago
SetThink( &CBaseTurret::TurretDeath );
7 years ago
SUB_UseTargets( this, USE_ON, 0 ); // wake up others
SetNextThink( 0.1 );
return 0;
}
8 years ago
if( pev->health <= 10 )
7 years ago
{
8 years ago
if( m_iOn && ( 1 || RANDOM_LONG( 0, 0x7FFF ) > 800 ) )
7 years ago
{
m_fBeserk = 1;
8 years ago
SetThink( &CBaseTurret::SearchThink );
7 years ago
}
}
return 1;
}
8 years ago
int CBaseTurret::MoveTurret( void )
7 years ago
{
int state = 0;
// any x movement?
8 years ago
if( m_vecCurAngles.x != m_vecGoalAngles.x )
7 years ago
{
float flDir = m_vecGoalAngles.x > m_vecCurAngles.x ? 1 : -1 ;
m_vecCurAngles.x += 0.1f * m_fTurnRate * flDir;
7 years ago
// if we started below the goal, and now we're past, peg to goal
8 years ago
if( flDir == 1 )
7 years ago
{
8 years ago
if( m_vecCurAngles.x > m_vecGoalAngles.x )
7 years ago
m_vecCurAngles.x = m_vecGoalAngles.x;
}
else
{
8 years ago
if( m_vecCurAngles.x < m_vecGoalAngles.x )
7 years ago
m_vecCurAngles.x = m_vecGoalAngles.x;
}
8 years ago
if( m_iOrientation == 0 )
SetBoneController( 1, -m_vecCurAngles.x );
7 years ago
else
8 years ago
SetBoneController( 1, m_vecCurAngles.x );
7 years ago
state = 1;
}
8 years ago
if( m_vecCurAngles.y != m_vecGoalAngles.y )
7 years ago
{
float flDir = m_vecGoalAngles.y > m_vecCurAngles.y ? 1 : -1 ;
8 years ago
float flDist = fabs( m_vecGoalAngles.y - m_vecCurAngles.y );
if( flDist > 180 )
7 years ago
{
flDist = 360 - flDist;
flDir = -flDir;
}
8 years ago
if( flDist > 30 )
7 years ago
{
8 years ago
if( m_fTurnRate < m_iBaseTurnRate * 10 )
7 years ago
{
m_fTurnRate += m_iBaseTurnRate;
}
}
8 years ago
else if( m_fTurnRate > 45 )
7 years ago
{
m_fTurnRate -= m_iBaseTurnRate;
}
else
{
m_fTurnRate += m_iBaseTurnRate;
}
m_vecCurAngles.y += 0.1f * m_fTurnRate * flDir;
7 years ago
8 years ago
if( m_vecCurAngles.y < 0 )
7 years ago
m_vecCurAngles.y += 360;
8 years ago
else if( m_vecCurAngles.y >= 360 )
7 years ago
m_vecCurAngles.y -= 360;
if( flDist < ( 0.05f * m_iBaseTurnRate ) )
7 years ago
m_vecCurAngles.y = m_vecGoalAngles.y;
8 years ago
//ALERT( at_console, "%.2f -> %.2f\n", m_vecCurAngles.y, y );
if( m_iOrientation == 0 )
SetBoneController( 0, m_vecCurAngles.y - pev->angles.y );
7 years ago
else
8 years ago
SetBoneController( 0, pev->angles.y - 180 - m_vecCurAngles.y );
7 years ago
state = 1;
}
8 years ago
if( !state )
7 years ago
m_fTurnRate = m_iBaseTurnRate;
8 years ago
//ALERT( at_console, "(%.2f, %.2f)->(%.2f, %.2f)\n", m_vecCurAngles.x,
// m_vecCurAngles.y, m_vecGoalAngles.x, m_vecGoalAngles.y );
7 years ago
return state;
}
//
// ID as a machine
//
8 years ago
int CBaseTurret::Classify( void )
7 years ago
{
if (m_iClass) return m_iClass;
8 years ago
if( m_iOn || m_iAutoStart )
7 years ago
return CLASS_MACHINE;
return CLASS_NONE;
}
//=========================================================
// Sentry gun - smallest turret, placed near grunt entrenchments
//=========================================================
class CSentry : public CBaseTurret
{
public:
8 years ago
void Spawn();
void Precache( void );
7 years ago
// other functions
8 years ago
void Shoot( Vector &vecSrc, Vector &vecDirToEnemy );
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
7 years ago
void EXPORT SentryTouch( CBaseEntity *pOther );
void EXPORT SentryDeath( void );
};
LINK_ENTITY_TO_CLASS( monster_sentry, CSentry )
7 years ago
void CSentry::Precache()
{
8 years ago
CBaseTurret::Precache();
7 years ago
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/sentry.mdl" );
7 years ago
}
void CSentry::Spawn()
{
8 years ago
Precache();
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/sentry.mdl" );
7 years ago
if (!pev->health) //LRC
pev->health = gSkillData.sentryHealth;
8 years ago
m_HackedGunPos = Vector( 0, 0, 48 );
pev->view_ofs.z = 48;
// m_flMaxWait = 1E6;
if( m_flMaxWait == 0 )
m_flMaxWait = TURRET_MAXWAIT;//G-Cont. now sentry can deployed
8 years ago
m_flMaxSpin = 1E6;
7 years ago
CBaseTurret::Spawn();
m_iRetractHeight = 64;
m_iDeployHeight = 64;
8 years ago
m_iMinPitch = -60;
UTIL_SetSize( pev, Vector( -16, -16, -m_iRetractHeight ), Vector( 16, 16, m_iRetractHeight ) );
7 years ago
8 years ago
SetTouch( &CSentry::SentryTouch );
SetThink( &CSentry::Initialize );
SetNextThink( 0.3f );
7 years ago
}
8 years ago
void CSentry::Shoot( Vector &vecSrc, Vector &vecDirToEnemy )
7 years ago
{
FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_MP5, 1 );
8 years ago
switch( RANDOM_LONG( 0, 2 ) )
7 years ago
{
8 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;
7 years ago
}
pev->effects = pev->effects | EF_MUZZLEFLASH;
}
8 years ago
int CSentry::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
7 years ago
{
8 years ago
if( !pev->takedamage )
7 years ago
return 0;
8 years ago
if( !m_iOn )
7 years ago
{
SetThink(&CSentry:: Deploy );
SetUse( NULL );
SetNextThink( 0.1f );
7 years ago
}
pev->health -= flDamage;
8 years ago
if( pev->health <= 0 )
7 years ago
{
pev->health = 0;
pev->takedamage = DAMAGE_NO;
pev->dmgtime = gpGlobals->time;
8 years ago
ClearBits( pev->flags, FL_MONSTER ); // why are they set in the first place???
7 years ago
9 years ago
SetUse( NULL );
8 years ago
SetThink( &CSentry::SentryDeath );
7 years ago
SUB_UseTargets( this, USE_ON, 0 ); // wake up others
SetNextThink( 0.1f );
7 years ago
return 0;
}
return 1;
}
void CSentry::SentryTouch( CBaseEntity *pOther )
{
8 years ago
if( pOther && ( pOther->IsPlayer() || ( pOther->pev->flags & FL_MONSTER ) ) )
7 years ago
{
8 years ago
TakeDamage( pOther->pev, pOther->pev, 0, 0 );
7 years ago
}
}
8 years ago
void CSentry::SentryDeath( void )
7 years ago
{
//BOOL iActive = FALSE;
7 years ago
8 years ago
StudioFrameAdvance();
SetNextThink( 0.1f );
7 years ago
8 years ago
if( pev->deadflag != DEAD_DEAD )
7 years ago
{
pev->deadflag = DEAD_DEAD;
8 years ago
float flRndSound = RANDOM_FLOAT( 0, 1 );
7 years ago
if( flRndSound <= 0.33f )
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die.wav", 1.0, ATTN_NORM );
else if( flRndSound <= 0.66f )
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die2.wav", 1.0, ATTN_NORM );
7 years ago
else
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "turret/tu_die3.wav", 1.0, ATTN_NORM );
7 years ago
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_STATIC, "turret/tu_active2.wav", 0, 0, SND_STOP, 100 );
7 years ago
SetBoneController( 0, 0 );
SetBoneController( 1, 0 );
8 years ago
SetTurretAnim( TURRET_ANIM_DIE );
7 years ago
pev->solid = SOLID_NOT;
pev->angles.y = UTIL_AngleMod( pev->angles.y + RANDOM_LONG( 0, 2 ) * 120 );
8 years ago
EyeOn();
7 years ago
}
8 years ago
EyeOff();
7 years ago
Vector vecSrc, vecAng;
GetAttachment( 1, vecSrc, vecAng );
8 years ago
if( pev->dmgtime + RANDOM_FLOAT( 0, 2 ) > gpGlobals->time )
7 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();
}
8 years ago
if( pev->dmgtime + RANDOM_FLOAT( 0, 8 ) > gpGlobals->time )
7 years ago
{
UTIL_Sparks( vecSrc );
}
8 years ago
if( m_fSequenceFinished && pev->dmgtime + 5 < gpGlobals->time )
7 years ago
{
pev->framerate = 0;
SetThink( NULL );
}
}