Team Fortress 2 Source Code as on 22/4/2020
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.

1341 lines
31 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TF_TURRET_H
  7. #define TF_TURRET_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "ehandle.h"
  12. #include "tf_shareddefs.h"
  13. #if 0
  14. extern Vector VecBModelOrigin( entvars_t* pevBModel );
  15. #define TURRET_SHOTS 2
  16. #define TURRET_RANGE (100 * 12)
  17. #define TURRET_SPREAD Vector( 0, 0, 0 )
  18. #define TURRET_TURNRATE 30 //angles per 0.1 second
  19. #define TURRET_MAXWAIT 15 // seconds turret will stay active w/o a target
  20. #define TURRET_MAXSPIN 5 // seconds turret barrel will spin w/o a target
  21. #define TURRET_MACHINE_VOLUME 0.5
  22. typedef enum
  23. {
  24. TURRET_ANIM_NONE = 0,
  25. TURRET_ANIM_FIRE,
  26. TURRET_ANIM_SPIN,
  27. TURRET_ANIM_DEPLOY,
  28. TURRET_ANIM_RETIRE,
  29. TURRET_ANIM_DIE,
  30. } TURRET_ANIM;
  31. class CBaseTurret : public CBaseMonster
  32. {
  33. public:
  34. void Spawn(void);
  35. virtual void Precache(void);
  36. void KeyValue( KeyValueData *pkvd );
  37. void EXPORT TurretUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  38. virtual void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType);
  39. virtual int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
  40. virtual int Classify(void);
  41. int BloodColor( void ) { return DONT_BLEED; }
  42. void GibMonster( void ) {} // UNDONE: Throw turret gibs?
  43. // Think functions
  44. void EXPORT ActiveThink(void);
  45. void EXPORT SearchThink(void);
  46. void EXPORT AutoSearchThink(void);
  47. void EXPORT TurretDeath(void);
  48. virtual void EXPORT SpinDownCall(void) { m_iSpin = 0; }
  49. virtual void EXPORT SpinUpCall(void) { m_iSpin = 1; }
  50. // void SpinDown(void);
  51. // float EXPORT SpinDownCall( void ) { return SpinDown(); }
  52. // virtual float SpinDown(void) { return 0;}
  53. // virtual float Retire(void) { return 0;}
  54. void EXPORT Deploy(void);
  55. void EXPORT Retire(void);
  56. void EXPORT Initialize(void);
  57. virtual void Ping(void);
  58. virtual void EyeOn(void);
  59. virtual void EyeOff(void);
  60. virtual int Save( CSave &save );
  61. virtual int Restore( CRestore &restore );
  62. static TYPEDESCRIPTION m_SaveData[];
  63. // other functions
  64. void SetTurretAnim(TURRET_ANIM anim);
  65. int MoveTurret(void);
  66. virtual void Shoot(Vector &vecSrc, Vector &vecDirToEnemy) { };
  67. float m_flMaxSpin; // Max time to spin the barrel w/o a target
  68. int m_iSpin;
  69. CSprite *m_pEyeGlow;
  70. int m_eyeBrightness;
  71. int m_iDeployHeight;
  72. int m_iRetractHeight;
  73. int m_iMinPitch;
  74. int m_iBaseTurnRate; // angles per second
  75. float m_fTurnRate; // actual turn rate
  76. int m_iOrientation; // 0 = floor, 1 = Ceiling
  77. int m_iOn;
  78. int m_fBeserk; // Sometimes this bitch will just freak out
  79. int m_iAutoStart; // true if the turret auto deploys when a target
  80. // enters its range
  81. Vector m_vecLastSight;
  82. float m_flLastSight; // Last time we saw a target
  83. float m_flMaxWait; // Max time to seach w/o a target
  84. int m_iSearchSpeed; // Not Used!
  85. // movement
  86. float m_flStartYaw;
  87. Vector m_vecCurAngles;
  88. Vector m_vecGoalAngles;
  89. float m_flPingTime; // Time until the next ping, used when searching
  90. float m_flSpinUpTime; // Amount of time until the barrel should spin down when searching
  91. };
  92. TYPEDESCRIPTION CBaseTurret::m_SaveData[] =
  93. {
  94. DEFINE_FIELD( CBaseTurret, m_flMaxSpin, FIELD_FLOAT ),
  95. DEFINE_FIELD( CBaseTurret, m_iSpin, FIELD_INTEGER ),
  96. DEFINE_FIELD( CBaseTurret, m_pEyeGlow, FIELD_CLASSPTR ),
  97. DEFINE_FIELD( CBaseTurret, m_eyeBrightness, FIELD_INTEGER ),
  98. DEFINE_FIELD( CBaseTurret, m_iDeployHeight, FIELD_INTEGER ),
  99. DEFINE_FIELD( CBaseTurret, m_iRetractHeight, FIELD_INTEGER ),
  100. DEFINE_FIELD( CBaseTurret, m_iMinPitch, FIELD_INTEGER ),
  101. DEFINE_FIELD( CBaseTurret, m_iBaseTurnRate, FIELD_INTEGER ),
  102. DEFINE_FIELD( CBaseTurret, m_fTurnRate, FIELD_FLOAT ),
  103. DEFINE_FIELD( CBaseTurret, m_iOrientation, FIELD_INTEGER ),
  104. DEFINE_FIELD( CBaseTurret, m_iOn, FIELD_INTEGER ),
  105. DEFINE_FIELD( CBaseTurret, m_fBeserk, FIELD_INTEGER ),
  106. DEFINE_FIELD( CBaseTurret, m_iAutoStart, FIELD_INTEGER ),
  107. DEFINE_FIELD( CBaseTurret, m_vecLastSight, FIELD_POSITION_VECTOR ),
  108. DEFINE_FIELD( CBaseTurret, m_flLastSight, FIELD_TIME ),
  109. DEFINE_FIELD( CBaseTurret, m_flMaxWait, FIELD_FLOAT ),
  110. DEFINE_FIELD( CBaseTurret, m_iSearchSpeed, FIELD_INTEGER ),
  111. DEFINE_FIELD( CBaseTurret, m_flStartYaw, FIELD_FLOAT ),
  112. DEFINE_FIELD( CBaseTurret, m_vecCurAngles, FIELD_VECTOR ),
  113. DEFINE_FIELD( CBaseTurret, m_vecGoalAngles, FIELD_VECTOR ),
  114. DEFINE_FIELD( CBaseTurret, m_flPingTime, FIELD_TIME ),
  115. DEFINE_FIELD( CBaseTurret, m_flSpinUpTime, FIELD_TIME ),
  116. };
  117. IMPLEMENT_SAVERESTORE( CBaseTurret, CBaseMonster );
  118. class CTurret : public CBaseTurret
  119. {
  120. public:
  121. void Spawn(void);
  122. void Precache(void);
  123. // Think functions
  124. void SpinUpCall(void);
  125. void SpinDownCall(void);
  126. virtual int Save( CSave &save );
  127. virtual int Restore( CRestore &restore );
  128. static TYPEDESCRIPTION m_SaveData[];
  129. // other functions
  130. void Shoot(Vector &vecSrc, Vector &vecDirToEnemy);
  131. private:
  132. int m_iStartSpin;
  133. };
  134. TYPEDESCRIPTION CTurret::m_SaveData[] =
  135. {
  136. DEFINE_FIELD( CTurret, m_iStartSpin, FIELD_INTEGER ),
  137. };
  138. IMPLEMENT_SAVERESTORE( CTurret, CBaseTurret );
  139. class CMiniTurret : public CBaseTurret
  140. {
  141. public:
  142. void Spawn( );
  143. void Precache(void);
  144. // other functions
  145. void Shoot(Vector &vecSrc, Vector &vecDirToEnemy);
  146. };
  147. LINK_ENTITY_TO_CLASS( monster_turret, CTurret );
  148. LINK_ENTITY_TO_CLASS( monster_miniturret, CMiniTurret );
  149. void CBaseTurret::KeyValue( KeyValueData *pkvd )
  150. {
  151. if (FStrEq(pkvd->szKeyName, "maxsleep"))
  152. {
  153. m_flMaxWait = atof(pkvd->szValue);
  154. pkvd->fHandled = TRUE;
  155. }
  156. else if (FStrEq(pkvd->szKeyName, "orientation"))
  157. {
  158. m_iOrientation = atoi(pkvd->szValue);
  159. pkvd->fHandled = TRUE;
  160. }
  161. else if (FStrEq(pkvd->szKeyName, "searchspeed"))
  162. {
  163. m_iSearchSpeed = atoi(pkvd->szValue);
  164. pkvd->fHandled = TRUE;
  165. }
  166. else if (FStrEq(pkvd->szKeyName, "turnrate"))
  167. {
  168. m_iBaseTurnRate = atoi(pkvd->szValue);
  169. pkvd->fHandled = TRUE;
  170. }
  171. else if (FStrEq(pkvd->szKeyName, "style") ||
  172. FStrEq(pkvd->szKeyName, "height") ||
  173. FStrEq(pkvd->szKeyName, "value1") ||
  174. FStrEq(pkvd->szKeyName, "value2") ||
  175. FStrEq(pkvd->szKeyName, "value3"))
  176. pkvd->fHandled = TRUE;
  177. else
  178. CBaseMonster::KeyValue( pkvd );
  179. }
  180. void CBaseTurret::Spawn()
  181. {
  182. Precache( );
  183. pev->nextthink = gpGlobals->time + 1;
  184. pev->movetype = MOVETYPE_FLY;
  185. pev->sequence = 0;
  186. pev->frame = 0;
  187. pev->solid = SOLID_SLIDEBOX;
  188. // Make turrets invulnerable in multiplayer
  189. if (gpGlobals->deathmatch)
  190. pev->takedamage = DAMAGE_NO;
  191. else
  192. pev->takedamage = DAMAGE_AIM;
  193. SetBits (pev->flags, FL_MONSTER);
  194. SetUse( &CBaseTurret::TurretUse );
  195. // Start turrets automatically in multiplayer
  196. if (gpGlobals->deathmatch)
  197. m_iAutoStart = TRUE;
  198. if (( pev->spawnflags & SF_MONSTER_TURRET_AUTOACTIVATE )
  199. && !( pev->spawnflags & SF_MONSTER_TURRET_STARTINACTIVE ))
  200. {
  201. m_iAutoStart = TRUE;
  202. }
  203. ResetSequenceInfo( );
  204. SetBoneController( 0, 0 );
  205. SetBoneController( 1, 0 );
  206. m_flFieldOfView = VIEW_FIELD_FULL;
  207. // m_flSightRange = TURRET_RANGE;
  208. }
  209. void CBaseTurret::Precache( )
  210. {
  211. PRECACHE_SOUND ("turret/tu_fire1.wav");
  212. PRECACHE_SOUND ("turret/tu_ping.wav");
  213. PRECACHE_SOUND ("turret/tu_active2.wav");
  214. PRECACHE_SOUND ("turret/tu_die.wav");
  215. PRECACHE_SOUND ("turret/tu_die2.wav");
  216. PRECACHE_SOUND ("turret/tu_die3.wav");
  217. // PRECACHE_SOUND ("turret/tu_retract.wav"); // just use deploy sound to save memory
  218. PRECACHE_SOUND ("turret/tu_deploy.wav");
  219. PRECACHE_SOUND ("turret/tu_spinup.wav");
  220. PRECACHE_SOUND ("turret/tu_spindown.wav");
  221. PRECACHE_SOUND ("turret/tu_search.wav");
  222. PRECACHE_SOUND ("turret/tu_alert.wav");
  223. }
  224. #define TURRET_GLOW_SPRITE "sprites/flare3.spr"
  225. void CTurret::Spawn()
  226. {
  227. Precache( );
  228. SET_MODEL(ENT(pev), "models/turret.mdl");
  229. pev->health = gSkillData.turretHealth;
  230. m_HackedGunPos = Vector( 0, 0, 12.75 );
  231. m_flMaxSpin = TURRET_MAXSPIN;
  232. pev->view_ofs.z = 12.75;
  233. CBaseTurret::Spawn( );
  234. m_iRetractHeight = 16;
  235. m_iDeployHeight = 32;
  236. m_iMinPitch = -15;
  237. UTIL_SetSize(pev, Vector(-32, -32, -m_iRetractHeight), Vector(32, 32, m_iRetractHeight));
  238. SetThink(&CTurret::Initialize);
  239. m_pEyeGlow = CSprite::SpriteCreate( TURRET_GLOW_SPRITE, pev->origin, FALSE );
  240. m_pEyeGlow->SetTransparency( kRenderGlow, 255, 0, 0, 0, kRenderFxNoDissipation );
  241. m_pEyeGlow->SetAttachment( edict(), 2 );
  242. m_eyeBrightness = 0;
  243. pev->nextthink = gpGlobals->time + 0.3;
  244. }
  245. void CTurret::Precache()
  246. {
  247. CBaseTurret::Precache( );
  248. PRECACHE_MODEL ("models/turret.mdl");
  249. PRECACHE_MODEL (TURRET_GLOW_SPRITE);
  250. }
  251. void CMiniTurret::Spawn()
  252. {
  253. Precache( );
  254. SET_MODEL(ENT(pev), "models/miniturret.mdl");
  255. pev->health = gSkillData.miniturretHealth;
  256. m_HackedGunPos = Vector( 0, 0, 12.75 );
  257. m_flMaxSpin = 0;
  258. pev->view_ofs.z = 12.75;
  259. CBaseTurret::Spawn( );
  260. m_iRetractHeight = 16;
  261. m_iDeployHeight = 32;
  262. m_iMinPitch = -15;
  263. UTIL_SetSize(pev, Vector(-16, -16, -m_iRetractHeight), Vector(16, 16, m_iRetractHeight));
  264. SetThink(&CMiniTurret::Initialize);
  265. pev->nextthink = gpGlobals->time + 0.3;
  266. }
  267. void CMiniTurret::Precache()
  268. {
  269. CBaseTurret::Precache( );
  270. PRECACHE_MODEL ("models/miniturret.mdl");
  271. PRECACHE_SOUND("weapons/hks1.wav");
  272. PRECACHE_SOUND("weapons/hks2.wav");
  273. PRECACHE_SOUND("weapons/hks3.wav");
  274. }
  275. void CBaseTurret::Initialize(void)
  276. {
  277. m_iOn = 0;
  278. m_fBeserk = 0;
  279. m_iSpin = 0;
  280. SetBoneController( 0, 0 );
  281. SetBoneController( 1, 0 );
  282. if (m_iBaseTurnRate == 0)
  283. {
  284. // Make turrets turn faster in multiplayer
  285. if (gpGlobals->deathmatch)
  286. m_iBaseTurnRate = TURRET_TURNRATE * 2;
  287. else
  288. m_iBaseTurnRate = TURRET_TURNRATE;
  289. }
  290. if (m_flMaxWait == 0)
  291. {
  292. // Make turrets retarget faster
  293. //if (gpGlobals->deathmatch)
  294. //m_flMaxWait = 1;
  295. //else
  296. m_flMaxWait = TURRET_MAXWAIT;
  297. }
  298. m_flStartYaw = pev->angles.y;
  299. if (m_iOrientation == 1)
  300. {
  301. pev->idealpitch = 180;
  302. pev->angles.x = 180;
  303. pev->view_ofs.z = -pev->view_ofs.z;
  304. pev->effects |= EF_INVLIGHT;
  305. pev->angles.y = pev->angles.y + 180;
  306. if (pev->angles.y > 360)
  307. pev->angles.y = pev->angles.y - 360;
  308. }
  309. m_vecGoalAngles.x = 0;
  310. if (m_iAutoStart)
  311. {
  312. m_flLastSight = gpGlobals->time + m_flMaxWait;
  313. SetThink(&CBaseTurret::AutoSearchThink);
  314. pev->nextthink = gpGlobals->time + .1;
  315. }
  316. else
  317. SetThink(&CBaseTurret::SUB_DoNothing);
  318. }
  319. void CBaseTurret::TurretUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
  320. {
  321. if ( !ShouldToggle( useType, m_iOn ) )
  322. return;
  323. if (m_iOn)
  324. {
  325. m_hEnemy = NULL;
  326. pev->nextthink = gpGlobals->time + 0.1;
  327. m_iAutoStart = FALSE;// switching off a turret disables autostart
  328. //!!!! this should spin down first!!BUGBUG
  329. SetThink(&CBaseTurret::Retire);
  330. }
  331. else
  332. {
  333. pev->nextthink = gpGlobals->time + 0.1; // turn on delay
  334. // if the turret is flagged as an autoactivate turret, re-enable it's ability open self.
  335. if ( pev->spawnflags & SF_MONSTER_TURRET_AUTOACTIVATE )
  336. {
  337. m_iAutoStart = TRUE;
  338. }
  339. SetThink(&CBaseTurret::Deploy);
  340. }
  341. }
  342. void CBaseTurret::Ping( void )
  343. {
  344. // make the pinging noise every second while searching
  345. if (m_flPingTime == 0)
  346. m_flPingTime = gpGlobals->time + 1;
  347. else if (m_flPingTime <= gpGlobals->time)
  348. {
  349. m_flPingTime = gpGlobals->time + 1;
  350. EMIT_SOUND(ENT(pev), CHAN_ITEM, "turret/tu_ping.wav", 1, ATTN_NORM);
  351. EyeOn( );
  352. }
  353. else if (m_eyeBrightness > 0)
  354. {
  355. EyeOff( );
  356. }
  357. }
  358. void CBaseTurret::EyeOn( )
  359. {
  360. if (m_pEyeGlow)
  361. {
  362. if (m_eyeBrightness != 255)
  363. {
  364. m_eyeBrightness = 255;
  365. }
  366. m_pEyeGlow->SetBrightness( m_eyeBrightness );
  367. }
  368. }
  369. void CBaseTurret::EyeOff( )
  370. {
  371. if (m_pEyeGlow)
  372. {
  373. if (m_eyeBrightness > 0)
  374. {
  375. m_eyeBrightness = MAX( 0, m_eyeBrightness - 30 );
  376. m_pEyeGlow->SetBrightness( m_eyeBrightness );
  377. }
  378. }
  379. }
  380. void CBaseTurret::ActiveThink(void)
  381. {
  382. int fAttack = 0;
  383. Vector vecDirToEnemy;
  384. pev->nextthink = gpGlobals->time + 0.1;
  385. StudioFrameAdvance( );
  386. if ((!m_iOn) || (m_hEnemy == NULL))
  387. {
  388. m_hEnemy = NULL;
  389. m_flLastSight = gpGlobals->time + m_flMaxWait;
  390. SetThink(&CBaseTurret::SearchThink);
  391. return;
  392. }
  393. // if it's dead, look for something new
  394. if ( !m_hEnemy->IsAlive() )
  395. {
  396. if (!m_flLastSight)
  397. {
  398. m_flLastSight = gpGlobals->time + 0.5; // continue-shooting timeout
  399. }
  400. else
  401. {
  402. if (gpGlobals->time > m_flLastSight)
  403. {
  404. m_hEnemy = NULL;
  405. m_flLastSight = gpGlobals->time + m_flMaxWait;
  406. SetThink(&CBaseTurret::SearchThink);
  407. return;
  408. }
  409. }
  410. }
  411. Vector vecMid = pev->origin + pev->view_ofs;
  412. Vector vecMidEnemy = m_hEnemy->BodyTarget( vecMid );
  413. // Look for our current enemy
  414. int fEnemyVisible = FBoxVisible(pev, m_hEnemy->pev, vecMidEnemy );
  415. vecDirToEnemy = vecMidEnemy - vecMid; // calculate dir and dist to enemy
  416. float flDistToEnemy = vecDirToEnemy.Length();
  417. Vector vec = UTIL_VecToAngles(vecMidEnemy - vecMid);
  418. // Current enmey is not visible.
  419. if (!fEnemyVisible || (flDistToEnemy > TURRET_RANGE))
  420. {
  421. if (!m_flLastSight)
  422. {
  423. m_flLastSight = gpGlobals->time + 0.5;
  424. }
  425. else
  426. {
  427. // Should we look for a new target?
  428. if (gpGlobals->time > m_flLastSight)
  429. {
  430. m_hEnemy = NULL;
  431. m_flLastSight = gpGlobals->time + m_flMaxWait;
  432. SetThink(&CBaseTurret::SearchThink);
  433. return;
  434. }
  435. }
  436. fEnemyVisible = 0;
  437. }
  438. else
  439. {
  440. m_vecLastSight = vecMidEnemy;
  441. }
  442. UTIL_MakeAimVectors(m_vecCurAngles);
  443. /*
  444. ALERT( at_console, "%.0f %.0f : %.2f %.2f %.2f\n",
  445. m_vecCurAngles.x, m_vecCurAngles.y,
  446. gpGlobals->v_forward.x, gpGlobals->v_forward.y, gpGlobals->v_forward.z );
  447. */
  448. Vector vecLOS = vecDirToEnemy; //vecMid - m_vecLastSight;
  449. vecLOS = vecLOS.Normalize();
  450. // Is the Gun looking at the target
  451. if (DotProduct(vecLOS, gpGlobals->v_forward) <= 0.866) // 30 degree slop
  452. fAttack = FALSE;
  453. else
  454. fAttack = TRUE;
  455. // fire the gun
  456. if (m_iSpin && ((fAttack) || (m_fBeserk)))
  457. {
  458. Vector vecSrc, vecAng;
  459. GetAttachment( 0, vecSrc, vecAng );
  460. SetTurretAnim(TURRET_ANIM_FIRE);
  461. // In deathmatch, they just shoot right at you
  462. if (gpGlobals->deathmatch)
  463. {
  464. // Adjust for feigning spies
  465. vecAng = m_hEnemy->Center() - vecSrc;
  466. UTIL_MakeVectors(vecAng);
  467. Shoot(vecSrc, vecAng);
  468. }
  469. else
  470. {
  471. Shoot(vecSrc, gpGlobals->v_forward );
  472. }
  473. }
  474. else
  475. {
  476. SetTurretAnim(TURRET_ANIM_SPIN);
  477. }
  478. //move the gun
  479. if (m_fBeserk)
  480. {
  481. if (RANDOM_LONG(0,9) == 0)
  482. {
  483. m_vecGoalAngles.y = RANDOM_FLOAT(0,360);
  484. m_vecGoalAngles.x = RANDOM_FLOAT(0,90) - 90 * m_iOrientation;
  485. TakeDamage(pev,pev,1, DMG_GENERIC); // don't beserk forever
  486. return;
  487. }
  488. }
  489. else if (fEnemyVisible)
  490. {
  491. if (vec.y > 360)
  492. vec.y -= 360;
  493. if (vec.y < 0)
  494. vec.y += 360;
  495. //ALERT(at_console, "[%.2f]", vec.x);
  496. if (vec.x < -180)
  497. vec.x += 360;
  498. if (vec.x > 180)
  499. vec.x -= 360;
  500. // now all numbers should be in [1...360]
  501. // pin to turret limitations to [-90...15]
  502. if (m_iOrientation == 0)
  503. {
  504. if (vec.x > 90)
  505. vec.x = 90;
  506. else if (vec.x < m_iMinPitch)
  507. vec.x = m_iMinPitch;
  508. }
  509. else
  510. {
  511. if (vec.x < -90)
  512. vec.x = -90;
  513. else if (vec.x > -m_iMinPitch)
  514. vec.x = -m_iMinPitch;
  515. }
  516. // ALERT(at_console, "->[%.2f]\n", vec.x);
  517. m_vecGoalAngles.y = vec.y;
  518. m_vecGoalAngles.x = vec.x;
  519. }
  520. SpinUpCall();
  521. MoveTurret();
  522. }
  523. void CTurret::Shoot(Vector &vecSrc, Vector &vecDirToEnemy)
  524. {
  525. // Make turrets more dangerous in multiplayer
  526. if (gpGlobals->deathmatch)
  527. FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_12MM, 1, 20 );
  528. else
  529. FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_12MM, 1 );
  530. EMIT_SOUND(ENT(pev), CHAN_WEAPON, "turret/tu_fire1.wav", 1, 0.6);
  531. pev->effects = pev->effects | EF_MUZZLEFLASH;
  532. }
  533. void CMiniTurret::Shoot(Vector &vecSrc, Vector &vecDirToEnemy)
  534. {
  535. // Make turrets more dangerous in multiplayer
  536. if (gpGlobals->deathmatch)
  537. FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_12MM, 1, 15 );
  538. else
  539. FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_9MM, 1 );
  540. switch(RANDOM_LONG(0,2))
  541. {
  542. case 0: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks1.wav", 1, ATTN_NORM); break;
  543. case 1: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks2.wav", 1, ATTN_NORM); break;
  544. case 2: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks3.wav", 1, ATTN_NORM); break;
  545. }
  546. pev->effects = pev->effects | EF_MUZZLEFLASH;
  547. }
  548. void CBaseTurret::Deploy(void)
  549. {
  550. pev->nextthink = gpGlobals->time + 0.1;
  551. StudioFrameAdvance( );
  552. if (pev->sequence != TURRET_ANIM_DEPLOY)
  553. {
  554. m_iOn = 1;
  555. SetTurretAnim(TURRET_ANIM_DEPLOY);
  556. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_deploy.wav", TURRET_MACHINE_VOLUME, ATTN_NORM);
  557. SUB_UseTargets( this, USE_ON, 0 );
  558. }
  559. if (m_fSequenceFinished)
  560. {
  561. pev->maxs.z = m_iDeployHeight;
  562. pev->mins.z = -m_iDeployHeight;
  563. UTIL_SetSize(pev, pev->mins, pev->maxs);
  564. m_vecCurAngles.x = 0;
  565. if (m_iOrientation == 1)
  566. {
  567. m_vecCurAngles.y = UTIL_AngleMod( pev->angles.y + 180 );
  568. }
  569. else
  570. {
  571. m_vecCurAngles.y = UTIL_AngleMod( pev->angles.y );
  572. }
  573. SetTurretAnim(TURRET_ANIM_SPIN);
  574. pev->framerate = 0;
  575. SetThink(&CBaseTurret::SearchThink);
  576. }
  577. m_flLastSight = gpGlobals->time + m_flMaxWait;
  578. }
  579. void CBaseTurret::Retire(void)
  580. {
  581. // make the turret level
  582. m_vecGoalAngles.x = 0;
  583. m_vecGoalAngles.y = m_flStartYaw;
  584. pev->nextthink = gpGlobals->time + 0.1;
  585. StudioFrameAdvance( );
  586. EyeOff( );
  587. if (!MoveTurret())
  588. {
  589. if (m_iSpin)
  590. {
  591. SpinDownCall();
  592. }
  593. else if (pev->sequence != TURRET_ANIM_RETIRE)
  594. {
  595. SetTurretAnim(TURRET_ANIM_RETIRE);
  596. EMIT_SOUND_DYN(ENT(pev), CHAN_BODY, "turret/tu_deploy.wav", TURRET_MACHINE_VOLUME, ATTN_NORM, 0, 120);
  597. SUB_UseTargets( this, USE_OFF, 0 );
  598. }
  599. else if (m_fSequenceFinished)
  600. {
  601. m_iOn = 0;
  602. m_flLastSight = 0;
  603. SetTurretAnim(TURRET_ANIM_NONE);
  604. pev->maxs.z = m_iRetractHeight;
  605. pev->mins.z = -m_iRetractHeight;
  606. UTIL_SetSize(pev, pev->mins, pev->maxs);
  607. if (m_iAutoStart)
  608. {
  609. SetThink(&CBaseTurret::AutoSearchThink);
  610. pev->nextthink = gpGlobals->time + .1;
  611. }
  612. else
  613. SetThink(&CBaseTurret::SUB_DoNothing);
  614. }
  615. }
  616. else
  617. {
  618. SetTurretAnim(TURRET_ANIM_SPIN);
  619. }
  620. }
  621. void CTurret::SpinUpCall(void)
  622. {
  623. StudioFrameAdvance( );
  624. pev->nextthink = gpGlobals->time + 0.1;
  625. // Are we already spun up? If not start the two stage process.
  626. if (!m_iSpin)
  627. {
  628. SetTurretAnim( TURRET_ANIM_SPIN );
  629. // for the first pass, spin up the the barrel
  630. if (!m_iStartSpin)
  631. {
  632. pev->nextthink = gpGlobals->time + 1.0; // spinup delay
  633. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_spinup.wav", TURRET_MACHINE_VOLUME, ATTN_NORM);
  634. m_iStartSpin = 1;
  635. pev->framerate = 0.1;
  636. }
  637. // after the barrel is spun up, turn on the hum
  638. else if (pev->framerate >= 1.0)
  639. {
  640. pev->nextthink = gpGlobals->time + 0.1; // retarget delay
  641. EMIT_SOUND(ENT(pev), CHAN_STATIC, "turret/tu_active2.wav", TURRET_MACHINE_VOLUME, ATTN_NORM);
  642. SetThink(&CTurret::ActiveThink);
  643. m_iStartSpin = 0;
  644. m_iSpin = 1;
  645. }
  646. else
  647. {
  648. pev->framerate += 0.075;
  649. }
  650. }
  651. if (m_iSpin)
  652. {
  653. SetThink(&CTurret::ActiveThink);
  654. }
  655. }
  656. void CTurret::SpinDownCall(void)
  657. {
  658. if (m_iSpin)
  659. {
  660. SetTurretAnim( TURRET_ANIM_SPIN );
  661. if (pev->framerate == 1.0)
  662. {
  663. EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, "turret/tu_active2.wav", 0, 0, SND_STOP, 100);
  664. EMIT_SOUND(ENT(pev), CHAN_ITEM, "turret/tu_spindown.wav", TURRET_MACHINE_VOLUME, ATTN_NORM);
  665. }
  666. pev->framerate -= 0.02;
  667. if (pev->framerate <= 0)
  668. {
  669. pev->framerate = 0;
  670. m_iSpin = 0;
  671. }
  672. }
  673. }
  674. void CBaseTurret::SetTurretAnim(TURRET_ANIM anim)
  675. {
  676. if (pev->sequence != anim)
  677. {
  678. switch(anim)
  679. {
  680. case TURRET_ANIM_FIRE:
  681. case TURRET_ANIM_SPIN:
  682. if (pev->sequence != TURRET_ANIM_FIRE && pev->sequence != TURRET_ANIM_SPIN)
  683. {
  684. pev->frame = 0;
  685. }
  686. break;
  687. default:
  688. pev->frame = 0;
  689. break;
  690. }
  691. pev->sequence = anim;
  692. ResetSequenceInfo( );
  693. switch(anim)
  694. {
  695. case TURRET_ANIM_RETIRE:
  696. pev->frame = 255;
  697. pev->framerate = -1.0;
  698. break;
  699. case TURRET_ANIM_DIE:
  700. pev->framerate = 1.0;
  701. break;
  702. }
  703. //ALERT(at_console, "Turret anim #%d\n", anim);
  704. }
  705. }
  706. //
  707. // This search function will sit with the turret deployed and look for a new target.
  708. // After a set amount of time, the barrel will spin down. After m_flMaxWait, the turret will
  709. // retact.
  710. //
  711. void CBaseTurret::SearchThink(void)
  712. {
  713. // ensure rethink
  714. SetTurretAnim(TURRET_ANIM_SPIN);
  715. StudioFrameAdvance( );
  716. pev->nextthink = gpGlobals->time + 0.1;
  717. if (m_flSpinUpTime == 0 && m_flMaxSpin)
  718. m_flSpinUpTime = gpGlobals->time + m_flMaxSpin;
  719. Ping( );
  720. // If we have a target and we're still healthy
  721. if (m_hEnemy != NULL)
  722. {
  723. if (!m_hEnemy->IsAlive() )
  724. m_hEnemy = NULL;// Dead enemy forces a search for new one
  725. }
  726. // Acquire Target
  727. if (m_hEnemy == NULL)
  728. {
  729. Look(TURRET_RANGE);
  730. m_hEnemy = BestVisibleEnemy();
  731. }
  732. // If we've found a target, spin up the barrel and start to attack
  733. if (m_hEnemy != NULL)
  734. {
  735. m_flLastSight = 0;
  736. m_flSpinUpTime = 0;
  737. SetThink(&CBaseTurret::ActiveThink);
  738. }
  739. else
  740. {
  741. // Are we out of time, do we need to retract?
  742. if (gpGlobals->time > m_flLastSight)
  743. {
  744. //Before we retrace, make sure that we are spun down.
  745. m_flLastSight = 0;
  746. m_flSpinUpTime = 0;
  747. SetThink(&CBaseTurret::Retire);
  748. }
  749. // should we stop the spin?
  750. else if ((m_flSpinUpTime) && (gpGlobals->time > m_flSpinUpTime))
  751. {
  752. SpinDownCall();
  753. }
  754. // generic hunt for new victims
  755. m_vecGoalAngles.y = (m_vecGoalAngles.y + 0.1 * m_fTurnRate);
  756. if (m_vecGoalAngles.y >= 360)
  757. m_vecGoalAngles.y -= 360;
  758. MoveTurret();
  759. }
  760. }
  761. //
  762. // This think function will deploy the turret when something comes into range. This is for
  763. // automatically activated turrets.
  764. //
  765. void CBaseTurret::AutoSearchThink(void)
  766. {
  767. // ensure rethink
  768. StudioFrameAdvance( );
  769. // Think slower in Multiplayer
  770. pev->nextthink = gpGlobals->time + 2;
  771. // If we have a target and we're still healthy
  772. if (m_hEnemy != NULL)
  773. {
  774. if (!m_hEnemy->IsAlive() )
  775. m_hEnemy = NULL;// Dead enemy forces a search for new one
  776. }
  777. // Acquire Target
  778. if (m_hEnemy == NULL)
  779. {
  780. Look( TURRET_RANGE );
  781. m_hEnemy = BestVisibleEnemy();
  782. }
  783. if (m_hEnemy != NULL)
  784. {
  785. SetThink(&CBaseTurret::Deploy);
  786. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_alert.wav", TURRET_MACHINE_VOLUME, ATTN_NORM);
  787. }
  788. }
  789. void CBaseTurret :: TurretDeath( void )
  790. {
  791. BOOL iActive = FALSE;
  792. StudioFrameAdvance( );
  793. pev->nextthink = gpGlobals->time + 0.1;
  794. if (pev->deadflag != DEAD_DEAD)
  795. {
  796. pev->deadflag = DEAD_DEAD;
  797. float flRndSound = RANDOM_FLOAT ( 0 , 1 );
  798. if ( flRndSound <= 0.33 )
  799. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_die.wav", 1.0, ATTN_NORM);
  800. else if ( flRndSound <= 0.66 )
  801. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_die2.wav", 1.0, ATTN_NORM);
  802. else
  803. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_die3.wav", 1.0, ATTN_NORM);
  804. EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, "turret/tu_active2.wav", 0, 0, SND_STOP, 100);
  805. if (m_iOrientation == 0)
  806. m_vecGoalAngles.x = -15;
  807. else
  808. m_vecGoalAngles.x = -90;
  809. SetTurretAnim(TURRET_ANIM_DIE);
  810. EyeOn( );
  811. }
  812. EyeOff( );
  813. if (pev->dmgtime + RANDOM_FLOAT( 0, 2 ) > gpGlobals->time)
  814. {
  815. // lots of smoke
  816. MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
  817. WRITE_BYTE( TE_SMOKE );
  818. WRITE_COORD( RANDOM_FLOAT( pev->absmin.x, pev->absmax.x ) );
  819. WRITE_COORD( RANDOM_FLOAT( pev->absmin.y, pev->absmax.y ) );
  820. WRITE_COORD( pev->origin.z - m_iOrientation * 64 );
  821. WRITE_SHORT( g_sModelIndexSmoke );
  822. WRITE_BYTE( 25 ); // scale * 10
  823. WRITE_BYTE( 10 - m_iOrientation * 5); // framerate
  824. MESSAGE_END();
  825. }
  826. if (pev->dmgtime + RANDOM_FLOAT( 0, 5 ) > gpGlobals->time)
  827. {
  828. Vector vecSrc = Vector( RANDOM_FLOAT( pev->absmin.x, pev->absmax.x ), RANDOM_FLOAT( pev->absmin.y, pev->absmax.y ), 0 );
  829. if (m_iOrientation == 0)
  830. vecSrc = vecSrc + Vector( 0, 0, RANDOM_FLOAT( pev->origin.z, pev->absmax.z ) );
  831. else
  832. vecSrc = vecSrc + Vector( 0, 0, RANDOM_FLOAT( pev->absmin.z, pev->origin.z ) );
  833. UTIL_Sparks( vecSrc );
  834. }
  835. if (m_fSequenceFinished && !MoveTurret( ) && pev->dmgtime + 5 < gpGlobals->time)
  836. {
  837. pev->framerate = 0;
  838. SetThink( NULL );
  839. }
  840. }
  841. void CBaseTurret :: TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType)
  842. {
  843. if ( ptr->iHitgroup == 10 )
  844. {
  845. // hit armor
  846. if ( pev->dmgtime != gpGlobals->time || (RANDOM_LONG(0,10) < 1) )
  847. {
  848. UTIL_Ricochet( ptr->vecEndPos, RANDOM_FLOAT( 1, 2) );
  849. pev->dmgtime = gpGlobals->time;
  850. }
  851. flDamage = 0.1;// don't hurt the monster much, but allow bits_COND_LIGHT_DAMAGE to be generated
  852. }
  853. if ( !pev->takedamage )
  854. return;
  855. AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
  856. }
  857. // take damage. bitsDamageType indicates type of damage sustained, ie: DMG_BULLET
  858. int CBaseTurret::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType)
  859. {
  860. if ( !pev->takedamage )
  861. return 0;
  862. if (!m_iOn)
  863. flDamage /= 10.0;
  864. pev->health -= flDamage;
  865. if (pev->health <= 0)
  866. {
  867. pev->health = 0;
  868. pev->takedamage = DAMAGE_NO;
  869. pev->dmgtime = gpGlobals->time;
  870. ClearBits (pev->flags, FL_MONSTER); // why are they set in the first place???
  871. SetUse(NULL);
  872. SetThink(&CBaseTurret::TurretDeath);
  873. SUB_UseTargets( this, USE_ON, 0 ); // wake up others
  874. pev->nextthink = gpGlobals->time + 0.1;
  875. return 0;
  876. }
  877. if (pev->health <= 10)
  878. {
  879. if (m_iOn && (1 || RANDOM_LONG(0, 0x7FFF) > 800))
  880. {
  881. m_fBeserk = 1;
  882. SetThink(&CBaseTurret::SearchThink);
  883. }
  884. }
  885. return 1;
  886. }
  887. int CBaseTurret::MoveTurret(void)
  888. {
  889. int state = 0;
  890. // any x movement?
  891. if (m_vecCurAngles.x != m_vecGoalAngles.x)
  892. {
  893. float flDir = m_vecGoalAngles.x > m_vecCurAngles.x ? 1 : -1 ;
  894. m_vecCurAngles.x += 0.1 * m_iBaseTurnRate * flDir;
  895. // if we started below the goal, and now we're past, peg to goal
  896. if (flDir == 1)
  897. {
  898. if (m_vecCurAngles.x > m_vecGoalAngles.x)
  899. m_vecCurAngles.x = m_vecGoalAngles.x;
  900. }
  901. else
  902. {
  903. if (m_vecCurAngles.x < m_vecGoalAngles.x)
  904. m_vecCurAngles.x = m_vecGoalAngles.x;
  905. }
  906. if (m_iOrientation == 0)
  907. SetBoneController(1, -m_vecCurAngles.x);
  908. else
  909. SetBoneController(1, m_vecCurAngles.x);
  910. state = 1;
  911. }
  912. if (m_vecCurAngles.y != m_vecGoalAngles.y)
  913. {
  914. float flDir = m_vecGoalAngles.y > m_vecCurAngles.y ? 1 : -1 ;
  915. float flDist = fabs(m_vecGoalAngles.y - m_vecCurAngles.y);
  916. if (flDist > 180)
  917. {
  918. flDist = 360 - flDist;
  919. flDir = -flDir;
  920. }
  921. if (flDist > 30)
  922. {
  923. if (m_fTurnRate < m_iBaseTurnRate * 10)
  924. {
  925. m_fTurnRate += m_iBaseTurnRate;
  926. }
  927. }
  928. else if (m_fTurnRate > 45)
  929. {
  930. m_fTurnRate -= m_iBaseTurnRate;
  931. }
  932. else
  933. {
  934. m_fTurnRate += m_iBaseTurnRate;
  935. }
  936. m_vecCurAngles.y += 0.1 * m_fTurnRate * flDir;
  937. if (m_vecCurAngles.y < 0)
  938. m_vecCurAngles.y += 360;
  939. else if (m_vecCurAngles.y >= 360)
  940. m_vecCurAngles.y -= 360;
  941. if (flDist < (0.05 * m_iBaseTurnRate))
  942. m_vecCurAngles.y = m_vecGoalAngles.y;
  943. //ALERT(at_console, "%.2f -> %.2f\n", m_vecCurAngles.y, y);
  944. if (m_iOrientation == 0)
  945. SetBoneController(0, m_vecCurAngles.y - pev->angles.y );
  946. else
  947. SetBoneController(0, pev->angles.y - 180 - m_vecCurAngles.y );
  948. state = 1;
  949. }
  950. if (!state)
  951. m_fTurnRate = m_iBaseTurnRate;
  952. //ALERT(at_console, "(%.2f, %.2f)->(%.2f, %.2f)\n", m_vecCurAngles.x,
  953. // m_vecCurAngles.y, m_vecGoalAngles.x, m_vecGoalAngles.y);
  954. return state;
  955. }
  956. //
  957. // ID as a machine
  958. //
  959. int CBaseTurret::Classify ( void )
  960. {
  961. if (m_iOn || m_iAutoStart)
  962. return CLASS_MACHINE;
  963. return CLASS_NONE;
  964. }
  965. //=========================================================
  966. // Sentry gun - smallest turret, placed near grunt entrenchments
  967. //=========================================================
  968. class CSentry : public CBaseTurret
  969. {
  970. public:
  971. void Spawn( );
  972. void Precache(void);
  973. // other functions
  974. void Shoot(Vector &vecSrc, Vector &vecDirToEnemy);
  975. int TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType);
  976. void EXPORT SentryTouch( CBaseEntity *pOther );
  977. void EXPORT SentryDeath( void );
  978. };
  979. LINK_ENTITY_TO_CLASS( monster_sentry, CSentry );
  980. void CSentry::Precache()
  981. {
  982. CBaseTurret::Precache( );
  983. PRECACHE_MODEL ("models/sentry.mdl");
  984. }
  985. void CSentry::Spawn()
  986. {
  987. Precache( );
  988. SET_MODEL(ENT(pev), "models/sentry.mdl");
  989. pev->health = gSkillData.sentryHealth;
  990. m_HackedGunPos = Vector( 0, 0, 48 );
  991. pev->view_ofs.z = 48;
  992. m_flMaxWait = 1E6;
  993. m_flMaxSpin = 1E6;
  994. CBaseTurret::Spawn();
  995. m_iRetractHeight = 64;
  996. m_iDeployHeight = 64;
  997. m_iMinPitch = -60;
  998. UTIL_SetSize(pev, Vector(-16, -16, -m_iRetractHeight), Vector(16, 16, m_iRetractHeight));
  999. SetTouch(&CSentry::SentryTouch);
  1000. SetThink(&CSentry::Initialize);
  1001. pev->nextthink = gpGlobals->time + 0.3;
  1002. }
  1003. void CSentry::Shoot(Vector &vecSrc, Vector &vecDirToEnemy)
  1004. {
  1005. // Make turrets more dangerous in multiplayer
  1006. if (gpGlobals->deathmatch)
  1007. FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_12MM, 1, 10 );
  1008. else
  1009. FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_MP5, 1 );
  1010. switch(RANDOM_LONG(0,2))
  1011. {
  1012. case 0: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks1.wav", 1, ATTN_NORM); break;
  1013. case 1: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks2.wav", 1, ATTN_NORM); break;
  1014. case 2: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks3.wav", 1, ATTN_NORM); break;
  1015. }
  1016. pev->effects = pev->effects | EF_MUZZLEFLASH;
  1017. }
  1018. int CSentry::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType)
  1019. {
  1020. if ( !pev->takedamage )
  1021. return 0;
  1022. if (!m_iOn)
  1023. {
  1024. SetThink( &CSentry::Deploy );
  1025. SetUse( NULL );
  1026. pev->nextthink = gpGlobals->time + 0.1;
  1027. }
  1028. pev->health -= flDamage;
  1029. if (pev->health <= 0)
  1030. {
  1031. pev->health = 0;
  1032. pev->takedamage = DAMAGE_NO;
  1033. pev->dmgtime = gpGlobals->time;
  1034. ClearBits (pev->flags, FL_MONSTER); // why are they set in the first place???
  1035. SetUse(NULL);
  1036. SetThink(&CSentry::SentryDeath);
  1037. SUB_UseTargets( this, USE_ON, 0 ); // wake up others
  1038. pev->nextthink = gpGlobals->time + 0.1;
  1039. return 0;
  1040. }
  1041. return 1;
  1042. }
  1043. void CSentry::SentryTouch( CBaseEntity *pOther )
  1044. {
  1045. if (pOther && (pOther->pev->flags & (FL_CLIENT | FL_MONSTER)))
  1046. {
  1047. TakeDamage(pOther->pev, pOther->pev, 0, 0 );
  1048. }
  1049. }
  1050. void CSentry :: SentryDeath( void )
  1051. {
  1052. BOOL iActive = FALSE;
  1053. StudioFrameAdvance( );
  1054. pev->nextthink = gpGlobals->time + 0.1;
  1055. if (pev->deadflag != DEAD_DEAD)
  1056. {
  1057. pev->deadflag = DEAD_DEAD;
  1058. float flRndSound = RANDOM_FLOAT ( 0 , 1 );
  1059. if ( flRndSound <= 0.33 )
  1060. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_die.wav", 1.0, ATTN_NORM);
  1061. else if ( flRndSound <= 0.66 )
  1062. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_die2.wav", 1.0, ATTN_NORM);
  1063. else
  1064. EMIT_SOUND(ENT(pev), CHAN_BODY, "turret/tu_die3.wav", 1.0, ATTN_NORM);
  1065. EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, "turret/tu_active2.wav", 0, 0, SND_STOP, 100);
  1066. SetBoneController( 0, 0 );
  1067. SetBoneController( 1, 0 );
  1068. SetTurretAnim(TURRET_ANIM_DIE);
  1069. pev->solid = SOLID_NOT;
  1070. pev->angles.y = UTIL_AngleMod( pev->angles.y + RANDOM_LONG( 0, 2 ) * 120 );
  1071. EyeOn( );
  1072. }
  1073. EyeOff( );
  1074. Vector vecSrc, vecAng;
  1075. GetAttachment( 1, vecSrc, vecAng );
  1076. if (pev->dmgtime + RANDOM_FLOAT( 0, 2 ) > gpGlobals->time)
  1077. {
  1078. // lots of smoke
  1079. MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
  1080. WRITE_BYTE( TE_SMOKE );
  1081. WRITE_COORD( vecSrc.x + RANDOM_FLOAT( -16, 16 ) );
  1082. WRITE_COORD( vecSrc.y + RANDOM_FLOAT( -16, 16 ) );
  1083. WRITE_COORD( vecSrc.z - 32 );
  1084. WRITE_SHORT( g_sModelIndexSmoke );
  1085. WRITE_BYTE( 15 ); // scale * 10
  1086. WRITE_BYTE( 8 ); // framerate
  1087. MESSAGE_END();
  1088. }
  1089. if (pev->dmgtime + RANDOM_FLOAT( 0, 8 ) > gpGlobals->time)
  1090. {
  1091. UTIL_Sparks( vecSrc );
  1092. }
  1093. if (m_fSequenceFinished && pev->dmgtime + 5 < gpGlobals->time)
  1094. {
  1095. pev->framerate = 0;
  1096. SetThink( NULL );
  1097. }
  1098. }
  1099. #endif
  1100. #endif // TF_TURRET_H