Guest User

Untitled

a guest
Aug 19th, 2016
40
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ================
  3. rvVehicle::State_Wait_Driver
  4. ================
  5. */
  6. stateResult_t rvVehicle::State_Wait_Driver ( int blendFrames ) {
  7. if ( !vfl.driver || vfl.stalled ) {
  8. return SRESULT_WAIT;
  9. }
  10.  
  11. return SRESULT_DONE;
  12. }
  13.  
  14. //militia_add
  15. /*
  16. ================
  17. rvVehicle::ServerReceiveEvent
  18. ================
  19. */
  20. bool rvVehicle::ServerReceiveEvent( int event, int time, const idBitMsg &msg ) {
  21.  
  22. int i, k;
  23. bool partEvent = false;
  24. for ( i = 0; i < positions.Num(); i ++ ) {
  25. partEvent = positions[i].ClientReceiveEvent( event, time, msg );
  26. /*
  27. for ( k = 0; k < positions[i].mParts.Num(); k ++ ) {
  28. partEvent = positions[i].mParts[k]->ClientReceiveEvent( event, time, msg );
  29.  
  30. partEvent = positions[i].mParts[k]->ClientReceiveEvent( event, time, msg );
  31. continue;
  32. }
  33. */
  34. }
  35.  
  36. if ( partEvent ) {
  37. return true;
  38. }
  39.  
  40. // client->server events
  41. switch( event ) {
  42. case EVENT_VEHICLE_IMPULSE: {
  43. int weapon = msg.ReadBits( 6 );
  44. int position = msg.ReadShort();
  45. positions[ position ].SelectWeapon( weapon );
  46. return true;
  47. }
  48.  
  49. /*
  50. case EVENT_VEHICLE_FLASHLIGHT_ON: {
  51. return true;
  52. }
  53.  
  54.  
  55. case EVENT_VEHICLE_FLASHLIGHT_OFF: {
  56. return true;
  57. }
  58. */
  59. default: {
  60. return false;
  61. }
  62. }
  63. }
  64.  
  65. /*
  66. =====================
  67. rvVehicle::ClientDamageEffects
  68. =====================
  69. */
  70. void rvVehicle::ClientDamageEffects ( idActor* driver, const idVec3& dir, int damage, idEntity *inflictor, idEntity *attacker, const char *damageDefName, const float damageScale, const int location, const int save ) {
  71.  
  72. if ( gameLocal.isMultiplayer && !gameLocal.serverInfo.GetBool( "si_playerViewEffects", "0" ) ) {
  73. return;
  74. }
  75.  
  76. if ( !driver || !driver->IsType( idPlayer::GetClassType() ) ) {
  77. return;
  78. }
  79.  
  80. const idDict *damageDef = gameLocal.FindEntityDefDict( damageDefName, false );
  81. if ( !damageDef ) {
  82. gameLocal.Warning( "rvVehicle::ClientDamageEffects : Unknown damageDef '%s'", damageDefName );
  83. return;
  84. }
  85.  
  86. if ( gameLocal.isDedicatedServer ) {
  87. return;
  88. }
  89.  
  90. idVec3 from;
  91. idVec3 localDir;
  92.  
  93. idPlayer* player = driver->GetStaticPlayer();
  94. idUserInterface *hud = player->GetHud();
  95.  
  96.  
  97. from = dir;
  98. from.Normalize();
  99. viewAxis.ProjectVector( from, localDir );
  100.  
  101. // Visual effects
  102. if ( health > 0 && damage ) {
  103.  
  104.  
  105. player->playerView.DamageImpulse( localDir, damageDef, damage );
  106.  
  107. if ( hud ) {
  108. hud->HandleNamedEvent( "vehicleHit" );
  109. }
  110.  
  111. if ( !stricmp( damageDef->GetString( "filter" ), "electrical" ) ) {
  112.  
  113. if ( hud ) {
  114. hud->HandleNamedEvent( "electricWarningOn" );
  115. }
  116.  
  117. PostEventMS( &EV_HUDShockWarningOff, spawnArgs.GetInt( "hud_shock_warning_time", "2500" ) );
  118.  
  119. if ( damage >= spawnArgs.GetInt( "electric_stall_damage", "20" ) ) {
  120.  
  121. rvClientCrawlEffect* effect;
  122. effect = new rvClientCrawlEffect ( gameLocal.GetEffect( spawnArgs , "fx_electrical_stall" ), this, SEC2MS( spawnArgs.GetFloat ( "hud_shock_warning_time", "2.5" ) ) );
  123. effect->Play ( gameLocal.time, false );
  124.  
  125. if ( renderEntity.gui[ 0 ] ) {
  126. renderEntity.gui[ 0 ]->HandleNamedEvent( "shock_stall" );
  127. }
  128.  
  129. if ( renderEntity.gui[ 1 ] ) {
  130. renderEntity.gui[ 1 ]->HandleNamedEvent( "shock_stall" );
  131. }
  132.  
  133. vfl.stalled = true;
  134. PostEventMS( &EV_StalledRestart, spawnArgs.GetInt( "electric_stall_delay", "3500" ), save, damage );
  135. }
  136. }
  137.  
  138.  
  139. if ( damageDef->GetFloat( "dot_duration" ) ) {
  140. int endTime;
  141. if ( damageDef->GetFloat( "dot_duration" ) == -1 ) {
  142. endTime = -1;
  143. } else {
  144. endTime = gameLocal.GetTime() + SEC2MS(damageDef->GetFloat( "dot_duration" ));
  145. }
  146. int interval = SEC2MS(damageDef->GetFloat( "dot_interval", "0" ));
  147. if ( driver && ( endTime == -1 || gameLocal.GetTime() + interval <= endTime ) ) {//post it again
  148. driver->PostEventMS( &EV_DamageOverTime, interval, endTime, interval, inflictor, attacker, dir, damageDefName, damageScale, location );
  149. }
  150. if ( driver && damageDef->GetString( "fx_dot", NULL ) ) {
  151. driver->ProcessEvent( &EV_DamageOverTimeEffect, endTime, interval, damageDefName );
  152. }
  153. if ( driver && damageDef->GetString( "snd_dot_start", NULL ) ) {
  154. driver->StartSound ( "snd_dot_start", SND_CHANNEL_ANY, 0, false, NULL );
  155. }
  156. }
  157.  
  158.  
  159.  
  160. // Let the hud know about the hit
  161. if ( hud ) {
  162. hud->SetStateFloat ( "hitdir", localDir.ToAngles()[YAW] + 180.0f );
  163. hud->HandleNamedEvent ( "playerHit" );
  164. }
  165. }
  166.  
  167. // Sound effects
  168. if ( damageDef->GetFloat ( "hl_volumeDB", "-40" ) ) {
  169. player->HearingLoss ( damageDef );
  170. }
  171.  
  172. }
  173.  
  174. /*
  175. ================
  176. rvVehicle::IsDead
  177. ================
  178. */
  179. bool rvVehicle::IsDead( void ) {
  180. return vfl.dead;
  181. }
  182.  
  183. /*
  184. ================
  185. rvVehicle::IsTelefragged
  186. ================
  187. */
  188. bool rvVehicle::IsTelefragged( void ) {
  189. return vfl.telefragged;
  190. }
  191.  
  192. /*
  193. ================
  194. rvVehicle::TelefragDeath
  195. ================
  196. */
  197. void rvVehicle::TelefragDeath( idEntity* teleportkiller ) {
  198. vfl.telefragged = true;
  199.  
  200. if ( gameLocal.isClient ) {
  201. return;
  202. }
  203.  
  204. CancelEvents( &EV_SetFire );
  205.  
  206. StopAllEffects( true, true );
  207.  
  208. if ( iminantDeath ) {
  209. iminantDeath->Stop( true );
  210. iminantDeath = NULL;
  211. }
  212.  
  213. if ( afterDeath ) {
  214. afterDeath->Stop( true );
  215. afterDeath = NULL;
  216. }
  217.  
  218. if ( fl.onFire ) {
  219. StopFire();
  220. }
  221.  
  222. if ( gameLocal.isClient ) {
  223. return;
  224. }
  225.  
  226. Damage ( teleportkiller, teleportkiller, teleportkiller->GetPhysics()->GetOrigin(), "damage_vehicle_telefrag", 1.0f, INVALID_JOINT );
  227.  
  228. }
  229.  
  230. /*
  231. ================
  232. rvVehicle::Event_vehicleRespawn
  233. ================
  234. */
  235. void rvVehicle::Event_vehicleRespawn( void ) {
  236.  
  237. if ( gameLocal.isClient ) {
  238. return;
  239. }
  240.  
  241. CancelEvents( &EV_SetFire );
  242.  
  243. StopAllEffects( true, true );
  244.  
  245. vfl.fx_iminantDeath = false;
  246. vfl.fx_afterDeath = false;
  247.  
  248. if ( iminantDeath ) {
  249. iminantDeath->Stop( true );
  250. iminantDeath = NULL;
  251. }
  252.  
  253. if ( afterDeath ) {
  254. afterDeath->Stop( true );
  255. afterDeath = NULL;
  256. }
  257.  
  258. if ( fl.onFire ) {
  259. StopFire();
  260. }
  261.  
  262. StartSound ( "snd_death", SND_CHANNEL_ANY, 0, true, NULL );
  263.  
  264. gameLocal.PlayEffect( gameLocal.GetEffect ( spawnArgs, "fx_death" ), GetPhysics()->GetAbsBounds().GetCenter(), GetPhysics()->GetAxis(), false, vec3_origin, true );
  265.  
  266. this->GetSelf()->Hide();
  267.  
  268. UpdateVisuals();
  269.  
  270. vfl.dead = false;
  271. vfl.locked = false;
  272. vfl.stalled = false;
  273. vfl.telefragged = false;
  274.  
  275. fl.hidden = true;
  276. hasRespawned = false;
  277.  
  278. fl.takedamage = spawnArgs.GetBool( "takeDamage", "1" );
  279.  
  280. incomingWarnProjectile = NULL;
  281. incomingWarnProjectiledist = 0.0f;
  282.  
  283. spawnTime = gameLocal.time + SEC2MS( spawnArgs.GetInt( "respawnDelay", "6" ) );
  284. if ( spawnLock ) {
  285. vfl.spawnLocked = true;
  286. vfl.locked = true;
  287. }
  288.  
  289. healthRegenAmount.Init( gameLocal.time, 0, healthMax, healthMax );
  290. health = healthRegenAmount.GetCurrentValue( gameLocal.time );
  291.  
  292. shieldMaxHealth = spawnArgs.GetInt ( "shieldHealth", "0" );
  293. shieldHitTime = 0;
  294. shieldHealth.Init ( gameLocal.time, 0, shieldMaxHealth, shieldMaxHealth );
  295.  
  296. team = gameLocal.GetTeamNum( spawnArgs );
  297.  
  298. spawnLock = spawnArgs.GetBool( "spawnLock", "0" );
  299. if ( spawnLock ) {
  300. vfl.spawnLocked = true;
  301. vfl.locked = true;
  302. } else if ( !spawnLock ) {
  303. vfl.spawnLocked = false;
  304. vfl.locked = false;
  305. }
  306.  
  307. ResetSpawnOrigin();
  308.  
  309. setFireTime = GetLimitRandomInt( MIN_SETFIRE_TIME, MAX_SETFIRE_TIME );
  310.  
  311. PostEventSec( &EV_vehicleRespawnInit, VEHICLE_RESPAWN_DELAY );
  312.  
  313. }
  314.  
  315. /*
  316. ================
  317. rvVehicle::Respawn
  318. ================
  319. */
  320. void rvVehicle::Event_Respawn( void ) {
  321.  
  322. if ( gameLocal.isClient ) {
  323. return;
  324. }
  325.  
  326. gameLocal.PlayEffect( gameLocal.GetEffect ( spawnArgs, "fx_respawn" ), spawnOrigin, spawnAxis, false, vec3_origin, true );
  327.  
  328. PostEventMS( &EV_vehicleShow, SEC2MS( spawnArgs.GetInt( "respawnDelay", "6" ) ) );
  329. }
  330.  
  331. /*
  332. ================
  333. rvVehicle::Event_vehicleShow
  334. ================
  335. */
  336. void rvVehicle::Event_vehicleRespawnEnd( void ) {
  337. if ( gameLocal.isClient ) {
  338. return;
  339. }
  340. hasRespawned = true;
  341. this->GetSelf()->Show();
  342. }
  343.  
  344. /*
  345. ================
  346. rvVehicle::ResetSpawnOrigin
  347. ================
  348. */
  349. void rvVehicle::ResetSpawnOrigin( void ) {
  350.  
  351. if ( gameLocal.isClient ) {
  352. return;
  353. }
  354.  
  355. GetPhysics()->SetOrigin( spawnOrigin );
  356. GetPhysics()->SetAxis( spawnAxis );
  357.  
  358. SetPositions();
  359.  
  360. int i, k;
  361. for ( i = 0; i < positions.Num(); i ++ ) {
  362. for ( k = 0; k < positions[i].mParts.Num(); k ++ ) {
  363. positions[i].mParts[k]->RunPrePhysics();
  364. }
  365. }
  366.  
  367. }
  368.  
  369. /*
  370. ================
  371. rvVehicle::Event_vehicleShow
  372. ================
  373. */
  374. void rvVehicle::Event_vehicleShow( void ) {
  375. this->GetSelf()->Show();
  376. UpdateVisuals();
  377. }
  378.  
  379. /*
  380. ================
  381. rvVehicle::Event_vehicleHide
  382. ================
  383. */
  384. void rvVehicle::Event_vehicleHide( void ) {
  385. this->GetSelf()->Hide();
  386. UpdateVisuals();
  387. }
  388.  
  389. /*
  390. ================
  391. rvVehicle::Event_ExplodeDeath
  392. ================
  393. */
  394. void rvVehicle::Event_ExplodeDeath( void ) {
  395.  
  396. if ( gameLocal.isClient ) {
  397. return;
  398. }
  399.  
  400. CancelEvents( &EV_SetFire );
  401.  
  402. StopAllEffects( true, true );
  403.  
  404. if ( iminantDeath ) {
  405. iminantDeath->Stop( true );
  406. iminantDeath = NULL;
  407. }
  408.  
  409. if ( afterDeath ) {
  410. afterDeath->Stop( true );
  411. afterDeath = NULL;
  412. }
  413.  
  414. StopFire();
  415.  
  416. StartSound ( "snd_death", SND_CHANNEL_ANY, 0, true, NULL );
  417.  
  418. gameLocal.PlayEffect ( gameLocal.GetEffect ( spawnArgs, "fx_death" ), GetPhysics()->GetAbsBounds().GetCenter(), GetPhysics()->GetAxis(), false, vec3_origin, true );
  419.  
  420. this->GetSelf()->Hide();
  421.  
  422. fl.hidden = true;
  423. hasRespawned = false;
  424.  
  425. UpdateVisuals();
  426.  
  427. if ( !gameLocal.isMultiplayer || gameLocal.isMultiplayer && !gameLocal.serverInfo.GetBool( "si_vehicleRespawn" ) ) {
  428.  
  429. PostEventMS( &EV_Remove, 0 );
  430.  
  431. }
  432.  
  433. }
  434.  
  435. /*
  436. ================
  437. rvVehicle::ClientReceiveEvent
  438. ================
  439. */
  440. bool rvVehicle::ClientReceiveEvent( int event, int time, const idBitMsg &msg ) {
  441.  
  442. if ( idEntity::ClientReceiveEvent( event, time, msg ) ) {
  443. return true;
  444. }
  445.  
  446. if ( idActor::ClientReceiveEvent( event, time, msg ) ) {
  447. return true;
  448. }
  449.  
  450. int i, k;
  451. bool partEvent = false;
  452. for ( i = 0; i < positions.Num(); i ++ ) {
  453. partEvent = positions[i].ClientReceiveEvent( event, time, msg );
  454. /*
  455. for ( k = 0; k < positions[i].mParts.Num(); k ++ ) {
  456. partEvent = positions[i].mParts[k]->ClientReceiveEvent( event, time, msg );
  457. }
  458. */
  459. }
  460.  
  461. if ( partEvent ) {
  462. return true;
  463. }
  464.  
  465. return false;
  466. }
  467.  
  468. /*
  469. ==================
  470. rvVehicle::vehicleTeam
  471. ==================
  472. */
  473. int rvVehicle::vehicleTeam( void ) {
  474. return team;
  475. }
  476.  
  477. /*
  478. ==================
  479. rvVehicle::allowSteal
  480. ==================
  481. */
  482. bool rvVehicle::allowSteal( void ) {
  483.  
  484. if ( !gameLocal.isMultiplayer ) {
  485. return false;
  486. }
  487. if ( !gameLocal.serverInfo.GetInt( "si_vehicleSteal" ) ) {
  488. return false;
  489. }
  490. return true;
  491. }
  492.  
  493. /*
  494. ==================
  495. rvVehicle::setToPlayerTeam
  496. ==================
  497. */
  498. void rvVehicle::setToPlayerTeam( int pTeam ) {
  499.  
  500. if ( ! allowSteal() ) {
  501. return;
  502. }
  503.  
  504. if( pTeam == TEAM_MARINE ) {
  505. team = TEAM_MARINE;
  506. } else if( pTeam == TEAM_STROGG ) {
  507. team = TEAM_STROGG;
  508. }
  509. }
  510.  
  511. /*
  512. ==================
  513. rvVehicle::Health
  514. ==================
  515. */
  516. int rvVehicle::Health( void ) {
  517. return health;
  518. }
  519.  
  520. /*
  521. ==================
  522. rvVehicle::hasLowHealth
  523. ==================
  524. */
  525. bool rvVehicle::hasLowHealth( void ) {
  526.  
  527. if ( health < healthLow ) {
  528. return true;
  529. }
  530.  
  531. return false;
  532. }
  533.  
  534. /*
  535. ==================
  536. rvVehicle::KillDrivers
  537. ==================
  538. */
  539. void rvVehicle::KillDrivers ( idEntity* inflictor, idEntity* attacker, const char *damageDefName ) {
  540.  
  541. int damage;
  542.  
  543. if ( gameLocal.isClient ) {
  544. return;
  545. }
  546.  
  547. if ( !inflictor ) {
  548. inflictor = gameLocal.world;
  549. }
  550. if ( !attacker ) {
  551. attacker = gameLocal.world;
  552. }
  553.  
  554. const idDict *damageDef = gameLocal.FindDamageDefDict( damageDefName, false );
  555. if ( !damageDef ) {
  556. damage = GetLimitRandomInt( 0, 100 );
  557. } else {
  558. damage = damageDef->GetInt( "damage" );
  559. }
  560.  
  561. for ( int i = 0; i < positions.Num(); i ++ ) {
  562.  
  563. idActor* driver = positions[i].GetDriver();
  564. if ( !driver ) {
  565. continue;
  566. }
  567.  
  568. if ( driver->IsType( idPlayer::GetClassType() ) ) {
  569. idPlayer* player = static_cast<idPlayer*>( driver );
  570. player->ViewBloodSpray( damage );
  571. }
  572.  
  573. driver->KillDriver( inflictor, attacker, damageDefName, GetLimitRandomFloat( 0.0f, 3.0f ), INVALID_JOINT );
  574.  
  575. }
  576. }
  577.  
  578. /*
  579. =====================
  580. rvVehicle::GetMainDriverPosition
  581. =====================
  582. */
  583. rvVehiclePosition* rvVehicle::GetMainDriverPosition ( void ) {
  584.  
  585. int i;
  586. rvVehiclePosition* pos = NULL;
  587. for ( i = 0; i < positions.Num(); i++ ) {
  588.  
  589. if ( !positions[i].IsDriver() ) {
  590. continue;
  591. }
  592. pos = &positions[i];
  593. }
  594.  
  595. return pos;
  596. }
  597.  
  598. /*
  599. ==================
  600. rvVehicle::Event_FlippedDeath
  601. ==================
  602. */
  603. void rvVehicle::Event_FlippedDeath ( void ) {
  604.  
  605. assert( !gameLocal.isClient );
  606.  
  607. if ( !spawnArgs.GetBool( "locked_flip_death" ) ) {
  608.  
  609. for ( int i = 0; i < positions.Num(); i ++ ) {
  610. idActor* driver = positions[i].GetDriver();
  611. if ( !driver ) {
  612. continue;
  613. }
  614.  
  615. driver->ProcessEvent ( &AI_ExitVehicle, true );
  616. }
  617.  
  618. Lock( );
  619.  
  620. } else if ( spawnArgs.GetBool( "locked_flip_death" ) ) {
  621.  
  622. KillDrivers ( this, this, "damage_vehicle_death" );
  623.  
  624. }
  625.  
  626. }
  627.  
  628. /*
  629. ==================
  630. rvVehicle::HealthRegen
  631. ==================
  632. */
  633. void rvVehicle::HealthRegenSelf ( void ) {
  634.  
  635. if ( !spawnArgs.GetBool( "regenHealth", "0" ) ) {
  636. return;
  637. }
  638.  
  639. if ( healthRegenRate && shieldHitTime + healthRegenDelay <= gameLocal.time ) {
  640.  
  641. if ( healthRegenAmount.IsDone( gameLocal.time )) {
  642.  
  643. healthRegenAmount.Init( gameLocal.time, SEC2MS((float)(healthMax - health)/healthRegenRate), health, healthMax );
  644. } else {
  645.  
  646. health = healthRegenAmount.GetCurrentValue( gameLocal.time );
  647.  
  648. }
  649. }
  650. }
  651.  
  652. /*
  653. ==================
  654. rvVehicle::HealthRegen
  655. ==================
  656. */
  657. void rvVehicle::HealthRegen ( const char *damageDefName, float regenVal ) {
  658.  
  659. if ( healthRegenAmount.GetCurrentValue( gameLocal.time ) >= healthMax ) {
  660. healthRegenAmount.Init( gameLocal.time, 0, healthMax, healthMax );
  661. health = healthRegenAmount.GetCurrentValue( gameLocal.time );
  662. return;
  663. }
  664.  
  665. if ( health > healthLow && iminantDeath ) {
  666. if ( iminantDeath ) {
  667. iminantDeath->Stop( true );
  668. iminantDeath = NULL;
  669. }
  670. }
  671.  
  672. const idDict *damageDef = gameLocal.FindEntityDefDict( damageDefName, false );
  673. if ( !damageDef ) {
  674. gameLocal.Warning( "rvVehicle::HealthRegen : Unknown damageDef '%s'", damageDefName );
  675. return;
  676. }
  677.  
  678. healthRegenAmount.Init( gameLocal.time, 0, damageDef->GetInt( "damage" ) * regenVal, healthMax );
  679. health = healthRegenAmount.GetCurrentValue( gameLocal.time );
  680.  
  681. }
  682.  
  683. /*
  684. ==================
  685. rvVehicle::GetControlMode
  686. ==================
  687. */
  688. int rvVehicle::GetControlMode ( void ) {
  689. if ( spawnArgs.GetBool( "Flying", "0" ) ) {
  690. return 1;
  691. }
  692.  
  693. return controlMode;
  694. }
  695.  
  696. /*
  697. ==================
  698. rvVehicle::GetSoundHandle
  699. ==================
  700. */
  701.  
  702. int rvVehicle::GetSoundHandle( void ) {
  703. return refSound.referenceSoundHandle;
  704. }
  705.  
  706. /*
  707. ==================
  708. rvVehicle::projectileWarning
  709. ==================
  710. */
  711. bool rvVehicle::projectileWarning ( void ) {
  712. if ( incomingWarnProjectile && incomingWarnProjectile->entityNumber != ENTITYNUM_WORLD && incomingWarnProjectile->IsType( idProjectile::GetClassType() ) && ( incomingWarnProjectile->fl.guidedProjectile || incomingWarnProjectile->fl.driftingProjectile ) ) {
  713. return true;
  714. }
  715.  
  716. return false;
  717. }
RAW Paste Data