home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / Target.cpp < prev    next >
C/C++ Source or Header  |  2005-11-14  |  60KB  |  2,315 lines

  1. /*
  2.  
  3. Invisible entities that affect other entities or the world when activated.
  4.  
  5. */
  6.  
  7. #include "../idlib/precompiled.h"
  8. #pragma hdrstop
  9.  
  10. #include "Game_local.h"
  11. #include "Projectile.h"
  12.  
  13. /*
  14. ===============================================================================
  15.  
  16. idTarget
  17.  
  18. ===============================================================================
  19. */
  20.  
  21. CLASS_DECLARATION( idEntity, idTarget )
  22. END_CLASS
  23.  
  24.  
  25. /*
  26. ===============================================================================
  27.  
  28. idTarget_Remove
  29.  
  30. ===============================================================================
  31. */
  32.  
  33. CLASS_DECLARATION( idTarget, idTarget_Remove )
  34.     EVENT( EV_Activate, idTarget_Remove::Event_Activate )
  35. END_CLASS
  36.  
  37. /*
  38. ================
  39. idTarget_Remove::Event_Activate
  40. ================
  41. */
  42. void idTarget_Remove::Event_Activate( idEntity *activator ) {
  43.     int            i;
  44.     idEntity    *ent;
  45.  
  46.     for( i = 0; i < targets.Num(); i++ ) {
  47.         ent = targets[ i ].GetEntity();
  48.         if ( ent ) {
  49.             ent->PostEventMS( &EV_Remove, 0 );
  50.         }
  51.     }
  52.  
  53.     // delete our self when done
  54.     PostEventMS( &EV_Remove, 0 );
  55. }
  56.  
  57.  
  58. /*
  59. ===============================================================================
  60.  
  61. idTarget_Show
  62.  
  63. ===============================================================================
  64. */
  65.  
  66. CLASS_DECLARATION( idTarget, idTarget_Show )
  67.     EVENT( EV_Activate, idTarget_Show::Event_Activate )
  68. END_CLASS
  69.  
  70. /*
  71. ================
  72. idTarget_Show::Event_Activate
  73. ================
  74. */
  75. void idTarget_Show::Event_Activate( idEntity *activator ) {
  76.     int            i;
  77.     idEntity    *ent;
  78.  
  79.     for( i = 0; i < targets.Num(); i++ ) {
  80.         ent = targets[ i ].GetEntity();
  81.         if ( ent ) {
  82.             ent->Show();
  83.         }
  84.     }
  85.  
  86.     // delete our self when done
  87.     PostEventMS( &EV_Remove, 0 );
  88. }
  89.  
  90.  
  91. /*
  92. ===============================================================================
  93.  
  94. idTarget_Damage
  95.  
  96. ===============================================================================
  97. */
  98.  
  99. CLASS_DECLARATION( idTarget, idTarget_Damage )
  100.     EVENT( EV_Activate, idTarget_Damage::Event_Activate )
  101. END_CLASS
  102.  
  103. /*
  104. ================
  105. idTarget_Damage::Event_Activate
  106. ================
  107. */
  108. void idTarget_Damage::Event_Activate( idEntity *activator ) {
  109.     int            i;
  110.     const char *damage;
  111.     idEntity *    ent;
  112.  
  113.     damage = spawnArgs.GetString( "def_damage", "damage_generic" );
  114.     for( i = 0; i < targets.Num(); i++ ) {
  115.         ent = targets[ i ].GetEntity();
  116.         if ( ent ) {
  117.             ent->Damage( this, this, vec3_origin, damage, 1.0f, INVALID_JOINT );
  118.         }
  119.     }
  120. }
  121.  
  122.  
  123. /*
  124. ===============================================================================
  125.  
  126. idTarget_SessionCommand
  127.  
  128. ===============================================================================
  129. */
  130.  
  131. CLASS_DECLARATION( idTarget, idTarget_SessionCommand )
  132.     EVENT( EV_Activate, idTarget_SessionCommand::Event_Activate )
  133. END_CLASS
  134.  
  135. /*
  136. ================
  137. idTarget_SessionCommand::Event_Activate
  138. ================
  139. */
  140. void idTarget_SessionCommand::Event_Activate( idEntity *activator ) {
  141.     gameLocal.sessionCommand = spawnArgs.GetString( "command" );
  142. }
  143.  
  144.  
  145. /*
  146. ===============================================================================
  147.  
  148. idTarget_EndLevel
  149.  
  150. Just a modified form of idTarget_SessionCommand
  151. ===============================================================================
  152. */
  153.  
  154. CLASS_DECLARATION( idTarget, idTarget_EndLevel )
  155.     EVENT( EV_Activate,        idTarget_EndLevel::Event_Activate )
  156. END_CLASS
  157.  
  158. /*
  159. ================
  160. idTarget_EndLevel::Event_Activate
  161. ================
  162. */
  163. void idTarget_EndLevel::Event_Activate( idEntity *activator ) {
  164.     idStr nextMap;
  165.  
  166. #ifdef ID_DEMO_BUILD
  167.     if ( spawnArgs.GetBool( "endOfGame" ) ) {
  168.         cvarSystem->SetCVarBool( "g_nightmare", true );
  169.         gameLocal.sessionCommand = "endofDemo";
  170.         return;
  171.     }
  172. #else
  173.     if ( spawnArgs.GetBool( "endOfGame" ) ) {
  174.         cvarSystem->SetCVarBool( "g_nightmare", true );
  175.         gameLocal.sessionCommand = "endOfGame";
  176.         return;
  177.     }
  178. #endif
  179.     if ( !spawnArgs.GetString( "nextMap", "", nextMap ) ) {
  180.         gameLocal.Printf( "idTarget_SessionCommand::Event_Activate: no nextMap key\n" );
  181.         return;
  182.     }
  183.  
  184.     if ( spawnArgs.GetInt( "devmap", "0" ) ) {
  185.         gameLocal.sessionCommand = "devmap ";    // only for special demos
  186.     } else {
  187.         gameLocal.sessionCommand = "map ";
  188.     }
  189.  
  190.     gameLocal.sessionCommand += nextMap;
  191.  
  192. // RAVEN BEGIN
  193. // jscott: additional info for multiple maps
  194.     const char* entityFilter;
  195.     if( spawnArgs.GetString( "entityFilter", "", &entityFilter ) && *entityFilter ) {
  196.         gameLocal.sessionCommand += " ";
  197.         gameLocal.sessionCommand += entityFilter;
  198.     }    
  199. // RAVEN END
  200. }
  201.  
  202.  
  203. /*
  204. ===============================================================================
  205.  
  206. idTarget_WaitForButton
  207.  
  208. ===============================================================================
  209. */
  210.  
  211. CLASS_DECLARATION( idTarget, idTarget_WaitForButton )
  212.     EVENT( EV_Activate, idTarget_WaitForButton::Event_Activate )
  213. END_CLASS
  214.  
  215. /*
  216. ================
  217. idTarget_WaitForButton::Event_Activate
  218. ================
  219. */
  220. void idTarget_WaitForButton::Event_Activate( idEntity *activator ) {
  221.     if ( thinkFlags & TH_THINK ) {
  222.         BecomeInactive( TH_THINK );
  223.     } else {
  224.         // always allow during cinematics
  225.         cinematic = true;
  226.         BecomeActive( TH_THINK );
  227.     }
  228. }
  229.  
  230. /*
  231. ================
  232. idTarget_WaitForButton::Think
  233. ================
  234. */
  235. void idTarget_WaitForButton::Think( void ) {
  236.     idPlayer *player;
  237.  
  238.     if ( thinkFlags & TH_THINK ) {
  239.         player = gameLocal.GetLocalPlayer();
  240.         if ( player && ( !player->oldButtons & BUTTON_ATTACK ) && ( player->usercmd.buttons & BUTTON_ATTACK ) ) {
  241.             player->usercmd.buttons &= ~BUTTON_ATTACK;
  242.             BecomeInactive( TH_THINK );
  243.             ActivateTargets( player );
  244.         }
  245.     } else {
  246.         BecomeInactive( TH_ALL );
  247.     }
  248. }
  249.  
  250.  
  251. /*
  252. ===============================================================================
  253.  
  254. idTarget_SetGlobalShaderParm
  255.  
  256. ===============================================================================
  257. */
  258.  
  259. CLASS_DECLARATION( idTarget, idTarget_SetGlobalShaderTime )
  260. EVENT( EV_Activate,    idTarget_SetGlobalShaderTime::Event_Activate )
  261. END_CLASS
  262.  
  263. /*
  264. ================
  265. idTarget_SetGlobalShaderTime::Event_Activate
  266. ================
  267. */
  268. void idTarget_SetGlobalShaderTime::Event_Activate( idEntity *activator ) {
  269.     int parm = spawnArgs.GetInt( "globalParm" );
  270.     float time = -MS2SEC( gameLocal.time );
  271.     if ( parm >= 0 && parm < MAX_GLOBAL_SHADER_PARMS ) {
  272.         gameLocal.globalShaderParms[parm] = time;
  273.     }
  274. }
  275.  
  276. /*
  277. ===============================================================================
  278.  
  279. idTarget_SetShaderParm
  280.  
  281. ===============================================================================
  282. */
  283.  
  284. CLASS_DECLARATION( idTarget, idTarget_SetShaderParm )
  285.     EVENT( EV_Activate,    idTarget_SetShaderParm::Event_Activate )
  286. END_CLASS
  287.  
  288. /*
  289. ================
  290. idTarget_SetShaderParm::Event_Activate
  291. ================
  292. */
  293. void idTarget_SetShaderParm::Event_Activate( idEntity *activator ) {
  294.     int            i;
  295.     idEntity *    ent;
  296.     float        value;
  297.     idVec3        color;
  298.     int            parmnum;
  299.  
  300.     // set the color on the targets
  301.     if ( spawnArgs.GetVector( "_color", "1 1 1", color ) ) {
  302.         for( i = 0; i < targets.Num(); i++ ) {
  303.             ent = targets[ i ].GetEntity();
  304.             if ( ent ) {
  305.                 ent->SetColor( color[ 0 ], color[ 1 ], color[ 2 ] );
  306.             }
  307.         }
  308.     }
  309.  
  310.     // set any shader parms on the targets
  311.     for( parmnum = 0; parmnum < MAX_ENTITY_SHADER_PARMS; parmnum++ ) {
  312.         if ( spawnArgs.GetFloat( va( "shaderParm%d", parmnum ), "0", value ) ) {
  313.             for( i = 0; i < targets.Num(); i++ ) {
  314.                 ent = targets[ i ].GetEntity();
  315.                 if ( ent ) {
  316.                     ent->SetShaderParm( parmnum, value );
  317.                 }
  318.             }
  319.             if (spawnArgs.GetBool("toggle") && (value == 0 || value == 1)) {
  320.                 int val = value;
  321.                 val ^= 1;
  322.                 value = val;
  323.                 spawnArgs.SetFloat(va("shaderParm%d", parmnum), value);
  324.             }
  325.         }
  326.     }
  327. }
  328.  
  329.  
  330. /*
  331. ===============================================================================
  332.  
  333. idTarget_SetShaderTime
  334.  
  335. ===============================================================================
  336. */
  337.  
  338. CLASS_DECLARATION( idTarget, idTarget_SetShaderTime )
  339.     EVENT( EV_Activate,    idTarget_SetShaderTime::Event_Activate )
  340. END_CLASS
  341.  
  342. /*
  343. ================
  344. idTarget_SetShaderTime::Event_Activate
  345. ================
  346. */
  347. void idTarget_SetShaderTime::Event_Activate( idEntity *activator ) {
  348.     int            i;
  349.     idEntity *    ent;
  350.     float        time;
  351.  
  352.     time = -MS2SEC( gameLocal.time );
  353.     for( i = 0; i < targets.Num(); i++ ) {
  354.         ent = targets[ i ].GetEntity();
  355.         if ( ent ) {
  356.             ent->SetShaderParm( SHADERPARM_TIMEOFFSET, time );
  357. // RAVEN BEGIN
  358. // jnewquist: Use accessor for static class type 
  359.             if ( ent->IsType( idLight::GetClassType() ) ) {
  360. // RAVEN END
  361.                 static_cast<idLight *>(ent)->SetLightParm( SHADERPARM_TIMEOFFSET, time );
  362.             }
  363.         }
  364.     }
  365. }
  366.  
  367. /*
  368. ===============================================================================
  369.  
  370. idTarget_FadeEntity
  371.  
  372. ===============================================================================
  373. */
  374.  
  375. CLASS_DECLARATION( idTarget, idTarget_FadeEntity )
  376.     EVENT( EV_Activate,                idTarget_FadeEntity::Event_Activate )
  377. END_CLASS
  378.  
  379. /*
  380. ================
  381. idTarget_FadeEntity::idTarget_FadeEntity
  382. ================
  383. */
  384. idTarget_FadeEntity::idTarget_FadeEntity( void ) {
  385.     fadeFrom.Zero();
  386.     fadeStart = 0;
  387.     fadeEnd = 0;
  388. }
  389.  
  390. /*
  391. ================
  392. idTarget_FadeEntity::Save
  393. ================
  394. */
  395. void idTarget_FadeEntity::Save( idSaveGame *savefile ) const {
  396.     savefile->WriteVec4( fadeFrom );
  397.     savefile->WriteInt( fadeStart );
  398.     savefile->WriteInt( fadeEnd );
  399. }
  400.  
  401. /*
  402. ================
  403. idTarget_FadeEntity::Restore
  404. ================
  405. */
  406. void idTarget_FadeEntity::Restore( idRestoreGame *savefile ) {
  407.     savefile->ReadVec4( fadeFrom );
  408.     savefile->ReadInt( fadeStart );
  409.     savefile->ReadInt( fadeEnd );
  410. }
  411.  
  412. /*
  413. ================
  414. idTarget_FadeEntity::Event_Activate
  415. ================
  416. */
  417. void idTarget_FadeEntity::Event_Activate( idEntity *activator ) {
  418.     idEntity *ent;
  419.     int i;
  420.  
  421.     if ( !targets.Num() ) {
  422.         return;
  423.     }
  424.  
  425.     // always allow during cinematics
  426.     cinematic = true;
  427.     BecomeActive( TH_THINK );
  428.  
  429.     ent = this;
  430.     for( i = 0; i < targets.Num(); i++ ) {
  431.         ent = targets[ i ].GetEntity();
  432.         if ( ent ) {
  433.             ent->GetColor( fadeFrom );
  434.             break;
  435.         }
  436.     }
  437.  
  438.     fadeStart = gameLocal.time;
  439.     fadeEnd = gameLocal.time + SEC2MS( spawnArgs.GetFloat( "fadetime" ) );
  440. }
  441.  
  442. /*
  443. ================
  444. idTarget_FadeEntity::Think
  445. ================
  446. */
  447. void idTarget_FadeEntity::Think( void ) {
  448.     int            i;
  449.     idEntity    *ent;
  450.     idVec4        color;
  451.     idVec4        fadeTo;
  452.     float        frac;
  453.  
  454.     if ( thinkFlags & TH_THINK ) {
  455.         GetColor( fadeTo );
  456.         if ( gameLocal.time >= fadeEnd ) {
  457.             color = fadeTo;
  458.             BecomeInactive( TH_THINK );
  459.         } else {
  460.             frac = ( float )( gameLocal.time - fadeStart ) / ( float )( fadeEnd - fadeStart );
  461.             color.Lerp( fadeFrom, fadeTo, frac );
  462.         }
  463.  
  464.         // set the color on the targets
  465.         for( i = 0; i < targets.Num(); i++ ) {
  466.             ent = targets[ i ].GetEntity();
  467.             if ( ent ) {
  468.                 ent->SetColor( color );
  469.             }
  470.         }
  471.     } else {
  472.         BecomeInactive( TH_ALL );
  473.     }
  474. }
  475.  
  476. /*
  477. ===============================================================================
  478.  
  479. idTarget_LightFadeIn
  480.  
  481. ===============================================================================
  482. */
  483.  
  484. CLASS_DECLARATION( idTarget, idTarget_LightFadeIn )
  485.     EVENT( EV_Activate,                idTarget_LightFadeIn::Event_Activate )
  486. END_CLASS
  487.  
  488. /*
  489. ================
  490. idTarget_LightFadeIn::Event_Activate
  491. ================
  492. */
  493. void idTarget_LightFadeIn::Event_Activate( idEntity *activator ) {
  494.     idEntity *ent;
  495.     idLight *light;
  496.     int i;
  497.     float time;
  498.  
  499.     if ( !targets.Num() ) {
  500.         return;
  501.     }
  502.  
  503.     time = spawnArgs.GetFloat( "fadetime" );
  504.     ent = this;
  505.     for( i = 0; i < targets.Num(); i++ ) {
  506.         ent = targets[ i ].GetEntity();
  507.         if ( !ent ) {
  508.             continue;
  509.         }
  510. // RAVEN BEGIN
  511. // jnewquist: Use accessor for static class type 
  512.         if ( ent->IsType( idLight::GetClassType() ) ) {
  513. // RAVEN END
  514.             light = static_cast<idLight *>( ent );
  515.             light->FadeIn( time );
  516.         } else {
  517.             gameLocal.Printf( "'%s' targets non-light '%s'", name.c_str(), ent->GetName() );
  518.         }
  519.     }
  520. }
  521.  
  522. /*
  523. ===============================================================================
  524.  
  525. idTarget_LightFadeOut
  526.  
  527. ===============================================================================
  528. */
  529.  
  530. CLASS_DECLARATION( idTarget, idTarget_LightFadeOut )
  531.     EVENT( EV_Activate,                idTarget_LightFadeOut::Event_Activate )
  532. END_CLASS
  533.  
  534. /*
  535. ================
  536. idTarget_LightFadeOut::Event_Activate
  537. ================
  538. */
  539. void idTarget_LightFadeOut::Event_Activate( idEntity *activator ) {
  540.     idEntity *ent;
  541.     idLight *light;
  542.     int i;
  543.     float time;
  544.  
  545.     if ( !targets.Num() ) {
  546.         return;
  547.     }
  548.  
  549.     time = spawnArgs.GetFloat( "fadetime" );
  550.     ent = this;
  551.     for( i = 0; i < targets.Num(); i++ ) {
  552.         ent = targets[ i ].GetEntity();
  553.         if ( !ent ) {
  554.             continue;
  555.         }
  556. // RAVEN BEGIN
  557. // jnewquist: Use accessor for static class type 
  558.         if ( ent->IsType( idLight::GetClassType() ) ) {
  559. // RAVEN END
  560.             light = static_cast<idLight *>( ent );
  561.             light->FadeOut( time );
  562.         } else {
  563.             gameLocal.Printf( "'%s' targets non-light '%s'", name.c_str(), ent->GetName() );
  564.         }
  565.     }
  566. }
  567.  
  568. /*
  569. ===============================================================================
  570.  
  571. idTarget_Give
  572.  
  573. ===============================================================================
  574. */
  575.  
  576. CLASS_DECLARATION( idTarget, idTarget_Give )
  577.     EVENT( EV_Activate,                idTarget_Give::Event_Activate )
  578. // RAVEN BEGIN
  579. // abahr:
  580.     EVENT( EV_PostSpawn,            idTarget_Give::Event_PostSpawn )
  581. // RAVEN END
  582. END_CLASS
  583.  
  584. /*
  585. ================
  586. idTarget_Give::Spawn
  587. ================
  588. */
  589. void idTarget_Give::Spawn( void ) {
  590. // RAVEN BEGIN
  591. // abahr: fixing issue with EV_Activate not taking NULL ptrs
  592.     if ( spawnArgs.GetBool( "onSpawn" ) ) {
  593.         PostEventMS( &EV_PostSpawn, 50 );
  594.  
  595. // mwhitlock: Dynamic memory consolidation
  596. #if defined(_RV_MEM_SYS_SUPPORT)
  597.         const idKeyValue *kv = spawnArgs.MatchPrefix( "item", NULL );
  598.         while ( kv ) {
  599.             const idDict *dict = gameLocal.FindEntityDefDict( kv->GetValue(), false );
  600.             kv = spawnArgs.MatchPrefix( "item", kv );
  601.         }
  602. #endif
  603.     }
  604. // RAVEN END
  605. }
  606.  
  607. // RAVEN BEGIN
  608. // abahr: fixing issue with EV_Activate not taking NULL ptrs
  609. /*
  610. ================
  611. idTarget_Give::Event_PostSpawn
  612. ================
  613. */
  614. void idTarget_Give::Event_PostSpawn() {
  615.     ProcessEvent( &EV_Activate, gameLocal.GetLocalPlayer() );
  616. }
  617. // RAVEN END
  618.  
  619. /*
  620. ================
  621. idTarget_Give::Event_Activate
  622. ================
  623. */
  624. void idTarget_Give::Event_Activate( idEntity *activator ) {
  625.     
  626.     if ( spawnArgs.GetBool( "development" ) && developer.GetInteger() == 0 ) {
  627.         return;
  628.     }
  629.  
  630.     static int giveNum = 0;
  631.     idPlayer *player = gameLocal.GetLocalPlayer();
  632.     if ( player ) {
  633.         const idKeyValue *kv = spawnArgs.MatchPrefix( "item", NULL );
  634.         while ( kv ) {
  635.             const idDict *dict = gameLocal.FindEntityDefDict( kv->GetValue(), false );
  636.             if ( dict ) {
  637.                 idDict d2;
  638.                 d2.Copy( *dict );
  639.                 d2.Set( "name", va( "givenitem_%i", giveNum++ ) );
  640.                 idEntity *ent = NULL;
  641. // RAVEN BEGIN
  642. // jnewquist: Use accessor for static class type 
  643.                 if ( gameLocal.SpawnEntityDef( d2, &ent ) && ent && ent->IsType( idItem::GetClassType() ) ) {
  644. // RAVEN END
  645.                     idItem *item = static_cast<idItem*>(ent);
  646.                     item->GiveToPlayer( gameLocal.GetLocalPlayer() );
  647.                     item->PostEventMS ( &EV_Remove, 0 );
  648.  
  649.                     // rules are that if we are given a weapon by a character, we are supposed to switch to it regardless of
  650.                     //    whether auto-switch is on or not.
  651.                     if ( !gameLocal.isMultiplayer && !player->GetUserInfo()->GetBool( "ui_autoSwitch" ) && !spawnArgs.GetBool( "onSpawn" )) {
  652.                         const idKeyValue *kv = ent->spawnArgs.FindKey( "weaponclass" );
  653.                         if ( kv ) {
  654.                             // does player already have this weapon selected?
  655.                             if ( player->weapon && idStr::Icmp(player->weapon->GetClassname(), kv->GetValue())) {
  656.                                 kv = ent->spawnArgs.FindKey( "inv_weapon" );
  657.                                 if ( kv ) {
  658.                                     // nope, so attempt to switch to this weapon
  659.                                     player->SelectWeapon(kv->GetValue());
  660.                                 }
  661.                             }
  662.                         }
  663.                     }
  664.                 }
  665.             }
  666.             kv = spawnArgs.MatchPrefix( "item", kv );
  667.         }
  668.     }
  669. }
  670.  
  671. /*
  672. ===============================================================================
  673.  
  674. idTarget_GiveEmail
  675.  
  676. ===============================================================================
  677. */
  678.  
  679. CLASS_DECLARATION( idTarget, idTarget_GiveEmail )
  680. EVENT( EV_Activate,                idTarget_GiveEmail::Event_Activate )
  681. END_CLASS
  682.  
  683. /*
  684. ================
  685. idTarget_GiveEmail::Spawn
  686. ================
  687. */
  688. void idTarget_GiveEmail::Spawn( void ) {
  689. }
  690.  
  691. /*
  692. ================
  693. idTarget_GiveEmail::Event_Activate
  694. ================
  695. */
  696. void idTarget_GiveEmail::Event_Activate( idEntity *activator ) {
  697. // RAVEN BEGIN
  698. // bdube: not using email    
  699. /*
  700.     idPlayer *player = gameLocal.GetLocalPlayer();
  701.     const idDeclPDA *pda = player->GetPDA();
  702.     if ( pda ) {
  703.         player->GiveEmail( spawnArgs.GetString( "email" ) );
  704.     } else {
  705.         player->ShowTip( spawnArgs.GetString( "text_infoTitle" ), spawnArgs.GetString( "text_PDANeeded" ), true );
  706.     }
  707. */
  708. // RAVEN END
  709. }
  710.  
  711.  
  712. /*
  713. ===============================================================================
  714.  
  715. idTarget_SetModel
  716.  
  717. ===============================================================================
  718. */
  719.  
  720. CLASS_DECLARATION( idTarget, idTarget_SetModel )
  721.     EVENT( EV_Activate,    idTarget_SetModel::Event_Activate )
  722. END_CLASS
  723.  
  724. /*
  725. ================
  726. idTarget_SetModel::Spawn
  727. ================
  728. */
  729. void idTarget_SetModel::Spawn( void ) {
  730.     const char *model;
  731.  
  732.     model = spawnArgs.GetString( "newmodel" );
  733.     if ( declManager->FindType( DECL_MODELDEF, model, false ) == NULL ) {
  734.         // precache the render model
  735.         renderModelManager->FindModel( model );
  736.         // precache .cm files only
  737.         collisionModelManager->PreCacheModel( gameLocal.GetMapName(), model );
  738.     }
  739. }
  740.  
  741. /*
  742. ================
  743. idTarget_SetModel::Event_Activate
  744. ================
  745. */
  746. void idTarget_SetModel::Event_Activate( idEntity *activator ) {
  747.     for( int i = 0; i < targets.Num(); i++ ) {
  748.         idEntity *ent = targets[ i ].GetEntity();
  749.         if ( ent ) {
  750.             ent->SetModel( spawnArgs.GetString( "newmodel" ) );
  751.         }
  752.     }
  753. }
  754.  
  755.  
  756. /*
  757. ===============================================================================
  758.  
  759. idTarget_SetInfluence
  760.  
  761. ===============================================================================
  762. */
  763.  
  764. const idEventDef EV_RestoreInfluence( "<RestoreInfluece>" );
  765. const idEventDef EV_GatherEntities( "<GatherEntities>" );
  766. const idEventDef EV_Flash( "<Flash>", "fd" );
  767. const idEventDef EV_ClearFlash( "<ClearFlash>", "f" );
  768.  
  769. CLASS_DECLARATION( idTarget, idTarget_SetInfluence )
  770.     EVENT( EV_Activate,    idTarget_SetInfluence::Event_Activate )
  771.     EVENT( EV_RestoreInfluence,    idTarget_SetInfluence::Event_RestoreInfluence )
  772.     EVENT( EV_GatherEntities, idTarget_SetInfluence::Event_GatherEntities )
  773.     EVENT( EV_Flash, idTarget_SetInfluence::Event_Flash )
  774.     EVENT( EV_ClearFlash, idTarget_SetInfluence::Event_ClearFlash )
  775. END_CLASS
  776.  
  777. /*
  778. ================
  779. idTarget_SetInfluence::idTarget_SetInfluence
  780. ================
  781. */
  782. idTarget_SetInfluence::idTarget_SetInfluence( void ) {
  783.     flashIn = 0.0f;
  784.     flashOut = 0.0f;
  785.     delay = 0.0f;
  786.     switchToCamera = NULL;
  787.     soundFaded = false;
  788.     restoreOnTrigger = false;
  789. }
  790.  
  791. /*
  792. ================
  793. idTarget_SetInfluence::Save
  794. ================
  795. */
  796. void idTarget_SetInfluence::Save( idSaveGame *savefile ) const {
  797.     int i;
  798.  
  799.     savefile->WriteInt( lightList.Num() );
  800.     for( i = 0; i < lightList.Num(); i++ ) {
  801.         savefile->WriteInt( lightList[ i ] );
  802.     }
  803.  
  804.     savefile->WriteInt( guiList.Num() );
  805.     for( i = 0; i < guiList.Num(); i++ ) {
  806.         savefile->WriteInt( guiList[ i ] );
  807.     }
  808.  
  809.     savefile->WriteInt( soundList.Num() );
  810.     for( i = 0; i < soundList.Num(); i++ ) {
  811.         savefile->WriteInt( soundList[ i ] );
  812.     }
  813.  
  814.     savefile->WriteInt( genericList.Num() );
  815.     for( i = 0; i < genericList.Num(); i++ ) {
  816.         savefile->WriteInt( genericList[ i ] );
  817.     }
  818.  
  819.     savefile->WriteFloat( flashIn );
  820.     savefile->WriteFloat( flashOut );
  821.  
  822.     savefile->WriteFloat( delay );
  823.  
  824.     savefile->WriteString( flashInSound );
  825.     savefile->WriteString( flashOutSound );
  826.  
  827.     savefile->WriteObject( switchToCamera );
  828.  
  829.     savefile->WriteFloat( fovSetting.GetStartTime() );
  830.     savefile->WriteFloat( fovSetting.GetDuration() );
  831.     savefile->WriteFloat( fovSetting.GetStartValue() );
  832.     savefile->WriteFloat( fovSetting.GetEndValue() );
  833.  
  834.     savefile->WriteBool( soundFaded );
  835.     savefile->WriteBool( restoreOnTrigger );
  836. }
  837.  
  838. /*
  839. ================
  840. idTarget_SetInfluence::Restore
  841. ================
  842. */
  843. void idTarget_SetInfluence::Restore( idRestoreGame *savefile ) {
  844.     int i, num;
  845.     int itemNum;
  846.     float set;
  847.  
  848.     savefile->ReadInt( num );
  849.     for( i = 0; i < num; i++ ) {
  850.         savefile->ReadInt( itemNum );
  851.         lightList.Append( itemNum );
  852.     }
  853.  
  854.     savefile->ReadInt( num );
  855.     for( i = 0; i < num; i++ ) {
  856.         savefile->ReadInt( itemNum );
  857.         guiList.Append( itemNum );
  858.     }
  859.  
  860.     savefile->ReadInt( num );
  861.     for( i = 0; i < num; i++ ) {
  862.         savefile->ReadInt( itemNum );
  863.         soundList.Append( itemNum );
  864.     }
  865.  
  866.     savefile->ReadInt( num );
  867.     for ( i = 0; i < num; i++ ) {
  868.         savefile->ReadInt( itemNum );
  869.         genericList.Append( itemNum );
  870.     }
  871.  
  872.     savefile->ReadFloat( flashIn );
  873.     savefile->ReadFloat( flashOut );
  874.  
  875.     savefile->ReadFloat( delay );
  876.  
  877.     savefile->ReadString( flashInSound );
  878.     savefile->ReadString( flashOutSound );
  879.  
  880.     savefile->ReadObject( reinterpret_cast<idClass *&>( switchToCamera ) );
  881.  
  882.     savefile->ReadFloat( set );
  883.     fovSetting.SetStartTime( set );
  884.     savefile->ReadFloat( set );
  885.     fovSetting.SetDuration( set );
  886.     savefile->ReadFloat( set );
  887.     fovSetting.SetStartValue( set );
  888.     savefile->ReadFloat( set );
  889.     fovSetting.SetEndValue( set );
  890.  
  891.     savefile->ReadBool( soundFaded );
  892.     savefile->ReadBool( restoreOnTrigger );
  893. }
  894.  
  895. /*
  896. ================
  897. idTarget_SetInfluence::Spawn
  898. ================
  899. */
  900. void idTarget_SetInfluence::Spawn() {
  901.     PostEventMS( &EV_GatherEntities, 0 );
  902.     flashIn = spawnArgs.GetFloat( "flashIn", "0" );
  903.     flashOut = spawnArgs.GetFloat( "flashOut", "0" );
  904.     flashInSound = spawnArgs.GetString( "snd_flashin" );
  905.     flashOutSound = spawnArgs.GetString( "snd_flashout" );
  906.     delay = spawnArgs.GetFloat( "delay" );
  907.     soundFaded = false;
  908.     restoreOnTrigger = false;
  909.  
  910.     // always allow during cinematics
  911.     cinematic = true;
  912. }
  913.  
  914. /*
  915. ================
  916. idTarget_SetInfluence::Event_Flash
  917. ================
  918. */
  919. void idTarget_SetInfluence::Event_Flash( float flash, int out ) {
  920.     idPlayer *player = gameLocal.GetLocalPlayer();
  921.     player->playerView.Fade( idVec4( 1, 1, 1, 1 ), flash );
  922.     const idSoundShader *shader = NULL;
  923.     if ( !out && flashInSound.Length() ){
  924.         shader = declManager->FindSound( flashInSound );
  925.         player->StartSoundShader( shader, SND_CHANNEL_VOICE, 0, false, NULL );
  926.     } else if ( out && ( flashOutSound.Length() || flashInSound.Length() ) ) {
  927.         shader = declManager->FindSound( flashOutSound.Length() ? flashOutSound : flashInSound );
  928.         player->StartSoundShader( shader, SND_CHANNEL_VOICE, 0, false, NULL );
  929.     }
  930.     PostEventSec( &EV_ClearFlash, flash, flash );
  931. }
  932.  
  933.  
  934. /*
  935. ================
  936. idTarget_SetInfluence::Event_ClearFlash
  937. ================
  938. */
  939. void idTarget_SetInfluence::Event_ClearFlash( float flash ) {
  940.     idPlayer *player = gameLocal.GetLocalPlayer();
  941.     player->playerView.Fade( vec4_zero , flash );        
  942. }
  943. /*
  944. ================
  945. idTarget_SetInfluence::Event_GatherEntities
  946. ================
  947. */
  948. void idTarget_SetInfluence::Event_GatherEntities() {
  949.     int i, listedEntities;
  950.     idEntity *entityList[ MAX_GENTITIES ];
  951.  
  952.     bool lights = spawnArgs.GetBool( "effect_lights" );
  953.     bool sounds = spawnArgs.GetBool( "effect_sounds" );
  954.     bool guis = spawnArgs.GetBool( "effect_guis" );
  955.     bool models = spawnArgs.GetBool( "effect_models" );
  956.     bool vision = spawnArgs.GetBool( "effect_vision" );
  957.     bool targetsOnly = spawnArgs.GetBool( "targetsOnly" );
  958.  
  959.     lightList.Clear();
  960.     guiList.Clear();
  961.     soundList.Clear();
  962.  
  963.     if ( spawnArgs.GetBool( "effect_all" ) ) {
  964.         lights = sounds = guis = models = vision = true;
  965.     }
  966.  
  967.     if ( targetsOnly ) {
  968.         listedEntities = targets.Num();
  969.         for ( i = 0; i < listedEntities; i++ ) {
  970.             entityList[i] = targets[i].GetEntity();
  971.         }
  972.     } else {
  973.         float radius = spawnArgs.GetFloat( "radius" );
  974.         listedEntities = gameLocal.EntitiesWithinRadius( GetPhysics()->GetOrigin(), radius, entityList, MAX_GENTITIES );
  975.     }
  976.  
  977.     for( i = 0; i < listedEntities; i++ ) {
  978.         idEntity *ent = entityList[ i ];
  979.         if ( ent ) {
  980. // RAVEN BEGIN
  981. // jnewquist: Use accessor for static class type 
  982.             if ( lights && ent->IsType( idLight::GetClassType() ) && ent->spawnArgs.FindKey( "color_demonic" ) ) {
  983. // RAVEN END
  984.                 lightList.Append( ent->entityNumber );
  985.                 continue;
  986.             }
  987. // RAVEN BEGIN
  988. // jnewquist: Use accessor for static class type 
  989.             if ( sounds && ent->IsType( idSound::GetClassType() ) && ent->spawnArgs.FindKey( "snd_demonic" ) ) {
  990. // RAVEN END
  991.                 soundList.Append( ent->entityNumber );
  992.                 continue;
  993.             }
  994.             if ( guis && ent->GetRenderEntity() && ent->GetRenderEntity()->gui[ 0 ] && ent->spawnArgs.FindKey( "gui_demonic" ) ) {
  995.                 guiList.Append( ent->entityNumber );
  996.                 continue;
  997.             }
  998. // RAVEN BEGIN
  999. // jnewquist: Use accessor for static class type 
  1000.             if ( ent->IsType( idStaticEntity::GetClassType() ) && ent->spawnArgs.FindKey( "color_demonic" ) ) {
  1001. // RAVEN END
  1002.                 genericList.Append( ent->entityNumber );
  1003.                 continue;
  1004.             }
  1005.         }
  1006.     }
  1007.     idStr temp;
  1008.     temp = spawnArgs.GetString( "switchToView" );
  1009.     switchToCamera = ( temp.Length() ) ? gameLocal.FindEntity( temp ) : NULL;
  1010.  
  1011. }
  1012.  
  1013. /*
  1014. ================
  1015. idTarget_SetInfluence::Event_Activate
  1016. ================
  1017. */
  1018. void idTarget_SetInfluence::Event_Activate( idEntity *activator ) {
  1019.     int i, j;
  1020.     idEntity *ent;
  1021.     idLight *light;
  1022.     idSound *sound;
  1023.     idStaticEntity *generic;
  1024.     const char *parm;
  1025.     const char *skin;
  1026.     bool update;
  1027.     idVec3 color;
  1028.     idVec4 colorTo;
  1029.     idPlayer *player;
  1030.  
  1031.     player = gameLocal.GetLocalPlayer();
  1032.  
  1033.     if ( spawnArgs.GetBool( "triggerActivate" ) ) {
  1034.         if ( restoreOnTrigger ) {
  1035.             ProcessEvent( &EV_RestoreInfluence );
  1036.             restoreOnTrigger = false;
  1037.             return;
  1038.         }
  1039.         restoreOnTrigger = true;
  1040.     }
  1041.  
  1042.     float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" );
  1043.  
  1044.     if ( delay > 0.0f ) {
  1045.         PostEventSec( &EV_Activate, delay, activator );
  1046.         delay = 0.0f;
  1047.         // start any sound fading now
  1048.         if ( fadeTime ) {
  1049.             soundSystem->FadeSoundClasses( SOUNDWORLD_GAME, 0, -40.0f, fadeTime );
  1050.             soundFaded = true;
  1051.         }
  1052.         return;
  1053.     } else if ( fadeTime && !soundFaded ) {
  1054.         soundSystem->FadeSoundClasses( SOUNDWORLD_GAME, 0, -40.0f, fadeTime );
  1055.         soundFaded = true;
  1056.     }
  1057.  
  1058.     if ( spawnArgs.GetBool( "triggerTargets" ) ) {
  1059.         ActivateTargets( activator );
  1060.     }
  1061.  
  1062.     if ( flashIn ) {
  1063.         PostEventSec( &EV_Flash, 0.0f, flashIn, 0 );
  1064.     }
  1065.  
  1066.     parm = spawnArgs.GetString( "snd_influence" );
  1067.     if ( parm && *parm ) {
  1068.         PostEventSec( &EV_StartSoundShader, flashIn, parm, SND_CHANNEL_ANY );
  1069.     }
  1070.  
  1071.     if ( switchToCamera ) {
  1072.         switchToCamera->PostEventSec( &EV_Activate, flashIn + 0.05f, this );
  1073.     }
  1074.  
  1075. // RAVEN BEGIN
  1076. // mekberg: allow for initial fov and both fovs.
  1077.     int fov = spawnArgs.GetInt( "fov" );
  1078.     int fovInitial = spawnArgs.GetInt( "fov_initial" );
  1079.     if ( fov && fovInitial) {
  1080.         fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "fovTime" ) ), fovInitial, fov );
  1081.         BecomeActive( TH_THINK );
  1082.     } else if ( fov ) {
  1083.         fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "fovTime" ) ), player->DefaultFov(), fov );
  1084.         BecomeActive( TH_THINK );
  1085.     } else if ( fovInitial ) {
  1086.         fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "fovTime" ) ), fovInitial, player->DefaultFov() );
  1087.         BecomeActive( TH_THINK );
  1088.     }
  1089. // RAVEN END
  1090.  
  1091.     for ( i = 0; i < genericList.Num(); i++ ) {
  1092.         ent = gameLocal.entities[genericList[i]];
  1093.         if ( ent == NULL ) {
  1094.             continue;
  1095.         }
  1096.         generic = static_cast<idStaticEntity*>( ent );
  1097.         color = generic->spawnArgs.GetVector( "color_demonic" );
  1098.         colorTo.Set( color.x, color.y, color.z, 1.0f );
  1099.         generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  1100.     }
  1101.  
  1102.     for ( i = 0; i < lightList.Num(); i++ ) {
  1103.         ent = gameLocal.entities[lightList[i]];
  1104. // RAVEN BEGIN
  1105. // jnewquist: Use accessor for static class type 
  1106.         if ( ent == NULL || !ent->IsType( idLight::GetClassType() ) ) {
  1107. // RAVEN END
  1108.             continue;
  1109.         }
  1110.         light = static_cast<idLight *>(ent);
  1111.         parm = light->spawnArgs.GetString( "mat_demonic" );
  1112.         if ( parm && *parm ) {
  1113.             light->SetShader( parm );
  1114.         }
  1115.         
  1116.         color = light->spawnArgs.GetVector( "_color" );
  1117.         color = light->spawnArgs.GetVector( "color_demonic", color.ToString() );
  1118.         colorTo.Set( color.x, color.y, color.z, 1.0f );
  1119.         light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  1120.     }
  1121.  
  1122.     for ( i = 0; i < soundList.Num(); i++ ) {
  1123.         ent = gameLocal.entities[soundList[i]];
  1124. // RAVEN BEGIN
  1125. // jnewquist: Use accessor for static class type 
  1126.         if ( ent == NULL || !ent->IsType( idSound::GetClassType() ) ) {
  1127. // RAVEN END
  1128.             continue;
  1129.         }
  1130.         sound = static_cast<idSound *>(ent);
  1131.         parm = sound->spawnArgs.GetString( "snd_demonic" );
  1132.         if ( parm && *parm ) {
  1133.             if ( sound->spawnArgs.GetBool( "overlayDemonic" ) ) {
  1134.                 sound->StartSound( "snd_demonic", SND_CHANNEL_DEMONIC, 0, false, NULL );
  1135.             } else {
  1136.                 sound->StopSound( SND_CHANNEL_ANY, false );
  1137.                 sound->SetSound( parm );
  1138.             }
  1139.         }
  1140.     }
  1141.  
  1142.     for ( i = 0; i < guiList.Num(); i++ ) {
  1143.         ent = gameLocal.entities[guiList[i]];
  1144.         if ( ent == NULL || ent->GetRenderEntity() == NULL ) {
  1145.             continue;
  1146.         }
  1147.         update = false;
  1148.         for ( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  1149.             if ( ent->GetRenderEntity()->gui[ j ] && ent->spawnArgs.FindKey( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j+1 ) ) ) {
  1150.                 ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j+1 ) ), true );
  1151.                 update = true;
  1152.             }
  1153.         }
  1154.         if ( update ) {
  1155.             ent->UpdateVisuals();
  1156.             ent->Present();
  1157.         }
  1158.     
  1159.     }
  1160.  
  1161.     player->SetInfluenceLevel( spawnArgs.GetInt( "influenceLevel" ) );
  1162.  
  1163.     int snapAngle = spawnArgs.GetInt( "snapAngle" );
  1164.     if ( snapAngle ) {
  1165.         idAngles ang( 0, snapAngle, 0 );
  1166.         player->SetViewAngles( ang );
  1167.         player->SetAngles( ang );
  1168.     }
  1169.  
  1170.     if ( spawnArgs.GetBool( "effect_vision" ) ) {
  1171.         parm = spawnArgs.GetString( "mtrVision" );
  1172.         skin = spawnArgs.GetString( "skinVision" );
  1173.         player->SetInfluenceView( parm, skin, spawnArgs.GetInt( "visionRadius" ), this ); 
  1174.     }
  1175.  
  1176.     parm = spawnArgs.GetString( "mtrWorld" );
  1177.     if ( parm && *parm ) {
  1178.         gameLocal.SetGlobalMaterial( declManager->FindMaterial( parm ) );
  1179.     }
  1180.  
  1181.     if ( !restoreOnTrigger ) {
  1182.         PostEventMS( &EV_RestoreInfluence, SEC2MS( spawnArgs.GetFloat( "time" ) ) );
  1183.     }
  1184. }
  1185.  
  1186. /*
  1187. ================
  1188. idTarget_SetInfluence::Think
  1189. ================
  1190. */
  1191. void idTarget_SetInfluence::Think( void ) {
  1192.     if ( thinkFlags & TH_THINK ) {
  1193.         idPlayer *player = gameLocal.GetLocalPlayer();
  1194.         player->SetInfluenceFov( fovSetting.GetCurrentValue( gameLocal.time ) );
  1195.         if ( fovSetting.IsDone( gameLocal.time ) ) {
  1196.             if ( !spawnArgs.GetBool( "leaveFOV" ) ) {
  1197.                 player->SetInfluenceFov( 0 );
  1198.             }
  1199.             BecomeInactive( TH_THINK );
  1200.         }
  1201.     } else {
  1202.         BecomeInactive( TH_ALL );
  1203.     }
  1204. }
  1205.  
  1206.  
  1207. /*
  1208. ================
  1209. idTarget_SetInfluence::Event_RestoreInfluence
  1210. ================
  1211. */
  1212. void idTarget_SetInfluence::Event_RestoreInfluence() {
  1213.     int i, j;
  1214.     idEntity *ent;
  1215.     idLight *light;
  1216.     idSound *sound;
  1217.     idStaticEntity *generic;
  1218.     bool update;
  1219.     idVec3 color;
  1220.     idVec4 colorTo;
  1221.  
  1222.     if ( flashOut ) {
  1223.         PostEventSec( &EV_Flash, 0.0f, flashOut, 1 );
  1224.     }
  1225.  
  1226.     if ( switchToCamera ) {
  1227.         switchToCamera->PostEventMS( &EV_Activate, 0.0f, this );
  1228.     }
  1229.  
  1230.     for ( i = 0; i < genericList.Num(); i++ ) {
  1231.         ent = gameLocal.entities[genericList[i]];
  1232.         if ( ent == NULL ) {
  1233.             continue;
  1234.         }
  1235.         generic = static_cast<idStaticEntity*>( ent );
  1236.         colorTo.Set( 1.0f, 1.0f, 1.0f, 1.0f );
  1237.         generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  1238.     }
  1239.  
  1240.     for ( i = 0; i < lightList.Num(); i++ ) {
  1241.         ent = gameLocal.entities[lightList[i]];
  1242. // RAVEN BEGIN
  1243. // jnewquist: Use accessor for static class type 
  1244.         if ( ent == NULL || !ent->IsType( idLight::GetClassType() ) ) {
  1245. // RAVEN END
  1246.             continue;
  1247.         }
  1248.         light = static_cast<idLight *>(ent);
  1249.         if ( !light->spawnArgs.GetBool( "leave_demonic_mat" ) ) {
  1250.             const char *texture = light->spawnArgs.GetString( "texture", "lights/squarelight1" );
  1251.             light->SetShader( texture );
  1252.         }
  1253.         color = light->spawnArgs.GetVector( "_color" );
  1254.         colorTo.Set( color.x, color.y, color.z, 1.0f );
  1255.         light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  1256.     }
  1257.  
  1258.     for ( i = 0; i < soundList.Num(); i++ ) {
  1259.         ent = gameLocal.entities[soundList[i]];
  1260. // RAVEN BEGIN
  1261. // jnewquist: Use accessor for static class type 
  1262.         if ( ent == NULL || !ent->IsType( idSound::GetClassType() ) ) {
  1263. // RAVEN END
  1264.             continue;
  1265.         }
  1266.         sound = static_cast<idSound *>(ent);
  1267.         sound->StopSound( SND_CHANNEL_ANY, false );
  1268.         sound->SetSound( sound->spawnArgs.GetString( "s_shader" ) );
  1269.     }
  1270.  
  1271.     for ( i = 0; i < guiList.Num(); i++ ) {
  1272.         ent = gameLocal.entities[guiList[i]];
  1273.         if ( ent == NULL || GetRenderEntity() == NULL ) {
  1274.             continue;
  1275.         }
  1276.         update = false;
  1277.         for( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  1278.             if ( ent->GetRenderEntity()->gui[ j ] ) {
  1279.                 ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui" : va( "gui%d", j+1 ) ) );
  1280.                 update = true;
  1281.             }
  1282.         }
  1283.         if ( update ) {
  1284.             ent->UpdateVisuals();
  1285.             ent->Present();
  1286.         }
  1287.     }
  1288.  
  1289.     idPlayer *player = gameLocal.GetLocalPlayer();
  1290.     player->SetInfluenceLevel( 0 );
  1291.     player->SetInfluenceView( NULL, NULL, 0.0f, NULL );
  1292.     player->SetInfluenceFov( 0 );
  1293.     gameLocal.SetGlobalMaterial( NULL );
  1294.     float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" );
  1295.     if ( fadeTime ) {
  1296.         soundSystem->FadeSoundClasses( SOUNDWORLD_GAME, 0, 0.0f, fadeTime / 2.0f );
  1297.     }
  1298.  
  1299. }
  1300.  
  1301. /*
  1302. ===============================================================================
  1303.  
  1304. idTarget_SetKeyVal
  1305.  
  1306. ===============================================================================
  1307. */
  1308.  
  1309. CLASS_DECLARATION( idTarget, idTarget_SetKeyVal )
  1310.     EVENT( EV_Activate,    idTarget_SetKeyVal::Event_Activate )
  1311. END_CLASS
  1312.  
  1313. /*
  1314. ================
  1315. idTarget_SetKeyVal::Event_Activate
  1316. ================
  1317. */
  1318. void idTarget_SetKeyVal::Event_Activate( idEntity *activator ) {
  1319.     int i;
  1320.     idStr key, val;
  1321.     idEntity *ent;
  1322.     const idKeyValue *kv;
  1323.     int n;
  1324.  
  1325.     for( i = 0; i < targets.Num(); i++ ) {
  1326.         ent = targets[ i ].GetEntity();
  1327.         if ( ent ) {
  1328.             kv = spawnArgs.MatchPrefix("keyval");
  1329.             while ( kv ) {
  1330.                 n = kv->GetValue().Find( ";" );
  1331.                 if ( n > 0 ) {
  1332.                     key = kv->GetValue().Left( n );
  1333.                     val = kv->GetValue().Right( kv->GetValue().Length() - n - 1 );
  1334.                     ent->spawnArgs.Set( key, val );
  1335.                     for ( int j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  1336.                         if ( ent->GetRenderEntity()->gui[ j ] ) {
  1337.                             if ( idStr::Icmpn( key, "gui_", 4 ) == 0 ) {
  1338.                                 ent->GetRenderEntity()->gui[ j ]->SetStateString( key, val );
  1339.                                 ent->GetRenderEntity()->gui[ j ]->StateChanged( gameLocal.time );
  1340.                             }
  1341.                         }
  1342.                     }
  1343.                 }
  1344.                 kv = spawnArgs.MatchPrefix( "keyval", kv );
  1345.             }
  1346.             ent->UpdateChangeableSpawnArgs( NULL );
  1347.             ent->UpdateVisuals();
  1348.             ent->Present();
  1349.         }
  1350.     }
  1351. }
  1352.  
  1353. /*
  1354. ===============================================================================
  1355.  
  1356. idTarget_SetFov
  1357.  
  1358. ===============================================================================
  1359. */
  1360.  
  1361. CLASS_DECLARATION( idTarget, idTarget_SetFov )
  1362.     EVENT( EV_Activate,    idTarget_SetFov::Event_Activate )
  1363. END_CLASS
  1364.  
  1365.  
  1366. /*
  1367. ================
  1368. idTarget_SetFov::Save
  1369. ================
  1370. */
  1371. void idTarget_SetFov::Save( idSaveGame *savefile ) const {
  1372.  
  1373.     savefile->WriteFloat( fovSetting.GetStartTime() );
  1374.     savefile->WriteFloat( fovSetting.GetDuration() );
  1375.     savefile->WriteFloat( fovSetting.GetStartValue() );
  1376.     savefile->WriteFloat( fovSetting.GetEndValue() );
  1377. }
  1378.  
  1379. /*
  1380. ================
  1381. idTarget_SetFov::Restore
  1382. ================
  1383. */
  1384. void idTarget_SetFov::Restore( idRestoreGame *savefile ) {
  1385.     float setting;
  1386.  
  1387.     savefile->ReadFloat( setting );
  1388.     fovSetting.SetStartTime( setting );
  1389.     savefile->ReadFloat( setting );
  1390.     fovSetting.SetDuration( setting );
  1391.     savefile->ReadFloat( setting );
  1392.     fovSetting.SetStartValue( setting );
  1393.     savefile->ReadFloat( setting );
  1394.     fovSetting.SetEndValue( setting );
  1395.  
  1396.     fovSetting.GetCurrentValue( gameLocal.time );
  1397. }
  1398.  
  1399. /*
  1400. ================
  1401. idTarget_SetFov::Event_Activate
  1402. ================
  1403. */
  1404. void idTarget_SetFov::Event_Activate( idEntity *activator ) {
  1405.     // always allow during cinematics
  1406.     cinematic = true;
  1407.  
  1408.     idPlayer *player = gameLocal.GetLocalPlayer();
  1409.     fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "time" ) ), player ? player->DefaultFov() : g_fov.GetFloat(), spawnArgs.GetFloat( "fov" ) );
  1410.     BecomeActive( TH_THINK );
  1411. }
  1412.  
  1413. /*
  1414. ================
  1415. idTarget_SetFov::Think
  1416. ================
  1417. */
  1418. void idTarget_SetFov::Think( void ) {
  1419.     if ( thinkFlags & TH_THINK ) {
  1420.         idPlayer *player = gameLocal.GetLocalPlayer();
  1421.         player->SetInfluenceFov( fovSetting.GetCurrentValue( gameLocal.time ) );
  1422.         if ( fovSetting.IsDone( gameLocal.time ) ) {
  1423.             player->SetInfluenceFov( 0.0f );
  1424.             BecomeInactive( TH_THINK );
  1425.         }
  1426.     } else {
  1427.         BecomeInactive( TH_ALL );
  1428.     }
  1429. }
  1430.  
  1431.  
  1432. /*
  1433. ===============================================================================
  1434.  
  1435. idTarget_SetPrimaryObjective
  1436.  
  1437. ===============================================================================
  1438. */
  1439.  
  1440. CLASS_DECLARATION( idTarget, idTarget_SetPrimaryObjective )
  1441.     EVENT( EV_Activate,    idTarget_SetPrimaryObjective::Event_Activate )
  1442. END_CLASS
  1443.  
  1444. /*
  1445. ================
  1446. idTarget_SetPrimaryObjective::Event_Activate
  1447. ================
  1448. */
  1449. void idTarget_SetPrimaryObjective::Event_Activate( idEntity *activator ) {
  1450.     idPlayer *player = gameLocal.GetLocalPlayer();
  1451.     if ( player && player->objectiveSystem ) {
  1452.         player->objectiveSystem->SetStateString( "missionobjective", spawnArgs.GetString( "text", common->GetLocalizedString( "#str_104253" ) ) );
  1453.     }
  1454. }
  1455.  
  1456. // RAVEN BEGIN
  1457. // bdube: added database entry trigger
  1458. // twhitaker: removed database entry trigger
  1459. /*
  1460. ===============================================================================
  1461.  
  1462. rvTarget_AddDatabaseEntry
  1463.  
  1464. ===============================================================================
  1465. */
  1466. /*
  1467. CLASS_DECLARATION( idTarget, rvTarget_AddDatabaseEntry )
  1468.     EVENT( EV_Activate,    rvTarget_AddDatabaseEntry::Event_Activate )
  1469. END_CLASS
  1470. */
  1471. /*
  1472. ================
  1473. rvTarget_AddDatabaseEntry::Event_Activate
  1474. ================
  1475. */
  1476. /*void rvTarget_AddDatabaseEntry::Event_Activate( idEntity *activator ) {
  1477.     idPlayer *player = gameLocal.GetLocalPlayer();
  1478.     if ( player ) { 
  1479.         player->GiveDatabaseEntry ( gameLocal.FindEntityDefDict ( spawnArgs.GetString ( "def_db", "" ) ) );
  1480.     }
  1481. }
  1482. */
  1483. // jshepard: secret area trigger
  1484. /*
  1485. ===============================================================================
  1486.  
  1487. rvTarget_SecretArea
  1488.  
  1489. ===============================================================================
  1490. */
  1491.  
  1492. CLASS_DECLARATION( idTarget, rvTarget_SecretArea )
  1493.     EVENT( EV_Activate,    rvTarget_SecretArea::Event_Activate )
  1494. END_CLASS
  1495.  
  1496. /*
  1497. ================
  1498. rvTarget_SecretArea::Event_Activate
  1499. ================
  1500. */
  1501. void rvTarget_SecretArea::Event_Activate( idEntity *activator ) {
  1502.     idPlayer *player = gameLocal.GetLocalPlayer();
  1503.     if ( player ) { 
  1504.         player->DiscoverSecretArea( spawnArgs.GetString ( "description" ));
  1505.     }
  1506. }
  1507.  
  1508. /*
  1509. ===============================================================================
  1510.  
  1511. rvTarget_BossBattle
  1512.  
  1513. ===============================================================================
  1514. */
  1515.  
  1516. const idEventDef EV_SetShieldPercent( "setShieldPercent", "f" );
  1517. const idEventDef EV_SetBossMaxHealth( "setMaxBossHealth", "f" );
  1518. const idEventDef EV_AllowShieldBar( "allowShieldBar", "f" );
  1519. const idEventDef EV_AllowShieldWarningBar( "allowShieldWarnBar", "f" );
  1520.  
  1521.  
  1522. CLASS_DECLARATION( idTarget, rvTarget_BossBattle )
  1523.     EVENT( EV_Activate,    rvTarget_BossBattle::Event_Activate )
  1524.     EVENT( EV_SetShieldPercent, rvTarget_BossBattle::Event_SetShieldPercent )
  1525.     EVENT( EV_SetBossMaxHealth, rvTarget_BossBattle::Event_SetBossMaxHealth )
  1526.     EVENT( EV_AllowShieldBar, rvTarget_BossBattle::Event_AllowShieldBar )
  1527.     EVENT( EV_AllowShieldWarningBar, rvTarget_BossBattle::Event_AllowShieldWarningBar )
  1528. END_CLASS
  1529.  
  1530. /*
  1531. ================
  1532. rvTarget_BossBattle::Event_Activate
  1533. ================
  1534. */
  1535. void rvTarget_BossBattle::Event_Activate( idEntity *activator ) {
  1536.     idPlayer* player = gameLocal.GetLocalPlayer();
  1537.     idEntity* enemy  = gameLocal.FindEntity ( spawnArgs.GetString ( "target" ) );
  1538.     if ( player && enemy ) { 
  1539.         player->StartBossBattle ( enemy );
  1540.     }
  1541.     
  1542.     StartSound ( "snd_activate", SND_CHANNEL_ANY, 0, false, NULL );
  1543. }
  1544.  
  1545.  
  1546. /*
  1547. ================
  1548. rvTarget_BossBattle::Event_AllowShieldBar
  1549. ================
  1550. */
  1551. void rvTarget_BossBattle::Event_AllowShieldBar( float activate )
  1552. {
  1553.     idUserInterface *hud = gameLocal.GetLocalPlayer()->GetHud();
  1554.     if ( hud ) 
  1555.     {
  1556.         if( activate )    {
  1557.             hud->HandleNamedEvent( "showBossShieldBar" );
  1558.             hud->HandleNamedEvent( "updateBossShield" );
  1559.         } else {
  1560.             hud->HandleNamedEvent( "hideBossShieldBar" );
  1561.         }
  1562.     }
  1563. }
  1564.  
  1565. /*
  1566. ================
  1567. rvTarget_BossBattle::Event_AllowShieldWarningBar
  1568. ================
  1569. */
  1570. void rvTarget_BossBattle::Event_AllowShieldWarningBar( float activate )
  1571. {
  1572.     idUserInterface *hud = gameLocal.GetLocalPlayer()->GetHud();
  1573.     if ( hud ) 
  1574.     {
  1575.         if( activate )    {
  1576.             hud->HandleNamedEvent( "showBossShieldWarn" );
  1577.             hud->HandleNamedEvent( "updateBossShield" );
  1578.         } else {
  1579.             hud->HandleNamedEvent( "hideBossShieldWarn" );
  1580.         }
  1581.     }
  1582. }
  1583.  
  1584. /*
  1585. ================
  1586. rvTarget_BossBattle::Event_SetShieldPercent
  1587. ================
  1588. */
  1589. void rvTarget_BossBattle::Event_SetShieldPercent( float percent ) {
  1590.  
  1591.     idUserInterface *hud = gameLocal.GetLocalPlayer()->GetHud();
  1592.     if ( hud ) 
  1593.     {
  1594.         hud->SetStateFloat( "boss_shield_percent", percent );
  1595.         hud->HandleNamedEvent( "updateBossShield" );
  1596.     }
  1597. }
  1598.  
  1599. /*
  1600. ================
  1601. rvTarget_BossBattle::Event_SetMaxBossHealth
  1602. ================
  1603. */
  1604. void rvTarget_BossBattle::Event_SetBossMaxHealth( float f ) {
  1605.  
  1606.     idUserInterface *hud = gameLocal.GetLocalPlayer()->GetHud();
  1607.     if ( hud ) 
  1608.     {
  1609.  
  1610.         hud->SetStateInt ( "boss_maxhealth",f );
  1611.     }
  1612. }
  1613.  
  1614. /*
  1615. ===============================================================================
  1616.  
  1617. rvTarget_LaunchProjectile
  1618.  
  1619. ===============================================================================
  1620. */
  1621.  
  1622. const idEventDef EV_LaunchProjectile( "launchProjectile", "e" );
  1623. CLASS_DECLARATION( idTarget, rvTarget_LaunchProjectile )
  1624.     EVENT( EV_Activate,    rvTarget_LaunchProjectile::Event_Activate )
  1625.     EVENT( EV_LaunchProjectile,    rvTarget_LaunchProjectile::Event_LaunchProjectile )
  1626. END_CLASS
  1627.  
  1628. /*
  1629. ================
  1630. rvTarget_LaunchProjectile::Spawn
  1631. ================
  1632. */
  1633. void rvTarget_LaunchProjectile::Spawn( void ) {
  1634.     if ( spawnArgs.GetBool( "start_on" ) ) {
  1635.         PostEventMS( &EV_Activate, 0, this );
  1636.     }
  1637. }
  1638.  
  1639. /*
  1640. ================
  1641. rvTarget_LaunchProjectile::Event_LaunchProjectile
  1642. ================
  1643. */
  1644. void rvTarget_LaunchProjectile::Event_LaunchProjectile( idEntity *activator ) {
  1645.     const idDict*    projectileDict;
  1646.     idEntity*        ent;
  1647.  
  1648.     projectileDict = gameLocal.FindEntityDefDict ( spawnArgs.GetString ( "def_projectile" ), false );
  1649.     if ( !projectileDict ) {
  1650.         gameLocal.Error ( "Could not find entityDef '%s' for launch projectile target '%s'", spawnArgs.GetString ( "def_projectile" ), GetName() );
  1651.     }
  1652.     
  1653.     gameLocal.SpawnEntityDef( *projectileDict, &ent, false );
  1654.     if ( !ent ) {
  1655.         gameLocal.Error( "Could not spawn entityDef '%s'", projectileDict->GetString( "classname" ) );
  1656.     }
  1657.             
  1658.     if ( !ent->IsType( idProjectile::GetClassType() ) ) {
  1659.         gameLocal.Error( "'%s' is not an idProjectile", ent->GetClassname() );
  1660.     }    
  1661.     
  1662.     idVec3 dir;
  1663.     if ( targets.Num ( ) && targets[0] ) {
  1664.         dir = targets[0]->GetPhysics()->GetOrigin() - GetPhysics()->GetOrigin();
  1665.         dir.Normalize();
  1666.     } else {
  1667.         dir = GetPhysics()->GetAxis()[0];
  1668.     }
  1669.  
  1670.     idProjectile* proj = static_cast<idProjectile*>(ent);
  1671.  
  1672.     proj->Create( this, GetPhysics()->GetOrigin(), dir, this );
  1673.     proj->Launch( GetPhysics()->GetOrigin(), dir, GetPhysics()->GetLinearVelocity(), 0.0f, 1.0f );
  1674.     
  1675.     
  1676.     if ( targets.Num() && proj->IsType ( idGuidedProjectile::GetClassType ( ) ) ) {
  1677.         static_cast<idGuidedProjectile*>(proj)->GuideTo ( targets[0] );
  1678.     }
  1679.  
  1680.     if ( spawnArgs.GetFloat( "loop_interval" ) )
  1681.     {
  1682.         PostEventSec( &EV_Activate, spawnArgs.GetFloat( "loop_interval" ), activator );
  1683.     }
  1684. }
  1685.  
  1686. /*
  1687. ================
  1688. rvTarget_LaunchProjectile::Event_Activate
  1689. ================
  1690. */
  1691. void rvTarget_LaunchProjectile::Event_Activate( idEntity *activator ) {
  1692.     
  1693.     idVec3 dir;
  1694.     if ( targets.Num ( ) && targets[0] ) {
  1695.         dir = targets[0]->GetPhysics()->GetOrigin() - GetPhysics()->GetOrigin();
  1696.         dir.Normalize();
  1697.     } else {
  1698.         dir = GetPhysics()->GetAxis()[0];
  1699.     }
  1700.  
  1701.     if ( spawnArgs.GetString( "fx_launch", NULL ) )
  1702.     {
  1703.         gameLocal.PlayEffect( gameLocal.GetEffect( spawnArgs, "fx_launch" ), GetPhysics()->GetOrigin(), dir.ToMat3() );
  1704.     }
  1705.  
  1706.     if ( spawnArgs.GetFloat( "delay" ) )
  1707.     {
  1708.         PostEventSec( &EV_LaunchProjectile, spawnArgs.GetFloat( "delay" ), activator );
  1709.         return;
  1710.     }
  1711.     ProcessEvent( &EV_LaunchProjectile, activator );
  1712. }
  1713.  
  1714. /*
  1715. ===============================================================================
  1716.  
  1717. rvTarget_ExitArea
  1718.  
  1719. ===============================================================================
  1720. */
  1721.  
  1722. CLASS_DECLARATION( idTarget, rvTarget_ExitAreaAlert )
  1723.     EVENT( EV_Activate,    rvTarget_ExitAreaAlert::Event_Activate )
  1724. END_CLASS
  1725.  
  1726. void rvTarget_ExitAreaAlert::Event_Activate( idEntity *activator )    {
  1727.     gameLocal.UpdateEndLevel();
  1728. }
  1729.  
  1730. /*
  1731. ===============================================================================
  1732.  
  1733. rvTarget_AmmoStash
  1734.  
  1735. ===============================================================================
  1736. */
  1737.  
  1738. int CompareAmmoData( const void* ammo1, const void* ammo2)    {
  1739.     if ((( ammodata_t *)ammo2)->percentFull > (( ammodata_t *)ammo1)->percentFull )    {
  1740.         return -1;
  1741.     } else    {
  1742.         return 1;
  1743.     }
  1744. }
  1745.  
  1746. CLASS_DECLARATION( idTarget, rvTarget_AmmoStash )
  1747.     EVENT( EV_Activate,    rvTarget_AmmoStash::Event_Activate )
  1748. END_CLASS
  1749.  
  1750. void rvTarget_AmmoStash::Event_Activate( idEntity *activator )    {
  1751.  
  1752.     const idKeyValue*    kv;
  1753.     idPlayer*            player;
  1754.     int                    typeCount;
  1755.     idEntity*            entAmmo;
  1756.     idItem*                item;
  1757.     idDict                args;
  1758.  
  1759.  
  1760.     player = gameLocal.GetLocalPlayer();
  1761.  
  1762.     //set up the array
  1763.     memset( AmmoArray, 0, sizeof( ammodata_t) * AMMO_ARRAY_SIZE);
  1764.     for( int t= 0; t < AMMO_ARRAY_SIZE; t++)    {
  1765.         AmmoArray[ t ].percentFull = 2.0f;
  1766.     }
  1767.  
  1768.     // we only check for certain types of ammo.
  1769.     kv = spawnArgs.MatchPrefix ( "def_ammo", NULL );
  1770.     if ( kv ) {
  1771.         kv->GetValue();
  1772.         for ( typeCount = 0; typeCount < AMMO_ARRAY_SIZE && kv; kv = spawnArgs.MatchPrefix ( "def_ammo", kv ) ) {
  1773.  
  1774.             AmmoArray[ typeCount ].ammoName = kv->GetValue();
  1775.             AmmoArray[ typeCount ].ammoIndex = player->inventory.AmmoIndexForAmmoClass( AmmoArray[ typeCount ].ammoName.c_str() );
  1776.  
  1777.             //check and see how much ammo this weapon can hold...
  1778.             AmmoArray[ typeCount ].ammoMax = player->inventory.MaxAmmoForAmmoClass( player, AmmoArray[ typeCount ].ammoName.c_str() );
  1779.         
  1780.             //and the current amount
  1781.             AmmoArray[ typeCount ].ammoCount = player->inventory.HasAmmo( AmmoArray[ typeCount ].ammoIndex, 1);
  1782.  
  1783.             if( AmmoArray[ typeCount ].ammoMax > 0)    {
  1784.                 AmmoArray[ typeCount ].percentFull = float( AmmoArray[ typeCount ].ammoCount / AmmoArray[ typeCount ].ammoMax );
  1785.             } else    {
  1786.                 AmmoArray[ typeCount ].percentFull = 2.0f;
  1787.             }
  1788.             
  1789.             //increment
  1790.             typeCount++;
  1791.         }
  1792.         
  1793.     } else {
  1794.         gameLocal.Warning("Bad ammo data on rvTarget_AmmoStash '%s'", this->GetName());
  1795.         return;
  1796.     }
  1797.  
  1798.     //TEMP: print out the ammo counts
  1799.     //for( int t= 0; t < AMMO_ARRAY_SIZE; t++)    {
  1800.     //    gameLocal.Printf("Ammo %d is %s and %f full\n", t, AmmoArray[ t ].ammoName.c_str(), AmmoArray[ t].percentFull);
  1801.     //}
  1802.     
  1803.     //sort the types of ammo by need. The most-needed ammo will be placed.
  1804.     qsort( ( void * )AmmoArray, AMMO_ARRAY_SIZE ,sizeof( ammodata_t), CompareAmmoData );                        
  1805.  
  1806.     //TEMP: print out the ammo counts
  1807.     //gameLocal.Printf("--------------------------------\nresorting\n--------------------------------\n" );
  1808.     //for( int t= 0; t < AMMO_ARRAY_SIZE; t++)    {
  1809.     //    gameLocal.Printf("Ammo %d is %s and %f full\n", t, AmmoArray[ t ].ammoName.c_str(), AmmoArray[ t].percentFull);
  1810.     //}    
  1811.  
  1812.     int i;
  1813.     //run through our targets until we have no more targets.
  1814.     for ( i = targets.Num() - 1; i >= 0; i -- ) {
  1815.         idEntity* ent;
  1816.         ent = targets[i];
  1817.         if ( idStr::Icmp ( ent->spawnArgs.GetString ( "classname" ), "target_null" ) ) {
  1818.             continue;
  1819.         }
  1820.     
  1821.         //drop the most needed ammo at ent's location.
  1822.         args.Set       ( "origin",            ent->GetPhysics()->GetOrigin().ToString() );
  1823.         args.SetFloat  ( "angle",            ent->GetPhysics()->GetAxis().ToAngles()[YAW] );
  1824.         args.Set       ( "classname",        AmmoArray[ 0 ].ammoName );    
  1825.  
  1826.         gameLocal.SpawnEntityDef ( args, &entAmmo );
  1827.         
  1828.         //now assume that the item was picked up.
  1829.         item = static_cast< idItem* >(entAmmo);        
  1830.         kv = entAmmo->spawnArgs.MatchPrefix ( "inv_ammo", NULL );
  1831.         
  1832.         if( kv )    {
  1833.             
  1834.             //add the ammo as if the player picked it up
  1835.             AmmoArray[ 0 ].ammoCount +=  atoi(kv->GetValue().c_str());
  1836.             AmmoArray[ 0 ].percentFull = (float)AmmoArray[ 0 ].ammoCount / (float)AmmoArray[ 0 ].ammoMax;
  1837.  
  1838.             //resort the ammo.
  1839.             qsort( ( void * )AmmoArray, AMMO_ARRAY_SIZE ,sizeof( ammodata_t), CompareAmmoData );        
  1840.  
  1841.             
  1842.             //TEMP: print out the ammo counts
  1843.             //gameLocal.Printf("--------------------------------\nresorting\n--------------------------------\n" );
  1844.             //for( int t= 0; t < AMMO_ARRAY_SIZE; t++)    {
  1845.             //    gameLocal.Printf("Ammo %d is %s and %f full\n", t, AmmoArray[ t ].ammoName.c_str(), AmmoArray[ t].percentFull);
  1846.             //}                
  1847.         } else {
  1848.             gameLocal.Warning("Bad ammo data on target_ammostash '%s'", this->GetName());
  1849.             return;
  1850.         }
  1851.     }    
  1852.  
  1853. }
  1854.  
  1855. /*
  1856. ===============================================================================
  1857.  
  1858. rvTarget_TetherAI
  1859.  
  1860. ===============================================================================
  1861. */
  1862.  
  1863. CLASS_DECLARATION( idTarget, rvTarget_TetherAI )
  1864.     EVENT( EV_Activate,    rvTarget_TetherAI::Event_Activate )
  1865. END_CLASS
  1866.  
  1867. /*
  1868. ================
  1869. rvTarget_TetherAI::Event_Activate
  1870. ================
  1871. */
  1872. void rvTarget_TetherAI::Event_Activate( idEntity *activator ) {
  1873.     int i;
  1874.     if ( activator->IsType ( idAI::GetClassType() ) ) {
  1875.         activator->ProcessEvent ( &EV_Activate, this );
  1876.     }
  1877.     
  1878.     // All targetted AI will be activated with the tether AI entity
  1879.     for ( i = 0; i < targets.Num(); i ++ ) {
  1880.         if ( !targets[i] ) {
  1881.             continue;
  1882.         }
  1883.         if ( targets[i]->IsType ( idAI::GetClassType() ) ) {
  1884.             targets[i]->ProcessEvent ( &EV_Activate, this );
  1885.         }
  1886.     }            
  1887. }
  1888. /*
  1889. ===============================================================================
  1890.  
  1891. rvTarget_Nailable
  1892.  
  1893. ===============================================================================
  1894. */
  1895.  
  1896. CLASS_DECLARATION( idTarget, rvTarget_Nailable )
  1897. END_CLASS
  1898. void rvTarget_Nailable::Spawn() {
  1899.  
  1900.     //InitDefaultPhysics( origin, axis );
  1901.  
  1902. //    int contents = GetPhysics()->GetContents();
  1903. //    contents &= CONTENTS_BODY;
  1904. //    contents &= CONTENTS_SOLID;
  1905.     GetPhysics()->SetContents( MASK_SHOT_BOUNDINGBOX );
  1906.  
  1907. }
  1908.  
  1909. // RAVEN END
  1910.  
  1911. /*
  1912. ===============================================================================
  1913.  
  1914. idTarget_LockDoor
  1915.  
  1916. ===============================================================================
  1917. */
  1918.  
  1919. CLASS_DECLARATION( idTarget, idTarget_LockDoor )
  1920.     EVENT( EV_Activate,    idTarget_LockDoor::Event_Activate )
  1921. END_CLASS
  1922.  
  1923. /*
  1924. ================
  1925. idTarget_LockDoor::Event_Activate
  1926. ================
  1927. */
  1928. void idTarget_LockDoor::Event_Activate( idEntity *activator ) {
  1929.     int i;
  1930.     idEntity *ent;
  1931.     int lock;
  1932.  
  1933.     lock = spawnArgs.GetInt( "locked", "1" );
  1934.     for( i = 0; i < targets.Num(); i++ ) {
  1935.         ent = targets[ i ].GetEntity();
  1936. // RAVEN BEGIN
  1937. // jnewquist: Use accessor for static class type 
  1938.         if ( ent && ent->IsType( idDoor::GetClassType() ) ) {
  1939. // RAVEN END
  1940.             if ( static_cast<idDoor *>( ent )->IsLocked() ) {
  1941.                 static_cast<idDoor *>( ent )->Lock( 0 );
  1942.             } else {
  1943.                 static_cast<idDoor *>( ent )->Lock( lock );
  1944.             }
  1945.         }
  1946.     }
  1947. }
  1948.  
  1949. /*
  1950. ===============================================================================
  1951.  
  1952. idTarget_CallObjectFunction
  1953.  
  1954. ===============================================================================
  1955. */
  1956.  
  1957. CLASS_DECLARATION( idTarget, idTarget_CallObjectFunction )
  1958.     EVENT( EV_Activate,    idTarget_CallObjectFunction::Event_Activate )
  1959. END_CLASS
  1960.  
  1961. /*
  1962. ================
  1963. idTarget_CallObjectFunction::Event_Activate
  1964. ================
  1965. */
  1966. void idTarget_CallObjectFunction::Event_Activate( idEntity *activator ) {
  1967.     int                    i;
  1968.     idEntity            *ent;
  1969.     const function_t    *func;
  1970.     const char            *funcName;
  1971.     idThread            *thread;
  1972.  
  1973.     funcName = spawnArgs.GetString( "call" );
  1974.     for( i = 0; i < targets.Num(); i++ ) {
  1975.         ent = targets[ i ].GetEntity();
  1976.         if ( ent && ent->scriptObject.HasObject() ) {
  1977.             func = ent->scriptObject.GetFunction( funcName );
  1978.             if ( !func ) {
  1979.                 gameLocal.Error( "Function '%s' not found on entity '%s' for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
  1980.             }
  1981.             if ( func->type->NumParameters() != 1 ) {
  1982.                 gameLocal.Error( "Function '%s' on entity '%s' has the wrong number of parameters for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
  1983.             }
  1984.             if ( !ent->scriptObject.GetTypeDef()->Inherits( func->type->GetParmType( 0 ) ) ) {
  1985.                 gameLocal.Error( "Function '%s' on entity '%s' is the wrong type for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
  1986.             }
  1987.             // create a thread and call the function
  1988. // RAVEN BEGIN
  1989. // mwhitlock: Dynamic memory consolidation
  1990.             RV_PUSH_HEAP_MEM(this);
  1991. // RAVEN END
  1992.             thread = new idThread();
  1993. // RAVEN BEGIN
  1994. // mwhitlock: Dynamic memory consolidation
  1995.             RV_POP_HEAP();
  1996. // RAVEN END
  1997.             thread->CallFunction( ent, func, true );
  1998.             thread->Start();
  1999.         }
  2000.     }
  2001. }
  2002.  
  2003.  
  2004. /*
  2005. ===============================================================================
  2006.  
  2007. idTarget_EnableLevelWeapons
  2008.  
  2009. ===============================================================================
  2010. */
  2011.  
  2012. CLASS_DECLARATION( idTarget, idTarget_EnableLevelWeapons )
  2013.     EVENT( EV_Activate,    idTarget_EnableLevelWeapons::Event_Activate )
  2014. END_CLASS
  2015.  
  2016. /*
  2017. ================
  2018. idTarget_EnableLevelWeapons::Event_Activate
  2019. ================
  2020. */
  2021. void idTarget_EnableLevelWeapons::Event_Activate( idEntity *activator ) {
  2022.     int i;
  2023.     const char *weap;
  2024.  
  2025.     gameLocal.world->spawnArgs.SetBool( "no_Weapons", spawnArgs.GetBool( "disable" ) );
  2026.  
  2027.     if ( spawnArgs.GetBool( "disable" ) ) {
  2028.         for( i = 0; i < gameLocal.numClients; i++ ) {
  2029.             if ( gameLocal.entities[ i ] ) {
  2030.                 gameLocal.entities[ i ]->ProcessEvent( &EV_Player_DisableWeapon );
  2031.             }
  2032.         }
  2033.     } else {
  2034.         weap = spawnArgs.GetString( "weapon" );
  2035.         for( i = 0; i < gameLocal.numClients; i++ ) {
  2036.             if ( gameLocal.entities[ i ] ) {
  2037.                 gameLocal.entities[ i ]->ProcessEvent( &EV_Player_EnableWeapon );
  2038.                 if ( weap && weap[ 0 ] ) {
  2039.                     gameLocal.entities[ i ]->PostEventSec( &EV_Player_SelectWeapon, 0.5f, weap );
  2040.                 }
  2041.             }
  2042.         }
  2043.     }
  2044. }
  2045.  
  2046. /*
  2047. ===============================================================================
  2048.  
  2049. idTarget_Tip
  2050.  
  2051. ===============================================================================
  2052. */
  2053.  
  2054. const idEventDef EV_TipOff( "<TipOff>" );
  2055. extern const idEventDef EV_GetPlayerPos( "<getplayerpos>" );
  2056.  
  2057. CLASS_DECLARATION( idTarget, idTarget_Tip )
  2058.     EVENT( EV_Activate,        idTarget_Tip::Event_Activate )
  2059.     EVENT( EV_TipOff,        idTarget_Tip::Event_TipOff )
  2060.     EVENT( EV_GetPlayerPos,    idTarget_Tip::Event_GetPlayerPos )
  2061. END_CLASS
  2062.  
  2063.  
  2064. /*
  2065. ================
  2066. idTarget_Tip::idTarget_Tip
  2067. ================
  2068. */
  2069. idTarget_Tip::idTarget_Tip( void ) {
  2070.     playerPos.Zero();
  2071. }
  2072.  
  2073. /*
  2074. ================
  2075. idTarget_Tip::Spawn
  2076. ================
  2077. */
  2078. void idTarget_Tip::Spawn( void ) {
  2079. }
  2080.  
  2081. /*
  2082. ================
  2083. idTarget_Tip::Save
  2084. ================
  2085. */
  2086. void idTarget_Tip::Save( idSaveGame *savefile ) const {
  2087.     savefile->WriteVec3( playerPos );
  2088. }
  2089.  
  2090. /*
  2091. ================
  2092. idTarget_Tip::Restore
  2093. ================
  2094. */
  2095. void idTarget_Tip::Restore( idRestoreGame *savefile ) {
  2096.     savefile->ReadVec3( playerPos );
  2097. }
  2098.  
  2099. /*
  2100. ================
  2101. idTarget_Tip::Event_Activate
  2102. ================
  2103. */
  2104. void idTarget_Tip::Event_GetPlayerPos( void ) {
  2105.     idPlayer *player = gameLocal.GetLocalPlayer();
  2106.     if ( player ) {
  2107.         playerPos = player->GetPhysics()->GetOrigin();
  2108.         PostEventMS( &EV_TipOff, 100 );
  2109.     }
  2110. }
  2111.  
  2112. /*
  2113. ================
  2114. idTarget_Tip::Event_Activate
  2115. ================
  2116. */
  2117. void idTarget_Tip::Event_Activate( idEntity *activator ) {
  2118.     idPlayer *player = gameLocal.GetLocalPlayer();
  2119.     if ( player ) {
  2120.         if ( player->IsTipVisible() ) {
  2121.             PostEventSec( &EV_Activate, 5.1f, activator );
  2122.             return;
  2123.         }
  2124.         player->ShowTip( spawnArgs.GetString( "text_title" ), spawnArgs.GetString( "text_tip" ), false );
  2125.         PostEventMS( &EV_GetPlayerPos, 2000 );
  2126.     }
  2127. }
  2128.  
  2129. /*
  2130. ================
  2131. idTarget_Tip::Event_TipOff
  2132. ================
  2133. */
  2134. void idTarget_Tip::Event_TipOff( void ) {
  2135.     idPlayer *player = gameLocal.GetLocalPlayer();
  2136.     if ( player ) {
  2137.         idVec3 v = player->GetPhysics()->GetOrigin() - playerPos;
  2138.         if ( v.Length() > 96.0f ) {
  2139.             player->HideTip();
  2140.         } else {
  2141.             PostEventMS( &EV_TipOff, 100 );
  2142.         }
  2143.     }
  2144. }
  2145.  
  2146.  
  2147. /*
  2148. ===============================================================================
  2149.  
  2150. idTarget_GiveSecurity
  2151.  
  2152. ===============================================================================
  2153. */
  2154.  
  2155. CLASS_DECLARATION( idTarget, idTarget_GiveSecurity )
  2156. EVENT( EV_Activate,    idTarget_GiveSecurity::Event_Activate )
  2157. END_CLASS
  2158.  
  2159. /*
  2160. ================
  2161. idTarget_GiveEmail::Event_Activate
  2162. ================
  2163. */
  2164. void idTarget_GiveSecurity::Event_Activate( idEntity *activator ) {
  2165. // RAVEN BEGIN
  2166. // bdube: not using security
  2167. /*
  2168.     idPlayer *player = gameLocal.GetLocalPlayer();
  2169.     if ( player ) {
  2170.         player->GiveSecurity( spawnArgs.GetString( "text_security" ) );
  2171.     }
  2172. */
  2173. // RAVEN END
  2174. }
  2175.  
  2176.  
  2177. /*
  2178. ===============================================================================
  2179.  
  2180. idTarget_RemoveWeapons
  2181.  
  2182. ===============================================================================
  2183. */
  2184.  
  2185. CLASS_DECLARATION( idTarget, idTarget_RemoveWeapons )
  2186. EVENT( EV_Activate,    idTarget_RemoveWeapons::Event_Activate )
  2187. END_CLASS
  2188.  
  2189. /*
  2190. ================
  2191. idTarget_RemoveWeapons::Event_Activate
  2192. ================
  2193. */
  2194. void idTarget_RemoveWeapons::Event_Activate( idEntity *activator ) {
  2195.     for( int i = 0; i < gameLocal.numClients; i++ ) {
  2196.         if ( gameLocal.entities[ i ] ) {
  2197.             idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  2198.             const idKeyValue *kv = spawnArgs.MatchPrefix( "weapon", NULL );
  2199.             while ( kv ) {
  2200.                 player->RemoveWeapon( kv->GetValue() );
  2201.                 kv = spawnArgs.MatchPrefix( "weapon", kv );
  2202.             }
  2203. // RAVEN BEGIN
  2204. // bdube: default to initial weapon
  2205.             player->SelectWeapon( 0, true );
  2206. // RAVEN END
  2207.         }
  2208.     }
  2209. }
  2210.  
  2211.  
  2212. /*
  2213. ===============================================================================
  2214.  
  2215. idTarget_LevelTrigger
  2216.  
  2217. ===============================================================================
  2218. */
  2219.  
  2220. CLASS_DECLARATION( idTarget, idTarget_LevelTrigger )
  2221. EVENT( EV_Activate,    idTarget_LevelTrigger::Event_Activate )
  2222. END_CLASS
  2223.  
  2224. /*
  2225. ================
  2226. idTarget_LevelTrigger::Event_Activate
  2227. ================
  2228. */
  2229. void idTarget_LevelTrigger::Event_Activate( idEntity *activator ) {
  2230.     for( int i = 0; i < gameLocal.numClients; i++ ) {
  2231.         if ( gameLocal.entities[ i ] ) {
  2232.             idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  2233.             player->SetLevelTrigger( spawnArgs.GetString( "levelName" ), spawnArgs.GetString( "triggerName" ) );
  2234.         }
  2235.     }
  2236. }
  2237.  
  2238.  
  2239. /*
  2240. ===============================================================================
  2241.  
  2242. idTarget_EnableStamina
  2243.  
  2244. ===============================================================================
  2245. */
  2246.  
  2247. CLASS_DECLARATION( idTarget, idTarget_EnableStamina )
  2248. EVENT( EV_Activate,    idTarget_EnableStamina::Event_Activate )
  2249. END_CLASS
  2250.  
  2251. /*
  2252. ================
  2253. idTarget_EnableStamina::Event_Activate
  2254. ================
  2255. */
  2256. void idTarget_EnableStamina::Event_Activate( idEntity *activator ) {
  2257.     for( int i = 0; i < gameLocal.numClients; i++ ) {
  2258.         if ( gameLocal.entities[ i ] ) {
  2259.             idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  2260.             if ( spawnArgs.GetBool( "enable" ) ) {
  2261.                 pm_stamina.SetFloat( player->spawnArgs.GetFloat( "pm_stamina" ) );
  2262.             } else {
  2263.                 pm_stamina.SetFloat( 0.0f );
  2264.             }
  2265.         }
  2266.     }
  2267. }
  2268.  
  2269. /*
  2270. ===============================================================================
  2271.  
  2272. idTarget_FadeSoundClass
  2273.  
  2274. ===============================================================================
  2275. */
  2276.  
  2277. const idEventDef EV_RestoreVolume( "<RestoreVolume>" );
  2278. CLASS_DECLARATION( idTarget, idTarget_FadeSoundClass )
  2279. EVENT( EV_Activate,    idTarget_FadeSoundClass::Event_Activate )
  2280. EVENT( EV_RestoreVolume, idTarget_FadeSoundClass::Event_RestoreVolume )
  2281. END_CLASS
  2282.  
  2283. /*
  2284. ================
  2285. idTarget_FadeSoundClass::Event_Activate
  2286. ================
  2287. */
  2288. void idTarget_FadeSoundClass::Event_Activate( idEntity *activator ) {
  2289.     float fadeTime = spawnArgs.GetFloat( "fadeTime" );
  2290.     float fadeDB = spawnArgs.GetFloat( "fadeDB" );
  2291.     float fadeDuration = spawnArgs.GetFloat( "fadeDuration" );
  2292.     int fadeClass = spawnArgs.GetInt( "fadeClass" );
  2293.     // start any sound fading now
  2294.     if ( fadeTime ) {
  2295.         soundSystem->FadeSoundClasses( SOUNDWORLD_GAME, fadeClass, spawnArgs.GetBool( "fadeIn" ) ? fadeDB : 0.0f - fadeDB, fadeTime );
  2296.         if ( fadeDuration ) {
  2297.             PostEventSec( &EV_RestoreVolume, fadeDuration );
  2298.         }
  2299.     }
  2300. }
  2301.  
  2302. /*
  2303. ================
  2304. idTarget_FadeSoundClass::Event_RestoreVolume
  2305. ================
  2306. */
  2307. void idTarget_FadeSoundClass::Event_RestoreVolume() {
  2308.     float fadeTime = spawnArgs.GetFloat( "fadeTime" );
  2309.     float fadeDB = spawnArgs.GetFloat( "fadeDB" );
  2310. //    int fadeClass = spawnArgs.GetInt( "fadeClass" );
  2311.     // restore volume
  2312.     soundSystem->FadeSoundClasses( SOUNDWORLD_GAME, 0, fadeDB, fadeTime );
  2313. }
  2314.  
  2315.