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