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.

1335 lines
31 KiB

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